/* 大董学社・市场观研助手 — 深色金融风（默认） + 日间主题 */
:root {
  --bg: #0d1117;
  --bg2: #131a24;
  --card: #161f2c;
  --card2: #1b2634;
  --line: #243146;
  --text: #d8e2ee;
  --muted: #7d8fa5;
  --up: #f04a5c;      /* 红涨 */
  --down: #22b57f;    /* 绿跌 */
  --accent: #4d9fff;
  --gold: #e8b339;
  --input-bg: #0f1620;
  --hover: rgba(77,159,255,.06);
  --shadow: rgba(0,0,0,.4);
}
/* 日间模式 */
:root[data-theme="light"] {
  --bg: #eef2f8;
  --bg2: #f7f9fc;
  --card: #ffffff;
  --card2: #f2f5fa;
  --line: #dde5f0;
  --text: #1c2a3a;
  --muted: #64748b;
  --accent: #2f6bd8;
  --gold: #c4891a;
  --input-bg: #ffffff;
  --hover: rgba(47,107,216,.06);
  --shadow: rgba(30,58,95,.15);
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", sans-serif;
  font-size: 14px;
  min-height: 100vh;
}

header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 24px;
  background: linear-gradient(135deg, #101823 0%, #0d1420 60%, #121b2e 100%);
  border-bottom: 1px solid var(--line);
}
:root[data-theme="light"] header {
  background: linear-gradient(135deg, #ffffff 0%, #f2f6fc 60%, #e8f0fb 100%);
}
.brand { display: flex; align-items: center; gap: 14px; cursor: pointer; }
.brand:hover h1 { color: var(--accent); transition: color .2s; }
.logo-svg { width: 44px; height: 44px; flex: none; filter: drop-shadow(0 2px 6px rgba(77,159,255,.35)); }
.klt-title { display: flex; align-items: center; justify-content: space-between; flex: 1; min-width: 0; }
.kline-name { font-size: 15px; font-weight: bold; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kline-name .code { color: var(--muted); font-weight: normal; font-family: Consolas, monospace; }
header h1 { font-size: 20px; letter-spacing: 1px; }
header .sub { color: var(--muted); font-size: 12px; }
.session-bar { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.badge { padding: 3px 12px; border-radius: 20px; background: #223047; color: var(--accent); font-size: 12px; }
.badge.open { background: var(--up); color: #fff; font-weight: bold; animation: badge-breath 1.8s ease-in-out infinite; }
@keyframes badge-breath { 0%,100% { box-shadow: 0 0 0 rgba(240,74,92,.0); } 50% { box-shadow: 0 0 10px rgba(240,74,92,.6); } }

nav {
  display: flex; gap: 4px; padding: 0 20px;
  background: var(--bg2); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 50;
}
nav a {
  padding: 12px 18px; color: var(--muted); cursor: pointer;
  font-size: 14px; border-bottom: 2px solid transparent; user-select: none;
}
nav a:hover { color: var(--text); }
nav a.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: bold; }

main { max-width: 1280px; margin: 0 auto; padding: 18px 20px 40px; }
.tab { display: none; }
.tab.active { display: block; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 16px 18px; margin-bottom: 16px;
}
.card h3 { font-size: 15px; margin-bottom: 12px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row { display: flex; gap: 16px; flex-wrap: wrap; }
.half { flex: 1 1 460px; }
.muted { color: var(--muted); font-size: 12px; font-weight: normal; }

/* 指数卡片 */
.ticker-bar {
  overflow: hidden; background: var(--card); border: 1px solid var(--line);
  border-radius: 10px; margin-bottom: 12px; padding: 8px 0; position: relative;
}
.ticker-scroll {
  display: flex; gap: 46px; white-space: nowrap; width: max-content;
  font-size: 14px; line-height: 24px;
  animation: marquee 30s linear infinite;
}
.ticker-scroll:hover { animation-play-state: paused; }
@keyframes marquee { 0% { transform: translateX(0); } 100% { transform: translateX(-50%); } }
.ticker-item { flex-shrink: 0; color: var(--text); }
.ticker-item .tx-red { color: var(--up); font-weight: 600; font-family: Consolas, monospace; }
.ticker-item .tx-green { color: var(--down); font-weight: 600; font-family: Consolas, monospace; }
.index-refresh-bar {
  display: flex; align-items: center; gap: 10px; margin-bottom: 10px;
  color: var(--muted); font-size: 12.5px;
}
.live-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--up);
  box-shadow: 0 0 8px var(--up); animation: pulse-dot 1.6s ease-in-out infinite;
}
@keyframes pulse-dot { 0%,100% { opacity: 1; } 50% { opacity: .3; } }
.grid-index { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 16px; }
.idx-card {
  background: linear-gradient(160deg, var(--card2), var(--card));
  border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; position: relative;
}
.idx-card .mkt { position: absolute; top: 10px; right: 12px; font-size: 11px; color: var(--muted); }
.idx-card .name { color: var(--muted); font-size: 13px; }
.idx-card .price { font-size: 26px; font-weight: bold; margin: 4px 0; font-family: Consolas, monospace; }
.idx-card .chg { font-size: 13px; font-family: Consolas, monospace; }
.idx-card .hl { font-size: 12px; color: var(--muted); margin-top: 6px; }
.up { color: var(--up); } .down { color: var(--down); } .flat { color: var(--muted); }
.idx-card .state { font-size: 11px; padding: 1px 8px; border-radius: 10px; background: #223047; margin-left: 8px; vertical-align: middle; }
.idx-card .state.live { background: var(--up); color: #fff; font-weight: bold; animation: badge-breath 1.8s ease-in-out infinite; }

/* 情绪 */
.sentiment-box { display: flex; flex-direction: column; gap: 10px; }
.sentiment-box-items { display: flex; flex-wrap: wrap; gap: 10px; }
.senti-breadth { display: flex; align-items: center; gap: 12px; padding: 10px 4px 4px; }
.sb-side { font-size: 14px; font-weight: 700; white-space: nowrap; }
.sb-side.up { color: var(--up); }
.sb-side.down { color: var(--down); }
.sb-bar { flex: 1; display: flex; height: 12px; border-radius: 7px; overflow: hidden; }
.sb-fill.up { background: linear-gradient(90deg, #d93a4c, #f04a5c); }
.sb-fill.down { background: linear-gradient(270deg, #1c9c6d, #22b57f); }
.senti-amount { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 4px; }
.sa-item { flex: 1 1 200px; background: var(--card2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sa-item span { color: var(--muted); font-size: 12.5px; }
.sa-item b { font-size: 15px; font-family: Consolas, monospace; }
.sa-item b.up { color: var(--up); }
.sa-item b.down { color: var(--down); }
.senti-item { flex: 1 1 100px; background: var(--card2); border: 1px solid var(--line); border-radius: 10px; padding: 10px; text-align: center; }
.senti-item b { display: block; font-size: 20px; margin-top: 2px; }
.senti-item span { color: var(--muted); font-size: 12px; }
.report { white-space: pre-wrap; font-family: inherit; line-height: 1.9; font-size: 13.5px; color: var(--text); }

/* 新闻 */
.news-list { list-style: none; }
.news-list li { padding: 9px 4px; border-bottom: 1px dashed var(--line); display: flex; gap: 10px; align-items: baseline; }
.news-list li:last-child { border-bottom: none; }
.news-time { color: var(--muted); font-size: 12px; white-space: nowrap; font-family: Consolas, monospace; }
.news-tag { font-size: 11px; padding: 1px 7px; border-radius: 8px; white-space: nowrap; }
.tag-利好 { background: rgba(240,74,92,.15); color: var(--up); }
.tag-利空 { background: rgba(34,181,127,.15); color: var(--down); }
.tag-中性 { background: #223047; color: var(--muted); }
.news-title { flex: 1; }
.news-src { color: var(--muted); font-size: 11px; white-space: nowrap; }

/* 表格 */
.tbl-wrap { overflow: auto; max-height: 640px; border: 1px solid var(--line); border-radius: 8px; }
.tbl-wrap.tall { max-height: 520px; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; white-space: nowrap; }
.tbl th { position: sticky; top: 0; background: var(--card2); color: var(--muted); font-weight: normal; padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); z-index: 2; }
.tbl td { padding: 8px 12px; border-bottom: 1px solid rgba(36,49,70,.5); }
.tbl tr:hover td { background: rgba(77,159,255,.06); }
.tbl td.num { font-family: Consolas, monospace; }
.tbl a { color: var(--accent); cursor: pointer; text-decoration: none; }

/* 分段选择 */
.seg { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.seg a { padding: 6px 16px; background: var(--card2); border: 1px solid var(--line); border-radius: 8px; color: var(--muted); cursor: pointer; font-size: 13px; user-select: none; }
.seg a:hover { color: var(--text); }
.seg a.active { background: rgba(77,159,255,.15); border-color: var(--accent); color: var(--accent); }
.inline-seg { margin-left: auto; margin-bottom: 0; }

.screen-status { background: rgba(232,179,57,.08); border: 1px solid rgba(232,179,57,.3); color: var(--gold); border-radius: 8px; padding: 12px 16px; margin-bottom: 12px; }
.edu-note { color: var(--muted); font-size: 12px; line-height: 1.8; margin-top: 10px; }
.hint-red { color: var(--up); font-weight: bold; margin-left: 6px; }
#screen-edu { background: rgba(77,159,255,.06); border-left: 3px solid var(--accent); padding: 10px 14px; border-radius: 0 8px 8px 0; }

/* 个股 */
.search-bar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.search-bar input { flex: 1 1 260px; }
input {
  background: var(--input-bg); border: 1px solid var(--line); color: var(--text);
  padding: 10px 14px; border-radius: 8px; font-size: 14px; outline: none;
}
input:focus { border-color: var(--accent); }
select {
  background: var(--input-bg); border: 1px solid var(--line); color: var(--text);
  padding: 8px 10px; border-radius: 8px; font-size: 13px; outline: none;
}
.btn {
  border: none; border-radius: 8px; padding: 10px 20px; cursor: pointer; font-size: 14px;
  background: #223047; color: var(--text);
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: #3b8ff5; }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--muted); }
.btn.ghost:hover { color: var(--text); border-color: var(--accent); }
.btn.small { padding: 4px 12px; font-size: 12px; margin-left: auto; }
.stock-info { display: flex; flex-wrap: wrap; gap: 8px 22px; font-size: 13.5px; }
.stock-info .kv b { font-family: Consolas, monospace; font-size: 15px; }
.stock-info .big b { font-size: 26px; }
.chart { height: 340px; }

/* 自选 */
.watch-alerts { margin-top: 12px; }
.watch-alerts .alert-item { background: rgba(232,179,57,.08); border-left: 3px solid var(--gold); padding: 8px 12px; border-radius: 0 8px 8px 0; margin-bottom: 6px; font-size: 13px; }

/* AI 聊天 */
.chat-card { display: flex; flex-direction: column; }
.chat-box { height: 420px; overflow-y: auto; background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 14px; margin-bottom: 10px; }
.msg { margin-bottom: 14px; display: flex; }
.msg .bubble { max-width: 86%; padding: 10px 14px; border-radius: 12px; line-height: 1.75; font-size: 13.5px; white-space: pre-wrap; }
.msg.user { justify-content: flex-end; }
.msg.user .bubble { background: #24466e; border-bottom-right-radius: 2px; }
.msg.ai .bubble { background: var(--card2); border: 1px solid var(--line); border-bottom-left-radius: 2px; }
.msg.ai .bubble table { border-collapse: collapse; margin: 8px 0; font-size: 12.5px; }
.msg.ai .bubble th, .msg.ai .bubble td { border: 1px solid var(--line); padding: 5px 10px; }
.msg.ai .bubble th { background: var(--card); color: var(--muted); }
.chat-quick { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.chip { font-size: 12px; padding: 4px 12px; background: var(--card2); border: 1px solid var(--line); border-radius: 20px; color: var(--muted); cursor: pointer; user-select: none; }
.chip:hover { color: var(--accent); border-color: var(--accent); }
.chat-input-bar { display: flex; gap: 10px; }
.chat-input-bar input { flex: 1; }

/* 弹窗 */
.modal-mask { position: fixed; inset: 0; background: rgba(0,0,0,.65); display: flex; align-items: center; justify-content: center; z-index: 999; backdrop-filter: blur(3px); }
.modal { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 26px 30px; max-width: 520px; width: 92%; }
.modal-title { font-size: 17px; font-weight: bold; margin-bottom: 14px; color: var(--gold); }
.compliance-body { line-height: 1.9; font-size: 13.5px; color: var(--text); margin-bottom: 18px; }
.compliance-body p { margin-bottom: 6px; }

footer { text-align: center; color: var(--muted); font-size: 12px; padding: 18px; border-top: 1px solid var(--line); line-height: 1.8; }

@media (max-width: 760px) {
  body { font-size: 13px; }
  header { padding: 10px 12px; flex-wrap: wrap; gap: 8px; }
  header h1 { font-size: 15.5px; letter-spacing: 0; }
  header .sub { font-size: 10px; }
  .logo-svg { width: 34px; height: 34px; }
  .session-bar { width: 100%; justify-content: space-between; font-size: 11px; gap: 6px; flex-wrap: wrap; }
  #clock { font-size: 11px; }
  nav { overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  nav::-webkit-scrollbar { display: none; }
  nav a { padding: 10px 11px; font-size: 12.5px; white-space: nowrap; }
  main { padding: 10px 10px 30px; }
  .card { padding: 12px; border-radius: 10px; }
  .card h3 { font-size: 13.5px; }
  .row { gap: 10px; }
  .half { flex: 1 1 100%; }
  .idx-card .price { font-size: 19px; }
  .idx-card .hl { font-size: 10.5px; }
  .index-refresh-bar { font-size: 11px; flex-wrap: wrap; }
  /* 表格横向滚动优化 */
  .tbl-wrap { max-height: 60vh; -webkit-overflow-scrolling: touch; }
  .tbl { font-size: 12px; }
  .tbl th, .tbl td { padding: 7px 8px; }
  /* 情绪区 */
  .senti-breadth { font-size: 12px; gap: 8px; }
  .sa-item { flex: 1 1 100%; }
  .sa-item b { font-size: 13.5px; }
  /* 聊天 */
  .chat-box { height: 58vh; }
  .msg .bubble { max-width: 92%; font-size: 13px; }
  .msg.ai .bubble table { font-size: 11px; }
  .chat-quick { gap: 6px; }
  .chip { font-size: 11.5px; padding: 4px 10px; }
  /* 图表 */
  .chart { height: 270px; }
  /* 搜索与按钮 */
  .search-bar input { padding: 9px 11px; font-size: 13px; }
  .btn { padding: 9px 15px; font-size: 13px; }
  .stock-info { gap: 6px 12px; font-size: 12px; }
  .stock-info .big b { font-size: 20px; }
  /* 弹窗 */
  .modal { padding: 18px 16px; width: 94%; }
  .compliance-body { font-size: 12.5px; }
  /* 学堂管理条 */
  .school-admin-bar { gap: 6px; }
  .school-admin-bar input, .school-admin-bar select { font-size: 12px; padding: 7px 9px; }
  /* 新闻 */
  .news-list li { flex-wrap: wrap; gap: 4px 8px; }
  .news-title { flex-basis: 100%; order: 5; font-size: 12.5px; }
  .report { font-size: 12.5px; }
  footer { font-size: 10.5px; line-height: 1.7; }
}
@media (max-width: 400px) {
  nav a { padding: 9px 8px; font-size: 12px; }
  .idx-card { min-width: 0; }
  .grid-index { grid-template-columns: repeat(2, 1fr); gap: 8px; }
}

/* ---------- 主题开关 / 用户区 ---------- */
.icon-btn {
  background: var(--card2); border: 1px solid var(--line); color: var(--text);
  width: 34px; height: 34px; border-radius: 50%; cursor: pointer; font-size: 15px;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { border-color: var(--accent); }
#user-area { display: flex; align-items: center; gap: 8px; }
.user-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(232,179,57,.12); border: 1px solid rgba(232,179,57,.35);
  color: var(--gold); border-radius: 20px; padding: 3px 12px; font-size: 12.5px; white-space: nowrap;
}
.user-chip.admin { background: rgba(77,159,255,.12); border-color: rgba(77,159,255,.4); color: var(--accent); }
.btn.mini { padding: 4px 12px; font-size: 12px; }

/* ---------- 登录弹窗 ---------- */
.auth-body label { display: block; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
.auth-body input { width: 100%; margin-top: 5px; }
.auth-actions { display: flex; gap: 10px; margin-top: 6px; }
.auth-actions .btn { flex: 1; }
.auth-msg { color: var(--up); font-size: 12.5px; min-height: 18px; margin: 6px 0 2px; }
.auth-msg.ok { color: var(--down); }
.auth-tip { margin-top: 10px; line-height: 1.7; }

/* ---------- 大董学堂 ---------- */
.school-admin-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.school-divider { width: 1px; height: 26px; background: var(--line); margin: 0 4px; }
.school-lock { background: var(--card2); border: 1px dashed var(--line); border-radius: 10px; padding: 18px; text-align: center; margin-bottom: 12px; }
.school-lock p { margin-bottom: 10px; color: var(--muted); }
.school-lock-bar { display: flex; gap: 10px; justify-content: center; }
.del-link { color: var(--muted); cursor: pointer; font-size: 12px; white-space: nowrap; }
.del-link:hover { color: var(--up); }

/* ---------- 自选公开开关 / 广场 ---------- */
.public-toggle { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; font-size: 12.5px; color: var(--muted); }
.public-toggle input { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; }
.public-toggle:has(input:checked) { color: var(--gold); }

/* ---------- 公式指标文章 ---------- */
.articles-list { display: flex; flex-direction: column; gap: 8px; }
.article-item { background: var(--card2); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.article-head { display: flex; align-items: center; gap: 10px; padding: 11px 14px; cursor: pointer; flex-wrap: wrap; }
.article-head:hover { background: var(--hover); }
.article-date { color: var(--muted); font-size: 12px; font-family: Consolas, monospace; white-space: nowrap; }
.article-title { flex: 1; font-size: 14px; font-weight: 600; min-width: 120px; }
.article-views { color: var(--muted); font-size: 12px; white-space: nowrap; }
.article-views b { color: var(--gold); font-family: Consolas, monospace; }
.article-del { color: var(--muted); cursor: pointer; font-size: 12px; white-space: nowrap; }
.article-del:hover { color: var(--up); }
.article-body { padding: 4px 16px 14px; border-top: 1px dashed var(--line); line-height: 1.9; font-size: 13.5px; white-space: pre-wrap; word-break: break-word; }
.article-body a { color: var(--accent); }

/* ---------- 新闻当日统计条 ---------- */
.news-stats { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 12px; }
.nstat { flex: 1 1 200px; background: var(--card2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; }
.nstat .nstat-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.nstat .nstat-label { font-size: 13px; }
.nstat .nstat-count { font-size: 20px; font-weight: 700; font-family: Consolas, monospace; }
.nstat .nstat-bar { height: 6px; border-radius: 4px; background: var(--line); overflow: hidden; }
.nstat .nstat-fill { height: 100%; border-radius: 4px; transition: width .4s ease; }
.nstat.good .nstat-label, .nstat.good .nstat-count { color: var(--up); }
.nstat.good .nstat-fill { background: linear-gradient(90deg, rgba(240,74,92,.5), var(--up)); }
.nstat.bad .nstat-label, .nstat.bad .nstat-count { color: var(--down); }
.nstat.bad .nstat-fill { background: linear-gradient(90deg, rgba(34,181,127,.5), var(--down)); }
.nstat.neutral .nstat-label, .nstat.neutral .nstat-count { color: var(--muted); }
.nstat.neutral .nstat-fill { background: var(--muted); }

/* ---------- 可排序表头 ---------- */
.tbl th[data-idx] { cursor: pointer; user-select: none; }
.tbl th[data-idx]:hover { color: var(--accent); }
.tbl th.sorted { color: var(--accent); }
.remark-edit { color: var(--accent); cursor: pointer; font-size: 12px; margin-left: 6px; white-space: nowrap; }
.remark-edit:hover { text-decoration: underline; }
textarea {
  width: 100%; background: var(--input-bg); border: 1px solid var(--line); color: var(--text);
  padding: 10px 14px; border-radius: 8px; font-size: 14px; outline: none; resize: vertical;
  font-family: inherit; margin-top: 5px;
}
textarea:focus { border-color: var(--accent); }
