:root {
  --bg: #f6f7f9; --surface: #ffffff; --surface-2: #f0f2f5; --border: #e2e5ea;
  --text: #1c2330; --muted: #657084; --accent: #2457d6; --accent-soft: #e6edfc;
  --g: #1b8a4b; --g-bg: #e3f5ea; --y: #a86a00; --y-bg: #fdf1d6; --r: #c22f2f; --r-bg: #fbe3e3;
  --radius: 10px; --shadow: 0 1px 2px rgba(20, 30, 50, .06);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12161d; --surface: #1a202a; --surface-2: #232b37; --border: #2d3745;
    --text: #e6eaf0; --muted: #94a0b4; --accent: #6b95ff; --accent-soft: #1f2d52;
    --g: #4cc27e; --g-bg: #153424; --y: #f0b64a; --y-bg: #3a2c10; --r: #ff7b7b; --r-bg: #401b1b;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #12161d; --surface: #1a202a; --surface-2: #232b37; --border: #2d3745;
  --text: #e6eaf0; --muted: #94a0b4; --accent: #6b95ff; --accent-soft: #1f2d52;
  --g: #4cc27e; --g-bg: #153424; --y: #f0b64a; --y-bg: #3a2c10; --r: #ff7b7b; --r-bg: #401b1b; --shadow: none;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
.wrap { max-width: 1280px; margin: 0 auto; padding: 0 16px 48px; }
header.top { padding: 18px 0 8px; display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: baseline; justify-content: space-between; }
header.top h1 { font-size: 20px; margin: 0; letter-spacing: -.01em; }
header.top .asof { color: var(--muted); font-size: 12.5px; }
.demo-banner { background: var(--y-bg); color: var(--y); border: 1px solid var(--y); border-radius: var(--radius); padding: 8px 12px; margin: 6px 0 10px; font-weight: 600; }
.note-banner { background: var(--accent-soft); color: var(--text); border-radius: var(--radius); padding: 8px 12px; margin: 8px 0; font-size: 13px; }

select, input[type=date] { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 7px; padding: 6px 8px; min-height: 34px; }

nav.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--border); margin-bottom: 14px; -webkit-overflow-scrolling: touch; }
nav.tabs button { background: none; border: 0; border-bottom: 2px solid transparent; color: var(--muted); font: inherit; font-weight: 600; padding: 10px 14px; cursor: pointer; white-space: nowrap; }
nav.tabs button:hover { color: var(--text); }
nav.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }

h2 { font-size: 16px; margin: 22px 0 10px; }
h3 { font-size: 14px; margin: 0 0 8px; }
.grid { display: grid; gap: 12px; }
.kpis { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.cols-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); min-width: 0; }
.kpi .label { color: var(--muted); font-size: 12px; }
.kpi .value { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin: 2px 0; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 12px; color: var(--muted); }
.kpi.g { border-left: 4px solid var(--g); } .kpi.y { border-left: 4px solid var(--y); } .kpi.r { border-left: 4px solid var(--r); }

.tablewrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { padding: 8px 10px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--border); }
th:first-child, td:first-child, td.l, th.l { text-align: left; }
th { background: var(--surface-2); color: var(--muted); font-size: 12px; font-weight: 600; position: sticky; top: 0; cursor: pointer; user-select: none; }
tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; } tr.click:hover td { background: var(--surface-2); }
td.sub { color: var(--muted); }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.pill.g { background: var(--g-bg); color: var(--g); } .pill.y { background: var(--y-bg); color: var(--y); } .pill.r { background: var(--r-bg); color: var(--r); } .pill.n { background: var(--surface-2); color: var(--muted); }
.cell-g { color: var(--g); font-weight: 600; } .cell-y { color: var(--y); font-weight: 600; } .cell-r { color: var(--r); font-weight: 600; }

.insight { border-left: 4px solid var(--border); padding: 8px 12px; margin: 8px 0; background: var(--surface-2); border-radius: 0 8px 8px 0; }
.insight.r { border-left-color: var(--r); } .insight.y { border-left-color: var(--y); } .insight.g { border-left-color: var(--g); } .insight.n { border-left-color: var(--muted); }
.insight b { display: block; }
.insight .why { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.insight .do { margin-top: 3px; }
.chart-box { position: relative; height: 280px; }
.muted { color: var(--muted); } .small { font-size: 12.5px; }
.empty { padding: 24px; text-align: center; color: var(--muted); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.btn { font: inherit; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 7px; padding: 6px 12px; cursor: pointer; min-height: 34px; }
.btn.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.legend-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }
ul.clean { margin: 6px 0; padding-left: 18px; } ul.clean li { margin: 3px 0; }
@media (max-width: 640px) {
  .kpi .value { font-size: 22px; }
  th, td { padding: 7px 8px; }
}

.legend { display: grid; gap: 6px; font-size: 13px; }
.legend .pill { min-width: 52px; text-align: center; margin-right: 6px; }
tr.sel td { background: var(--accent-soft); }
select:disabled { opacity: .5; }

.info { display: inline-flex; align-items: center; justify-content: center; width: 15px; height: 15px; margin-left: 4px; padding: 0; border-radius: 50%; border: 1px solid var(--muted); background: transparent; color: var(--muted); font: 600 10px/1 var(--font, inherit); cursor: pointer; vertical-align: 1px; }
.info:hover { color: var(--accent); border-color: var(--accent); }
.lv { display: inline-block; padding: 0 7px; border-radius: 5px; border: 0; font: 700 11px/18px inherit; color: #fff; cursor: pointer; vertical-align: 1px; }
.lv-L1 { background: #6b7a90; } .lv-L2 { background: #6d5bd0; } .lv-L3 { background: #0e8f80; } .lv-L4 { background: #1b8a4b; } .lv-x { background: #9a8f80; }
th .lv { font-size: 10px; line-height: 15px; padding: 0 5px; }
.term { background: none; border: 0; padding: 0; font: inherit; color: inherit; cursor: pointer; text-decoration: underline dotted var(--muted); text-underline-offset: 3px; }
.term:hover { color: var(--accent); }
.gloss { position: fixed; inset: 0; background: rgba(10, 15, 25, .5); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.gloss[hidden] { display: none; }
.gloss-card { position: relative; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 12px; max-width: 520px; width: 100%; max-height: 85vh; overflow: auto; padding: 18px 20px 16px; }
.gloss-close { position: absolute; top: 8px; right: 10px; border: 0; background: none; font-size: 24px; line-height: 1; color: var(--muted); cursor: pointer; }
.gloss-body h3 { font-size: 17px; margin: 2px 0 8px; } .gloss-body p { margin: 0 0 10px; }
.g-grp { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; }
.g-row { margin: 6px 0; font-size: 13px; } .g-src { margin-top: 10px; color: var(--muted); font-size: 12px; }
.gl-card h3 { font-size: 15px; } .gl-card p { font-size: 13px; }
.kpi .label .info, .controls .info { vertical-align: 0; }
input[type=search] { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 7px; padding: 6px 10px; min-height: 34px; }

[hidden] { display: none !important; }
.controls { position: sticky; top: 0; z-index: 20; display: grid; grid-template-columns: 1.3fr 1fr 1fr 1.2fr 1.5fr auto; gap: 12px 14px; align-items: end;
  padding: 12px 14px; margin: 8px 0 6px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.controls .field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.controls .lbl { display: flex; align-items: center; height: 16px; font-size: 12px; font-weight: 600; color: var(--muted); }
.controls select, .controls input[type=date], .controls .btn { width: 100%; height: 38px; min-height: 38px; box-sizing: border-box; font-size: 14px; }
.controls .field-btn .btn { padding: 0 16px; white-space: nowrap; }
.filter-note { margin: 0 0 12px; padding: 0 2px; font-size: 12.5px; color: var(--muted); }
.filter-note b { color: var(--text); font-weight: 600; }
.filter-note .warn { color: var(--y); }
@media (max-width: 980px) { .controls { grid-template-columns: repeat(3, 1fr); } .controls .field-btn { grid-column: auto; } }
@media (max-width: 640px) { .controls { grid-template-columns: repeat(2, 1fr); position: static; } }
