/* ============================================================================
   指数比对 · 全局样式（原生 CSS，零构建）
   ----------------------------------------------------------------------------
   组织方式：
     1. 设计令牌（颜色、字号、尺寸）—— 深色模式只覆盖令牌，组件规则不重复写
     2. 布局骨架（顶栏 / 页面容器 / 卡片）
     3. 指数页组件（概览卡、横条、脉冲）
     4. 竞价页占位（B8 填写，只保留共用变量）
     5. 响应式：≥1280 桌面 / 768–1279 平板 / <768 手机
   ----------------------------------------------------------------------------
   两条必须守住的规则（需求 5.1）：
     · 条区宽度用百分比，靠 CSS transition 动，不用 canvas、不用逐帧 JS 计算
     · 数字一律 tabular-nums —— 否则每秒刷新时数字左右跳动，看着像在抖
   ========================================================================== */

/* ── 1. 设计令牌 ─────────────────────────────────────────────────────────── */
:root {
  /* 吸顶状态栏的实测高度：auction.css 的 sticky 表头要按它下移，
     否则表头会停在 top:0 被状态栏（z-index 更高）整块盖住。
     auction.js 启动时用 offsetHeight 覆盖成真实值。 */
  --topbar-h: 48px;
  /* 页面 */
  --bg: #f3f4f6;
  --card: #ffffff;
  --fg: #111827;
  --fg-soft: #374151;
  --muted: #6b7280;
  --line: #e5e7eb;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);

  /* 语义色（A 股习惯：涨红跌绿） */
  --up: #e53935;
  --down: #43a047;
  --accent: #0b6bcb;      /* 今日：亮色 */
  --warm: #d97706;        /* 最大日：暖色 */
  --cool: #0284c7;        /* 最小日：冷色 */
  --neutral: #94a3b8;     /* 昨日：中性灰 */

  /* 尺寸 */
  --radius: 12px;
  --row-h: 40px;          /* 桌面行高；手机 44px（需求 6.4） */
  --bar-h: 18px;

  --pulse-h: 56px;
  --pulse-count-max: 40;

  --num-font: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
}

/* 深色：只换令牌，组件规则一份都不重写 —— 少一套规则就少一处漏改 */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --card: #171a21;
    --fg: #e8eaed;
    --fg-soft: #c4cad3;
    --muted: #9aa3af;
    --line: #262b36;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --up: #ff5c57;
    --down: #4ade80;
    --accent: #4c9aff;
    --warm: #ffa94d;
    --cool: #4dc9ff;
    --neutral: #6b7280;
  }
}

/* ── 2. 布局骨架 ─────────────────────────────────────────────────────────── */
* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  /* 16px 起步：iOS 上小于 16px 的输入框聚焦会放大页面（需求 6.4） */
  font-size: 16px;
  font-family: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  min-height: 100dvh;               /* 手机地址栏伸缩时 100vh 会抖，用 dvh */
  padding-bottom: env(safe-area-inset-bottom);
}

.num { font-variant-numeric: tabular-nums; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 16px;
  padding-top: calc(8px + env(safe-area-inset-top));
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.tabs { display: flex; gap: 4px; }

.tab {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 14px;
  border-radius: 999px;
  color: var(--muted);
  text-decoration: none;
  font-size: 15px;
  /* 44×44 触控目标靠 min-height + padding 达成（需求 6.4） */
}

.tab:hover { background: color-mix(in srgb, var(--fg) 6%, transparent); }

.tab.is-active {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent);
  font-weight: 600;
}

.status {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.status .sep { opacity: .45; }

/* 窄屏（手机）：顶栏三项（标签 / 状态 / 账号）一行放不下，允许换行；
   状态条整条占一行、从左边排，既不遮挡账号按钮，也不会把"截至"截掉。 */
@media (max-width: 767px) {
  .topbar { flex-wrap: wrap; row-gap: 4px; }
  .status { width: 100%; margin-left: 0; justify-content: flex-start; flex-wrap: wrap; }
  /* 账号 chip 单独占一行并靠右：与状态条挤在同一行时，"登出"会被裁掉半个 */
  .auth-chip { width: 100%; justify-content: flex-end; }
}

/* 连接状态点：颜色 + 文字双通道，不靠颜色单独表意 */
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  flex: none;
}
.dot[data-state="live"] { background: var(--down); box-shadow: 0 0 0 3px color-mix(in srgb, var(--down) 22%, transparent); }
.dot[data-state="stale"] { background: var(--warm); }
/* idle：等待数据 / 已收盘 —— 中性灰，不闪。它表示"没有新东西"，不是故障。 */
.dot[data-state="idle"] { background: var(--muted); }
.dot[data-state="down"] { background: var(--up); }
.dot[data-state="connecting"] { background: var(--muted); animation: blink 1.1s ease-in-out infinite; }

@keyframes blink { 50% { opacity: .25; } }

.page {
  max-width: 1400px;                 /* 需求 5.5：内容最大 1400px 居中 */
  margin: 0 auto;
  padding: 12px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 14px;
}

/* ── 四格（桌面 ≥1100px）───────────────────────────────────────────────
   四格不是四张"卡片"叠在一起，而是一屏放四个可比的画面：
   每格自带下拉（左上格固定 = 两市合计）、四个数字、5 行对比条、28 根脉冲。
   窄屏回到单格（.grid 变一列，其余三格由 JS 置 hidden），行为与四格之前一致。 */
.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  align-items: start;
}

.cell {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  min-width: 0;                      /* 允许内部长数字收缩，否则两列会互相挤 */
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* 固定格角标：告诉用户"这格不能切"，比一个灰掉的下拉更清楚 */
.fixed-tag {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 2px 6px;
  font-size: 12px;
  color: var(--muted);
}

.pulse-block { display: flex; flex-direction: column; gap: 6px; }

/* 该日此刻没有数据（quality=missing）：柱子只留一条淡占位，
   金额与百分比由 JS 写成「—」，避免"0 高柱 + 0%"被读成"那天成交额为 0"。 */
.vcol.is-missing .vbar {
  background: color-mix(in srgb, var(--muted) 35%, transparent);
  border: 1px dashed color-mix(in srgb, var(--muted) 55%, transparent);
}
.vcol.is-missing .vval { color: var(--muted); }

/* hidden 属性在「作者写了 display:flex」时会失效（display 覆盖 UA 的 [hidden]{display:none}），
   窄屏靠 JS 给其余三格加 hidden —— 没有这一条手机上会多出三张空卡。 */
.cell[hidden] { display: none; }

@media (max-width: 1099px) {
  .grid { grid-template-columns: minmax(0, 1fr); }
}


.muted { color: var(--muted); }
.empty { color: var(--muted); text-align: center; padding: 24px 0; margin: 0; }

/* ── 3. 指数页：概览卡 ───────────────────────────────────────────────────── */
.ov-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.ov-id { display: flex; align-items: center; gap: 10px; }

.picker {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--fg);
  border-radius: 8px;
  padding: 8px 30px 8px 10px;
  font-size: 16px;
  max-width: 60vw;
  /* 自绘下拉箭头：默认箭头在深色模式下几乎看不见 */
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
                    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) 52%, calc(100% - 11px) 52%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.ov-code { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }

.ov-quote { display: flex; align-items: baseline; gap: 10px; }

.point {
  font-size: 30px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.5px;
}

.chg { font-size: 16px; font-variant-numeric: tabular-nums; }
.chg.up { color: var(--up); }
.chg.down { color: var(--down); }
.chg.flat { color: var(--muted); }

.ov-stats {
  display: flex;
  gap: 28px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.stat { display: flex; flex-direction: column; gap: 2px; }
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 18px; font-weight: 600; }

.winbox { margin-top: 10px; border-top: 1px dashed var(--line); padding-top: 8px; }
.winbox > summary {
  cursor: pointer;
  font-size: 13px;
  color: var(--muted);
  list-style: none;
}
.winbox > summary::-webkit-details-marker { display: none; }
.winbox > summary::before { content: "▸ "; }
.winbox[open] > summary::before { content: "▾ "; }

.winlist {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
}

.winlist li {
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.winlist li.ok { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
/* 窗口不成立就显示「—」，不加"样本 N 天"之类的话（需求 5.1 规则 12） */
.winlist li.no { opacity: .7; }

/* 窗口成立性（顶栏，排在连接状态之前）：7 个小胶囊，成立=强调色、不成立=灰 */
.winbar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.wchip {
  font-size: 12px;
  line-height: 1.6;
  padding: 0 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  background: color-mix(in srgb, var(--fg) 4%, transparent);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.wchip.ok {
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

@media (max-width: 767px) {
  /* 手机上顶栏项多（标签/窗口/状态/账号），一行放不下；
     窗口胶囊改成"横向滚动单行"，不再换行占两行高度。 */
  .winbar {
    width: 100%;
    /* 关键：flex 项默认 min-width:auto，nowrap 的胶囊行会按"内容宽度"把顶栏撑宽
       （实测 492px 视口里顶栏被撑到 732px，右侧「截至」直接跑到屏幕外）。
       必须显式给 min-width:0 + max-width:100%，overlay 滚动才会生效。 */
    min-width: 0;
    max-width: 100%;
    flex: 1 1 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .winbar::-webkit-scrollbar { display: none; }
  .wchip { font-size: 11px; padding: 0 6px; }
}

/* ── 3.1 对比柱（竖向） ────────────────────────────────────────────────────
   用户 2026-11-20 裁决：对比条改竖柱、所有对比日都画、金额从高到低左→右、
   每次数据更新重排、今日高亮、不要动画。旧的横排 .bar-row 规则保留但已无调用点。 */
.barlist {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  align-items: stretch;
  justify-content: flex-start;
  gap: 8px;
  height: 168px;
  padding-top: 4px;
}

.vcol {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  border-radius: 8px;
  padding: 2px 2px 0;
}

/* 今日：淡蓝底 + 蓝柱；这是"今日那根"的提示（用户认可，不需再加其他标记） */
.vcol[data-kind="today"] {
  background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 10%, transparent), transparent 72%);
}
.vcol.is-overtaken { animation: overtakeGlow 1.2s ease-out 2; }

.vflag {
  font-size: 10px;
  line-height: 1.2;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
}

.vval {
  font-size: 11px;
  line-height: 1.3;
  height: 15px;                 /* 固定高度：不标的柱子也占位，标签才能对齐 */
  margin-top: 3px;              /* 与柱底留一点缝 */
  font-variant-numeric: tabular-nums;
  color: var(--fg-soft);
  white-space: nowrap;
  overflow: hidden;
}

.vtrack {
  flex: 1 1 auto;
  width: 100%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.vbar {
  width: 74%;
  max-width: 46px;
  min-height: 3px;
  border-radius: 4px 4px 0 0;
  background: color-mix(in srgb, var(--fg) 18%, transparent);
  /* 柱高变化不做动画：四格同时动会晃眼 */
}

.vcol[data-kind="today"] .vbar { background: var(--accent); }
.vcol[data-kind="yesterday"] .vbar { background: var(--neutral); }
.vcol[data-kind="max"] .vbar { background: var(--warm); }
.vcol[data-kind="min"] .vbar { background: var(--cool); }

.vlab {
  margin-top: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: 10px;
  line-height: 1.25;
  color: var(--muted);
  white-space: nowrap;
}
.vlab b { font-size: 10px; font-weight: 600; color: var(--fg-soft); max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.vlab i { font-style: normal; font-variant-numeric: tabular-nums; }
/* 超越状态行（每格恒有）：今日超昨日 = 红，落后 = 绿，与涨跌同色规则 */
.overtake-list li.ot-status { font-weight: 600; }
.overtake-list li.ot-status.up { color: var(--up); }
.overtake-list li.ot-status.down { color: var(--down); }
/* 第三行：相对今日的百分比（"量到今天的百分之多少"） */
.vlab u {
  font-style: normal;
  text-decoration: none;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  opacity: .95;
}
.vcol[data-kind="today"] .vlab b { color: var(--accent); font-weight: 700; }

/* 窄屏：柱子更宽、行高略降，仍保持竖排（用户裁决：手机端也这样改） */
@media (max-width: 767px) {
  .barlist { height: 148px; gap: 6px; }
  .vbar { width: 82%; max-width: 54px; }
}

/* ── 3.1b 横条（旧版，B7 起使用，2026-11-20 被竖柱取代，保留兼容） ────────── */
.bar-row {
  display: grid;
  /* 条区用 1fr 吃掉剩余宽度：这样最长的一条正好顶到右侧，归一化才看得出来 */
  /* 第一列放行标签：`昨日（5 日最小）` 这种合成标签最长，104px 会被截成「昨日（5 日最…」，
     用户就分不清它是"最大"还是"最小"了。132px 刚好放下 9 个中文字。 */
  grid-template-columns: 132px minmax(0, 1fr) 92px 56px 34px;
  align-items: center;
  gap: 10px;
  height: var(--row-h);
  border-radius: 8px;
  padding: 0 4px;
  /* 换位动画由 JS 写 transform + transition（FLIP），这里只兜底 */
  transition: transform 250ms cubic-bezier(.2, .7, .3, 1), background-color 250ms ease;
  will-change: transform;
}

.bar-row + .bar-row { border-top: 1px solid color-mix(in srgb, var(--line) 60%, transparent); }

.bar-label {
  font-size: 14px;
  color: var(--fg-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar-track {
  position: relative;
  height: var(--bar-h);
  border-radius: 4px;
  background: color-mix(in srgb, var(--fg) 7%, transparent);
  overflow: hidden;
}

.bar-fill {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 4px;
  background: var(--neutral);
  /* 条长变化用 width：百分比在窄屏更稳，scaleX 会把圆角拉变形 */
  transition: width 250ms cubic-bezier(.2, .7, .3, 1);
}

.bar-val {
  text-align: right;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  color: var(--fg);
  white-space: nowrap;
}

.bar-ratio {
  text-align: right;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  white-space: nowrap;
}

.bar-rank {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  text-align: right;
  white-space: nowrap;
}
.bar-rank .up { color: var(--up); }
.bar-rank .down { color: var(--down); }

/* 颜色语义（需求 5.1 规则 8）：今日亮色、昨日中性灰、最大日暖、最小日冷。
   只改 fill 的填充色，不整行染色 —— 整行染色会让 9 行看起来像霓虹灯。 */
.bar-row[data-kind="today"] .bar-fill { background: var(--accent); }
.bar-row[data-kind="yesterday"] .bar-fill { background: var(--neutral); }
.bar-row[data-kind="max"] .bar-fill { background: var(--warm); }
.bar-row[data-kind="min"] .bar-fill { background: var(--cool); }

/* 今日：加粗 + 高饱和 + 行首 ▶（需求 5.1 规则 5） */
.bar-row[data-kind="today"] {
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}
.bar-row[data-kind="today"] .bar-label {
  font-weight: 700;
  color: var(--accent);
}
.bar-row[data-kind="today"] .bar-label::before { content: "▶ "; }
.bar-row[data-kind="today"] .bar-val { font-weight: 700; }

/* 超越记录（需求 5.1 规则 10）：行短暂高亮 + 条区下方一行文字，不引入时间轴 */
.bar-row.is-overtaken {
  animation: overtakeGlow 1.2s ease-out 2;
}
@keyframes overtakeGlow {
  0% { background: color-mix(in srgb, var(--warm) 26%, transparent); }
  100% { background: transparent; }
}

.overtake-list {
  list-style: none;
  margin: 8px 0 0;
  padding: 8px 0 0;
  border-top: 1px dashed var(--line);
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  font-size: 12px;
  color: var(--warm);
}
.overtake-list li::before { content: "⚑ "; }

/* ── 3.2 脉冲 ────────────────────────────────────────────────────────────── */
.pulse-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 13px;
  color: var(--fg-soft);
  margin-bottom: 8px;
}
.pulse-head .muted { font-size: 12px; }

.pulse-bars {
  display: flex;
  align-items: flex-end;
  /* 从右往左排（最新一根贴右边），根数少时左侧留白，不会把单根拉成整条 */
  justify-content: flex-end;
  gap: 2px;
  height: var(--pulse-h);
}

.pulse-bar {
  /* 每根占固定 1/N 的槽位（N = --pulse-count-max，桌面 40 / 手机 24）。
     旧写法 flex:1 在"只有 1 根"时会把那一根拉满整行 ——
     开盘头两分钟每格都只有 1–2 根，看起来像图坏了（2026-11-20 创业板就是这样）。 */
  flex: 0 0 calc((100% - (var(--pulse-count-max) - 1) * 2px) / var(--pulse-count-max));
  min-width: 2px;
  background: var(--accent);
  border-radius: 2px 2px 0 0;
  /* 由 JS 只改 height；不再改别的属性，避免每帧重排整段 */
  transition: height 220ms ease;
  opacity: .9;
}
/* 增量 ≤0：标灰（可能是真没成交，也可能是累计额回退被钳零，见决策记录 B5/E-02） */
.pulse-bar.is-zero { background: var(--neutral); opacity: .55; }

/* 已知缺口（09:25–09:30 上游没有 3 秒级数据）：留白，不画 0 高柱。
   画成 0 高柱会让人以为"这段时间一笔成交都没有"，实际是"这段时间没有分时数据"。 */
.pulse-bar.is-gap { visibility: hidden; }

/* ── 4. 竞价页占位（B8 实现）─────────────────────────────────────────────── */
.placeholder { text-align: center; padding: 48px 16px; }
.placeholder h1 { font-size: 20px; margin: 0 0 8px; }
.placeholder p { color: var(--muted); margin: 0; }

/* ── 5. 响应式 ───────────────────────────────────────────────────────────── */

/* 平板：标签与数字列略收，行高不变 */
@media (max-width: 1279px) {
  .bar-row { grid-template-columns: 96px minmax(0, 1fr) 88px 52px 32px; }
}

/* 手机：行高 44px、条区 45%、脉冲 24 根（需求 6.4） */
@media (max-width: 767px) {
  :root {
    --row-h: 44px;
    --pulse-h: 24px;
    --pulse-count-max: 24;
  }

  .page { padding: 8px 12px 16px; gap: 8px; }
  .card { padding: 10px 12px; }

  .topbar { gap: 8px; padding: 6px 12px; padding-top: calc(6px + env(safe-area-inset-top)); }
  .status { font-size: 12px; gap: 4px; }
  /* 手机上保留「截至 hh:mm:ss」（需求 5.1 规则 9 的必备信息），
     省掉的是"延迟"那一格 —— 滞后量在手机上本来就看不出来，且「数据滞后」时状态点会变橙。 */
  #lagText, .status .sep:nth-of-type(1) { display: none; }

  .point { font-size: 24px; }
  .ov-stats { gap: 18px; margin-top: 8px; }
  .stat .v { font-size: 16px; }

  .bar-row {
    grid-template-columns: 78px minmax(0, 45%) minmax(0, 1fr) 32px;
    gap: 8px;
  }
  /* 手机去掉 ratio 列（比值在桌面看趋势用，小屏优先保数字） */
  .bar-ratio { display: none; }
  .bar-label { font-size: 13px; }
  .bar-val { font-size: 13px; }

  .winbox { margin-top: 6px; }
}

/* 尊重「减少动态效果」设置：不闪、不滑，直接定位 */
@media (prefers-reduced-motion: reduce) {
  .bar-row, .bar-fill, .pulse-bar { transition: none !important; }
  .bar-row.is-overtaken { animation: none; outline: 2px solid var(--warm); }
  .dot[data-state="connecting"] { animation: none; }
}
