/* Tokens (dataviz reference palette). Light by default; dark from the OS setting or the theme toggle. */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f4f3f0;
  --text-1: #0b0b0b;
  --text-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-wash: rgba(42, 120, 214, 0.10);
  --yes: #c3c2b7;
  --na: #e8e7e2;
  --good: #006300;
  --critical: #d03b3b;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04), 0 8px 24px rgba(11, 11, 11, 0.06);
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #222221;
    --text-1: #ffffff;
    --text-2: #c3c2b7;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --accent-wash: rgba(57, 135, 229, 0.16);
    --yes: #5c5b57;
    --na: #33332f;
    --good: #0ca30c;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #222221;
  --text-1: #ffffff;
  --text-2: #c3c2b7;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;
  --accent-wash: rgba(57, 135, 229, 0.16);
  --yes: #5c5b57;
  --na: #33332f;
  --good: #0ca30c;
  --shadow: none;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--page); color: var(--text-1); font-size: 14px; line-height: 1.45; }
h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 17px; }
h2 { font-size: 15px; }
h3.minor { font-size: 13px; color: var(--text-2); margin: 18px 0 8px; }
.sub { margin: 2px 0 0; color: var(--text-2); font-size: 13px; }
button, select, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* Top bar & tabs */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 18px 28px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); box-shadow: inset 0 0 0 8px var(--accent-wash); }
.controls { display: flex; align-items: flex-end; gap: 8px; }
.tabs { display: flex; gap: 4px; padding: 0 28px; background: var(--surface); border-bottom: 1px solid var(--border); }
.tabs button { border: 0; background: none; padding: 12px 14px; color: var(--text-2); cursor: pointer; border-bottom: 2px solid transparent; }
.tabs button[aria-selected="true"] { color: var(--text-1); border-bottom-color: var(--accent); font-weight: 600; }
main { padding: 24px 28px 48px; max-width: 1480px; margin: 0 auto; }

/* Controls */
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.field.grow { flex: 1 1 260px; }
select, input[type="search"] { height: 34px; padding: 0 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); min-width: 120px; }
input[type="search"] { width: 100%; }
button.ghost, button.primary { height: 34px; padding: 0 12px; border-radius: 8px; cursor: pointer; }
button.ghost { border: 1px solid var(--border); background: var(--surface); }
button.ghost:hover { background: var(--surface-2); }
button.icon { width: 34px; padding: 0; }
button.primary { border: 0; background: var(--accent); color: #fff; font-weight: 600; }
button.primary:disabled { opacity: 0.45; cursor: not-allowed; }
button.link { border: 0; background: none; color: var(--accent); cursor: pointer; padding: 4px 6px; font-size: 13px; }
.check { display: flex; align-items: center; gap: 6px; color: var(--text-2); height: 34px; }
.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; margin-bottom: 16px; }
.filters .push { margin-left: auto; }
.active-filter { display: flex; align-items: center; gap: 8px; margin: -4px 0 16px; padding: 8px 12px; background: var(--accent-wash); border-radius: 8px; color: var(--text-2); }
.active-filter q { color: var(--text-1); }

/* Cards & layout */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.grid-notif { display: grid; grid-template-columns: minmax(280px, 1fr) minmax(0, 2.4fr); gap: 16px; align-items: start; }
@media (max-width: 1100px) { .grid-2, .grid-notif { grid-template-columns: 1fr; } }

/* Hero & KPIs */
.hero-row { display: grid; grid-template-columns: minmax(220px, 1fr) minmax(0, 3fr); gap: 16px; margin-bottom: 16px; }
@media (max-width: 1100px) { .hero-row { grid-template-columns: 1fr; } }
.hero { display: flex; flex-direction: column; justify-content: center; gap: 4px; }
.label { color: var(--text-2); font-size: 13px; }
.hero-value { font-size: 52px; font-weight: 600; line-height: 1.05; letter-spacing: -0.02em; }
.hero-note { color: var(--text-2); font-size: 13px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.kpi .value { display: block; font-size: 26px; font-weight: 600; margin-top: 4px; }
.kpi .note { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }

/* Charts */
.chart { position: relative; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .cat { fill: var(--text-2); font-size: 12px; }
.chart .val { fill: var(--text-1); font-size: 12px; font-variant-numeric: tabular-nums; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; }
.chart .mark { fill: var(--accent); transition: opacity 0.12s; }
.chart .seg-no { fill: var(--accent); }
.chart .seg-yes { fill: var(--yes); }
.chart .seg-na { fill: var(--na); }
.chart .hit { fill: transparent; cursor: default; outline: none; }
.chart .row:hover .mark, .chart .row:focus-within .mark, .chart .row:hover rect:not(.hit) { opacity: 0.8; }
.chart .info-tag { fill: var(--muted); font-size: 11px; }
.chart .group { fill: var(--text-1); font-size: 12px; font-weight: 600; }
.empty { color: var(--muted); padding: 24px 0; text-align: center; }
.legend { display: flex; gap: 14px; align-items: center; color: var(--text-2); font-size: 12px; height: 34px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; }
.sw-no { background: var(--accent); } .sw-yes { background: var(--yes); } .sw-na { background: var(--na); border: 1px solid var(--border); }

/* Tooltip */
.tooltip { position: fixed; z-index: 30; pointer-events: none; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; box-shadow: 0 8px 24px rgba(0,0,0,0.14); font-size: 12px; min-width: 120px; }
.tooltip .t-title { color: var(--text-2); margin-bottom: 4px; }
.tooltip .t-row { display: flex; align-items: center; gap: 8px; }
.tooltip .t-row b { font-variant-numeric: tabular-nums; }
.tooltip .t-key { width: 12px; height: 2px; border-radius: 1px; }

/* Facts */
.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 0; }
.facts dt { color: var(--text-2); }
.facts dd { margin: 0; font-variant-numeric: tabular-nums; }

/* Tables */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th { text-align: left; color: var(--muted); font-weight: 500; padding: 8px 10px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
table.data td { padding: 10px; border-bottom: 1px solid var(--grid); vertical-align: top; }
table.data td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tbody tr { cursor: pointer; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data .msg { min-width: 240px; }
table.data .why { color: var(--text-2); min-width: 200px; }
.user-cell b { display: block; font-weight: 600; }
.user-cell span { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.table-view { margin-top: 8px; }

/* Pills & badges */
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 500; white-space: nowrap; }
.pill.no { background: var(--accent-wash); color: var(--accent); }
.pill.yes { background: var(--surface-2); color: var(--text-2); }
.pill.na { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.pill.draft { background: var(--surface-2); color: var(--text-2); }
.pill.recorded { background: var(--accent-wash); color: var(--accent); }
.pill.error { color: var(--critical); border: 1px solid var(--critical); }
.prio { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; color: var(--text-2); }
.prio::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--muted); }
.prio.High::before { background: var(--accent); }
.prio.Medium::before { background: var(--axis); }
.rule-code { font-variant-numeric: tabular-nums; font-weight: 600; }
.rule-name { display: block; color: var(--muted); font-size: 12px; }
.info { font-size: 11px; color: var(--muted); border: 1px solid var(--border); border-radius: 4px; padding: 0 4px; margin-left: 4px; }

/* Messages list */
.messages { list-style: none; padding: 0; margin: 0; max-height: 640px; overflow-y: auto; }
.messages li { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 10px 8px; border-radius: 8px; cursor: pointer; border-bottom: 1px solid var(--grid); }
.messages li:hover, .messages li.active { background: var(--accent-wash); }
.messages .m-text { color: var(--text-1); }
.messages .m-meta { color: var(--muted); font-size: 12px; grid-column: 1; }
.messages .m-count { grid-row: 1 / span 2; grid-column: 2; align-self: center; font-weight: 600; font-variant-numeric: tabular-nums; }

/* Pager */
.pager { display: flex; align-items: center; gap: 6px; color: var(--text-2); font-size: 13px; }
.pager button { height: 28px; padding: 0 10px; border: 1px solid var(--border); background: var(--surface); border-radius: 6px; cursor: pointer; }
.pager button:disabled { opacity: 0.4; cursor: default; }

/* Drawer */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.28); z-index: 20; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(720px, 100vw); background: var(--surface); z-index: 21; display: flex; flex-direction: column; box-shadow: -8px 0 32px rgba(0,0,0,0.18); }
.drawer-head { display: flex; justify-content: space-between; align-items: flex-start; padding: 20px 24px; border-bottom: 1px solid var(--border); }
.drawer-body { padding: 20px 24px 40px; overflow-y: auto; }
.drawer-body section { margin-bottom: 24px; }
.drawer-body h3 { font-size: 13px; color: var(--text-2); margin-bottom: 10px; }
.callout { background: var(--accent-wash); border-radius: 10px; padding: 14px 16px; }
.callout .msg { font-size: 15px; color: var(--text-1); margin: 6px 0; }
.callout .meta { color: var(--text-2); font-size: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--surface-2); border-radius: 999px; padding: 3px 10px; font-size: 12px; color: var(--text-2); }
.chip b { color: var(--text-1); font-variant-numeric: tabular-nums; }

/* Toast & loading */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--text-1); color: var(--surface); padding: 10px 16px; border-radius: 8px; z-index: 40; font-size: 13px; max-width: 90vw; }
.loading { opacity: 0.55; transition: opacity 0.15s; }
