/* ============ 主题变量 ============ */
:root[data-theme="dark"] {
  --bg: #0a0d13;
  --panel: #121722;
  --panel-2: #171d2b;
  --border: #232a3a;
  --text: #e6edf7;
  --muted: #8792a6;
  --gold: #3b82f6;
  --stock: #a855f7;
  --up: #ff4d4f;      /* 涨 → 红 */
  --down: #12b886;    /* 跌 → 绿 */
  --grid: #1c2434;
  --warn: #f0a020;
  --shadow: 0 6px 24px rgba(0, 0, 0, .35);
}
:root[data-theme="light"] {
  --bg: #f3f5f9;
  --panel: #ffffff;
  --panel-2: #f7f9fc;
  --border: #e2e8f0;
  --text: #16202f;
  --muted: #64748b;
  --gold: #2563eb;
  --stock: #9333ea;
  --up: #e0303a;
  --down: #0f9d58;
  --grid: #edf1f7;
  --warn: #d97706;
  --shadow: 0 4px 18px rgba(16, 32, 64, .08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

body { padding-bottom: 40px; }
main { max-width: 1180px; margin: 0 auto; padding: 0 20px; }

/* ============ 顶栏 ============ */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
  max-width: 1180px; margin: 0 auto;
  padding: 16px 20px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  margin-bottom: 22px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 19px; margin: 0; font-weight: 700; letter-spacing: .2px; }
.brand h1 em { color: var(--muted); font-style: normal; margin: 0 2px; }
.brand .tag {
  font-size: 11px; color: var(--muted);
  border: 1px solid var(--border); border-radius: 20px; padding: 2px 9px;
}
.dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--down);
  box-shadow: 0 0 0 0 currentColor; animation: pulse 2s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(18, 184, 134, .55); }
  70% { box-shadow: 0 0 0 8px rgba(18, 184, 134, 0); }
  100% { box-shadow: 0 0 0 0 rgba(18, 184, 134, 0); }
}

.toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.status { font-size: 12px; color: var(--muted); min-width: 130px; text-align: right; }
.status.live { color: var(--down); }
.status.warn { color: var(--warn); }

.switch { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); cursor: pointer; user-select: none; }
.switch input { accent-color: var(--gold); }

.btn {
  font: inherit; font-size: 12px;
  padding: 6px 14px; border-radius: 8px; cursor: pointer;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border);
  transition: .15s;
}
.btn:hover { border-color: var(--gold); color: var(--gold); }
.btn.ghost { background: transparent; }

/* ============ 卡片 ============ */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

/* ============ 现价对比 ============ */
.pairs {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: stretch;
  gap: 0;
  margin-bottom: 16px;
}
.vs {
  display: flex; align-items: center; justify-content: center;
  padding: 0 18px; color: var(--muted);
  font-weight: 700; font-size: 12px; letter-spacing: 1px;
}
.quote { padding: 20px 22px; position: relative; overflow: hidden; }
.quote::before {
  content: ""; position: absolute; inset: 0 auto 0 0; width: 3px;
}
.quote[data-key="gold"]::before { background: var(--gold); }
.quote[data-key="stock"]::before { background: var(--stock); }

.q-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 12px; }
.q-name { font-size: 16px; font-weight: 700; }
.q-code { font-size: 11px; color: var(--muted); letter-spacing: .6px; }

.q-price { display: flex; align-items: baseline; gap: 8px; }
.q-price .num {
  font-size: 42px; font-weight: 700; line-height: 1.05;
  font-variant-numeric: tabular-nums; letter-spacing: -1px;
}
.q-price .unit { font-size: 12px; color: var(--muted); }

.q-chg { display: flex; align-items: center; gap: 12px; margin: 8px 0 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
.q-chg .abs { font-size: 16px; }
.q-chg .pct { font-size: 14px; padding: 2px 8px; border-radius: 6px; background: color-mix(in srgb, currentColor 14%, transparent); }

.up { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--muted); }

.q-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px;
  padding-top: 14px; border-top: 1px solid var(--border);
}
.q-grid div { display: flex; flex-direction: column; gap: 4px; }
.q-grid label { font-size: 11px; color: var(--muted); }
.q-grid b { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }

.q-foot { margin-top: 12px; font-size: 11px; color: var(--muted); display: flex; justify-content: space-between; }

/* ============ 速览条 ============ */
.strip {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 0; margin-bottom: 16px; overflow: hidden;
}
.strip-item { padding: 16px 20px; border-right: 1px solid var(--border); }
.strip-item:last-child { border-right: 0; }
.strip-item label { display: block; font-size: 11px; color: var(--muted); margin-bottom: 6px; }
.strip-item .big { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; display: block; }
.strip-item .hint { font-size: 11px; color: var(--muted); }

/* ============ 图表 ============ */
.chart-card { padding: 18px 20px 20px; margin-bottom: 16px; }
.chart-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 14px;
}
.chart-head h2 { font-size: 15px; margin: 0; font-weight: 700; }
.chart-head h2 small { font-weight: 400; font-size: 11px; color: var(--muted); margin-left: 8px; }

.ranges { display: flex; gap: 4px; background: var(--panel-2); padding: 3px; border-radius: 9px; border: 1px solid var(--border); }
.ranges button {
  font: inherit; font-size: 12px; padding: 5px 14px; border: 0; border-radius: 7px;
  background: transparent; color: var(--muted); cursor: pointer; transition: .15s;
}
.ranges button:hover { color: var(--text); }
.ranges button.on { background: var(--gold); color: #fff; }

.legend { display: flex; gap: 18px; font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.legend span { display: flex; align-items: center; gap: 6px; }
.legend i { width: 16px; height: 3px; border-radius: 2px; display: inline-block; }
.legend i.box { height: 11px; width: 16px; background: color-mix(in srgb, var(--up) 22%, transparent); border: 1px dashed var(--up); border-radius: 3px; }
.legend i.candle {
  width: 16px; height: 12px; border-radius: 2px;
  background: linear-gradient(90deg, var(--up) 0 46%, transparent 46% 54%, var(--down) 54% 100%);
}
.legend i.line-gold { background: var(--gold); }
.legend .align-info { margin-left: auto; color: var(--warn); }
.legend .align-info b { font-variant-numeric: tabular-nums; }

.canvas-wrap { position: relative; width: 100%; height: 380px; }
.canvas-wrap.short { height: 200px; }
canvas { width: 100%; height: 100%; display: block; }

.tip {
  position: absolute; pointer-events: none; opacity: 0; transition: opacity .12s;
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 9px; padding: 9px 12px; font-size: 12px; line-height: 1.7;
  box-shadow: var(--shadow); white-space: nowrap; z-index: 5;
  font-variant-numeric: tabular-nums;
}
.tip.on { opacity: 1; }
.tip b { font-weight: 600; }
.tip .row { display: flex; justify-content: space-between; gap: 16px; }
.tip .k { color: var(--muted); }

/* ============ 表格 ============ */
.table-card { padding: 18px 20px 20px; margin-bottom: 16px; }
table.stats { width: 100%; border-collapse: collapse; font-size: 13px; }
table.stats th {
  text-align: right; font-weight: 600; font-size: 11px; color: var(--muted);
  padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.stats th:first-child, table.stats th:last-child { text-align: left; }
table.stats td {
  padding: 11px 10px; border-bottom: 1px solid var(--grid);
  text-align: right; font-variant-numeric: tabular-nums;
}
table.stats td:first-child { text-align: left; font-weight: 500; }
table.stats td:last-child { text-align: left; color: var(--muted); font-size: 12px; font-variant-numeric: normal; }
table.stats tr:last-child td { border-bottom: 0; }
.empty { text-align: center !important; color: var(--muted); padding: 24px 0 !important; }

/* ============ 背离列表 ============ */
.div-list { display: flex; flex-direction: column; gap: 8px; }
.tag-warn {
  display: inline-block; font-size: 10px; font-weight: 500;
  color: var(--warn); border: 1px solid var(--warn);
  border-radius: 4px; padding: 0 4px; margin-left: 4px;
  vertical-align: 1px;
}
.reunite-summary {
  display: flex; gap: 18px; flex-wrap: wrap;
  font-size: 12px; color: var(--muted);
}
.reunite-summary b { color: var(--text); font-variant-numeric: tabular-nums; }

.div-row .idx {
  display: inline-flex; align-items: center; justify-content: center;
  width: 17px; height: 17px; border-radius: 5px;
  font-size: 11px; font-weight: 700; color: #fff;
  margin-right: 4px; vertical-align: -3px;
}
.div-row {
  display: grid; grid-template-columns: 212px 100px 1fr 110px;
  align-items: center; gap: 14px;
  padding: 11px 14px; border-radius: 10px;
  background: var(--panel-2); border: 1px solid var(--border);
  font-size: 12.5px; font-variant-numeric: tabular-nums;
}
.div-row .dir { font-weight: 600; }
.div-row .bar { height: 6px; border-radius: 3px; background: var(--grid); overflow: hidden; }
.div-row .bar i { display: block; height: 100%; border-radius: 3px; }
.div-row .desc { color: var(--muted); font-size: 12px; }

.foot {
  display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  font-size: 11.5px; color: var(--muted); padding: 8px 2px 0;
}

/* ============ 响应式 ============ */
@media (max-width: 900px) {
  .pairs { grid-template-columns: 1fr; }
  .vs { padding: 10px 0; }
  .strip { grid-template-columns: repeat(2, 1fr); }
  .strip-item:nth-child(2) { border-right: 0; }
  .strip-item:nth-child(1), .strip-item:nth-child(2) { border-bottom: 1px solid var(--border); }
  .q-price .num { font-size: 36px; }
  .div-row { grid-template-columns: 1fr; gap: 6px; }
  .status { text-align: left; }
}
@media (max-width: 560px) {
  main { padding: 0 12px; }
  .topbar { padding: 12px; }
  .q-grid { grid-template-columns: repeat(2, 1fr); }
  .canvas-wrap { height: 300px; }
}
