:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --surface-3: #e7e6e1;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --ring: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --s1: #2a78d6;
  --s2: #eb6834;
  --s3: #1baf7a;
  --good: #0ca30c;
  --good-text: #006300;
  --warning: #fab219;
  --critical: #d03b3b;
  --critical-text: #b42c2c;
  --on-warning: #0b0b0b;
  --on-critical: #ffffff;
  --cell-normal: #ebeae5;
  --tag-observed-bg: #e3eefb;  --tag-observed-ink: #184f95;
  --tag-model-bg: #e8f5ef;     --tag-model-ink: #0d6b4a;
  --tag-synth-bg: #fbeee5;     --tag-synth-ink: #9a3b12;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);
  --radius: 10px;
  --font: 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: #232321; --surface-3: #2c2c2a;
    --ink: #f0efec; --ink-2: #c3c2b7; --muted: #898781; --grid: #2c2c2a; --axis: #383835;
    --ring: rgba(255,255,255,0.10);
    --accent: #3987e5; --s1: #3987e5; --s2: #d95926; --s3: #199e70;
    --good-text: #0ca30c; --critical-text: #e66767; --cell-normal: #262624;
    --tag-observed-bg: #13263f; --tag-observed-ink: #9ec5f4;
    --tag-model-bg: #10291f;    --tag-model-ink: #7fd8b4;
    --tag-synth-bg: #33200f;    --tag-synth-ink: #f3b48f;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232321; --surface-3: #2c2c2a;
  --ink: #f0efec; --ink-2: #c3c2b7; --muted: #898781; --grid: #2c2c2a; --axis: #383835;
  --ring: rgba(255,255,255,0.10);
  --accent: #3987e5; --s1: #3987e5; --s2: #d95926; --s3: #199e70;
  --good-text: #0ca30c; --critical-text: #e66767; --cell-normal: #262624;
  --tag-observed-bg: #13263f; --tag-observed-ink: #9ec5f4;
  --tag-model-bg: #10291f;    --tag-model-ink: #7fd8b4;
  --tag-synth-bg: #33200f;    --tag-synth-ink: #f3b48f;
  --shadow: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--page); color: var(--ink); font: 14px/1.5 var(--font); }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 18px; font-weight: 650; }
h2 { font-size: 16px; font-weight: 650; }
h3 { font-size: 14px; font-weight: 600; }
p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
code, .mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12px; }
.wrap { max-width: 1240px; margin: 0 auto; padding: 0 16px; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.ink2 { color: var(--ink-2); }

/* top bar */
.topbar { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--page) 92%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--ring); }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding-top: 12px; padding-bottom: 12px; flex-wrap: wrap; }
.sub { color: var(--ink-2); font-size: 13px; }
.scenario-picker { display: inline-flex; background: var(--surface-2); border-radius: 8px; padding: 3px; gap: 2px; }
.scenario-picker button { border: 0; background: transparent; padding: 6px 14px; border-radius: 6px; cursor: pointer; color: var(--ink-2); white-space: nowrap; }
.scenario-picker button[aria-checked="true"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 0 0 1px var(--ring); }
.scenario-picker small { color: var(--muted); margin-left: 4px; }

/* layout */
main { padding-top: 16px; padding-bottom: 64px; display: grid; gap: 16px; }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: 0 0 0 1px var(--ring), var(--shadow); padding: 18px; min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.card-head p { color: var(--ink-2); font-size: 13px; margin-top: 2px; max-width: 760px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: minmax(0, 1fr); } }

/* banners */
.banner { border-radius: var(--radius); padding: 12px 14px; display: flex; gap: 10px; align-items: flex-start; font-size: 13px; }
.banner strong { font-weight: 650; }
.banner.demo { background: var(--surface-2); color: var(--ink-2); }
.banner.danger { background: color-mix(in srgb, var(--critical) 14%, var(--surface)); color: var(--ink); box-shadow: inset 3px 0 0 var(--critical); }
.banner .icon { flex: none; margin-top: 1px; }

/* provenance tags */
.tags { display: flex; gap: 6px; flex-wrap: wrap; }
.tag { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 600; letter-spacing: .02em;
  padding: 2px 8px; border-radius: 999px; white-space: nowrap; cursor: help; }
.tag.observed { background: var(--tag-observed-bg); color: var(--tag-observed-ink); }
.tag.model { background: var(--tag-model-bg); color: var(--tag-model-ink); }
.tag.synthetic { background: var(--tag-synth-bg); color: var(--tag-synth-ink); }
.tag.review { background: var(--surface-2); color: var(--ink-2); }
.legend-row { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; font-size: 12px; color: var(--ink-2); }

/* status chips */
.status { display: inline-flex; align-items: center; gap: 5px; font-weight: 600; font-size: 12px; white-space: nowrap; }
.status .sw { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.sw.normal { background: var(--cell-normal); box-shadow: inset 0 0 0 1px var(--axis); }
.sw.warning { background: var(--warning); }
.sw.critical { background: var(--critical); }

/* KPI tiles */
.kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 1000px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.kpi { background: var(--surface); border-radius: var(--radius); box-shadow: 0 0 0 1px var(--ring), var(--shadow); padding: 14px 16px; min-width: 0; }
.kpi .label { color: var(--ink-2); font-size: 12px; }
.kpi .value { font-size: 26px; font-weight: 650; margin-top: 2px; line-height: 1.2; }
.kpi .value small { font-size: 13px; font-weight: 500; color: var(--ink-2); }
.kpi .delta { font-size: 12px; color: var(--ink-2); margin-top: 2px; }
.kpi .delta.up { color: var(--critical-text); }
.kpi .delta.down { color: var(--good-text); }

/* heatmap */
.heat-scroll { overflow-x: auto; }
.heat { display: grid; grid-template-columns: 92px repeat(24, minmax(26px, 1fr)); gap: 2px; min-width: 720px; }
.heat .hh { font-size: 11px; color: var(--muted); text-align: center; padding-bottom: 2px; }
.heat .day { font-size: 12px; color: var(--ink-2); display: flex; align-items: center; padding-right: 6px; cursor: pointer; border-radius: 4px; }
.heat .day.sel { color: var(--ink); font-weight: 650; }
.heat .day.sel::before { content: ""; width: 3px; height: 16px; border-radius: 2px; background: var(--accent); margin-right: 6px; }
.cell { position: relative; height: 30px; border-radius: 4px; display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-variant-numeric: tabular-nums; cursor: pointer; background: var(--cell-normal); color: var(--ink-2); border: 0; padding: 0; }
.cell.warning { background: var(--warning); color: var(--on-warning); }
.cell.critical { background: var(--critical); color: var(--on-critical); font-weight: 600; }
.cell.changed::after { content: ""; position: absolute; top: 3px; right: 3px; width: 6px; height: 6px; border-radius: 50%;
  background: currentColor; box-shadow: 0 0 0 1.5px var(--surface); }
.cell:focus-visible, .day:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.row-sel .cell { box-shadow: inset 0 -2px 0 color-mix(in srgb, var(--ink) 35%, transparent); }

/* charts */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart text { fill: var(--muted); font-size: 11px; font-family: var(--font); font-variant-numeric: tabular-nums; }
.chart .ref-label { fill: var(--ink-2); font-weight: 600; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--ink-2); margin-bottom: 8px; }
.legend .key { display: inline-flex; align-items: center; gap: 6px; }
.legend .line { width: 16px; height: 2px; border-radius: 2px; }
.legend .dash { width: 16px; height: 0; border-top: 2px dashed var(--ink-2); }
.legend .dot { width: 8px; height: 8px; border-radius: 50%; border: 2px solid var(--ink-2); }
.legend .box { width: 10px; height: 10px; border-radius: 3px; }

.tooltip { position: fixed; z-index: 50; pointer-events: none; background: var(--surface); color: var(--ink);
  box-shadow: 0 0 0 1px var(--ring), 0 6px 24px rgba(0,0,0,.14); border-radius: 8px; padding: 8px 10px; font-size: 12px; max-width: 280px; }
.tooltip .t-title { font-weight: 650; margin-bottom: 4px; }
.tooltip .t-row { display: flex; justify-content: space-between; gap: 14px; }
.tooltip .t-row span:last-child { font-variant-numeric: tabular-nums; font-weight: 600; }
.tooltip .t-key { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }

/* day pills */
.pills { display: flex; gap: 6px; flex-wrap: wrap; }
.pill { border: 0; background: var(--surface-2); color: var(--ink-2); padding: 4px 10px; border-radius: 999px; font-size: 12px; cursor: pointer; }
.pill[aria-pressed="true"] { background: var(--ink); color: var(--surface); font-weight: 600; }

/* tables */
.table-scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th { text-align: left; font-weight: 600; color: var(--ink-2); font-size: 12px; padding: 6px 10px; border-bottom: 1px solid var(--axis); white-space: nowrap; }
td { padding: 7px 10px; border-bottom: 1px solid var(--grid); vertical-align: top; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.current td { background: color-mix(in srgb, var(--accent) 7%, transparent); }
.pos { color: var(--critical-text); }
.neg { color: var(--good-text); }

/* recommendations */
.recs { display: grid; gap: 10px; }
.rec { border-radius: 8px; padding: 12px 14px; background: var(--surface-2); box-shadow: inset 3px 0 0 var(--warning); }
.rec.critical { box-shadow: inset 3px 0 0 var(--critical); }
.rec-head { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; align-items: baseline; }
.rec-when { font-weight: 650; }
.rec p { color: var(--ink-2); font-size: 13px; margin-top: 4px; }
.rec ul { margin: 6px 0 0; padding-left: 18px; font-size: 13px; }
.rec .tags { margin-top: 8px; }
.day-group h3 { margin: 6px 0 2px; color: var(--ink-2); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.empty { color: var(--ink-2); background: var(--surface-2); border-radius: 8px; padding: 14px; font-size: 13px; }

/* schedule editor */
.sched td { vertical-align: middle; }
.sched input, .sched select { background: var(--surface); border: 1px solid var(--axis); border-radius: 6px; padding: 4px 6px; font-size: 13px; min-width: 0; }
.sched input[type="text"] { width: 150px; }
.sched input[type="datetime-local"] { width: 190px; }
.sched tbody.flight tr:first-child td { border-bottom: 0; padding-bottom: 4px; }
.sched tbody.flight + tbody.flight tr:first-child td { padding-top: 12px; }
.sched .sub-row td { padding-top: 0; }
.flight-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px 16px; flex-wrap: wrap; }
.sched .effect { font-size: 12px; color: var(--ink-2); }
.sched .effect strong { font-weight: 600; color: var(--ink-2); }
.sched .effect.ignored { color: var(--muted); font-style: italic; }
.btn { border: 0; background: var(--surface-2); color: var(--ink); padding: 6px 12px; border-radius: 6px; cursor: pointer; font-size: 13px; white-space: nowrap; box-shadow: inset 0 0 0 1px var(--ring); }
.btn:hover { background: var(--surface-3); }
.btn.primary { background: var(--accent); color: #fff; box-shadow: none; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.small { padding: 3px 8px; font-size: 12px; }
.btn.danger { color: var(--critical-text); }
.btn:disabled { opacity: .5; cursor: progress; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.path { font-size: 12px; color: var(--muted); word-break: break-all; }
.errors { margin-top: 10px; }
.errors li { color: var(--critical-text); font-size: 13px; }

.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 60; background: var(--ink); color: var(--surface);
  padding: 10px 16px; border-radius: 8px; font-size: 13px; max-width: calc(100% - 32px); box-shadow: 0 6px 24px rgba(0,0,0,.2); }
.toast.error { background: var(--critical); color: #fff; }

/* model + assumptions */
dl.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 14px; margin: 0; font-size: 13px; }
dl.kv dt { color: var(--ink-2); }
dl.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.check { color: var(--good-text); font-weight: 600; }
details summary { cursor: pointer; color: var(--ink-2); font-size: 13px; margin-top: 10px; }
.loading { padding: 40px 0; color: var(--ink-2); text-align: center; }
.setup ol { padding-left: 20px; }
.setup li { margin: 6px 0; }
.setup pre { background: var(--surface-2); padding: 10px 12px; border-radius: 8px; overflow-x: auto; font-size: 12px; }
.section-gap { margin-top: 18px; }

@media (max-width: 640px) {
  .card { padding: 14px; }
  .kpi .value { font-size: 22px; }
  .scenario-picker button { padding: 6px 10px; }
}
@media (forced-colors: active) {
  .cell.warning { forced-color-adjust: none; background-image: repeating-linear-gradient(45deg, transparent 0 4px, rgba(0,0,0,.35) 4px 5px); }
  .cell.critical { forced-color-adjust: none; background-image: repeating-linear-gradient(135deg, transparent 0 3px, rgba(255,255,255,.5) 3px 4px); }
}
