:root {
  color-scheme: light;
  --paper: #f3f1ea;
  --card: #f8f7f2;
  --ink: #13221b;
  --muted: #636f69;
  --line: rgba(19, 34, 27, 0.14);
  --line-soft: rgba(19, 34, 27, 0.07);
  --accent: #147653;
  --accent-deep: #0e5f46;
  --accent-soft: #dce9df;
  --danger: #a44737;
  --warn: #8a6415;
  --mono: ui-monospace, "Cascadia Mono", "Consolas", "Noto Sans Mono", monospace;
  --serif: "Iowan Old Style", "Palatino Linotype", "Source Han Serif SC", "Songti SC", Georgia, serif;
  --sans: Inter, "Segoe UI Variable", "PingFang SC", "Microsoft YaHei UI", system-ui, sans-serif;
  --rail: 322px;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --paper: #111713;
    --card: #171e19;
    --ink: #edf2ed;
    --muted: #9ba9a1;
    --line: rgba(237, 242, 237, 0.15);
    --line-soft: rgba(237, 242, 237, 0.075);
    --accent: #66c89b;
    --accent-deep: #89dfb7;
    --accent-soft: #213c30;
    --danger: #ee9b88;
    --warn: #d9ab5c;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: var(--paper); }
body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background: var(--paper);
  font-family: var(--sans);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p { margin: 0; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 3px; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

.app-shell { width: 100%; min-height: 100svh; display: flex; flex-direction: column; }

/* ---- 顶栏 ---------------------------------------------------- */
.masthead {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 18px;
  height: 58px; padding: 0 22px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(10px);
}
.brand {
  display: inline-flex; align-items: center; gap: 10px;
  text-decoration: none; color: inherit;
  font-weight: 760; letter-spacing: -0.03em; font-size: 15px;
}
.brand-mark {
  width: 15px; aspect-ratio: 1;
  border: 1.5px solid var(--accent); border-radius: 50% 0 50% 50%; rotate: -35deg;
  box-shadow: inset 4px -4px 0 var(--accent-soft);
}
.masthead-context { color: var(--muted); font-size: 12.5px; }
.health { margin-left: auto; display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.health-dot { width: 7px; height: 7px; border-radius: 50%; background: #a6aca8; transition: background 200ms ease; }
.health.is-ok .health-dot { background: var(--accent); }
.health.is-error { color: var(--danger); }
.health.is-error .health-dot { background: var(--danger); }

/* ---- 骨架 ---------------------------------------------------- */
.workbench {
  flex: 1;
  display: grid;
  grid-template-columns: var(--rail) minmax(0, 1fr);
  align-items: start;
}

.rail {
  position: sticky; top: 58px;
  height: calc(100svh - 58px);
  border-right: 1px solid var(--line);
  overflow: hidden;
}
.rail-scroll { height: 100%; overflow-y: auto; padding: 22px 20px 60px; }
.rail-scroll::-webkit-scrollbar { width: 10px; }
.rail-scroll::-webkit-scrollbar-thumb { background: var(--line); border-radius: 10px; border: 3px solid var(--paper); }

.control-block { padding-bottom: 20px; margin-bottom: 20px; border-bottom: 1px solid var(--line-soft); }
.control-block:last-child { border-bottom: none; margin-bottom: 0; }
.control-block h2 {
  margin-bottom: 10px;
  font-size: 10.5px; font-weight: 760; letter-spacing: 0.13em; text-transform: uppercase;
  color: var(--muted);
}
.control-note { margin: -4px 0 10px; color: var(--muted); font-size: 11.5px; line-height: 1.6; }

/* ---- 分段控件 ------------------------------------------------ */
.segmented { display: flex; border: 1px solid var(--line); border-radius: 4px; overflow: hidden; }
.segmented.wrap { flex-wrap: wrap; }
.segmented button {
  flex: 1 1 auto; min-width: 0;
  padding: 7px 9px;
  border: none; background: transparent; cursor: pointer;
  font-size: 12.5px; font-weight: 600; color: var(--muted);
  white-space: nowrap;
  transition: background 140ms ease, color 140ms ease;
}
.segmented button + button { border-left: 1px solid var(--line); }
.segmented button:hover { background: var(--line-soft); color: var(--ink); }
.segmented button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent-deep); }
.segmented button i { font-style: normal; margin-left: 5px; opacity: 0.6; font-size: 11px; font-variant-numeric: tabular-nums; }
.segmented.small button { padding: 5px 9px; font-size: 11.5px; }

/* ---- chip ---------------------------------------------------- */
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
button.chip {
  padding: 5px 10px;
  border: 1px solid var(--line); border-radius: 100px; background: transparent;
  cursor: pointer; font-size: 12px; font-weight: 600; color: var(--muted);
  transition: border-color 140ms ease, background 140ms ease, color 140ms ease;
}
button.chip:hover { border-color: var(--muted); color: var(--ink); }
button.chip[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-deep); }
button.chip i { font-style: normal; margin-left: 5px; opacity: 0.55; font-size: 10.5px; font-variant-numeric: tabular-nums; }

button.linkish {
  padding: 0; border: none; background: none; cursor: pointer;
  color: var(--muted); font-size: 11px; text-decoration: underline; text-underline-offset: 3px;
}
button.linkish:hover { color: var(--accent-deep); }

.filter-group + .filter-group { margin-top: 14px; }
.filter-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
  margin-bottom: 7px;
  font-size: 11.5px; font-weight: 700; color: var(--ink);
}

/* ---- 开关 ---------------------------------------------------- */
.switch-row { margin-top: 12px; display: grid; gap: 11px; }
.switch { display: grid; grid-template-columns: auto 1fr; gap: 3px 9px; align-items: center; cursor: pointer; }
.switch input { grid-row: span 2; width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; }
.switch span { font-size: 12.5px; font-weight: 600; }
.switch small { grid-column: 2; color: var(--muted); font-size: 11px; }
.switch:has(input:disabled) { opacity: 0.45; cursor: not-allowed; }
.switch:has(input:disabled) input { cursor: not-allowed; }

select {
  width: 100%; padding: 7px 9px;
  border: 1px solid var(--line); border-radius: 4px;
  background: var(--card); color: var(--ink);
  font: inherit; font-size: 12.5px; cursor: pointer;
}
select:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---- 主舞台 -------------------------------------------------- */
.stage { padding: 26px clamp(20px, 3vw, 40px) 48px; min-width: 0; }
.stage-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 28px;
  flex-wrap: wrap;
  padding-bottom: 16px; border-bottom: 1px solid var(--line);
}
.eyebrow {
  color: var(--accent); font-size: 10px; font-weight: 760;
  letter-spacing: 0.16em; text-transform: uppercase;
}
.stage-title h1 {
  margin: 7px 0 6px;
  font-family: var(--serif); font-weight: 500;
  font-size: clamp(28px, 3vw, 40px); line-height: 1.06; letter-spacing: -0.035em;
}
.stage-sub { color: var(--muted); font-size: 12.5px; }

.legend { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; max-width: 620px; }
.legend-caption {
  margin-right: 3px; color: var(--muted);
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.08em;
}
.legend-item {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 4px 10px 4px 8px;
  border: 1px solid transparent; border-radius: 100px;
  background: transparent; cursor: pointer;
  font-size: 12px; font-weight: 600;
  transition: background 140ms ease, opacity 140ms ease;
}
.legend-item:hover { background: var(--line-soft); }
.legend-item[aria-pressed="true"] { border-color: var(--line); background: var(--card); }
.legend-item.is-off { opacity: 0.34; }
.legend-swatch { width: 16px; height: 3px; border-radius: 2px; background: var(--c); flex: none; }
.legend-swatch[data-dashed="true"] {
  background: repeating-linear-gradient(90deg, var(--c) 0 4px, transparent 4px 7px);
}

.chart-frame { position: relative; margin-top: 18px; }
.chart-host { width: 100%; height: 470px; overflow: hidden; }
.chart-empty {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  color: var(--muted); font-size: 13px;
}

/* ---- 读数表 -------------------------------------------------- */
.readout { margin-top: 26px; padding-top: 18px; border-top: 1px solid var(--line); }
.readout-head { display: flex; align-items: baseline; justify-content: space-between; gap: 18px; margin-bottom: 12px; }
.readout-head h2 {
  font-size: 10.5px; font-weight: 760; letter-spacing: 0.13em; text-transform: uppercase; color: var(--muted);
}
.readout-scroll { overflow-x: auto; }
.readout-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.readout-table th, .readout-table td { padding: 7px 12px; text-align: right; white-space: nowrap; }
.readout-table thead th {
  border-bottom: 1px solid var(--line);
  color: var(--muted); font-size: 11px; font-weight: 700;
}
.readout-table tbody th {
  text-align: left; font-weight: 600;
  display: flex; align-items: center; gap: 8px;
}
.readout-table tbody tr { border-bottom: 1px solid var(--line-soft); }
.readout-table tbody tr:hover { background: var(--line-soft); }
.readout-table tbody tr.is-dim { opacity: 0.34; }
.readout-table td { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 12px; }
.readout-dot { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.flag-badge {
  margin-left: 8px; padding: 1px 6px;
  border: 1px solid color-mix(in srgb, var(--warn) 45%, transparent);
  border-radius: 3px;
  color: var(--warn); font-size: 10px; font-weight: 700; white-space: nowrap;
  cursor: help;
}
.readout-note { margin-top: 11px; color: var(--muted); font-size: 11px; line-height: 1.7; }
.readout-note sub { font-size: 9px; }

/* ---- 页脚行 -------------------------------------------------- */
.stage-foot { margin-top: 22px; padding-top: 14px; border-top: 1px solid var(--line-soft); display: grid; gap: 6px; }
.provenance { color: var(--muted); font-size: 11.5px; line-height: 1.7; }
.quality { color: var(--warn); font-size: 11.5px; line-height: 1.7; }

/* ---- 窄屏 ---------------------------------------------------- */
@media (max-width: 1080px) {
  .workbench { grid-template-columns: 1fr; }
  .rail { position: static; height: auto; border-right: none; border-bottom: 1px solid var(--line); }
  .rail-scroll { height: auto; overflow: visible; padding: 18px 20px 24px; }
  .stage { padding: 22px 20px 40px; }
  .legend { max-width: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 1ms !important; animation-duration: 1ms !important; }
}
