:root {
  color-scheme: light;
  --page: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #fcfcfb;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #898781;
  --border: rgba(11, 11, 11, 0.10);
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --accent: #2a78d6;
  --accent-wash: #e6effa;
  --accent-ink: #1c5cab;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --up: #006300;
  --down: #d03b3b;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --wash-good: #e5f5e5;
  --wash-warning: #fdf3dc;
  --wash-serious: #fcebe3;
  --wash-critical: #f9e3e3;
  --wash-muted: #efeee9;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --surface-2: #1f1f1e; --text: #f0efec; --text-2: #c3c2b7;
    --muted: #898781; --border: rgba(255, 255, 255, 0.10); --grid: #2c2c2a; --axis: #383835;
    --accent: #3987e5; --accent-wash: #1c2a3d; --accent-ink: #86b6ef;
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70;
    --up: #0ca30c; --down: #e66767;
    --wash-good: #13291a; --wash-warning: #2e2510; --wash-serious: #2e1d15; --wash-critical: #2e1616; --wash-muted: #262624;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #1f1f1e; --text: #f0efec; --text-2: #c3c2b7;
  --muted: #898781; --border: rgba(255, 255, 255, 0.10); --grid: #2c2c2a; --axis: #383835;
  --accent: #3987e5; --accent-wash: #1c2a3d; --accent-ink: #86b6ef;
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70;
  --up: #0ca30c; --down: #e66767;
  --wash-good: #13291a; --wash-warning: #2e2510; --wash-serious: #2e1d15; --wash-critical: #2e1616; --wash-muted: #262624;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--page); color: var(--text); font-size: 14px; line-height: 1.45; }
a { color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.spacer { flex: 1; }
.ico { width: 18px; height: 18px; flex: none; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 20; height: 64px; display: flex; align-items: center; gap: 12px;
  padding: 0 20px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 19px; text-decoration: none; white-space: nowrap; margin-right: 12px; }
.brand span { font-weight: 700; color: var(--accent); }
.topnav { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.topnav a {
  padding: 8px 14px; border-radius: 6px; text-decoration: none; color: var(--text-2); white-space: nowrap; font-size: 14.5px;
}
.topnav a:hover { background: var(--wash-muted); }
.topnav a.active { background: var(--accent-wash); color: var(--text); font-weight: 600; }
.btn, .iconbtn {
  display: inline-flex; align-items: center; gap: 6px; height: 38px; padding: 0 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; cursor: pointer;
}
.btn:hover, .iconbtn:hover { background: var(--wash-muted); }
.iconbtn { width: 40px; justify-content: center; padding: 0; }
.btn[disabled] { opacity: .6; cursor: progress; }

/* shell */
.shell { display: flex; min-height: calc(100vh - 64px); }
.sidebar {
  width: 280px; flex: none; padding: 20px 10px; border-right: 1px solid var(--border); background: var(--page);
  position: sticky; top: 64px; height: calc(100vh - 64px); overflow-y: auto;
}
.side-title { font-size: 12.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--text-2); padding: 8px 12px; }
.side-link {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-radius: 8px; text-decoration: none;
  color: var(--text-2); font-size: 14.5px;
}
.side-link:hover { background: var(--wash-muted); }
.side-link.active { background: var(--accent-wash); color: var(--text); font-weight: 600; }
.side-sep { border-top: 1px solid var(--border); margin: 14px 12px; }
body.side-collapsed .sidebar { display: none; }
.main { flex: 1; min-width: 0; padding: 28px 32px 60px; }
h1 { font-size: 26px; margin: 4px 0 20px; }
h1 small { font-size: 14px; font-weight: 400; color: var(--muted); margin-left: 8px; }

/* filters */
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding-bottom: 18px; margin-bottom: 20px; border-bottom: 1px solid var(--border); }
.filters select, .filters input {
  height: 40px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font: inherit;
}

/* cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 20px; box-shadow: var(--shadow); margin-bottom: 20px; min-width: 0; }
.card-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.card-title { font-size: 13.5px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; margin: 0; }
.card-sub { color: var(--text-2); font-size: 13.5px; margin-top: 2px; }
.card-note { color: var(--text-2); font-size: 12.5px; margin: 12px 0 0; }
.cols { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.cols > .card { margin-bottom: 0; }
.cols + .card, .cols + .cols { margin-top: 20px; }

/* KPI tiles */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.kpi { border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px; background: var(--surface-2); }
.kpi-label { color: var(--text-2); font-size: 13.5px; }
.kpi-value { font-size: 26px; font-weight: 600; margin: 4px 0 2px; white-space: nowrap; }
.kpi-foot { display: flex; gap: 10px; flex-wrap: wrap; font-size: 13px; min-height: 18px; }

.delta { font-variant-numeric: tabular-nums; white-space: nowrap; }
.delta.up { color: var(--up); }
.delta.down { color: var(--down); }
.delta.flat, .delta.none { color: var(--muted); }

/* tables */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-weight: 600; color: var(--text-2); font-size: 12.5px; white-space: nowrap; position: sticky; top: 0; background: var(--surface); }
th.sortable { cursor: pointer; user-select: none; }
th.sortable::after { content: " ↕"; color: var(--muted); font-weight: 400; }
th.sorted-asc::after { content: " ↑"; color: var(--text); }
th.sorted-desc::after { content: " ↓"; color: var(--text); }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tbody tr:hover { background: var(--surface-2); }
td .sub { color: var(--muted); font-size: 12px; }
td.name { min-width: 220px; max-width: 380px; }
td.name a { text-decoration: none; }
td.name a:hover { text-decoration: underline; }
tr.total td { font-weight: 600; border-top: 2px solid var(--axis); }

/* badges (status: icon + label, never colour alone) */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px 2px 3px; border-radius: 999px; font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.badge .dot { width: 18px; height: 18px; border-radius: 999px; display: inline-grid; place-items: center; font-size: 11px; color: #fff; }
.s-good { background: var(--wash-good); } .s-good .dot { background: var(--good); }
.s-warning { background: var(--wash-warning); } .s-warning .dot { background: var(--warning); color: #0b0b0b; }
.s-serious { background: var(--wash-serious); } .s-serious .dot { background: var(--serious); }
.s-critical { background: var(--wash-critical); } .s-critical .dot { background: var(--critical); }
.s-info { background: var(--accent-wash); } .s-info .dot { background: var(--accent); }
.s-muted { background: var(--wash-muted); } .s-muted .dot { background: var(--muted); }
.rankpill { display: inline-block; min-width: 38px; text-align: center; padding: 1px 8px; border-radius: 6px; font-weight: 700; font-variant-numeric: tabular-nums; background: var(--wash-muted); }
.rankpill.top3 { background: var(--accent); color: #fff; }

/* bars inside tables */
.bar { position: relative; height: 8px; background: var(--wash-muted); border-radius: 4px; min-width: 80px; margin-top: 6px; }
.bar > i { position: absolute; inset: 0 auto 0 0; border-radius: 4px; background: var(--series-1); }

/* opportunities */
.opp-cols { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; align-items: start; }
.opp { border-top: 1px solid var(--border); padding: 12px 0; }
.opp:first-of-type { border-top: 0; }
.opp-kind { font-size: 12px; color: var(--text-2); text-transform: uppercase; letter-spacing: .05em; }
.opp-what { font-weight: 600; margin: 2px 0; overflow-wrap: anywhere; }
.opp-why { color: var(--text-2); font-size: 13px; }
.opp-act { font-size: 13px; margin-top: 4px; }
.opp-act::before { content: "→ "; color: var(--accent); font-weight: 700; }
.opp-val { float: right; font-weight: 600; font-variant-numeric: tabular-nums; margin-left: 10px; }

.empty { padding: 28px; text-align: center; color: var(--text-2); }
.empty strong { display: block; color: var(--text); font-size: 15px; margin-bottom: 6px; }
.callout { background: var(--accent-wash); border-radius: 8px; padding: 12px 14px; font-size: 13.5px; margin-bottom: 20px; }

/* charts */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .axis { stroke: var(--axis); stroke-width: 1; }
.chart text { fill: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.chart .series { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .crosshair { stroke: var(--axis); stroke-width: 1; }
.chart .hoverdot { stroke: var(--surface); stroke-width: 2; }
.chart .hbar { fill: var(--series-1); }
.chart .hbar-label { fill: var(--text); font-size: 12.5px; }
.chart .hbar-value { fill: var(--text-2); font-size: 12.5px; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12.5px; color: var(--text-2); margin-bottom: 8px; }
.legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 6px; }
.tooltip {
  position: fixed; z-index: 50; pointer-events: none; background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; font-size: 12.5px; box-shadow: 0 4px 16px rgba(0,0,0,.12); min-width: 140px;
}
.tooltip b { display: block; margin-bottom: 4px; }
.tooltip .row { display: flex; justify-content: space-between; gap: 14px; font-variant-numeric: tabular-nums; }
.tooltip .row i { display: inline-block; width: 10px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 6px; }

@media (max-width: 1100px) {
  .opp-cols, .cols { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 860px) {
  .sidebar { position: fixed; left: 0; top: 64px; z-index: 15; display: none; box-shadow: 4px 0 16px rgba(0,0,0,.15); }
  body.side-open .sidebar { display: block; }
  body.side-collapsed .sidebar { display: none; }
  .main { padding: 20px 16px 48px; }
  .hide-sm, #themeLabel, #refreshLabel { display: none; }
  .brand { font-size: 16px; }
  .topbar { padding: 0 12px; gap: 8px; }
  .kpi-value { font-size: 22px; }
}
