/* ===========================================================================
 * ctplite dashboard — design tokens & base styles
 * 单文件全部样式 (替代原 inline <style>), 用 CSS 变量驱动 light/dark 主题.
 * =========================================================================== */

/* ---------- 主题变量 (light 默认) ---------- */
:root {
  /* 色板 */
  --bg:           #f6f8fa;
  --surface:      #ffffff;
  --surface-2:    #f3f4f6;
  --surface-3:    #e5e7eb;
  --border:       #e5e7eb;
  --border-strong:#d1d5db;
  --text:         #1f2937;
  --text-muted:   #6b7280;
  --text-faint:   #9ca3af;
  --shadow-sm:    0 1px 2px rgba(15, 23, 42, .04);
  --shadow-md:    0 4px 12px rgba(15, 23, 42, .06);

  /* 语义色 */
  --brand:        #2563eb;
  --brand-hover:  #1d4ed8;
  --brand-soft:   #dbeafe;
  --brand-ink:    #1e40af;

  --up:           #dc2626;   /* 涨 / BUY (中国习惯: 红涨) */
  --down:         #16a34a;   /* 跌 / SELL */
  --up-soft:      #fee2e2;
  --down-soft:    #dcfce7;

  --ok:           #16a34a;
  --ok-soft:      #dcfce7;
  --ok-ink:       #166534;
  --warn:         #d97706;
  --warn-soft:    #fef3c7;
  --warn-ink:     #92400e;
  --bad:          #dc2626;
  --bad-soft:     #fee2e2;
  --bad-ink:      #991b1b;
  --info:         #2563eb;
  --info-soft:    #dbeafe;
  --info-ink:     #1e40af;
  --neutral:      #6b7280;
  --neutral-soft: #f3f4f6;
  --neutral-ink:  #374151;

  /* 间距 */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;

  /* 字号 */
  --fs-xs:  11px;
  --fs-sm:  12px;
  --fs-base:13px;
  --fs-md:  14px;
  --fs-lg:  16px;
  --fs-xl:  20px;
  --fs-2xl: 24px;

  /* 圆角 */
  --radius-sm: 4px;
  --radius:    6px;
  --radius-md: 8px;
  --radius-lg: 10px;

  /* 动效 */
  --transition-fast: 120ms ease-out;
  --transition:      180ms ease-out;
}

/* ---------- 暗色主题 ---------- */
:root[data-theme="dark"] {
  --bg:           #0b0f14;
  --surface:      #131820;
  --surface-2:    #1a212c;
  --surface-3:    #1f2937;
  --border:       #1f2937;
  --border-strong:#374151;
  --text:         #e5e7eb;
  --text-muted:   #9ca3af;
  --text-faint:   #6b7280;
  --shadow-sm:    0 1px 2px rgba(0, 0, 0, .4);
  --shadow-md:    0 4px 12px rgba(0, 0, 0, .45);

  --brand:        #60a5fa;
  --brand-hover:  #93c5fd;
  --brand-soft:   rgba(96, 165, 250, .15);
  --brand-ink:    #93c5fd;

  --up:           #f87171;
  --down:         #4ade80;
  --up-soft:      rgba(248, 113, 113, .15);
  --down-soft:    rgba(74, 222, 128, .15);

  --ok-soft:      rgba(74, 222, 128, .15);
  --ok-ink:       #86efac;
  --warn-soft:    rgba(245, 158, 11, .15);
  --warn-ink:     #fcd34d;
  --bad-soft:     rgba(248, 113, 113, .15);
  --bad-ink:      #fca5a5;
  --info-soft:    rgba(96, 165, 250, .15);
  --info-ink:     #93c5fd;
}

/* 跟随系统偏好 (仅在用户未手动选择时生效) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --bg:           #0b0f14;
    --surface:      #131820;
    --surface-2:    #1a212c;
    --surface-3:    #1f2937;
    --border:       #1f2937;
    --border-strong:#374151;
    --text:         #e5e7eb;
    --text-muted:   #9ca3af;
    --text-faint:   #6b7280;
    --shadow-sm:    0 1px 2px rgba(0, 0, 0, .4);
    --shadow-md:    0 4px 12px rgba(0, 0, 0, .45);
    --brand:        #60a5fa;
    --brand-soft:   rgba(96, 165, 250, .15);
    --brand-ink:    #93c5fd;
    --up:           #f87171;
    --down:         #4ade80;
    --up-soft:      rgba(248, 113, 113, .15);
    --down-soft:    rgba(74, 222, 128, .15);
    --ok-soft:      rgba(74, 222, 128, .15);
    --ok-ink:       #86efac;
    --warn-soft:    rgba(245, 158, 11, .15);
    --warn-ink:     #fcd34d;
    --bad-soft:     rgba(248, 113, 113, .15);
    --bad-ink:      #fca5a5;
    --info-soft:    rgba(96, 165, 250, .15);
    --info-ink:     #93c5fd;
  }
}
:root[data-theme="light"], :root:not([data-theme]) {
  color-scheme: light;
}

/* ---------- 基础 ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC",
               "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
  font-size: var(--fs-base);
  line-height: 1.5;
  margin: 0;
  padding: var(--space-4) var(--space-6);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-variant-numeric: tabular-nums;
  transition: background-color var(--transition), color var(--transition);
}

/* ---------- 顶栏 ---------- */
header.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--space-4);
}
header.topbar .brand {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
}
header.topbar h1 {
  font-size: var(--fs-xl);
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.01em;
}
header.topbar h1 .accent {
  color: var(--brand);
}
header.topbar .subtitle {
  font-size: var(--fs-sm);
  color: var(--text-muted);
}
header.topbar .topbar-meta {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--fs-sm);
  color: var(--text-muted);
}
header.topbar .topbar-meta .sep {
  color: var(--text-faint);
}
header.topbar .topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
header.topbar .topbar-actions label {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--fs-sm);
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}
header.topbar .topbar-actions input[type="checkbox"] {
  accent-color: var(--brand);
}

/* ---------- Section 分组 ---------- */
section.block {
  margin-top: var(--space-5);
}
section.block > h2.section-title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: 0 0 var(--space-3) 0;
  padding-left: var(--space-2);
  border-left: 3px solid var(--brand);
  font-size: var(--fs-lg);
  font-weight: 600;
  color: var(--text);
}
section.block > h2.section-title .tag {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  font-weight: 400;
  margin-left: var(--space-1);
}
section.block > h2.section-title .actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: 400;
}

/* ---------- 卡片网格 ---------- */
.grid { display: grid; gap: var(--space-3); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 1280px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
  body { padding: var(--space-3); }
  header.topbar { flex-wrap: wrap; gap: var(--space-2); }
  header.topbar .topbar-meta { flex-wrap: wrap; font-size: var(--fs-xs); }
  .data-table th, .data-table td { padding: var(--space-1) var(--space-2); }
  .stat { font-size: var(--fs-xl); }
  /* 小屏让表格有横向滚动提示 */
  .data-table-wrap::after {
    content: "↔ 横向滚动";
    position: sticky;
    right: 0;
    bottom: 0;
    display: inline-block;
    padding: 2px var(--space-2);
    background: var(--surface-2);
    color: var(--text-muted);
    font-size: var(--fs-xs);
    border-radius: var(--radius-sm);
    margin: var(--space-1);
    float: right;
  }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4);
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition-fast), transform var(--transition-fast);
}
.card:hover { box-shadow: var(--shadow-md); }
.card.full { grid-column: 1 / -1; }
.card .card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 0 0 var(--space-3) 0;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.card .card-head .actions {
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
}

/* ---------- 数值 / 指标 ---------- */
.stat {
  font-size: var(--fs-2xl);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.stat-sm {
  font-size: var(--fs-md);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.meta {
  font-size: var(--fs-xs);
  color: var(--text-muted);
}
.meta b, .meta strong { color: var(--text); font-weight: 600; }
.kv-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-1) 0;
  gap: var(--space-3);
}
.kv-row .label {
  color: var(--text-muted);
  font-size: var(--fs-xs);
}
.kv-row .val {
  font-size: var(--fs-base);
  font-weight: 500;
  color: var(--text);
  text-align: right;
  word-break: break-all;
}
.kv-row .val.muted { color: var(--text-muted); font-weight: 400; }

/* ---------- pill (状态徽章) ---------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px var(--space-2);
  border-radius: 999px;
  font-size: var(--fs-xs);
  font-weight: 600;
  background: var(--neutral-soft);
  color: var(--neutral-ink);
  white-space: nowrap;
}
.pill-ok    { background: var(--ok-soft);   color: var(--ok-ink); }
.pill-bad   { background: var(--bad-soft);  color: var(--bad-ink); }
.pill-warn  { background: var(--warn-soft); color: var(--warn-ink); }
.pill-info  { background: var(--info-soft); color: var(--info-ink); }
.pill::before {
  content: "";
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: .7;
}

/* ---------- 涨跌 / 方向 ---------- */
.up   { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--text-muted); }
.dir-BUY  { color: var(--up); }
.dir-SELL { color: var(--down); }
.dir-HOLD { color: var(--text-muted); }

/* CTP 报单状态色 */
.status-SUBMITTING { color: var(--text-muted); }
.status-ACCEPTED   { color: var(--info-ink); font-weight: 600; }
.status-PARTIAL    { color: var(--warn-ink); font-weight: 600; }
.status-FILLED     { color: var(--ok-ink);   font-weight: 600; }
.status-REJECTED   { color: var(--bad-ink);  font-weight: 600; }
.status-CANCELLED  { color: var(--text-muted); text-decoration: line-through; }

/* ---------- 表格 ---------- */
.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: var(--fs-sm);
}
.data-table th, .data-table td {
  padding: var(--space-2) var(--space-3);
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.data-table th {
  background: var(--surface-2);
  font-weight: 600;
  color: var(--text-muted);
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  position: sticky; top: 0;
}
.data-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table tbody tr:hover td { background: var(--surface-2); }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tr.empty-row td {
  text-align: center;
  color: var(--text-faint);
  padding: var(--space-6) var(--space-3);
  font-size: var(--fs-sm);
}
.data-table tr.error-row td {
  text-align: center;
  color: var(--bad-ink);
  background: var(--bad-soft);
  padding: var(--space-4) var(--space-3);
}
.data-table .skeleton-shimmer {
  height: 14px;
  border-radius: 3px;
  background: linear-gradient(
    90deg,
    var(--surface-2) 0%,
    var(--surface-3) 50%,
    var(--surface-2) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.2s ease-in-out infinite;
}
@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.data-table-wrap {
  max-height: 360px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  position: relative;
}
/* sticky 首列 (合约/时间) — 横向滚动时不会丢列名 */
.data-table th:first-child,
.data-table td:first-child {
  position: sticky;
  left: 0;
  background: var(--surface);
  z-index: 1;
  box-shadow: 1px 0 0 var(--border);
}
.data-table th:first-child {
  background: var(--surface-2);
  z-index: 2;
}

/* DataTable toolbar (搜索 + 状态 chip + 计数) */
.dt-toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom: 0;
  border-radius: var(--radius) var(--radius) 0 0;
  font-size: var(--fs-xs);
  flex-wrap: wrap;
}
.dt-toolbar + .data-table-wrap {
  border-top-left-radius: 0;
  border-top-right-radius: 0;
}
.dt-toolbar .dt-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
}
.dt-toolbar .dt-chip {
  cursor: pointer;
  padding: 2px var(--space-2);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-muted);
  border-radius: 999px;
  font-size: var(--fs-xs);
  font-weight: 500;
  font-family: inherit;
}
.dt-toolbar .dt-chip:hover {
  background: var(--surface-2);
  color: var(--text);
}
.dt-toolbar .dt-chip.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}
.dt-toolbar .dt-badge {
  font-variant-numeric: tabular-nums;
}

/* ---------- PnL 双向条 (正右负左) ---------- */
.pnl-bar-wrap {
  position: relative;
  height: 8px;
  background: var(--surface-2);
  border-radius: 4px;
  overflow: hidden;
}
.pnl-bar-zero {
  position: absolute;
  left: 50%;
  top: 0;
  width: 1px;
  height: 100%;
  background: var(--border-strong);
  z-index: 1;
}
.pnl-bar {
  position: absolute;
  top: 0;
  height: 100%;
  border-radius: 2px;
  transition: width var(--transition), left var(--transition),
              background var(--transition);
  background: var(--text-faint);
  z-index: 0;
}
.pnl-bar.up   { background: var(--up); }
.pnl-bar.down { background: var(--down); }

/* ---------- 持仓明细表 ---------- */
.position-table .dir-long  { color: var(--up); }
.position-table .dir-short { color: var(--down); }
.position-table .pnl-pos   { color: var(--up); }
.position-table .pnl-neg   { color: var(--down); }

/* ---------- risk-trend sparkline ---------- */
risk-trend {
  display: block;
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px dashed var(--border);
}
.risk-trend .rt-row {
  display: grid;
  grid-template-columns: 80px 1fr 64px;
  align-items: center;
  gap: var(--space-2);
  height: 28px;
}
.risk-trend .rt-row + .rt-row { margin-top: 2px; }
.risk-trend .rt-label {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  white-space: nowrap;
}
.risk-trend .rt-canvas {
  width: 100%;
  height: 28px;
  display: block;
}
.risk-trend .rt-val {
  font-size: var(--fs-xs);
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.risk-trend .rt-val.up   { color: var(--up); }
.risk-trend .rt-val.down { color: var(--down); }
@media (max-width: 720px) {
  .risk-trend .rt-row {
    grid-template-columns: 64px 1fr 48px;
  }
}

/* ---------- 滚回顶部 ---------- */
.scroll-top {
  position: fixed;
  right: var(--space-4);
  bottom: var(--space-4);
  width: 36px; height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  color: var(--text-muted);
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  box-shadow: var(--shadow-md);
  cursor: pointer;
  font-size: var(--fs-md);
  z-index: 100;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity var(--transition), transform var(--transition);
}
.scroll-top.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
.scroll-top:hover {
  background: var(--surface-2);
  color: var(--text);
}

/* ---------- Modal 弹层 ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 9998;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: modal-in var(--transition);
}
.modal[hidden] { display: none; }
.modal-mask {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, .4);
  cursor: pointer;
}
:root[data-theme="dark"] .modal-mask { background: rgba(0, 0, 0, .6); }
.modal-body {
  position: relative;
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 64px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
}
.modal-head h3 {
  margin: 0;
  font-size: var(--fs-md);
  font-weight: 600;
}
.modal-content {
  padding: var(--space-4);
  overflow: auto;
  font-size: var(--fs-sm);
  line-height: 1.6;
}
.modal-content h4 {
  margin: var(--space-3) 0 var(--space-2) 0;
  font-size: var(--fs-sm);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.modal-content h4:first-child { margin-top: 0; }
.modal-content .legend {
  margin: 0;
  padding-left: var(--space-5);
}
.modal-content .legend li {
  padding: 2px 0;
}
.modal-content kbd {
  display: inline-block;
  padding: 1px 6px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: 3px;
  font-family: ui-monospace, monospace;
  font-size: var(--fs-xs);
  margin-right: var(--space-2);
}
.modal-content code {
  background: var(--surface-2);
  padding: 1px 4px;
  border-radius: 3px;
  font-size: var(--fs-xs);
}
.modal-content .help-dl {
  margin: 0;
  display: grid;
  grid-template-columns: max-content 1fr;
  column-gap: var(--space-3);
  row-gap: var(--space-1);
}
.modal-content .help-dl dt {
  font-weight: 600;
  color: var(--text);
  font-size: var(--fs-xs);
}
.modal-content .help-dl dd {
  margin: 0;
  color: var(--text-muted);
  font-size: var(--fs-xs);
}
@keyframes modal-in {
  from { opacity: 0; transform: scale(.96); }
  to   { opacity: 1; transform: scale(1); }
}

/* ---------- 打印样式 ---------- */
@media print {
  /* 隐藏交互元素 */
  .toast-stack,
  .scroll-top,
  header.topbar .topbar-actions,
  .dt-toolbar,
  .modal,
  kline-chart,
  pnl-timeline,
  event-stream,
  .card .card-head .actions {
    display: none !important;
  }
  /* 简化配色 */
  :root, :root[data-theme="dark"], :root[data-theme="light"] {
    --bg: #ffffff;
    --surface: #ffffff;
    --surface-2: #f6f8fa;
    --text: #000000;
    --text-muted: #444444;
    --border: #cccccc;
    --brand: #003a8c;
    --up: #b30000;
    --down: #006400;
    color-scheme: light;
  }
  body {
    background: #fff;
    color: #000;
    padding: 0;
    font-size: 10pt;
  }
  /* 强制展开所有折叠 */
  .data-table-wrap {
    max-height: none;
    overflow: visible;
    border: 1px solid #ccc;
    page-break-inside: auto;
  }
  .data-table {
    page-break-inside: auto;
  }
  .data-table tr {
    page-break-inside: avoid;
  }
  .card {
    box-shadow: none;
    border: 1px solid #ccc;
    page-break-inside: avoid;
    margin-bottom: 8px;
  }
  /* 隐藏账户卡 (没数据时) 和 K 线 / 时间线 / 事件流 等动态图 */
  section.block { margin-top: 12pt; }
  h2.section-title { font-size: 12pt; }
  /* 让 link 不显示下划线虚线 */
  .link {
    color: #000;
    border-bottom: 0;
    text-decoration: none;
  }
}

/* ---------- 按钮 ---------- */
button {
  padding: var(--space-1) var(--space-3);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: var(--fs-sm);
  font-family: inherit;
  transition: background var(--transition-fast), border-color var(--transition-fast);
}
button:hover { background: var(--surface-2); }
button:active { transform: translateY(1px); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}
button.primary:hover { background: var(--brand-hover); }
button.danger {
  color: var(--bad);
  border-color: var(--bad-soft);
}
button.danger:hover { background: var(--bad-soft); }
button.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}
button.ghost:hover { background: var(--surface-2); color: var(--text); }

/* ---------- 链接 ---------- */
.link {
  color: var(--brand);
  text-decoration: none;
  font-size: var(--fs-xs);
  border-bottom: 1px dashed var(--brand-soft);
}
.link:hover { border-bottom-color: var(--brand); }

/* ---------- Select / Input ---------- */
select, input[type="text"], input[type="search"] {
  font-family: inherit;
  font-size: var(--fs-sm);
  padding: 3px var(--space-2);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  outline: none;
}
select:focus, input:focus { border-color: var(--brand); }
label.field {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--fs-sm);
  color: var(--text-muted);
}

/* ---------- Toast ---------- */
.toast-stack {
  position: fixed;
  top: var(--space-4);
  right: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  z-index: 9999;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  min-width: 220px;
  max-width: 360px;
  padding: var(--space-3) var(--space-4);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-left: 3px solid var(--brand);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  font-size: var(--fs-sm);
  animation: toast-in var(--transition);
}
.toast.toast-ok   { border-left-color: var(--ok); }
.toast.toast-warn { border-left-color: var(--warn); }
.toast.toast-bad  { border-left-color: var(--bad); }
.toast .toast-actions {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-2);
  justify-content: flex-end;
}
.toast.leaving { animation: toast-out var(--transition) forwards; }
@keyframes toast-in {
  from { transform: translateX(20px); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}
@keyframes toast-out {
  to { transform: translateX(20px); opacity: 0; }
}

/* ---------- 主题切换按钮 ---------- */
.theme-toggle {
  width: 28px; height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
}
.theme-toggle:hover { color: var(--text); background: var(--surface-2); }
.theme-toggle svg { width: 14px; height: 14px; }

/* ---------- 紧凑模式 ---------- */
:root[data-density="compact"] body { font-size: 12px; }
:root[data-density="compact"] .card { padding: var(--space-3); }
:root[data-density="compact"] .stat { font-size: var(--fs-xl); }
:root[data-density="compact"] .data-table th,
:root[data-density="compact"] .data-table td { padding: 4px var(--space-2); }

/* ---------- Utility ---------- */
.flex { display: flex; }
.flex-gap-2 { gap: var(--space-2); }
.flex-gap-3 { gap: var(--space-3); }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.text-right { text-align: right; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
.dot {
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* ---------- price-card 自定义元素 ---------- */
price-card {
  display: block;
}
.price-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3);
  transition: background var(--transition-fast), border-color var(--transition-fast);
}
.price-card.flash-up   { background: var(--up-soft);   border-color: var(--up); }
.price-card.flash-down { background: var(--down-soft); border-color: var(--down); }
.price-card .sym {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  font-weight: 600;
  letter-spacing: 0.04em;
  margin-bottom: var(--space-1);
}
.price-card .px {
  font-size: var(--fs-lg);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.price-card .chg {
  font-size: var(--fs-xs);
  font-variant-numeric: tabular-nums;
  margin-top: var(--space-1);
}
.price-card .arrow {
  display: inline-block;
  width: 0; height: 0;
  margin-right: 4px;
  vertical-align: middle;
}
.price-card .arrow.up   { border-left: 4px solid transparent; border-right: 4px solid transparent; border-bottom: 5px solid var(--up); }
.price-card .arrow.down { border-left: 4px solid transparent; border-right: 4px solid transparent; border-top:    5px solid var(--down); }

/* ---------- kline-chart 自定义元素 ---------- */
kline-chart {
  display: block;
  width: 100%;
  min-height: 320px;
}

/* ---------- event-stream 自定义元素 ---------- */
event-stream {
  display: block;
  max-height: 320px;
  overflow: auto;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: var(--fs-xs);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-2);
}
event-stream .ev {
  padding: 2px var(--space-2);
  border-bottom: 1px dashed var(--border);
  display: flex;
  gap: var(--space-3);
}
event-stream .ev:last-child { border-bottom: 0; }
event-stream .ev .t { color: var(--text-faint); flex-shrink: 0; }
event-stream .ev .topic { font-weight: 600; min-width: 50px; }
event-stream .ev .topic-signal { color: var(--info-ink); }
event-stream .ev .topic-order  { color: var(--warn-ink); }
event-stream .ev .topic-trade  { color: var(--ok-ink); }

/* ============================================================
 * v9: Market 页 (行情独立页) 样式
 * - topbar nav 链接
 * - 主力合约表格
 * - 按交易所分组的合约目录折叠区
 * ============================================================ */
.topbar-nav {
  display: inline-flex;
  gap: var(--space-2);
  margin-left: var(--space-3);
  vertical-align: middle;
}
.nav-link {
  display: inline-block;
  padding: 2px 10px;
  font-size: var(--fs-xs);
  color: var(--text-faint);
  text-decoration: none;
  border: 1px solid transparent;
  border-radius: var(--radius);
  transition: all .15s ease;
}
.nav-link:hover {
  color: var(--text);
  background: var(--surface-2);
}
.nav-link.active {
  color: var(--accent-ink, #fff);
  background: var(--accent, #2563eb);
  border-color: var(--accent, #2563eb);
  font-weight: 600;
}

/* 主力合约表格 */
.main-contracts-table th,
.main-contracts-table td { padding: 6px 10px; }
.main-contracts-table td.num,
.main-contracts-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.main-contracts-table tbody tr:hover { background: var(--surface-2); }
.main-contracts-table td.product,
.main-contracts-table td.symbol,
.main-contracts-table td.exchange { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
.main-contracts-table .empty-row td { color: var(--text-faint); text-align: center; padding: 20px; }
.main-contracts-table .up { color: var(--up, #ef4444); }
.main-contracts-table .down { color: var(--down, #16a34a); }

/* 交易所目录折叠区 */
.exchange-section {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: var(--space-2);
  background: var(--surface);
}
.exchange-section > summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
  padding: var(--space-2) var(--space-3);
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}
.exchange-section > summary::-webkit-details-marker { display: none; }
.exchange-section > summary::before {
  content: "▶";
  display: inline-block;
  transition: transform .15s ease;
  margin-right: var(--space-2);
  color: var(--text-faint);
  font-size: 10px;
}
.exchange-section[open] > summary::before { transform: rotate(90deg); }
.exchange-section > summary:hover { background: var(--surface-2); }
.exchange-section[open] > summary { border-bottom: 1px solid var(--border); }

.exchange-stats {
  display: flex;
  gap: var(--space-3);
  font-size: var(--fs-xs);
  color: var(--text-faint);
  font-weight: 400;
}
.exchange-stats .badge {
  background: var(--surface-2);
  padding: 1px 8px;
  border-radius: var(--radius);
  font-weight: 600;
}

.product-group {
  margin: 0;
  padding: var(--space-2) var(--space-3);
  border-top: 1px solid var(--border);
}
.product-group + .product-group { border-top: 0; }
.product-group-head {
  font-size: var(--fs-xs);
  color: var(--text-faint);
  font-weight: 600;
  margin-bottom: var(--space-1);
  display: flex;
  gap: var(--space-3);
  align-items: center;
}
.product-group-head .product-name { color: var(--text); font-size: var(--fs-sm); }
.product-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-xs);
  font-variant-numeric: tabular-nums;
}
.product-table th,
.product-table td {
  padding: 3px 8px;
  text-align: right;
  border-bottom: 1px dashed var(--border);
}
.product-table th:first-child,
.product-table td:first-child { text-align: left; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
.product-table tr:hover td { background: var(--surface-2); }
.product-table tr.is-main td {
  background: color-mix(in srgb, var(--warn-soft, #fde68a) 35%, transparent);
  font-weight: 600;
}
.main-badge {
  display: inline-block;
  background: var(--warn-soft, #fde68a);
  color: var(--warn-ink, #92400e);
  font-size: 10px;
  padding: 1px 6px;
  border-radius: var(--radius);
  margin-left: var(--space-1);
  font-weight: 700;
}
event-stream .ev .topic-risk   { color: var(--bad-ink); }