/* ============ tokens ============ */
:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --font-serif: "Songti SC", "STSong", "Noto Serif CJK SC", "Source Han Serif SC", "SimSun", Georgia, "Times New Roman", serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --radius: 14px;
  --sidebar-w: 276px;
  --thread-w: 800px;
  --ease: cubic-bezier(.2, .7, .2, 1);
}

:root[data-theme="light"] {
  --bg: #f6f5f1;
  --bg-2: #efede7;
  --surface: #ffffff;
  --surface-2: #faf9f5;
  --surface-3: #f2f0ea;
  --ink: #16181d;
  --ink-2: #3a3f48;
  --ink-3: #7b808a;
  --ink-4: #a5a9b0;
  --line: #e2dfd7;
  --line-2: #ebe8e1;
  --grid: #e6e3dc;
  --accent: #c14226;
  --accent-ink: #a3341a;
  --accent-soft: rgba(193, 66, 38, .08);
  --accent-soft-2: rgba(193, 66, 38, .14);
  --c1: #c14226;
  --c2: #2f5d8a;
  --c3: #c08a2d;
  --c4: #3f7f6e;
  --c5: #6b5b95;
  --c6: #8c8f96;
  --map-lo: #f4efe7;
  --map-mid: #e4a88c;
  --map-empty: #ebe8e1;
  --shadow-1: 0 1px 2px rgba(22, 24, 29, .04), 0 1px 1px rgba(22, 24, 29, .03);
  --shadow-2: 0 12px 32px -12px rgba(22, 24, 29, .18), 0 2px 6px rgba(22, 24, 29, .05);
  --shadow-3: 0 24px 64px -16px rgba(22, 24, 29, .28);
  --paper-dot: rgba(22, 24, 29, .055);
}

:root[data-theme="dark"] {
  --bg: #0e1116;
  --bg-2: #0a0d11;
  --surface: #151a21;
  --surface-2: #181e26;
  --surface-3: #1e252e;
  --ink: #ebe8e2;
  --ink-2: #c4c7cd;
  --ink-3: #878d97;
  --ink-4: #5c626c;
  --line: #262d37;
  --line-2: #1f252e;
  --grid: #232a33;
  --accent: #e66546;
  --accent-ink: #f48a68;
  --accent-soft: rgba(230, 101, 70, .10);
  --accent-soft-2: rgba(230, 101, 70, .18);
  --c1: #e66546;
  --c2: #6f9fd1;
  --c3: #d8a64a;
  --c4: #5fae98;
  --c5: #9d8ad0;
  --c6: #8c929c;
  --map-lo: #36414e;
  --map-mid: #8c4e38;
  --map-empty: #1b2129;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-2: 0 12px 32px -12px rgba(0, 0, 0, .6), 0 2px 6px rgba(0, 0, 0, .3);
  --shadow-3: 0 24px 64px -16px rgba(0, 0, 0, .7);
  --paper-dot: rgba(255, 255, 255, .045);
}

/* China convention: red = up; international: green = up */
:root[data-lang="zh"] { --up: #c8372d; --down: #1f8a5b; }
:root[data-lang="en"] { --up: #1f8a5b; --down: #c8372d; }
:root[data-theme="dark"][data-lang="zh"] { --up: #ef6a5c; --down: #45b584; }
:root[data-theme="dark"][data-lang="en"] { --up: #45b584; --down: #ef6a5c; }

/* ============ base ============ */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.6 var(--font-sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-feature-settings: "tnum" 1;
  opacity: 0;
  transition: opacity .25s ease;
}
body.ready { opacity: 1; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
a { color: inherit; }
[hidden] { display: none !important; }
::selection { background: var(--accent-soft-2); }

.svg-ico { width: 18px; height: 18px; flex: none; display: block; }
.ico { display: inline-flex; }
.spin { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.icon-btn {
  width: 34px; height: 34px; border-radius: 9px;
  display: inline-grid; place-items: center; color: var(--ink-3);
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface-3); color: var(--ink); }
.icon-btn.sm { width: 26px; height: 26px; border-radius: 7px; }
.icon-btn.sm .svg-ico { width: 15px; height: 15px; }

.chip-btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 28px; padding: 0 8px; border-radius: 8px;
  color: var(--ink-3); font-size: 12.5px;
  transition: background .15s, color .15s;
}
.chip-btn .svg-ico { width: 15px; height: 15px; }
.chip-btn:hover, .chip-btn.active { background: var(--surface-3); color: var(--ink); }

.primary-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 42px; padding: 0 18px; border-radius: 11px;
  background: var(--ink); color: var(--bg); font-weight: 600; font-size: 14px;
  transition: transform .15s var(--ease), opacity .15s, background .15s;
}
.primary-btn:hover { background: var(--accent); color: #fff; }
.primary-btn:active { transform: scale(.98); }
.primary-btn:disabled { opacity: .5; cursor: default; }
.primary-btn.sm { height: 32px; padding: 0 12px; font-size: 13px; border-radius: 9px; }
.primary-btn.sm .svg-ico { width: 15px; height: 15px; }

.ghost-btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 12px; border-radius: 9px;
  border: 1px solid var(--line); color: var(--ink-2); font-size: 13px;
}
.ghost-btn:hover { background: var(--surface); color: var(--ink); }
.ghost-btn .svg-ico { width: 15px; height: 15px; color: var(--accent); }

/* ============ app layout ============ */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
}

/* ---- sidebar ---- */
.sidebar {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--bg-2);
  border-right: 1px solid var(--line-2);
  padding: 14px 12px 12px;
  gap: 10px;
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 2px 4px 6px; }
.sidebar-close { display: none; }
.brand { display: flex; align-items: center; gap: 11px; text-decoration: none; }
.brand-mark, .modal-mark, .msg-avatar, .seal {
  display: block; flex: none;
  background:
    url(/img/econ-talk-white.png) center / 62% no-repeat,
    var(--accent);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .12), 0 4px 10px -4px var(--accent);
}
.brand-mark { width: 34px; height: 34px; border-radius: 9px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-name { font-family: var(--font-serif); font-weight: 700; font-size: 17px; letter-spacing: .01em; }
.brand-sub { font-size: 11.5px; color: var(--ink-3); }

.new-chat {
  display: flex; align-items: center; gap: 9px;
  height: 40px; padding: 0 12px; border-radius: 11px;
  background: var(--surface); border: 1px solid var(--line);
  font-weight: 600; font-size: 13.5px; box-shadow: var(--shadow-1);
  transition: border-color .15s, transform .15s var(--ease);
}
.new-chat:hover { border-color: var(--ink-4); }
.new-chat:active { transform: scale(.99); }
.new-chat .svg-ico { width: 17px; height: 17px; color: var(--accent); }
.new-chat kbd {
  margin-left: auto; font: 11px var(--font-sans); color: var(--ink-4);
  border: 1px solid var(--line); border-radius: 5px; padding: 1px 5px;
}

.conv-search {
  display: flex; align-items: center; gap: 8px;
  height: 34px; padding: 0 10px; border-radius: 9px;
  color: var(--ink-4);
}
.conv-search:focus-within { background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); }
.conv-search .svg-ico { width: 15px; height: 15px; }
.conv-search input { flex: 1; border: 0; background: none; outline: none; font-size: 13px; min-width: 0; color: var(--ink); }
.conv-search input::placeholder { color: var(--ink-4); }

.conv-list { flex: 1; overflow-y: auto; margin: 0 -4px; padding: 0 4px; scrollbar-width: thin; }
.conv-group + .conv-group { margin-top: 14px; }
.conv-label {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
  color: var(--ink-4); padding: 4px 10px 6px;
}
.conv-hint { font-weight: 500; letter-spacing: 0; padding: 0 5px; border-radius: 4px; background: var(--surface-3); }
.conv-item {
  position: relative; display: flex; align-items: center; gap: 6px;
  height: 36px; padding: 0 8px 0 10px; border-radius: 9px;
  text-decoration: none; color: var(--ink-2); font-size: 13.5px;
  transition: background .12s;
}
.conv-item:hover { background: var(--surface-3); }
.conv-item.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1); }
.conv-item.active::before {
  content: ""; position: absolute; left: 0; top: 9px; bottom: 9px; width: 2.5px; border-radius: 2px; background: var(--accent);
}
.conv-title { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-actions { display: none; gap: 1px; }
.conv-item:hover .conv-actions { display: flex; }
.conv-rename {
  flex: 1; min-width: 0; height: 26px; padding: 0 6px; border-radius: 6px;
  border: 1px solid var(--accent); background: var(--surface); outline: none; font-size: 13px;
}
.conv-empty { color: var(--ink-4); font-size: 13px; padding: 16px 10px; }

.sidebar-foot { position: relative; display: flex; flex-direction: column; gap: 8px; border-top: 1px solid var(--line-2); padding-top: 10px; }
.sidebar-foot-row { display: flex; align-items: center; gap: 2px; }
.copyright { margin: 0; padding: 0 6px; font-size: 11px; color: var(--ink-4); letter-spacing: .01em; }
.account { flex: 1; min-width: 0; }
.acct {
  width: 100%; display: flex; align-items: center; gap: 10px;
  padding: 6px 6px; border-radius: 10px; text-align: left;
}
.acct-guest:hover { background: var(--surface-3); }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-weight: 700; font-size: 13px;
  background: var(--ink); color: var(--bg);
}
.avatar.ghost { background: var(--surface-3); color: var(--ink-3); }
.avatar.ghost .svg-ico { width: 16px; height: 16px; }
.acct-text { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.acct-text b { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.acct-text small { font-size: 11.5px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.acct-cta { font-size: 12px; font-weight: 600; color: var(--accent); padding: 3px 8px; border-radius: 6px; background: var(--accent-soft); }
#settingsBtn[aria-expanded="true"] { background: var(--surface-3); color: var(--ink); }
.settings-menu {
  position: absolute; left: 0; right: 0; bottom: calc(100% + 8px); z-index: 6;
  padding: 12px; border-radius: 14px; background: var(--surface);
  border: 1px solid var(--line); box-shadow: var(--shadow-2);
  animation: pop .14s var(--ease);
}
.settings-title { font-weight: 600; font-size: 13px; margin-bottom: 12px; padding: 0 2px; }
.settings-group + .settings-group { margin-top: 12px; }
.settings-label {
  font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
  color: var(--ink-4); margin-bottom: 6px; padding: 0 2px;
}
.settings-seg {
  display: grid; grid-template-columns: 1fr 1fr; padding: 3px;
  border-radius: 10px; background: var(--surface-3);
}
.settings-seg button {
  height: 30px; border-radius: 8px; font-size: 12.5px; font-weight: 600;
  color: var(--ink-3); display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.settings-seg button:hover { color: var(--ink); }
.settings-seg button.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1); }
.settings-seg button .svg-ico { width: 14px; height: 14px; }

.scrim { display: none; }

/* ---- main ---- */
.main {
  position: relative; min-width: 0; min-height: 0;
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto;
}
.topbar {
  height: 56px; display: flex; align-items: center; gap: 10px;
  padding: 0 18px; position: relative; z-index: 3;
}
.menu-btn { display: none; }
.topbar-title { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; }
.title-text {
  font-weight: 600; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  padding: 3px 6px; margin-left: -6px; border-radius: 6px; cursor: text; outline: none;
}
.title-text:hover { background: var(--surface-3); }
.title-text[contenteditable="true"] { background: var(--surface); box-shadow: inset 0 0 0 1px var(--accent); }
.badge {
  display: inline-flex; align-items: center; gap: 4px; flex: none;
  font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 999px;
}
.badge .svg-ico { width: 12px; height: 12px; }
.badge-temp { color: var(--ink-3); background: var(--surface-3); border: 1px dashed var(--line); }
.badge-saved { color: var(--accent); background: var(--accent-soft); }
.topbar-actions { display: flex; gap: 8px; }

.scroller { overflow-y: auto; overflow-x: hidden; scroll-behavior: auto; position: relative; }
.is-home .scroller {
  background:
    radial-gradient(1200px 380px at 50% -140px, var(--accent-soft), transparent 70%),
    radial-gradient(var(--paper-dot) 1px, transparent 1.2px) 0 0 / 22px 22px;
}
.is-home .thread { display: none; }
.app:not(.is-home) .home { display: none; }

/* ============ home ============ */
.home { max-width: 1040px; margin: 0 auto; padding: 36px 28px 40px; }
.hero { text-align: center; padding: 30px 0 34px; animation: rise .6s var(--ease) both; }
.hero-eyebrow {
  display: inline-flex; align-items: center; gap: 10px;
  font-size: 12px; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-3);
  padding: 5px 12px 5px 6px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-1);
}
.seal { width: 22px; height: 22px; border-radius: 5px; }
.hero-title {
  font-family: var(--font-serif); font-weight: 700; letter-spacing: -.01em;
  font-size: clamp(32px, 4.6vw, 50px); line-height: 1.15; margin: 20px 0 14px;
}
.hero-title em {
  font-style: normal; color: var(--accent);
  background: linear-gradient(transparent 68%, var(--accent-soft-2) 0);
  padding: 0 .06em;
}
.hero-sub { max-width: 640px; margin: 0 auto; color: var(--ink-3); font-size: 15px; line-height: 1.75; }

.panel { margin-top: 26px; animation: rise .6s .08s var(--ease) both; }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; margin: 0 2px 12px; }
.panel-head h2 {
  margin: 0; font-size: 12px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-2);
  display: flex; align-items: center; gap: 8px;
}
.panel-head h2::before { content: ""; width: 14px; height: 2px; background: var(--accent); border-radius: 2px; }
.panel-head span { font-size: 12px; color: var(--ink-4); }

.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.tile {
  position: relative; text-align: left; overflow: hidden;
  display: flex; flex-direction: column; gap: 2px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px 0; min-height: 138px; box-shadow: var(--shadow-1);
  transition: transform .2s var(--ease), box-shadow .2s var(--ease), border-color .2s;
  animation: rise .5s calc(var(--i) * 40ms + 120ms) var(--ease) both;
}
.tile:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); border-color: var(--ink-4); }
.tile:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.tile-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.tile-name { font-size: 12.5px; color: var(--ink-2); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile-period { font-size: 11px; color: var(--ink-4); flex: none; margin-left: auto; font-variant-numeric: tabular-nums; }
.tile-value { display: flex; align-items: baseline; gap: 1px; margin-top: 4px; }
.tile-value .v { font-size: 28px; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.tile-value .u { font-size: 14px; color: var(--ink-3); font-weight: 500; }
.tile-foot { display: flex; align-items: center; gap: 6px; font-size: 12px; min-height: 18px; }
.tile-delta { font-weight: 600; font-variant-numeric: tabular-nums; }
.tile-vs { color: var(--ink-4); }
.up { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--ink-3); }
.tile-spark { height: 40px; margin: 6px -16px 0; }

.suggest-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.suggest {
  display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 12px; row-gap: 3px;
  text-align: left; padding: 14px 16px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-1);
  transition: transform .2s var(--ease), box-shadow .2s var(--ease), border-color .2s;
  animation: rise .5s calc(var(--i) * 40ms + 260ms) var(--ease) both;
}
.suggest:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); border-color: var(--ink-4); }
.suggest-ico {
  grid-row: span 2; width: 36px; height: 36px; border-radius: 10px;
  display: grid; place-items: center; background: var(--accent-soft); color: var(--accent);
}
.suggest-tag { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-4); }
.suggest-text { font-size: 13.5px; line-height: 1.55; color: var(--ink); }

@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ============ thread ============ */
.thread { max-width: var(--thread-w); margin: 0 auto; padding: 18px 28px 40px; display: flex; flex-direction: column; gap: 28px; }
.msg { animation: rise .35s var(--ease) both; }
.msg-user { align-self: flex-end; max-width: min(82%, 640px); display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.msg-user .bubble {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 18px 18px 5px 18px; padding: 10px 16px; font-size: 15px; line-height: 1.65;
  box-shadow: var(--shadow-1); white-space: normal; word-break: break-word;
}
.msg-atts { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }

.msg-ai { display: grid; grid-template-columns: 30px minmax(0, 1fr); gap: 14px; }
.msg-avatar { width: 30px; height: 30px; border-radius: 8px; margin-top: 2px; }
.msg-main { min-width: 0; display: flex; flex-direction: column; gap: 10px; }

.thinking { display: inline-flex; align-items: center; gap: 10px; color: var(--ink-3); font-size: 13.5px; height: 30px; }
.thinking-text {
  background: linear-gradient(90deg, var(--ink-3) 0%, var(--ink) 50%, var(--ink-3) 100%);
  background-size: 200% 100%; -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: shimmer 1.6s linear infinite;
}
.pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 0 var(--accent-soft-2); animation: pulse 1.4s ease-out infinite; }
.dots { display: inline-flex; gap: 3px; }
.dots i { width: 4px; height: 4px; border-radius: 50%; background: var(--ink-4); animation: dot 1.2s infinite; }
.dots i:nth-child(2) { animation-delay: .15s; }
.dots i:nth-child(3) { animation-delay: .3s; }
@keyframes shimmer { to { background-position: -200% 0; } }
@keyframes pulse { 70% { box-shadow: 0 0 0 8px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
@keyframes dot { 0%, 60%, 100% { opacity: .3; transform: none; } 30% { opacity: 1; transform: translateY(-2px); } }

/* tools timeline */
.tools { align-self: flex-start; max-width: 100%; }
.tools summary {
  list-style: none; display: inline-flex; align-items: center; gap: 8px; max-width: 100%;
  height: 30px; padding: 0 12px 0 10px; border-radius: 999px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line); color: var(--ink-3); font-size: 12.5px;
  box-shadow: var(--shadow-1); user-select: none;
}
.tools summary::-webkit-details-marker { display: none; }
.tools summary .svg-ico { width: 14px; height: 14px; color: var(--accent); }
.tools summary .chev { color: var(--ink-4); transition: transform .2s; }
.tools[open] summary .chev { transform: rotate(90deg); }
.tools summary .step-detail { color: var(--ink-4); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tool-steps {
  list-style: none; margin: 8px 0 0; padding: 8px 12px; border-radius: 12px;
  background: var(--surface-2); border: 1px solid var(--line-2); font-size: 12.5px;
}
.step { display: flex; align-items: center; gap: 8px; padding: 4px 0; color: var(--ink-2); min-width: 0; }
.step .svg-ico { width: 14px; height: 14px; color: var(--c4); flex: none; }
.step-running .svg-ico { color: var(--accent); }
.step-error .svg-ico { color: var(--down); }
.step-name { font-weight: 600; flex: none; }
.step-detail { color: var(--ink-3); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.step-ms { margin-left: auto; color: var(--ink-4); font-variant-numeric: tabular-nums; flex: none; }

/* ============ markdown ============ */
.msg-body { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.md { font-size: 15.5px; line-height: 1.8; color: var(--ink-2); word-wrap: break-word; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: .65em 0; }
.md strong { color: var(--ink); font-weight: 650; }
.msg-body > .md-seg:first-child > p:first-child {
  font-family: var(--font-serif); font-size: 18px; line-height: 1.7; color: var(--ink);
  padding: 2px 0 2px 16px; border-left: 3px solid var(--accent); margin-bottom: 1em;
}
.msg-body > .md-seg:first-child > p:first-child strong { font-weight: 700; }
.md h1, .md h2, .md h3, .md h4 {
  font-family: var(--font-serif); color: var(--ink); line-height: 1.4; font-weight: 700;
  margin: 1.5em 0 .5em;
}
.md h1 { font-size: 21px; }
.md h2 { font-size: 19px; }
.md h3 { font-size: 17px; display: flex; align-items: center; gap: 10px; }
.md h3::before { content: ""; width: 4px; height: 15px; border-radius: 2px; background: var(--accent); flex: none; }
.md h4 { font-size: 15.5px; }
.md ul, .md ol { padding-left: 1.3em; margin: .6em 0; }
.md li { margin: .3em 0; padding-left: .2em; }
.md li::marker { color: var(--ink-4); }
.md ol li::marker { font-variant-numeric: tabular-nums; font-weight: 600; }
.md a { color: var(--accent-ink); text-decoration: underline; text-decoration-color: var(--accent-soft-2); text-underline-offset: 3px; }
.md a:hover { text-decoration-color: currentColor; }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 1.6em 0; }
.md code { font-family: var(--font-mono); font-size: .86em; padding: .12em .38em; border-radius: 5px; background: var(--surface-3); color: var(--ink); }
.code-block { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; margin: 1em 0; background: var(--surface-2); }
.code-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 6px 4px 14px; font-size: 11.5px; color: var(--ink-3); border-bottom: 1px solid var(--line-2); }
.code-block pre { margin: 0; padding: 12px 14px; overflow-x: auto; font-size: 13px; line-height: 1.6; }
.code-block code { background: none; padding: 0; font-size: inherit; }

/* tables */
.table-wrap {
  position: relative; overflow-x: auto; margin: 1em 0;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
}
.table-tools { position: absolute; top: 4px; right: 4px; opacity: 0; transition: opacity .15s; }
.table-wrap:hover .table-tools { opacity: 1; }
.table-tools .chip-btn { background: var(--surface); }
.md table, .chart-data table { width: 100%; border-collapse: collapse; font-size: 13.5px; line-height: 1.5; font-variant-numeric: tabular-nums; }
.md th, .chart-data th {
  text-align: left; font-weight: 600; font-size: 12px; color: var(--ink-3); letter-spacing: .02em;
  padding: 10px 14px 8px; border-bottom: 1.5px solid var(--ink-2); white-space: nowrap; background: var(--surface-2);
}
.md td, .chart-data td { padding: 8px 14px; border-bottom: 1px solid var(--line-2); color: var(--ink-2); vertical-align: top; }
.md tr:last-child td, .chart-data tr:last-child td { border-bottom: 0; }
.md tbody tr:hover td, .chart-data tbody tr:hover td { background: var(--surface-2); }
.md td:first-child { color: var(--ink); font-weight: 500; }
.num { text-align: right !important; white-space: nowrap; font-variant-numeric: tabular-nums; }
.md td.num { color: var(--ink); font-weight: 500; }
.md td.num.up { color: var(--up); }
.md td.num.down { color: var(--down); }

/* kpi strip */
.kpi-strip { display: grid; grid-template-columns: repeat(var(--n), minmax(0, 1fr)); gap: 10px; margin: 1em 0 1.2em; }
.kpi {
  padding: 12px 14px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line);
  box-shadow: var(--shadow-1); min-width: 0; position: relative; overflow: hidden;
}
.kpi::after { content: ""; position: absolute; left: 0; top: 0; right: 0; height: 2px; background: linear-gradient(90deg, var(--accent), transparent); opacity: .7; }
.kpi-label {
  font-size: 12px; color: var(--ink-3); line-height: 1.4; min-height: 2.8em;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.kpi-value { font-size: 23px; font-weight: 650; color: var(--ink); letter-spacing: -.015em; line-height: 1.35; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-meta { display: flex; flex-wrap: wrap; gap: 4px 8px; font-size: 11.5px; line-height: 1.5; }
.kpi-delta { font-weight: 600; font-variant-numeric: tabular-nums; }
.kpi-delta.up { color: var(--up); }
.kpi-delta.down { color: var(--down); }
.kpi-period { color: var(--ink-4); }

/* callouts */
.md blockquote { margin: 1em 0; padding: 2px 0 2px 16px; border-left: 3px solid var(--line); color: var(--ink-3); }
.md blockquote.callout {
  border: 1px solid var(--line); border-left: 3px solid var(--c2); border-radius: 0 12px 12px 0;
  background: var(--surface-2); padding: 10px 16px; font-size: 13.5px; line-height: 1.7; color: var(--ink-2);
}
.md blockquote.callout-risk { border-left-color: var(--accent); background: var(--accent-soft); }
.md blockquote.callout p { margin: .3em 0; }
.callout-title { display: inline-block; font-size: 12px; letter-spacing: .06em; color: var(--c2) !important; margin-right: 4px; }
.callout-risk .callout-title { color: var(--accent) !important; }

/* citations */
.cites { display: inline-flex; gap: 2px; margin: 0 1px 0 2px; vertical-align: 1px; }
.cite {
  display: inline-grid; place-items: center; min-width: 17px; height: 17px; padding: 0 4px;
  border-radius: 5px; font-size: 10.5px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums;
  background: var(--accent-soft); color: var(--accent-ink);
  transition: background .12s, color .12s, transform .12s;
}
.cite:hover { background: var(--accent); color: #fff; transform: translateY(-1px); }
.cite.pending { opacity: .45; }

/* streaming caret */
.msg-ai.streaming .msg-body > .md-seg:last-child > p:last-child::after,
.msg-ai.streaming .msg-body > .md-seg:last-child > ul:last-child > li:last-child::after,
.msg-ai.streaming .msg-body > .md-seg:last-child > ol:last-child > li:last-child::after,
.msg-ai.streaming .msg-body > .md-seg:last-child > :is(h3, h4):last-child::after {
  content: ""; display: inline-block; width: 7px; height: 1.05em; margin-left: 3px; vertical-align: -2px;
  background: var(--accent); border-radius: 1px; animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* ============ charts ============ */
.chart-card {
  margin: 4px 0; padding: 14px 16px 10px; border-radius: 16px;
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-1);
  animation: rise .4s var(--ease) both;
}
.chart-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.chart-title { font-family: var(--font-serif); font-weight: 700; font-size: 15.5px; color: var(--ink); line-height: 1.4; }
.chart-sub { font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.chart-tools { display: flex; gap: 2px; opacity: .6; transition: opacity .15s; }
.chart-card:hover .chart-tools { opacity: 1; }
.chart-tools .chip-btn { width: 28px; padding: 0; justify-content: center; }
.chart-body { width: 100%; }
.chart-data { margin-top: 8px; max-height: 320px; overflow: auto; border-radius: 10px; border: 1px solid var(--line-2); }
.chart-data .table-wrap { margin: 0; border: 0; border-radius: 0; }
.chart-foot {
  display: flex; align-items: center; gap: 8px; justify-content: space-between;
  margin-top: 6px; padding-top: 8px; border-top: 1px dashed var(--line); font-size: 11.5px; color: var(--ink-3);
}
.chart-skeleton { border-radius: 16px; border: 1px solid var(--line); padding: 16px; background: var(--surface); }
.sk-line, .sk-body {
  border-radius: 6px;
  background: linear-gradient(90deg, var(--surface-3) 0%, var(--surface-2) 50%, var(--surface-3) 100%);
  background-size: 200% 100%; animation: shimmer 1.4s linear infinite;
}
.sk-line { height: 14px; width: 40%; margin-bottom: 14px; }
.sk-body { height: 240px; }
.tt-head { font-weight: 600; margin-bottom: 4px; font-size: 12px; color: var(--ink-3); }
.tt-row { display: flex; align-items: center; gap: 6px; font-size: 12.5px; line-height: 1.7; }
.tt-row span { color: var(--ink-2); }
.tt-row b { margin-left: auto; padding-left: 14px; font-variant-numeric: tabular-nums; }

/* ============ sources ============ */
.sources { margin-top: 6px; padding-top: 12px; border-top: 1px solid var(--line-2); }
.sources-head { display: flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); margin-bottom: 8px; }
.sources-head .svg-ico { width: 14px; height: 14px; }
.sources-head .count { font-weight: 600; padding: 0 6px; border-radius: 999px; background: var(--surface-3); letter-spacing: 0; }
.src-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.src {
  display: flex; gap: 10px; padding: 10px 12px; border-radius: 12px; min-width: 0;
  background: var(--surface); border: 1px solid var(--line-2); transition: border-color .15s, box-shadow .2s;
}
.src:hover { border-color: var(--line); box-shadow: var(--shadow-1); }
.src.flash { animation: flash 1.4s var(--ease); }
@keyframes flash { 0%, 30% { box-shadow: 0 0 0 3px var(--accent-soft-2); border-color: var(--accent); } }
.src-n {
  flex: none; width: 20px; height: 20px; border-radius: 6px; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent-ink); font-size: 11px; font-weight: 700;
}
.src-body { min-width: 0; flex: 1; }
.src-title { font-size: 13px; line-height: 1.5; color: var(--ink); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.src-title a { text-decoration: none; }
.src-title a:hover { color: var(--accent-ink); text-decoration: underline; text-underline-offset: 2px; }
.src-kind {
  display: inline-flex; align-items: center; gap: 3px; margin-right: 6px; vertical-align: 1px;
  font-size: 10.5px; font-weight: 700; color: var(--ink-3); padding: 0 5px; border-radius: 4px; background: var(--surface-3);
}
.src-kind .svg-ico { width: 11px; height: 11px; }
.src-meta { font-size: 11.5px; color: var(--ink-3); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.src-meta .sep { margin: 0 5px; color: var(--ink-4); }
.src-links { margin-top: 4px; font-size: 11.5px; }
.src-links summary { color: var(--ink-3); cursor: pointer; }
.src-links div { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 4px; }
.src-links a { color: var(--accent-ink); text-decoration: none; font-variant-numeric: tabular-nums; }
.src-more { margin-top: 8px; }
.src-more > summary { font-size: 12px; color: var(--ink-3); cursor: pointer; padding: 4px 0; }
.src-more .src-list { margin-top: 6px; }

.msg-actions { display: flex; gap: 4px; margin-left: -8px; }
.msg-error {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 12px;
  background: var(--accent-soft); color: var(--accent-ink); font-size: 13.5px;
}

/* popover */
.popover {
  position: fixed; z-index: 60; width: 340px; max-width: calc(100vw - 16px);
  padding: 12px 14px; border-radius: 12px; background: var(--surface);
  border: 1px solid var(--line); box-shadow: var(--shadow-3); font-size: 12.5px;
  animation: pop .14s var(--ease);
}
@keyframes pop { from { opacity: 0; transform: translateY(4px) scale(.98); } }
.pop-kind { display: flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); }
.pop-kind .svg-ico { width: 13px; height: 13px; color: var(--accent); }
.pop-n { margin-left: auto; font-weight: 700; color: var(--accent-ink); background: var(--accent-soft); border-radius: 5px; padding: 0 6px; }
.pop-title { font-weight: 600; font-size: 13.5px; color: var(--ink); line-height: 1.5; margin-top: 6px; }
.pop-meta { color: var(--ink-3); margin-top: 3px; }
.pop-snippet { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line-2); color: var(--ink-2); line-height: 1.65; max-height: 132px; overflow: hidden; }
.pop-link { display: inline-flex; align-items: center; gap: 4px; margin-top: 8px; color: var(--accent-ink); font-weight: 600; text-decoration: none; }
.pop-link .svg-ico { width: 13px; height: 13px; }

/* ============ composer ============ */
.composer-wrap { padding: 8px 28px 14px; position: relative; z-index: 2; }
.composer-wrap::before {
  content: ""; position: absolute; left: 0; right: 0; bottom: 100%; height: 36px; pointer-events: none;
  background: linear-gradient(transparent, var(--bg));
}
.composer {
  max-width: var(--thread-w); margin: 0 auto; background: var(--surface);
  border: 1px solid var(--line); border-radius: 20px; padding: 8px;
  box-shadow: var(--shadow-2); transition: border-color .15s, box-shadow .15s;
}
.composer:focus-within { border-color: var(--ink-4); box-shadow: var(--shadow-2), 0 0 0 4px var(--accent-soft); }
.composer-row { display: flex; align-items: flex-end; gap: 6px; }
.composer textarea {
  flex: 1; border: 0; outline: none; resize: none; background: none;
  font-size: 15px; line-height: 1.6; padding: 7px 4px; max-height: 220px; min-height: 38px;
}
.composer textarea::placeholder { color: var(--ink-4); }
.attach-btn { width: 38px; height: 38px; border-radius: 12px; }
.send-btn {
  width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; flex: none;
  background: var(--ink); color: var(--bg); transition: background .15s, transform .15s var(--ease), opacity .15s;
}
.send-btn:hover:not(:disabled) { background: var(--accent); color: #fff; }
.send-btn:active:not(:disabled) { transform: scale(.94); }
.send-btn:disabled { opacity: .25; cursor: default; }
.send-btn.stop { background: var(--accent); color: #fff; }
.composer-hint { max-width: var(--thread-w); margin: 7px auto 0; text-align: center; font-size: 11.5px; color: var(--ink-4); }
.composer-hint .dot { margin: 0 6px; }

.attachments { display: flex; flex-wrap: wrap; gap: 6px; padding: 2px 2px 8px; }
.file-chip {
  position: relative; overflow: hidden;
  display: inline-flex; align-items: center; gap: 7px; max-width: 280px;
  height: 32px; padding: 0 6px 0 10px; border-radius: 9px;
  background: var(--surface-2); border: 1px solid var(--line); font-size: 12.5px;
}
.file-chip.static { padding-right: 10px; background: var(--surface); }
.file-chip .svg-ico { width: 15px; height: 15px; color: var(--accent); }
.file-chip.error { border-color: var(--accent); background: var(--accent-soft); }
.fc-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.fc-status { color: var(--ink-3); font-size: 11.5px; white-space: nowrap; }
.fc-x { width: 20px; height: 20px; border-radius: 5px; display: grid; place-items: center; color: var(--ink-4); }
.fc-x:hover { background: var(--surface-3); color: var(--ink); }
.fc-x .svg-ico { width: 13px; height: 13px; }
.fc-bar { position: absolute; left: 0; bottom: 0; height: 2px; background: var(--accent); transition: width .2s; }

.dropzone {
  position: absolute; inset: 10px; z-index: 20; display: grid; place-items: center;
  border: 2px dashed var(--accent); border-radius: 22px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(6px); opacity: 0; pointer-events: none; transition: opacity .15s;
  text-align: center; color: var(--ink-2);
}
.dropzone.show { opacity: 1; }
.dropzone .svg-ico { width: 34px; height: 34px; margin: 0 auto 8px; color: var(--accent); }
.dropzone p { margin: 0; font-weight: 600; font-size: 16px; }
.dropzone small { color: var(--ink-3); }

/* ============ modal ============ */
.modal {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px;
  background: color-mix(in srgb, var(--bg-2) 55%, transparent); backdrop-filter: blur(8px);
  opacity: 0; transition: opacity .18s;
}
.modal.open { opacity: 1; }
.modal-card {
  position: relative; width: 100%; max-width: 400px; padding: 28px 28px 24px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow-3);
  transform: translateY(8px) scale(.98); transition: transform .22s var(--ease);
}
.modal.open .modal-card { transform: none; }
.modal-close { position: absolute; top: 12px; right: 12px; }
.modal-mark { width: 40px; height: 40px; border-radius: 11px; margin-bottom: 14px; }
.modal-card h2 { font-family: var(--font-serif); margin: 0; font-size: 22px; }
.modal-sub { margin: 6px 0 18px; color: var(--ink-3); font-size: 13.5px; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; padding: 3px; border-radius: 11px; background: var(--surface-3); margin-bottom: 16px; }
.tab { height: 32px; border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--ink-3); }
.tab.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1); }
.field { display: block; margin-bottom: 12px; }
.field span { display: block; font-size: 12px; font-weight: 600; color: var(--ink-3); margin-bottom: 5px; }
.field input {
  width: 100%; height: 42px; padding: 0 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface-2); outline: none; font-size: 14px;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus { border-color: var(--ink-4); box-shadow: 0 0 0 4px var(--accent-soft); background: var(--surface); }
.form-error { min-height: 18px; margin: 2px 0 10px; font-size: 12.5px; color: var(--accent-ink); }
#authSubmit { width: 100%; }

/* ============ toasts ============ */
.toasts { position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); z-index: 70; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  padding: 9px 16px; border-radius: 10px; font-size: 13px; font-weight: 500;
  background: var(--ink); color: var(--bg); box-shadow: var(--shadow-2);
  opacity: 0; transform: translateY(6px); transition: opacity .2s, transform .2s var(--ease);
}
.toast.show { opacity: 1; transform: none; }
.toast-error { background: var(--accent); color: #fff; }

/* ============ responsive ============ */
@media (max-width: 1080px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .suggest-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(86vw, var(--sidebar-w)); z-index: 40;
    transform: translateX(-100%); transition: transform .25s var(--ease); box-shadow: var(--shadow-3);
  }
  .sidebar-open .sidebar { transform: none; }
  .sidebar-close { display: inline-grid; }
  .scrim { display: block; position: fixed; inset: 0; z-index: 35; background: rgba(0, 0, 0, .28); opacity: 0; pointer-events: none; transition: opacity .2s; }
  .sidebar-open .scrim { opacity: 1; pointer-events: auto; }
  .menu-btn { display: inline-grid; }
  .topbar { padding: 0 10px; }
  .thread { padding: 12px 16px 32px; }
  .home { padding: 16px 16px 32px; }
  .composer-wrap { padding: 6px 12px 10px; }
  .src-list { grid-template-columns: minmax(0, 1fr); }
  .kpi-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar-actions .primary-btn span, .topbar-actions .ghost-btn span { display: none; }
}
@media (max-width: 560px) {
  .suggest-grid { grid-template-columns: minmax(0, 1fr); }
  .msg-ai { grid-template-columns: minmax(0, 1fr); }
  .msg-avatar { display: none; }
  .composer-hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

@media print {
  .sidebar, .composer-wrap, .topbar-actions, .menu-btn, .msg-actions, .chart-tools, .table-tools, .tools { display: none !important; }
  .app { display: block; height: auto; }
  .main, .scroller { display: block; overflow: visible; }
  body { background: #fff; opacity: 1; }
}
