/* swissTechAI brand tokens. Dark is the primary mode (it matches swisstechai.com);
   light is the same family on parchment. Chart series and ramps are read from these
   same tokens in js/charts.js and were validated against both surfaces with the
   data-viz palette checks (lightness band, chroma, CVD separation, contrast). */
:root {
  color-scheme: light;
  --page: #efeadf;
  --surface: #fbf8f1;
  --surface-2: #e8e2d4;
  --ink: #0f1b33;
  --ink-2: #33415c;
  --muted: #5b667e;
  --grid: #ded8c9;
  --axis: #b5ae9d;
  --border: rgba(15, 27, 51, 0.16);
  --accent: #a86a00;      /* focus ring / spinner: 4.19:1 on surface */
  --accent-ink: #8a5400;  /* link text: 5.9:1 on --surface, 5.2:1 on --page */
  --accent-fill: #f2a93b; /* amber fill, always with --accent-on text */
  --accent-on: #0f1b33;
  --good: #0b6b57;
  --bad: #b42323;
  --badge-bg: #fbebcb;
  --badge-ink: #6b4a00;
  --code-bg: #efeadf;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  --seq-0: #86b0e8; --seq-1: #6b9ae0; --seq-2: #5083d6; --seq-3: #3867bc; --seq-4: #27508f; --seq-5: #183763;
  --incident: rgba(180, 35, 35, 0.12);
  --radius: 6px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  --display: "Bebas Neue", "Inter", system-ui, sans-serif;
}

/* Dark = the site's navy. Steel blue is borders only; it fails contrast as text. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0f1b33; --surface: #13223f; --surface-2: #0b1220;
    --ink: #f0e9db; --ink-2: #c9cfdb; --muted: #a9b4c8;
    --grid: rgba(90, 121, 172, 0.26); --axis: rgba(90, 121, 172, 0.55); --border: rgba(90, 121, 172, 0.45);
    --accent: #f2a93b; --accent-ink: #f2a93b; --accent-fill: #f2a93b; --accent-on: #0f1b33;
    --good: #3ee6d1; --bad: #ff8a85;
    --badge-bg: rgba(242, 169, 59, 0.14); --badge-ink: #f2a93b; --code-bg: #0b1220;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --seq-0: #325693; --seq-1: #3e6cb8; --seq-2: #4a84db; --seq-3: #6fa3e9; --seq-4: #9bc2f2; --seq-5: #cfe2fb;
    --incident: rgba(255, 138, 133, 0.16);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0f1b33; --surface: #13223f; --surface-2: #0b1220;
  --ink: #f0e9db; --ink-2: #c9cfdb; --muted: #a9b4c8;
  --grid: rgba(90, 121, 172, 0.26); --axis: rgba(90, 121, 172, 0.55); --border: rgba(90, 121, 172, 0.45);
  --accent: #f2a93b; --accent-ink: #f2a93b; --accent-fill: #f2a93b; --accent-on: #0f1b33;
  --good: #3ee6d1; --bad: #ff8a85;
  --badge-bg: rgba(242, 169, 59, 0.14); --badge-ink: #f2a93b; --code-bg: #0b1220;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --seq-0: #325693; --seq-1: #3e6cb8; --seq-2: #4a84db; --seq-3: #6fa3e9; --seq-4: #9bc2f2; --seq-5: #cfe2fb;
  --incident: rgba(255, 138, 133, 0.16);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 15px/1.5 var(--font);
}
h1, h2 { margin: 0; line-height: 1.25; }
h1 { font-family: var(--display); font-weight: 400; font-size: clamp(2rem, 1.4rem + 2.4vw, 3.1rem); letter-spacing: 0.005em; }
h2 { font-size: 1.02rem; font-weight: 600; letter-spacing: -0.005em; }
code, pre, textarea { font-family: var(--mono); font-size: 0.85em; }
code { background: var(--code-bg); padding: 0.05em 0.3em; border-radius: 4px; }
a { color: var(--accent-ink); }
.muted { color: var(--muted); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 10; }
.skip-link:focus { left: 16px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.wrap { max-width: 1280px; margin: 0 auto; padding: 0 16px; }
@media (min-width: 720px) { .wrap { padding: 0 24px; } }

/* Header */
.site-header { background: var(--surface); border-bottom: 1px solid var(--border); padding: 20px 0 18px; }
.header-inner { display: flex; gap: 16px; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; }
.eyebrow { margin: 0 0 6px; color: var(--accent-ink); font-family: var(--mono); font-size: 0.78rem; text-transform: lowercase; letter-spacing: 0.04em; font-weight: 500; }
.subtitle { margin: 6px 0 0; color: var(--ink-2); max-width: 70ch; }
.badge {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  background: var(--badge-bg); color: var(--badge-ink);
  font-family: var(--mono); font-size: 0.74rem; font-weight: 500; padding: 5px 10px; border-radius: 999px;
}

/* Status */
.status { display: flex; align-items: center; gap: 10px; min-height: 40px; color: var(--ink-2); font-size: 0.9rem; }
.status.done .spinner { display: none; }
.spinner {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--grid); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }
.error-box { background: var(--surface); border: 1px solid var(--bad); color: var(--ink); padding: 14px 16px; border-radius: var(--radius); }

/* Filters */
.filters {
  display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: flex-end;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 16px;
}
@media (min-width: 960px) { .filters { position: sticky; top: 0; z-index: 5; } }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > label, .field > legend { font-family: var(--mono); font-size: 0.74rem; font-weight: 500; color: var(--muted); }
.field.dates { display: grid; grid-template-columns: auto auto; column-gap: 8px; }
.field.dates label:nth-of-type(1) { grid-column: 1; grid-row: 1; }
.field.dates label:nth-of-type(2) { grid-column: 2; grid-row: 1; }
fieldset.field { border: 0; padding: 0; margin: 0; }
fieldset.field legend { padding: 0; margin-bottom: 4px; }
select, input[type="date"], textarea {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--axis); border-radius: 6px; padding: 6px 8px; min-height: 36px;
}
select { padding-right: 28px; max-width: 100%; }
#f-model { min-width: 230px; } /* options arrive after DuckDB loads; reserve the width */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.chip span {
  display: inline-flex; align-items: center; gap: 4px; min-height: 32px;
  padding: 4px 10px; border-radius: 999px; border: 1px solid var(--axis);
  font-family: var(--mono); font-size: 0.8rem; color: var(--ink-2); user-select: none;
}
/* Selected chips are tinted, not solid amber: six solid fills would swamp the page.
   Solid amber is reserved for the one primary button. */
.chip input:checked + span { background: var(--badge-bg); border-color: var(--accent-fill); color: var(--badge-ink); font-weight: 500; }
.chip input:checked + span::before { content: "✓"; font-weight: 700; }
.chip input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn {
  font: inherit; font-family: var(--mono); font-size: 0.82rem; font-weight: 500; cursor: pointer; min-height: 36px;
  padding: 6px 14px; border-radius: 6px; border: 1px solid var(--axis); background: var(--surface); color: var(--ink);
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--accent-fill); border-color: var(--accent-fill); color: var(--accent-on); }
.btn.primary:hover:not(:disabled) { filter: brightness(0.9); }
.btn.ghost { border-color: transparent; color: var(--accent-ink); }
@media (max-width: 719px) {
  .field { flex: 1 1 140px; }
  .field.dates, fieldset.field { flex-basis: 100%; }
  .field.dates input { width: 100%; }
}

/* KPIs */
.kpis { margin-bottom: 16px; }
.kpi-period { margin: 0 0 8px; color: var(--muted); font-family: var(--mono); font-size: 0.78rem; }
.kpi-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 600px) { .kpi-grid { grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 1180px) { .kpi-grid { grid-template-columns: repeat(8, 1fr); } }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; min-height: 108px; }
.kpi .label { font-family: var(--mono); font-size: 0.74rem; color: var(--muted); font-weight: 500; }
.kpi .value { font-size: 1.55rem; font-weight: 650; margin-top: 3px; letter-spacing: -0.015em; font-variant-numeric: tabular-nums; }
.kpi .delta { font-size: 0.78rem; color: var(--muted); margin-top: 2px; }
.kpi .delta.good { color: var(--good); }
.kpi .delta.bad { color: var(--bad); }
.kpi.loading .value { color: var(--muted); }
.kpi-sql { margin-top: 8px; }

/* Panels */
.grid { display: grid; grid-template-columns: 1fr; gap: 16px; margin-bottom: 24px; }
@media (min-width: 960px) {
  .grid { grid-template-columns: 1fr 1fr; }
  .panel.wide { grid-column: 1 / -1; }
}
.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; min-width: 0;
}
.panel > header { margin-bottom: 8px; }
.panel .sub { margin: 2px 0 0; color: var(--muted); font-size: 0.85rem; }
.chart { width: 100%; height: 300px; position: relative; }
.chart.heat { height: 280px; }
.chart:empty::after, .chart.pending::after {
  content: attr(data-msg); position: absolute; inset: 0; display: grid; place-items: center;
  color: var(--muted); font-size: 0.9rem;
}
.chart.pending > * { opacity: 0.35; transition: opacity 0.2s; }
@media (max-width: 719px) { .chart { height: 260px; } }

details.sql { margin-top: 10px; border-top: 1px solid var(--grid); padding-top: 8px; }
details.sql summary { cursor: pointer; color: var(--accent-ink); font-family: var(--mono); font-size: 0.8rem; font-weight: 500; width: max-content; }
.sql-body pre {
  margin: 8px 0 0; padding: 10px 12px; background: var(--code-bg); border-radius: 6px;
  overflow-x: auto; white-space: pre; line-height: 1.45;
}
.sql-body .timing { margin: 6px 0 0; color: var(--muted); font-size: 0.8rem; }
.sql-body .preview { margin-top: 8px; }

/* Tables */
.table-wrap { overflow-x: auto; max-width: 100%; }
#p-table .table-wrap { min-height: 404px; } /* 10 rows; avoids a shift when the table arrives */
table { border-collapse: collapse; width: 100%; font-size: 0.86rem; }
th, td { padding: 7px 10px; text-align: left; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th { font-family: var(--mono); font-size: 0.74rem; color: var(--muted); font-weight: 500; background: var(--surface); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
th button {
  font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer;
  display: inline-flex; gap: 4px; align-items: center;
}
th[aria-sort="ascending"] button::after { content: "▲"; font-size: 0.7em; }
th[aria-sort="descending"] button::after { content: "▼"; font-size: 0.7em; }
.table-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.segmented { display: inline-flex; border: 1px solid var(--axis); border-radius: 8px; overflow: hidden; }
.segmented button { font: inherit; font-family: var(--mono); font-size: 0.8rem; border: 0; padding: 6px 12px; min-height: 34px; background: var(--surface); color: var(--ink-2); cursor: pointer; }
.segmented button[aria-pressed="true"] { background: var(--accent-fill); color: var(--accent-on); font-weight: 600; }
.pager { display: flex; gap: 12px; align-items: center; justify-content: flex-end; margin-top: 8px; font-size: 0.85rem; color: var(--ink-2); }
.mini { font-size: 0.8rem; }
.mini th, .mini td { padding: 4px 8px; }

/* Console */
.examples { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.examples button { font: inherit; font-family: var(--mono); font-size: 0.76rem; padding: 4px 10px; min-height: 32px; border-radius: 999px; border: 1px solid var(--axis); background: var(--surface); color: var(--ink-2); cursor: pointer; }
.examples button:hover { background: var(--surface-2); }
textarea { width: 100%; resize: vertical; line-height: 1.45; tab-size: 2; font-family: var(--mono); font-size: 0.85rem; }
.console-actions { display: flex; gap: 12px; align-items: center; margin: 8px 0; flex-wrap: wrap; font-size: 0.85rem; color: var(--ink-2); }
#console-status.err { color: var(--bad); }
.console-out { max-height: 420px; overflow: auto; }

.about p { max-width: 80ch; color: var(--ink-2); }

.site-footer { border-top: 1px solid var(--border); padding: 18px 0 28px; color: var(--muted); font-size: 0.85rem; background: var(--surface); }
.footer-inner { display: flex; flex-wrap: wrap; gap: 8px 20px; align-items: baseline; justify-content: space-between; }
.home-link { font-family: var(--mono); font-size: 0.8rem; color: var(--accent-ink); text-decoration: none; padding: 4px 0; }
.home-link:hover { text-decoration: underline; }

@media (forced-colors: active) {
  .chip input:checked + span { forced-color-adjust: none; background: Highlight; color: HighlightText; }
}
