/* 涨跌色：默认红涨绿跌（中国习惯），设置里可切换 */
:root { --up: var(--danger); --down: var(--success); --flat: var(--text-3); }
:root[data-color='us'] { --up: var(--success); --down: var(--danger); }
.up { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--flat); }

body { font-size: 13.5px; }
[hidden] { display: none !important; }
h1 { margin: 0; font-size: 28px; font-weight: 600; letter-spacing: -0.03em; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.row-gap { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.wrap { flex-wrap: wrap; }
[data-icon] { display: inline-flex; }
[data-icon] svg { width: 16px; height: 16px; }

/* ---------- 顶栏 ---------- */
.titlebar { height: 60px; flex: none; display: flex; align-items: center; gap: 16px; padding: 0 16px; background: var(--bg); }
.brand { display: flex; align-items: center; gap: 10px; flex: none; }
.logo-mark { width: 32px; height: 32px; border-radius: 9px; background: var(--ink); color: var(--ink-text); display: flex; align-items: center; justify-content: center; }
.brand-name { font-size: 15px; font-weight: 600; letter-spacing: -0.02em; }
.brand-sub { font-size: 11px; color: var(--text-3); }
.search { position: relative; flex: 1; max-width: 520px; height: 38px; display: flex; align-items: center; gap: 8px; padding: 0 10px 0 14px; background: var(--panel); border-radius: 99px; box-shadow: var(--shadow-card); transition: box-shadow 0.15s; }
.search:focus-within { box-shadow: 0 0 0 4px rgba(0, 113, 227, 0.15), var(--shadow-card); }
.search-ico { color: var(--text-3); }
.search-input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; font-size: 14px; }
.search-kbd { font: 11px var(--mono); color: var(--text-3); background: var(--fill); border-radius: 6px; padding: 2px 7px; }
.search-pop { position: absolute; top: 44px; left: 0; right: 0; max-height: 420px; }
.sr-item { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 8px 12px; border-radius: 10px; cursor: pointer; }
.sr-item:hover, .sr-item.active { background: var(--primary-soft); }
.sr-name { font-weight: 500; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-meta { font-size: 12px; color: var(--text-3); grid-column: 1; }
.sr-market { grid-row: 1 / span 2; grid-column: 2; align-self: center; }
.seg { display: inline-flex; padding: 3px; border-radius: 99px; background: var(--fill); flex: none; }
.seg button { height: 30px; padding: 0 16px; border: 0; border-radius: 99px; background: transparent; color: var(--text-2); font-weight: 500; transition: background 0.15s, color 0.15s; white-space: nowrap; }
.seg button:hover { color: var(--text); }
.seg button.active { background: var(--panel); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
.seg-sm button { height: 26px; padding: 0 11px; font-size: 12.5px; }
.tb-actions { display: flex; gap: 8px; margin-left: auto; }
.tb-round { width: 36px; height: 36px; border: 0; border-radius: 50%; background: var(--panel); box-shadow: var(--shadow-card); color: var(--text-2); display: flex; align-items: center; justify-content: center; transition: box-shadow 0.2s, color 0.15s; }
.tb-round:hover { box-shadow: var(--shadow-lift); color: var(--text); }
.only-narrow { display: none; }

/* ---------- 布局 ---------- */
.layout { flex: 1; min-height: 0; display: flex; }
.sidebar { width: 272px; flex: none; display: flex; flex-direction: column; margin: 4px 0 14px 14px; background: var(--panel); border-radius: var(--r-lg); box-shadow: var(--shadow-card); overflow: hidden; }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px 8px; font-size: 15px; font-weight: 600; letter-spacing: -0.02em; }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500; color: var(--text-3); }
.live i { width: 7px; height: 7px; border-radius: 50%; background: var(--success); }
.live.busy i { animation: pulse 0.9s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.3; } }
.watchlist { flex: 1; overflow: auto; padding: 4px 8px; }
.wl-item { position: relative; display: grid; grid-template-columns: 1fr 64px 76px; align-items: center; gap: 8px; height: 56px; padding: 0 10px; border-radius: 12px; cursor: pointer; transition: background 0.12s; }
.wl-item:hover { background: var(--panel-2); }
.wl-item.active { background: var(--primary-soft); }
.wl-name { font-weight: 500; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wl-sym { font-size: 11.5px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wl-spark { width: 64px; height: 26px; }
.wl-px { text-align: right; font-variant-numeric: tabular-nums; }
.wl-price { font-weight: 500; }
.wl-chg { font-size: 12px; }
.wl-del { position: absolute; right: 4px; top: 4px; width: 20px; height: 20px; border: 0; border-radius: 50%; background: var(--fill); color: var(--text-2); display: none; align-items: center; justify-content: center; padding: 0; }
.wl-del svg { width: 12px; height: 12px; }
.wl-item:hover .wl-del { display: flex; }
.side-foot { padding: 10px 18px 14px; font-size: 11.5px; line-height: 1.5; }
.main { flex: 1; min-width: 0; overflow: auto; padding: 4px 14px 24px; }
.view { display: flex; flex-direction: column; gap: 14px; max-width: 1480px; margin: 0 auto; animation: riseIn 0.3s var(--ease-out); }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; padding: 8px 4px 2px; flex-wrap: wrap; }
.page-desc { margin: 6px 0 0; color: var(--text-2); font-size: 14px; }
.btn [data-icon] svg { width: 15px; height: 15px; }
.btn:disabled { opacity: 0.5; cursor: default; transform: none; }

/* ---------- 卡片 ---------- */
.card { background: var(--panel); border-radius: var(--r-lg); box-shadow: var(--shadow-card); min-width: 0; }
.card-header { padding: 18px 22px 12px; }
.card-title { display: flex; align-items: center; gap: 8px; font-size: 16px; font-weight: 600; letter-spacing: -0.02em; }
.card-sub { margin-top: 4px; font-size: 12.5px; color: var(--text-3); }
.card-body { padding: 0 22px 20px; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); gap: 14px; align-items: start; }
.ai-badge { width: 24px; height: 24px; border-radius: 7px; background: var(--primary); color: #fff; align-items: center; justify-content: center; }
.ai-badge svg { width: 14px; height: 14px; }
.tag { display: inline-flex; align-items: center; height: 22px; padding: 0 9px; border-radius: 99px; background: var(--fill); color: var(--text-2); font-size: 12px; font-weight: 500; }

/* ---------- 指数 ---------- */
.idx-group { margin-bottom: 14px; }
.idx-title { font-size: 12px; font-weight: 600; color: var(--text-3); letter-spacing: 0.04em; margin: 0 4px 8px; }
.idx-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.idx-card { padding: 14px 16px 12px; cursor: pointer; transition: transform 0.25s var(--ease-out), box-shadow 0.25s; }
.idx-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lift); }
.idx-name { font-size: 13px; font-weight: 500; color: var(--text-2); display: flex; justify-content: space-between; gap: 6px; }
.idx-price { font-size: 22px; font-weight: 600; letter-spacing: -0.03em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.idx-chg { font-size: 13px; font-weight: 500; font-variant-numeric: tabular-nums; }
.idx-spark { width: 100%; height: 34px; margin-top: 6px; display: block; }
.dot { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 500; color: var(--text-3); white-space: nowrap; }
.dot::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--text-4); }
.dot.open::before { background: var(--success); }

/* ---------- 表格 ---------- */
/* 宽表格横向滚动，不撑破页面 */
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.tbl th { text-align: left; font-size: 12px; font-weight: 500; color: var(--text-3); padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 9px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl .num { text-align: right; }
.tbl tbody tr.click { cursor: pointer; }
.tbl tbody tr.click:hover td { background: var(--panel-2); }
.tbl .nm { max-width: 180px; overflow: hidden; text-overflow: ellipsis; }
.tbl .sub { display: block; font-size: 11.5px; color: var(--text-3); }

/* ---------- 个股 ---------- */
.stock-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 18px; padding: 10px 4px 0; flex-wrap: wrap; }
.sh-title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.sh-symbol { color: var(--text-3); font-size: 14px; }
.sh-price { display: flex; align-items: baseline; gap: 14px; margin-top: 6px; flex-wrap: wrap; }
.big { font-size: 40px; font-weight: 600; letter-spacing: -0.03em; }
.chg { font-size: 18px; font-weight: 500; }
.star { color: var(--text-3); }
.star.on { color: var(--warning); }
.state { font-size: 12.5px; }
.stats { display: grid; grid-template-columns: repeat(4, auto); gap: 6px 22px; font-size: 13px; }
.stat-l { color: var(--text-3); font-size: 12px; }
.stat-v { font-weight: 500; font-variant-numeric: tabular-nums; }
.stock-grid { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(360px, 1fr); gap: 14px; align-items: start; }
.col-main, .col-side { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.col-side { position: sticky; top: 0; }
.chart-card { overflow: hidden; }
.chart { height: 470px; margin: 0 8px 10px; position: relative; }
.chart-cmp { height: 380px; }
.legend { min-height: 18px; padding: 0 22px 4px; font-size: 12px; color: var(--text-2); display: flex; gap: 14px; flex-wrap: wrap; }
.legend b { font-weight: 500; }
.chart .loading { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: var(--panel); z-index: 5; }
.metrics { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 10px; margin-bottom: 14px; }
.metric { background: var(--panel-2); border-radius: 12px; padding: 10px 12px; }
.metric-l { font-size: 12px; color: var(--text-3); font-weight: 500; }
.metric-v { font-size: 18px; font-weight: 600; letter-spacing: -0.02em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.signals { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.sig { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 500; }
.sig::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--text-4); }
.sig.up::before { background: var(--up); }
.sig.down::before { background: var(--down); }
.sig.warn::before { background: var(--warning); }
.sig { color: var(--text); }
.news-item { display: block; padding: 10px 0; border-bottom: 1px solid var(--line); color: inherit; text-decoration: none; }
.news-item:last-child { border-bottom: 0; }
.news-item:hover .news-t { color: var(--primary); }
.news-t { font-size: 14px; font-weight: 500; line-height: 1.45; }
.news-m { font-size: 12px; color: var(--text-3); margin-top: 3px; }

/* ---------- AI ---------- */
.ai-controls { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: center; margin-bottom: 12px; }
.ai-controls .input { min-width: 0; }
.ai-out:empty { display: none; }
.ai-status { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); padding: 10px 12px; background: var(--panel-2); border-radius: 12px; margin-bottom: 10px; }
.ai-status .spinner { width: 14px; height: 14px; border-width: 2px; flex: none; }
.ai-status.err { color: var(--danger); background: var(--danger-bg); }
.ai-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 10px; font-size: 12px; color: var(--text-3); }
.sources { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.sources summary { cursor: pointer; font-size: 12.5px; color: var(--text-2); font-weight: 500; }
.sources ol { margin: 8px 0 0; padding-left: 20px; font-size: 12.5px; line-height: 1.7; }
.sources a { color: var(--primary); text-decoration: none; }
.md { font-size: 14px; line-height: 1.75; color: var(--text); overflow-wrap: anywhere; }
.md h1, .md h2, .md h3 { letter-spacing: -0.02em; line-height: 1.35; }
.md h1 { font-size: 20px; margin: 14px 0 6px; }
.md h2 { font-size: 16.5px; margin: 20px 0 6px; font-weight: 600; }
.md h3 { font-size: 15px; margin: 14px 0 4px; }
.md > :first-child { margin-top: 0; }
.md p { margin: 6px 0 10px; }
.md ul, .md ol { padding-left: 22px; margin: 6px 0 10px; }
.md li { margin: 3px 0; }
.md strong { font-weight: 600; }
.md a { color: var(--primary); text-decoration: none; }
.md a:hover { text-decoration: underline; }
.md code { font-family: var(--mono); font-size: 12.5px; background: var(--fill); border-radius: 5px; padding: 1px 5px; }
.md blockquote { margin: 8px 0; padding: 4px 14px; border-left: 3px solid var(--line-strong); color: var(--text-2); }
.md table { border-collapse: collapse; width: 100%; margin: 8px 0 12px; font-size: 13px; font-variant-numeric: tabular-nums; display: block; overflow-x: auto; }
.md th, .md td { border-bottom: 1px solid var(--line); padding: 7px 10px; text-align: left; white-space: nowrap; }
.md th { color: var(--text-3); font-weight: 500; font-size: 12px; }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }
.md em { color: var(--text-3); }
.caret::after { content: ''; display: inline-block; width: 7px; height: 15px; margin-left: 2px; vertical-align: -2px; background: var(--primary); border-radius: 2px; animation: pulse 0.8s infinite; }
.ai-empty { text-align: center; padding: 28px 10px 18px; color: var(--text-3); font-size: 13.5px; line-height: 1.7; }
.ai-empty .big-ico { width: 44px; height: 44px; border-radius: 14px; background: var(--primary-soft); color: var(--primary); display: inline-flex; align-items: center; justify-content: center; margin-bottom: 10px; }
.ai-empty .big-ico svg { width: 22px; height: 22px; }

.chat { margin-top: 14px; }
.chat-log { display: flex; flex-direction: column; gap: 10px; margin-bottom: 10px; }
.bubble-u { align-self: flex-end; max-width: 85%; background: var(--primary); color: #fff; padding: 8px 14px; border-radius: 18px 18px 4px 18px; font-size: 14px; line-height: 1.55; white-space: pre-wrap; }
.bubble-a { background: var(--panel-2); padding: 10px 14px; border-radius: 4px 18px 18px 18px; }
.chat-input { display: flex; gap: 8px; align-items: flex-end; }
.chat-input textarea { flex: 1; min-height: 38px; max-height: 140px; border-radius: 19px; padding: 8px 14px; resize: none; line-height: 1.5; }
.chat-input .btn { height: 38px; width: 38px; padding: 0; flex: none; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }

/* ---------- 对比 ---------- */
.cmp-picks { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pick { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 6px 0 12px; border-radius: 99px; background: var(--fill); font-weight: 500; font-size: 13px; }
.pick i { width: 9px; height: 9px; border-radius: 50%; }
.pick button { width: 20px; height: 20px; border: 0; border-radius: 50%; background: transparent; color: var(--text-2); padding: 0; display: flex; align-items: center; justify-content: center; }
.pick button:hover { background: var(--fill-hover); }
.pick button svg { width: 12px; height: 12px; }
.pick-add { position: relative; }
.pick-add .input { width: 200px; height: 30px; border-radius: 99px; }
.pick-add .popover { position: absolute; top: 36px; left: 0; width: 300px; }

/* ---------- 设置 ---------- */
.settings { width: 520px; }
.settings .form-row .form-label { width: 104px; }
.hint { font-size: 12px; color: var(--text-3); margin: -4px 0 0 116px; line-height: 1.5; }
.switch { position: relative; width: 42px; height: 25px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--fill-hover); border-radius: 99px; transition: background 0.2s; cursor: pointer; }
.switch span::after { content: ''; position: absolute; left: 2px; top: 2px; width: 21px; height: 21px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2); transition: transform 0.25s var(--spring); }
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::after { transform: translateX(17px); }
.test-result { font-size: 13px; }

.empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; min-height: 50vh; color: var(--text-3); font-size: 14px; }
.empty-ico svg { width: 34px; height: 34px; opacity: 0.6; stroke-width: 1.4; }
.skeleton { height: 14px; border-radius: 6px; background: var(--fill); animation: pulse 1.2s infinite; }

/* ---------- 响应式 ---------- */
@media (max-width: 1180px) {
  .stock-grid { grid-template-columns: minmax(0, 1fr); }
  .col-side { position: static; }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .stats { grid-template-columns: repeat(4, auto); }
}
@media (max-width: 960px) {
  .brand-text { display: none; }
  .titlebar { gap: 10px; }
}
@media (max-width: 760px) {
  .only-narrow { display: inline-flex; }
  .titlebar { height: auto; flex-wrap: wrap; padding: 10px 16px; row-gap: 10px; }
  .brand { display: none; }
  .search { order: 3; flex-basis: 100%; max-width: none; }
  #nav { order: 2; }
  .tb-actions { order: 2; }
  .seg button { padding: 0 11px; }
  .sidebar { position: fixed; z-index: 2000; left: 0; top: 0; bottom: 0; margin: 0; border-radius: 0 var(--r-lg) var(--r-lg) 0; transform: translateX(-105%); transition: transform 0.3s var(--ease-out); box-shadow: var(--shadow); }
  body.side-open .sidebar { transform: none; }
  .main { padding: 4px 16px 24px; }
  h1 { font-size: 24px; }
  .big { font-size: 32px; }
  .stats { grid-template-columns: repeat(2, auto); width: 100%; }
  .chart { height: 380px; margin: 0 2px 8px; }
  .card-header { padding: 16px 16px 10px; }
  .card-body { padding: 0 16px 16px; }
  .legend { padding: 0 16px 4px; }
  .ai-controls { grid-template-columns: 1fr auto; }
  .ai-controls .seg { grid-column: 1 / -1; justify-self: start; }
  .idx-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .idx-price { font-size: 18px; }
  .settings { width: auto; }
  .settings .form-row { flex-direction: column; align-items: stretch; gap: 6px; }
  .hint { margin-left: 0; }
  .pick-add .input { width: 160px; }
}
