/* dashboards/shared/ui.css
   看板共用设计系统：墨与纸。
   原则：界面骨架只用黑白灰，颜色只留给数据（涨跌、提醒、状态）。
   主题由 <html data-theme="light|dark"> 决定，涨跌配色由 <html data-trend="cn|intl"> 决定，
   两者都由 ui.js 在首屏绘制前设置。页面特有的布局与组件留在各自 <style> 内。 */

/* ── 令牌 ──────────────────────────────────────────── */
:root {
  color-scheme: light;
  --font-sans: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei UI", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Consolas, monospace;

  /* 表面：页面 < 卡片 < 凹陷/悬停 < 轨道 */
  --bg: #f2f1ec;
  --surface: #fbfaf7;
  --surface-2: #f0efe9;
  --surface-3: #e4e3db;
  --glass: rgba(242, 241, 236, 0.82);
  --wash:
    radial-gradient(900px 380px at 6% -8%, rgba(47, 73, 209, 0.06), transparent 62%),
    radial-gradient(700px 320px at 100% 0%, rgba(232, 162, 23, 0.06), transparent 60%);

  /* 墨色与分隔线 */
  --ink: #171611;
  --ink-2: #514f47;
  --ink-3: #67645b;
  --line: rgba(23, 22, 17, 0.1);
  --line-2: rgba(23, 22, 17, 0.18);

  /* 交互色（焦点、链接、盘中在线） */
  --accent: #2f49d1;
  --accent-soft: rgba(47, 73, 209, 0.1);

  /* 方向色：朱红 / 青绿。文字色过 AA，标记色通过色盲分离校验 */
  --c-red: #d94a40;
  --c-red-text: #b8352d;
  --c-red-soft: rgba(217, 74, 64, 0.12);
  --c-grn: #0d8f78;
  --c-grn-text: #0b7360;
  --c-grn-soft: rgba(13, 143, 120, 0.12);

  /* 提醒 */
  --warn: #e8a217;
  --warn-text: #8f5a00;
  --warn-soft: rgba(232, 162, 23, 0.16);
  --warn-line: rgba(196, 134, 8, 0.38);

  --shadow-1: 0 1px 2px rgba(23, 22, 17, 0.04);
  --shadow-pop: 0 10px 30px rgba(23, 22, 17, 0.12), 0 0 0 1px var(--line);

  --r-s: 8px;
  --r-m: 12px;
  --r-l: 16px;
  --topbar-h: 52px;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
}
/* 默认：红涨绿跌（A 股习惯）。data-trend="intl" 切换为绿涨红跌 */
:root {
  --up: var(--c-red);
  --up-text: var(--c-red-text);
  --up-soft: var(--c-red-soft);
  --down: var(--c-grn);
  --down-text: var(--c-grn-text);
  --down-soft: var(--c-grn-soft);
}
:root[data-trend="intl"] {
  --up: var(--c-grn);
  --up-text: var(--c-grn-text);
  --up-soft: var(--c-grn-soft);
  --down: var(--c-red);
  --down-text: var(--c-red-text);
  --down-soft: var(--c-red-soft);
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0c0d10;
  --surface: #14161a;
  --surface-2: #1b1e23;
  --surface-3: #2a2e36;
  --glass: rgba(12, 13, 16, 0.74);
  --wash:
    radial-gradient(900px 420px at 8% -10%, rgba(142, 162, 255, 0.11), transparent 62%),
    radial-gradient(700px 360px at 100% 0%, rgba(22, 165, 134, 0.07), transparent 60%);
  --ink: #f1f0ec;
  --ink-2: #b7b5ad;
  --ink-3: #96948d;
  --line: rgba(255, 255, 255, 0.08);
  --line-2: rgba(255, 255, 255, 0.16);
  --accent: #8ea2ff;
  --accent-soft: rgba(142, 162, 255, 0.15);
  --c-red: #e9564c;
  --c-red-text: #ff7f73;
  --c-red-soft: rgba(233, 86, 76, 0.16);
  --c-grn: #16a586;
  --c-grn-text: #3fcdae;
  --c-grn-soft: rgba(22, 165, 134, 0.16);
  --warn: #e0a12e;
  --warn-text: #f0b450;
  --warn-soft: rgba(224, 161, 46, 0.16);
  --warn-line: rgba(224, 161, 46, 0.36);
  --shadow-1: none;
  --shadow-pop: 0 12px 34px rgba(0, 0, 0, 0.55), 0 0 0 1px var(--line-2);
}

/* ── 基础 ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font: 400 14px/1.55 var(--font-sans);
  -webkit-font-smoothing: antialiased;
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: var(--wash);
}
h1, h2, h3, p, dl, dd, ul, ol { margin: 0; padding: 0; }
ul, ol { list-style: none; }
a { color: inherit; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
code { font-family: var(--font-mono); font-size: 0.92em; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
::selection { background: var(--accent-soft); }

/* ── 顶栏 ──────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: var(--topbar-h);
  background: var(--glass);
  -webkit-backdrop-filter: saturate(160%) blur(16px);
  backdrop-filter: saturate(160%) blur(16px);
  border-bottom: 1px solid var(--line);
}
.topbar-in {
  display: flex;
  align-items: center;
  gap: 12px;
  width: min(100%, 1240px);
  height: 100%;
  margin: 0 auto;
  padding: 0 16px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--ink);
  font-size: 15px;
  font-weight: 700;
  text-decoration: none;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: var(--ink);
  color: var(--bg);
}
.brand-mark svg { width: 15px; height: 15px; }
.tabs {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface-2);
}
.tabs a {
  padding: 5px 12px;
  border-radius: 8px;
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.tabs a:hover { color: var(--ink); }
.tabs a[aria-current="page"] {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 0 0 1px var(--line), 0 1px 2px rgba(0, 0, 0, 0.08);
}
.tools { display: flex; gap: 2px; margin-left: auto; }
.iconbtn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--ink-2);
  transition: background 0.15s, color 0.15s;
}
.iconbtn:hover { background: var(--surface-2); color: var(--ink); }
.iconbtn svg { width: 17px; height: 17px; }
.ic {
  width: 1em;
  height: 1em;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

/* ── 页面骨架 ──────────────────────────────────────── */
.page {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  column-gap: 44px;
  width: min(100%, 1240px);
  margin: 0 auto;
  padding: 0 16px calc(104px + env(safe-area-inset-bottom));
}
.main { min-width: 0; }
.page.solo { grid-template-columns: minmax(0, 1fr); }
.hero { padding: 30px 0 0; }
.eyebrow {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink-3);
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
h1 {
  margin-top: 10px;
  font-size: clamp(28px, 5vw, 40px);
  font-weight: 700;
  line-height: 1.12;
}
.lede {
  max-width: 64ch;
  margin-top: 10px;
  color: var(--ink-2);
  font-size: 14px;
  line-height: 1.65;
}
.section { margin-top: 44px; scroll-margin-top: calc(var(--topbar-h) + 18px); }
.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
  margin-bottom: 14px;
}
h2 { font-size: 18px; font-weight: 680; line-height: 1.3; }
.count {
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}
.count.warn { background: var(--warn-soft); color: var(--warn-text); }
.hint { margin-left: auto; color: var(--ink-3); font-size: 12px; }
.head-tools { display: flex; gap: 8px; margin-left: auto; align-items: center; }
.head-tools .hint { margin-left: 0; }

/* ── 分区导航：手机是底部悬浮坞，桌面是左侧导轨 ─────────── */
.sections {
  position: fixed;
  left: 50%;
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 40;
  display: flex;
  gap: 2px;
  max-width: calc(100vw - 24px);
  padding: 5px;
  overflow-x: auto;
  scrollbar-width: none;
  transform: translateX(-50%);
  border-radius: 18px;
  background: var(--glass);
  -webkit-backdrop-filter: saturate(160%) blur(18px);
  backdrop-filter: saturate(160%) blur(18px);
  box-shadow: var(--shadow-pop);
}
.sections::-webkit-scrollbar { display: none; }
.sections a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 13px;
  border-radius: 13px;
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 620;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.sections a .n {
  padding: 0 6px;
  border-radius: 999px;
  background: var(--warn-soft);
  color: var(--warn-text);
  font-size: 11px;
  font-weight: 700;
}
.sections a.active { background: var(--ink); color: var(--bg); }
.sections a.active .n { background: rgba(255, 255, 255, 0.22); color: inherit; }
@media (min-width: 1100px) {
  .page { grid-template-columns: 150px minmax(0, 1fr); padding-bottom: 72px; }
  .page.solo { grid-template-columns: minmax(0, 1fr); }
  .sections {
    position: sticky;
    top: calc(var(--topbar-h) + 30px);
    left: auto;
    bottom: auto;
    align-self: start;
    flex-direction: column;
    gap: 1px;
    max-width: none;
    margin-top: 76px;
    padding: 0;
    overflow: visible;
    transform: none;
    border-radius: 0;
    background: none;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    box-shadow: none;
  }
  .sections a {
    justify-content: space-between;
    padding: 7px 10px;
    border-radius: 9px;
    font-size: 13px;
  }
  .sections a:hover { background: var(--surface-2); color: var(--ink); }
  .sections a.active { background: var(--surface-3); color: var(--ink); }
  .sections a.active .n { background: var(--warn-soft); color: var(--warn-text); }
}

/* ── 控件 ──────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 13px;
  border: 1px solid var(--line-2);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
  font-weight: 620;
  line-height: 1;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, transform 0.08s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn .ic { width: 15px; height: 15px; }
.btn.is-busy .ic { animation: spin 0.9s linear infinite; }
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}
.search { position: relative; flex: 1 1 260px; min-width: 0; }
.search input {
  width: 100%;
  height: 38px;
  padding: 0 40px 0 36px;
  border: 1px solid var(--line-2);
  border-radius: 11px;
  background: var(--surface);
  font-size: 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.search input::placeholder { color: var(--ink-3); }
.search input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search .ic { position: absolute; top: 50%; left: 12px; transform: translateY(-50%); color: var(--ink-3); pointer-events: none; }
.search kbd {
  position: absolute;
  top: 50%;
  right: 10px;
  transform: translateY(-50%);
  padding: 1px 6px;
  border: 1px solid var(--line-2);
  border-radius: 5px;
  background: var(--surface-2);
  color: var(--ink-3);
  font: 600 11px var(--font-mono);
  pointer-events: none;
}
@media (hover: none) { .search kbd { display: none; } }
.chips {
  display: flex;
  gap: 6px;
  margin: -2px;
  padding: 2px;
  overflow-x: auto;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 12px;
  border: 1px solid var(--line-2);
  border-radius: 999px;
  background: transparent;
  color: var(--ink-2);
  font-size: 12.5px;
  font-weight: 620;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.chip:hover { background: var(--surface-2); color: var(--ink); }
.chip[aria-pressed="true"] { border-color: var(--ink); background: var(--ink); color: var(--bg); }
.chip .n { font-variant-numeric: tabular-nums; font-weight: 650; opacity: 0.6; }

/* ── 卡片与网格 ────────────────────────────────────── */
.card {
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--r-l);
  background: var(--surface);
  box-shadow: var(--shadow-1);
  transition: border-color 0.15s, transform 0.2s var(--ease);
}
.card:hover { border-color: var(--line-2); }
.grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr));
}
.top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.nm { font-size: 15px; font-weight: 680; line-height: 1.3; overflow-wrap: anywhere; }
.sub { margin-top: 2px; color: var(--ink-3); font-size: 12px; overflow-wrap: anywhere; }
.px {
  font-size: 22px;
  font-weight: 680;
  line-height: 1.1;
  text-align: right;
  white-space: nowrap;
}
.px + .delta { display: block; margin-top: 4px; text-align: right; }
.delta { font-size: 13px; font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pos { color: var(--up-text); }
.neg { color: var(--down-text); }
.flat { color: var(--ink-3); }
.sig { color: var(--accent); }
.warn { color: var(--warn-text); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }

/* 指标条：等分、细分隔线 */
.metrics { display: flex; margin-top: 14px; }
.m { flex: 1 1 0; min-width: 0; padding: 0 12px; border-left: 1px solid var(--line); }
.m:first-child { padding-left: 0; border-left: 0; }
.m:last-child { padding-right: 0; }
.m.wide { flex-grow: 1.5; }
.m > span { display: block; color: var(--ink-3); font-size: 11px; white-space: nowrap; }
.m > b {
  display: block;
  margin-top: 3px;
  font-size: 14px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

/* 刻度尺：细轨 + 填充 + 可选警戒线 */
.ruler-row {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 56px;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
}
.ruler-row .lbl { color: var(--ink-3); font-size: 11px; white-space: nowrap; }
.ruler-row .val { font-size: 13px; font-weight: 650; text-align: right; font-variant-numeric: tabular-nums; }
.meter { position: relative; height: 6px; border-radius: 3px; background: var(--surface-3); }
.meter > i { position: absolute; top: 0; bottom: 0; left: 0; border-radius: 3px; background: var(--ink-2); transition: width 0.5s var(--ease); }
.meter.warn > i { background: var(--warn); }
.meter > b { position: absolute; top: -3px; bottom: -3px; width: 2px; border-radius: 1px; background: var(--warn-text); }

/* 信号条 */
.signal {
  display: flex;
  gap: 9px;
  margin-top: 14px;
  padding: 9px 11px 9px 10px;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: 13px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}
.signal::before { content: ""; flex: none; width: 3px; border-radius: 2px; background: var(--ink-3); opacity: 0.45; }
.signal.hl { background: var(--accent-soft); color: var(--ink); }
.signal.hl::before { background: var(--accent); opacity: 1; }
.signal.warn { background: var(--warn-soft); color: var(--ink); }
.signal.warn::before { background: var(--warn); opacity: 1; }
.reason { margin-top: 10px; color: var(--ink-3); font-size: 12px; line-height: 1.6; overflow-wrap: anywhere; }

/* ── 徽标 ──────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 22px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: 11.5px;
  font-weight: 650;
  line-height: 1;
  white-space: nowrap;
}
.b-focus { background: var(--ink); color: var(--bg); }
.b-wait, .b-warn { border-color: var(--warn-line); background: var(--warn-soft); color: var(--warn-text); }
.b-exclude { border-color: var(--line-2); background: transparent; color: var(--ink-3); }
.b-ok { background: var(--accent-soft); color: var(--accent); }
.b-mute { background: var(--surface-3); color: var(--ink-2); }

/* 数据新鲜度 */
.fresh { display: inline-flex; align-items: center; gap: 7px; color: var(--ink-2); font-size: 12px; font-weight: 620; }
.fresh i { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.fresh.stale { color: var(--warn-text); }
.fresh.stale i { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-soft); }
.fresh.old { color: var(--warn-text); }
.fresh.old i { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-soft); }
.fresh.live i { animation: pulse 2s ease-out infinite; }

/* ── 表格 ──────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--r-l);
  background: var(--surface);
}
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink-3);
  font-size: 11px;
  font-weight: 650;
  text-align: right;
  white-space: nowrap;
}
td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: right; font-variant-numeric: tabular-nums; }
th:first-child, td:first-child { text-align: left; }
tr:last-child td { border-bottom: 0; }

/* ── 空态、提示、骨架 ──────────────────────────────── */
.empty {
  padding: 22px 16px;
  border: 1px dashed var(--line-2);
  border-radius: var(--r-m);
  color: var(--ink-3);
  font-size: 13px;
  line-height: 1.6;
  text-align: center;
  overflow-wrap: anywhere;
}
.notice {
  display: flex;
  gap: 11px;
  padding: 13px 14px;
  border: 1px solid var(--warn-line);
  border-radius: var(--r-m);
  background: var(--warn-soft);
  color: var(--ink);
  font-size: 13px;
  line-height: 1.6;
}
.notice .ic { width: 17px; height: 17px; margin-top: 2px; color: var(--warn-text); }
.notice ul { display: grid; gap: 4px; }
.skeleton {
  border-radius: var(--r-m);
  background: linear-gradient(100deg, var(--surface-2) 30%, var(--surface-3) 50%, var(--surface-2) 70%);
  background-size: 300% 100%;
  animation: shimmer 1.6s ease-in-out infinite;
}
.is-loading { opacity: 0.55; transition: opacity 0.2s; pointer-events: none; }

/* ── 动效 ──────────────────────────────────────────── */
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 var(--accent-soft), 0 0 0 3px var(--accent-soft); }
  70% { box-shadow: 0 0 0 7px transparent, 0 0 0 3px var(--accent-soft); }
  100% { box-shadow: 0 0 0 0 transparent, 0 0 0 3px var(--accent-soft); }
}
.reveal { animation: rise 0.55s var(--ease) both; animation-delay: calc(var(--i, 0) * 70ms); }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* ── 小屏微调 ──────────────────────────────────────── */
@media (max-width: 520px) {
  .brand-name { display: none; }
  .topbar-in { gap: 8px; padding: 0 12px; }
  .page { padding-left: 12px; padding-right: 12px; }
  .hero { padding-top: 22px; }
  .section { margin-top: 36px; }
  .hint { flex-basis: 100%; margin-left: 0; }
  .head-tools { margin-left: 0; }
}
