:root {
  --page: #eaf8fb; --surface: #ffffff; --soft: #cceff4; --ink: #102f3b; --muted: #4d6973; --line: #7fa4ad;
  --accent: #006d83; --accent-ink: #ffffff; --danger: #9d3044; --warn: #7a5600; --selected: #fff0c7;
  /* Validated diverging poles (dataviz reference: blue↔red, gray midpoint) and chart chrome. */
  --pos: #2a78d6; --neg: #e34948; --neutral: #f0efec; --series: #2a78d6; --fit: #52514e;
  --grid: #e1e0d9; --axis: #c3c2b7;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --page: #10251f; --surface: #182f27; --soft: #244239; --ink: #edf6ea; --muted: #aec6bb; --line: #587c6e;
    --accent: #7bd4b8; --accent-ink: #0b1c17; --danger: #ff9bab; --warn: #f2d27a; --selected: #4c492d;
    --pos: #3987e5; --neg: #e66767; --neutral: #383835; --series: #3987e5; --fit: #c3c2b7;
    --grid: #2c3f37; --axis: #4a5f56;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--page); color: var(--ink); font: 14px/1.45 ui-rounded, "SF Pro Rounded", "Segoe UI", system-ui, sans-serif; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 7px 14px; border-bottom: 1px solid var(--line); background: var(--soft); color: var(--ink); }
.top strong { font-size: 15px; }
.gate { max-width: 420px; margin: 48px auto; padding: 20px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink); }
#app { max-width: 1400px; margin: 0 auto; padding: 10px 12px 24px; }
.app-root { display: grid; gap: 10px; }
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; }
.controls label { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-weight: 600; font-size: 13px; }
select, input { padding: 5px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); font: inherit; }
.filter input { width: 170px; }
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.segmented button { padding: 5px 10px; border: 0; border-right: 1px solid var(--line); background: var(--surface); color: var(--ink); font: 600 13px/1.2 inherit; cursor: pointer; }
.segmented button:last-child { border-right: 0; }
.segmented button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
button { font-family: inherit; }
button:focus-visible, select:focus-visible, input:focus-visible, tr:focus-visible, .hit:focus-visible, .overlay:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.error > button { margin-left: 6px; padding: 3px 9px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); cursor: pointer; }
.muted { color: var(--muted); font-weight: 400; }
.note, .error { margin: 0; }
.note { color: var(--muted); }
.error { color: var(--danger); }
.workspace { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(360px, 0.95fr); gap: 12px; align-items: start; }
@media (max-width: 900px) { .workspace { grid-template-columns: 1fr; } }
.panel { position: relative; min-width: 0; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink); }
.stale { opacity: 0.6; transition: opacity 0.15s; }
.table-wrap { max-height: calc(100vh - 150px); overflow: auto; border-radius: 10px; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
caption { padding: 8px 10px; caption-side: top; text-align: left; color: var(--muted); font-size: 12px; }
caption strong { color: var(--ink); }
th, td { padding: 4px 8px; border-bottom: 1px solid var(--grid); text-align: left; white-space: nowrap; }
thead th { position: sticky; top: 0; z-index: 1; background: var(--surface); color: var(--muted); font-size: 12px; border-bottom: 1px solid var(--line); }
tbody th { max-width: 260px; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
tbody tr { cursor: pointer; }
tbody tr:hover th, tbody tr:hover td.n { background: color-mix(in srgb, var(--soft) 55%, transparent); }
tbody tr.selected th, tbody tr.selected td.n { background: var(--selected); }
td.r { min-width: 64px; border-left: 2px solid var(--surface); border-right: 2px solid var(--surface); }
td.thin { color: var(--muted); }
td.n { color: var(--muted); font-size: 12px; }
.num { text-align: right; }
.tag { margin-left: 6px; padding: 0 5px; border: 1px solid var(--line); border-radius: 6px; color: var(--muted); font-size: 11px; font-weight: 600; }
.empty { padding: 14px 10px; color: var(--muted); }
.detail { padding: 10px 12px 12px; }
.detail-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
h2 { margin: 0; font-size: 15px; }
h3 { margin: 12px 0 2px; font-size: 13px; }
.stat { margin: 6px 0; }
.warn { color: var(--warn); font-weight: 600; }
.chart { display: block; width: 100%; height: auto; overflow: visible; touch-action: pan-y; }
.grid line { stroke: var(--grid); stroke-width: 1; }
.baseline { stroke: var(--axis); stroke-width: 1; }
.axis-labels text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.fit { stroke: var(--fit); stroke-width: 2; stroke-linecap: round; }
.dot { fill: var(--series); stroke: var(--surface); stroke-width: 2; }
.hit { fill: transparent; cursor: default; }
.line { fill: none; stroke: var(--series); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.crosshair { stroke: var(--muted); stroke-width: 1; }
.overlay { fill: transparent; }
.tooltip { position: absolute; z-index: 5; min-width: 150px; max-width: 220px; padding: 6px 9px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18); pointer-events: none; font-size: 12px; }
.tip-title { color: var(--muted); margin-bottom: 2px; }
.tip-row strong { font-variant-numeric: tabular-nums; }
.tip-row span { color: var(--muted); }
