:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #e3e6eb;
  --text: #14181f;
  --text-2: #4a5160;
  --muted: #6b7280;
  --brand: #1f3a5f;
  --brand-2: #2a4f7f;
  --brand-ink: #ffffff;
  --accent: #2a78d6;
  --series-actual: #2a78d6;
  --series-budget: #8a8f98;
  --series-prior: #eb6834;
  --good: #0ca30c;
  --good-ink: #0a6e0a;
  --warn: #fab219;
  --warn-ink: #8a5a00;
  --serious: #ec835a;
  --crit: #d03b3b;
  --crit-ink: #b32a2a;
  --good-bg: #e9f7e9;
  --warn-bg: #fff5de;
  --crit-bg: #fdecec;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .05);
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #111317; --surface: #1a1d23; --surface-2: #20242b; --border: #2e333c;
    --text: #f1f3f6; --text-2: #c3c7cf; --muted: #9aa1ad;
    --brand: #8fb3e3; --brand-2: #a9c5ec; --brand-ink: #0d1b2e; --accent: #3987e5;
    --series-actual: #3987e5; --series-budget: #9aa1ad; --series-prior: #d95926;
    --good-ink: #5fd35f; --warn-ink: #fab219; --crit-ink: #ff8a8a;
    --good-bg: #16301a; --warn-bg: #33290f; --crit-bg: #3a1a1a;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111317; --surface: #1a1d23; --surface-2: #20242b; --border: #2e333c;
  --text: #f1f3f6; --text-2: #c3c7cf; --muted: #9aa1ad;
  --brand: #8fb3e3; --brand-2: #a9c5ec; --brand-ink: #0d1b2e; --accent: #3987e5;
  --series-actual: #3987e5; --series-budget: #9aa1ad; --series-prior: #d95926;
  --good-ink: #5fd35f; --warn-ink: #fab219; --crit-ink: #ff8a8a;
  --good-bg: #16301a; --warn-bg: #33290f; --crit-bg: #3a1a1a;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; } h2 { font-size: 17px; } h3 { font-size: 15px; }
.muted { color: var(--muted); } .small { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }

.app { display: flex; min-height: 100vh; }
.sidebar { width: 248px; flex: 0 0 248px; background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; z-index: 20; }
.brand { display: flex; gap: 10px; align-items: center; padding: 18px 18px 14px; color: var(--brand); }
.brand svg { width: 34px; height: 34px; flex: none; }
.brand-name { font-weight: 700; font-size: 16px; color: var(--text); }
.brand-sub { font-size: 12px; color: var(--muted); }
nav { padding: 6px 10px; flex: 1; overflow-y: auto; }
nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: var(--text-2); text-decoration: none; font-weight: 500; margin-bottom: 2px; }
nav a .ico { width: 20px; text-align: center; color: var(--muted); }
nav a:hover { background: var(--surface-2); color: var(--text); }
nav a.active { background: var(--brand); color: var(--brand-ink); }
nav a.active .ico { color: var(--brand-ink); }
.nav-sep { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 16px 10px 6px; }
.sidebar-foot { padding: 14px 18px; border-top: 1px solid var(--border); }
.demo-pill { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--warn-bg); color: var(--warn-ink); margin-bottom: 6px; }
.demo-pill.custom { background: var(--good-bg); color: var(--good-ink); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 10; background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 12px; padding: 10px 24px; }
.topbar-title { font-weight: 600; font-size: 16px; flex: 1; }
.topbar-controls { display: flex; gap: 10px; align-items: center; }
.ctl { display: flex; gap: 8px; align-items: center; font-size: 12px; color: var(--muted); }
select, input[type=number], input[type=text], input[type=month] { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; }
.menu-btn { display: none; }
#view { padding: 22px 24px 60px; max-width: 1320px; width: 100%; outline: none; }

.btn { font: inherit; font-weight: 600; border: 1px solid var(--brand); background: var(--brand); color: var(--brand-ink); padding: 7px 14px; border-radius: 8px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; text-decoration: none; }
.btn:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

.page-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-end; margin-bottom: 16px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--text-2); max-width: 760px; }
.howto { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--accent); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 16px; }
.howto summary { cursor: pointer; font-weight: 600; }
.howto ul { margin: 8px 0 2px; padding-left: 20px; color: var(--text-2); }

.grid { display: grid; gap: 14px; }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g21 { grid-template-columns: 2fr 1fr; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; min-width: 0; }
.card h2 { margin-bottom: 4px; }
.card .sub { color: var(--muted); font-size: 12px; margin-bottom: 12px; }
.mt { margin-top: 14px; }

.tile .label { font-size: 12px; color: var(--muted); font-weight: 500; }
.tile .value { font-size: 26px; font-weight: 700; margin: 2px 0; font-variant-numeric: tabular-nums; }
.tile .delta { font-size: 12px; font-weight: 600; }
.pos { color: var(--good-ink); } .neg { color: var(--crit-ink); }

.status { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; white-space: nowrap; }
.status.good { background: var(--good-bg); color: var(--good-ink); }
.status.warn { background: var(--warn-bg); color: var(--warn-ink); }
.status.crit { background: var(--crit-bg); color: var(--crit-ink); }
.status.info { background: var(--surface-2); color: var(--text-2); }

.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; background: var(--surface-2); position: sticky; top: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--surface-2); }
tr.sel td { background: var(--surface-2); }
tr.sel td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
tr.total td { font-weight: 700; border-top: 2px solid var(--border); }
td.sec { font-weight: 700; background: var(--surface-2); text-transform: uppercase; font-size: 11px; letter-spacing: .05em; color: var(--muted); }

.alert-list { list-style: none; margin: 0; padding: 0; }
.alert-list li { display: flex; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--border); align-items: flex-start; }
.alert-list li:last-child { border-bottom: 0; }
.alert-list .a-body { flex: 1; min-width: 0; }
.alert-list .a-title { font-weight: 600; }
.alert-list .a-text { color: var(--text-2); font-size: 13px; }
.alert-list .a-link { font-size: 12px; white-space: nowrap; }

.commentary { background: var(--surface-2); border-radius: 8px; padding: 12px 14px; line-height: 1.6; }
.commentary p { margin: 0 0 8px; } .commentary p:last-child { margin: 0; }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.kv div { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; }
.kv .k { font-size: 11px; color: var(--muted); }
.kv .v { font-weight: 700; font-variant-numeric: tabular-nums; }
.chart-box { position: relative; height: 280px; }
.chart-box.tall { height: 340px; }
.chart-box.short { height: 200px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-2); margin-bottom: 6px; }
.legend span::before { content: ""; display: inline-block; width: 14px; height: 3px; border-radius: 2px; margin-right: 6px; vertical-align: middle; background: var(--c); }
.legend span.dash::before { background: repeating-linear-gradient(90deg, var(--c) 0 5px, transparent 5px 8px); }

.bar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; position: relative; }
.bar > i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 99px; background: var(--accent); }
.bar > b { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--text); }

.pilot { display: flex; flex-direction: column; gap: 8px; }
.pilot .row { display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.pilot dl { margin: 0; display: grid; grid-template-columns: 110px 1fr; gap: 4px 10px; font-size: 13px; }
.pilot dt { color: var(--muted); } .pilot dd { margin: 0; }
.pilot.shelved { opacity: .85; border-style: dashed; }

.letter { white-space: pre-wrap; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; background: var(--surface-2); padding: 14px; border-radius: 8px; max-height: 420px; overflow: auto; }
.drop { border: 2px dashed var(--border); border-radius: var(--radius); padding: 22px; text-align: center; color: var(--text-2); }
.drop.over { border-color: var(--accent); background: var(--surface-2); }
.log { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; background: var(--surface-2); border-radius: 8px; padding: 10px; white-space: pre-wrap; max-height: 220px; overflow: auto; }
.toggle { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.toggle input { width: 18px; height: 18px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { font: inherit; background: var(--surface); color: var(--text-2); border: 0; padding: 6px 12px; cursor: pointer; }
.seg button.on { background: var(--brand); color: var(--brand-ink); font-weight: 600; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; opacity: 0; transition: .2s; pointer-events: none; z-index: 100; font-weight: 500; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.hero { background: linear-gradient(135deg, #1f3a5f, #2a5d8f); color: #fff; border-radius: var(--radius); padding: 20px 22px; margin-bottom: 16px; display: flex; gap: 20px; justify-content: space-between; flex-wrap: wrap; align-items: center; }
.hero h1 { color: #fff; }
.hero p { margin: 6px 0 0; color: #dbe6f5; max-width: 720px; }
.hero .steps { display: flex; gap: 8px; flex-wrap: wrap; }
.hero .steps a { color: #fff; background: rgba(255,255,255,.14); padding: 6px 12px; border-radius: 99px; text-decoration: none; font-size: 13px; font-weight: 500; }
.hero .steps a:hover { background: rgba(255,255,255,.24); }
.hero .x { background: none; border: 0; color: #dbe6f5; cursor: pointer; font-size: 18px; }

@media (max-width: 1080px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g21 { grid-template-columns: 1fr; } }
@media (max-width: 860px) {
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 40px rgba(0,0,0,.25); }
  .sidebar.open { transform: none; }
  .menu-btn { display: inline-block; font-size: 18px; background: none; border: 0; color: var(--text); cursor: pointer; padding: 4px 6px; }
  .g3, .g2 { grid-template-columns: 1fr; }
  #view { padding: 16px 16px 60px; }
  .topbar { padding: 10px 16px; }
  .topbar-title { font-size: 15px; }
}
@media (max-width: 640px) { .alert-list li { flex-wrap: wrap; } .alert-list .a-body { flex-basis: 100%; order: 2; } .alert-list .a-link { order: 3; } }
@media (max-width: 520px) { .g4 { grid-template-columns: 1fr 1fr; } .tile .value { font-size: 20px; } .ctl span { display: none; } }

/* print report */
@media print {
  .sidebar, .topbar, .howto, .no-print, .toast { display: none !important; }
  body { background: #fff; color: #000; }
  #view { padding: 0; max-width: none; }
  .card { box-shadow: none; break-inside: avoid; }
}
