/* 智研 Zhiyan — 主题变量与基础排印 */
:root {
  --brand: #1e3a8a;
  --brand-soft: #dbe6ff;
  --accent: #d97706;
  --accent-soft: #fff1d6;
  --surface: #0f172a;
  --surface-2: #1e293b;
  --paper: #ffffff;
  --paper-soft: #f8fafc;
  --line: #e2e8f0;
  --line-soft: #f1f5f9;
  --ink: #0f172a;
  --ink-soft: #334155;
  --muted: #64748b;
  --inverse: #e2e8f0;
  --pos: #0e7a5a;
  --pos-bg: #dcfce7;
  --neu: #64748b;
  --neu-bg: #f1f5f9;
  --cau: #b45309;
  --cau-bg: #fef3c7;
  --neg: #b91c1c;
  --neg-bg: #fee2e2;
  --mono: Consolas, "SF Mono", "Menlo", monospace;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-card: 0 1px 4px rgba(15, 23, 42, .06);
  --shadow-hover: 0 10px 28px rgba(15, 23, 42, .10);
}

:root[data-theme="dark"] {
  --paper: #0b1220;
  --paper-soft: #111a2e;
  --line: #243049;
  --line-soft: #1b2740;
  --ink: #e2e8f0;
  --ink-soft: #cbd5e1;
  --muted: #94a3b8;
  --brand-soft: #1c2a55;
  --accent-soft: #3d2b0a;
  --pos-bg: #052e21;
  --neu-bg: #1b2740;
  --cau-bg: #3d2b0a;
  --neg-bg: #3a0f0f;
  --shadow-card: 0 1px 4px rgba(0, 0, 0, .45);
  --shadow-hover: 0 10px 28px rgba(0, 0, 0, .55);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  font-family: -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--paper-soft);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 { color: var(--ink); letter-spacing: -.01em; }
h1 { font-size: 28px; line-height: 1.3; }
h2 { font-size: 20px; line-height: 1.35; }
h3 { font-size: 16px; line-height: 1.4; }

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

.mono, code, pre { font-family: var(--mono); }

.pos { color: var(--pos); }
.neu { color: var(--neu); }
.cau { color: var(--cau); }
.neg { color: var(--neg); }

.stance-pos { color: var(--pos); background: var(--pos-bg); }
.stance-neu { color: var(--neu); background: var(--neu-bg); }
.stance-cau { color: var(--cau); background: var(--cau-bg); }
.stance-neg { color: var(--neg); background: var(--neg-bg); }

.pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  letter-spacing: .05em;
  font-weight: 600;
}
.pill-brand { background: var(--brand-soft); color: var(--brand); }
.pill-accent { background: var(--accent-soft); color: var(--accent); }

.value.positive { color: var(--pos); }
.value.negative { color: var(--neg); }
.value.neutral { color: var(--neu); }

/* ---- 宏观导览: tone 色调 ---- */
.tone-hot      { color: #c2410c; }                /* 暖橙·扩张/热 */
.tone-warm     { color: var(--neg); }             /* 警示红 */
.tone-neutral  { color: var(--ink-soft); }
.tone-cool     { color: #0ea5e9; }
.tone-cold     { color: #0369a1; }                /* 冷蓝·收缩/冷 */
:root[data-theme="dark"] .tone-hot  { color: #fdba74; }
:root[data-theme="dark"] .tone-cold { color: #7dd3fc; }
:root[data-theme="dark"] .tone-cool { color: #67e8f9; }

/* smooth anchor scroll */
html { scroll-behavior: smooth; }

/* chart-hint small caption under each Plotly chart */
.chart-hint {
  font-size: 12px; color: var(--muted);
  margin: -4px 0 10px; line-height: 1.6;
  padding-left: 8px; border-left: 2px solid var(--line);
}

/* 指标行内 hint & 参考区间 */
.fin-row .ref {
  color: var(--muted); font-size: 11px; margin-left: 6px;
  font-weight: 400; letter-spacing: 0;
}
.fin-hint {
  font-size: 11px; color: var(--ink-soft); line-height: 1.5;
  padding: 2px 0 6px; border-bottom: 1px dashed transparent;
}
.group-desc {
  font-size: 11px; color: var(--muted); margin: -4px 0 8px;
  letter-spacing: 0; text-transform: none;
}

/* TL;DR 导读面板 */
.tldr-panel {
  background: linear-gradient(135deg, var(--brand-soft), transparent 70%);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 22px; margin-bottom: 16px;
}
.tldr-panel .tldr-headline {
  font-size: 16px; font-weight: 600; color: var(--ink);
  margin: 0 0 10px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.tldr-signals { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 0 10px; }
.tldr-chip {
  padding: 4px 12px; border-radius: 999px; font-size: 12px;
  background: var(--paper); border: 1px solid var(--line);
  display: inline-flex; align-items: center; gap: 6px;
}
.tldr-chip .lbl { color: var(--muted); font-size: 11px; }
.tldr-chip .num { font-family: var(--mono); font-weight: 600; }
.tldr-action {
  font-size: 13px; color: var(--ink-soft); line-height: 1.7;
  padding: 8px 12px; background: var(--paper-soft); border-radius: 6px;
  border-left: 3px solid var(--brand);
}

/* 五维综合 gauge */
.fw-composite {
  display: grid; grid-template-columns: 180px 1fr; gap: 18px;
  background: var(--paper-soft); border: 1px solid var(--line);
  border-radius: 10px; padding: 14px 18px; margin-bottom: 14px;
  align-items: center;
}
.fw-gauge { text-align: center; }
.fw-gauge-num {
  font-family: var(--mono); font-size: 28px; font-weight: 700;
  color: var(--brand); line-height: 1;
}
.fw-gauge-num span { font-size: 13px; color: var(--muted); margin-left: 4px; }
.fw-gauge-bar {
  position: relative; height: 8px; background: var(--line);
  border-radius: 4px; overflow: hidden; margin: 10px auto 0;
}
.fw-gauge-bar > span {
  position: absolute; inset: 0 auto 0 0;
  background: linear-gradient(90deg, #ef4444 0%, #f59e0b 40%, #22c55e 75%);
  border-radius: 4px; transition: width .4s ease;
}
.fw-composite-text { font-size: 13px; line-height: 1.7; color: var(--ink-soft); }
.fw-composite-sub { color: var(--muted); font-size: 12px; margin-top: 4px; }

/* FAQ 折叠 */
.faq-item {
  background: var(--paper-soft); border: 1px solid var(--line);
  border-radius: 8px; padding: 10px 14px; margin-bottom: 8px;
}
.faq-item > summary {
  cursor: pointer; font-weight: 600; font-size: 14px; color: var(--ink);
  list-style: none; display: flex; align-items: center; gap: 8px;
}
.faq-item > summary::before {
  content: "›"; display: inline-block;
  transition: transform .2s ease; color: var(--brand); font-size: 16px;
}
.faq-item[open] > summary::before { transform: rotate(90deg); }
.faq-item[open] { background: var(--paper); }
.faq-item p {
  margin: 8px 0 2px; font-size: 13px; line-height: 1.7;
  color: var(--ink-soft);
}

/* 侧边 TOC */
.macro-toc {
  position: sticky; top: 78px;
  background: var(--paper); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 8px;
  max-height: calc(100vh - 110px); overflow-y: auto;
}
.macro-toc h4 {
  margin: 0 0 8px; padding: 0 10px; font-size: 11px;
  color: var(--muted); letter-spacing: .1em; text-transform: uppercase;
}
.macro-toc a {
  display: block; padding: 8px 12px; font-size: 13px;
  color: var(--ink-soft); border-left: 2px solid transparent;
  border-radius: 0 6px 6px 0;
}
.macro-toc a:hover {
  background: var(--paper-soft); border-left-color: var(--brand);
  color: var(--brand); text-decoration: none;
}

/* ============ AI 对话 · 浮动球 + 抽屉 ============ */
.chat-fab {
  position: fixed; right: 24px; bottom: 24px;
  width: 56px; height: 56px; border-radius: 50%; border: none;
  background: var(--brand); color: #fff; font-size: 24px; cursor: pointer;
  box-shadow: 0 8px 24px rgba(15,23,42,.22);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; transition: transform .18s ease, box-shadow .18s ease;
}
.chat-fab:hover { transform: scale(1.06); box-shadow: 0 12px 28px rgba(15,23,42,.28); }
.chat-fab:focus-visible { outline: 3px solid var(--brand-soft); outline-offset: 2px; }

.chat-drawer {
  position: fixed; right: 0; top: 0; width: 420px; max-width: 92vw; height: 100vh;
  background: var(--paper); border-left: 1px solid var(--line);
  box-shadow: -8px 0 24px rgba(15,23,42,.18);
  transform: translateX(100%); transition: transform .28s cubic-bezier(.4,0,.2,1);
  z-index: 99; display: flex; flex-direction: column;
}
.chat-drawer.open { transform: translateX(0); }
.chat-drawer .chat-head {
  padding: 14px 16px; border-bottom: 1px solid var(--line);
  background: var(--paper-soft); display: flex; justify-content: space-between; align-items: flex-start; gap: 10px;
}
.chat-drawer .chat-head h3 { margin: 0 0 2px; font-size: 14px; }
.chat-drawer .chat-head .sub { color: var(--muted); font-size: 11px; }
.chat-drawer .chat-close {
  background: transparent; border: none; color: var(--muted); font-size: 22px;
  line-height: 1; cursor: pointer; padding: 0 4px; flex-shrink: 0;
}
.chat-drawer .chat-close:hover { color: var(--ink); }
.chat-drawer .chat-scroll {
  flex: 1; overflow-y: auto; padding: 14px 16px;
  display: flex; flex-direction: column; gap: 10px;
}
.chat-drawer .msg { padding: 8px 12px; border-radius: 10px; font-size: 13px; line-height: 1.55; max-width: 90%; word-break: break-word; }
.chat-drawer .msg.user { align-self: flex-end; background: var(--brand-soft); color: var(--brand); }
.chat-drawer .msg.asst { align-self: flex-start; background: var(--paper-soft); border: 1px solid var(--line); }
.chat-drawer .msg.asst p { margin: 6px 0; line-height: 1.6; }
.chat-drawer .msg.asst p:first-child { margin-top: 0; }
.chat-drawer .msg.asst p:last-child { margin-bottom: 0; }
.chat-drawer .msg.asst h3, .chat-drawer .msg.asst h4, .chat-drawer .msg.asst h5 {
  margin: 10px 0 6px; font-size: 14px; font-weight: 700; color: var(--ink);
}
.chat-drawer .msg.asst h3 { font-size: 15px; }
.chat-drawer .msg.asst ul, .chat-drawer .msg.asst ol { margin: 6px 0; padding-left: 22px; line-height: 1.7; }
.chat-drawer .msg.asst li { margin: 2px 0; }
.chat-drawer .msg.asst strong { font-weight: 700; color: var(--ink); }
.chat-drawer .msg.asst em { font-style: italic; }
.chat-drawer .msg.asst a { color: var(--brand); text-decoration: underline; }
.chat-drawer .msg.asst code {
  font-family: var(--mono); font-size: 12px; padding: 1px 5px;
  background: rgba(15,23,42,.06); border-radius: 4px; color: var(--ink);
}
.chat-drawer .msg.asst pre {
  background: rgba(15,23,42,.06); border-radius: 6px; padding: 10px 12px;
  overflow-x: auto; margin: 8px 0; font-size: 12px; line-height: 1.5;
}
.chat-drawer .msg.asst pre code { background: transparent; padding: 0; font-size: inherit; }
.chat-drawer .msg.asst blockquote {
  margin: 8px 0; padding: 6px 12px; color: var(--ink-soft);
  border-left: 3px solid var(--brand-soft); background: rgba(15,23,42,.03);
  border-radius: 0 4px 4px 0;
}
.chat-drawer .msg.sys  { align-self: center; color: var(--muted); font-size: 11px; font-style: italic; }
.chat-drawer .chat-input { border-top: 1px solid var(--line); padding: 10px; background: var(--paper); }
.chat-drawer .chat-input textarea {
  width: 100%; resize: none; border: 1px solid var(--line); border-radius: 6px;
  padding: 8px 10px; font-family: inherit; font-size: 13px; outline: none;
  background: var(--paper); color: var(--ink);
}
.chat-drawer .chat-input textarea:focus { border-color: var(--brand); }
.chat-drawer .chat-input .bar { display: flex; justify-content: flex-end; margin-top: 6px; }
.chat-drawer .chat-input .btn { padding: 6px 14px; font-size: 12px; }

@media (max-width: 640px) {
  .chat-drawer { width: 100vw; max-width: 100vw; }
  .chat-fab { right: 16px; bottom: 16px; width: 52px; height: 52px; font-size: 22px; }
}
