:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1c2430;
  --muted: #5b6676;
  --border: #dde2e8;
  --accent: #2f5bea;
  --accent-text: #ffffff;
  --error: #b42318;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c;
    --surface: #1b212a;
    --text: #e6eaf0;
    --muted: #9aa5b4;
    --border: #2c3542;
    --accent: #7c9cff;
    --accent-text: #0d1220;
    --error: #ff8a80;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar form { margin: 0; }
.brand { letter-spacing: 0.02em; }

.page { max-width: 1040px; margin: 0 auto; padding: 24px 16px; }
.footer { max-width: 1040px; margin: 0 auto; padding: 16px; color: var(--muted); font-size: 13px; }

h1 { font-size: 28px; margin: 0 0 8px; }
h2 { font-size: 18px; margin: 0 0 4px; }
.lede { color: var(--muted); max-width: 70ch; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}

.narrow { max-width: 420px; margin: 48px auto; }

.sections {
  list-style: none;
  padding: 0;
  margin: 24px 0 0;
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}

.sections p { color: var(--muted); margin: 0 0 12px; }

.badge {
  display: inline-block;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
}

button { font: inherit; cursor: pointer; }
button:disabled { opacity: 0.6; cursor: progress; }

.primary {
  background: var(--accent);
  color: var(--accent-text);
  border: 0;
  border-radius: 8px;
  padding: 10px 16px;
}

.link { background: none; border: 0; color: var(--accent); padding: 0; }
.error { color: var(--error); }

/* Component styles: tables, forms, badges, heat cells, notes, breadcrumbs and code. */
:root {
  --row-line: #eef1f5;
  --heat-hue: #2f5bea;
  --ok-text: #1e6b43;
  --ok-bg: #e6f4ec;
  --warn-text: #7a4f00;
  --warn-bg: #fdf1d6;
  --bad-text: #a4261b;
  --bad-bg: #fbe9e7;
  --code-bg: #eef1f5;
}

@media (prefers-color-scheme: dark) {
  :root {
    --row-line: #242c38;
    --heat-hue: #7c9cff;
    --ok-text: #7fd6a0;
    --ok-bg: #15301f;
    --warn-text: #f2c46b;
    --warn-bg: #3a2c10;
    --bad-text: #ff8a80;
    --bad-bg: #3d1a18;
    --code-bg: #242c38;
  }
}

.table-scroll { max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-scroll > table.data { width: max-content; min-width: 100%; }

table.data { width: 100%; border-collapse: collapse; }
table.data th,
table.data td { padding: 10px 12px; vertical-align: top; border-bottom: 1px solid var(--row-line); }
:where(table.data) th { text-align: left; font-weight: 600; color: var(--muted); border-bottom: 1px solid var(--border); }

th.num,
td.num { text-align: right; font-variant-numeric: tabular-nums; }

td.heat { text-align: center; font-variant-numeric: tabular-nums; color: var(--text); }
td.heat-0 { background: color-mix(in srgb, var(--heat-hue) 0%, var(--surface)); }
td.heat-1 { background: color-mix(in srgb, var(--heat-hue) 5%, var(--surface)); }
td.heat-2 { background: color-mix(in srgb, var(--heat-hue) 10%, var(--surface)); }
td.heat-3 { background: color-mix(in srgb, var(--heat-hue) 15%, var(--surface)); }
td.heat-4 { background: color-mix(in srgb, var(--heat-hue) 20%, var(--surface)); }
td.heat-5 { background: color-mix(in srgb, var(--heat-hue) 25%, var(--surface)); }
td.heat-6 { background: color-mix(in srgb, var(--heat-hue) 30%, var(--surface)); }
td.heat-7 { background: color-mix(in srgb, var(--heat-hue) 35%, var(--surface)); }
td.heat-8 { background: color-mix(in srgb, var(--heat-hue) 40%, var(--surface)); }
td.heat-9 { background: color-mix(in srgb, var(--heat-hue) 45%, var(--surface)); }
td.heat-10 { background: color-mix(in srgb, var(--heat-hue) 50%, var(--surface)); }
td.heat-na { background: transparent; color: var(--muted); }

form.stack { max-width: 32rem; }
form.stack > label:first-child { margin-top: 0; }
form.stack label { display: block; margin: 14px 0 4px; font-weight: 600; }
form.stack input,
form.stack select,
form.stack textarea { display: block; width: 100%; }
form.stack button { margin-top: 14px; }

form.inline { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0; }

input:not([type="checkbox"]):not([type="radio"]),
select,
textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  max-width: 100%;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible,
button:focus-visible,
a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

button {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
}

.badge-ok { color: var(--ok-text); background: var(--ok-bg); border-color: transparent; }
.badge-warn { color: var(--warn-text); background: var(--warn-bg); border-color: transparent; }
.badge-bad { color: var(--bad-text); background: var(--bad-bg); border-color: transparent; }
.badge-muted { color: var(--muted); background: var(--bg); }

.note { color: var(--muted); font-size: 14px; max-width: 70ch; margin: 8px 0 16px; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

nav.crumbs { font-size: 14px; color: var(--muted); margin: 0 0 12px; }
nav.crumbs a { color: var(--accent); }

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
  background: var(--code-bg);
  padding: 1px 5px;
  border-radius: 4px;
}

/* Charts (templates/_charts.html): inline SVG, coloured from the same tokens as the rest of the panel. */
.chart-figure { margin: 0 0 16px; }
svg.chart { display: block; width: 100%; max-width: 640px; height: auto; }
.chart-grid { stroke: var(--row-line); stroke-width: 1; }
.chart-axis { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart-cohort { fill: none; stroke: var(--muted); stroke-width: 1; stroke-opacity: 0.45; }
.chart-cohort:hover { stroke: var(--text); stroke-opacity: 1; stroke-width: 2; }
.chart-band { fill: var(--heat-hue); fill-opacity: 0.18; stroke: none; }
.chart-pooled { fill: none; stroke: var(--heat-hue); stroke-width: 2.5; stroke-linejoin: round; }
.chart-box { fill: var(--heat-hue); fill-opacity: 0.18; stroke: var(--heat-hue); stroke-width: 1.5; }
.chart-whisker { stroke: var(--muted); stroke-width: 1.5; }
.chart-median { stroke: var(--heat-hue); stroke-width: 3; }

/* A calendar post's uploaded video and images (templates/calendar_detail.html). */
ul.files { list-style: none; padding: 0; margin: 0 0 16px; }
ul.files li { margin: 0 0 16px; }
.file-preview { display: block; max-width: 100%; max-height: 360px; margin: 0 0 4px; }
