/* Tokens: keep in sync with dashboard/theme.py and DESIGN.md */
:root {
  color-scheme: light;
  --ground: #F4F2EC; --surface: #FFFFFF; --rail: #E8ECE5;
  --shell: #22382C; --on-shell: #F2F4EF;
  --ink: #1C211D; --muted: #545C56;
  --rule: #C9CEC5; --control: #6F7771;
  --focus: #2463B0; --error: #B3261E;
  --cattle: #9E3510; --horses: #2463B0; --deer: #B07C00; --grass: #3A7D44;
  --radius: 6px;
  --font: "Source Sans 3", "Segoe UI", system-ui, -apple-system, sans-serif;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --ground: #121614; --surface: #1A1F1C; --rail: #222924;
  --shell: #0F1E16; --on-shell: #E6E9E4;
  --ink: #E6E9E4; --muted: #A3ABA5;
  --rule: #39413B; --control: #7A837C;
  --focus: #6FA8F0; --error: #F2867E;
  --cattle: #E8693F; --horses: #6FA8F0; --deer: #F2D06B; --grass: #6CC28F;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --ground: #121614; --surface: #1A1F1C; --rail: #222924;
    --shell: #0F1E16; --on-shell: #E6E9E4;
    --ink: #E6E9E4; --muted: #A3ABA5;
    --rule: #39413B; --control: #7A837C;
    --focus: #6FA8F0; --error: #F2867E;
    --cattle: #E8693F; --horses: #6FA8F0; --deer: #F2D06B; --grass: #6CC28F;
  }
}

/* Dash 4 component theme -> our tokens (otherwise Dash's navy text is unreadable in dark) */
:root {
  --Dash-Text-Primary: var(--ink); --Dash-Text-Strong: var(--ink); --Dash-Text-Weak: var(--muted);
  --Dash-Text-Disabled: var(--muted); --Dash-Stroke-Strong: var(--control); --Dash-Stroke-Weak: var(--rule);
  --Dash-Fill-Interactive-Strong: var(--focus); --Dash-Fill-Inverse-Strong: var(--surface);
  --Dash-Fill-Interactive-Weak: transparent;
}
/* One tab stop per number field: hide Dash's -/+ steppers (arrow keys still step). */
.dash-input-stepper { display: none !important; }
/* Dash 4's input.css loads after this file and fixes the container at 34px with no border:
   these selectors are more specific, so they win (accessibility audit, fix 1). */
.dash-input-container.input {
  height: auto; min-height: 44px; overflow: visible; max-width: 12rem; padding: 0;
  border: 1px solid var(--control); background: var(--surface); border-radius: var(--radius);
}
.dash-input-container.input:has(:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }
.dash-input-container.input:has([aria-invalid="true"]) { border: 2px solid var(--error); }
.dash-input-container.input .dash-input-element {
  width: 100%; min-height: 42px; padding: 8px 10px; border: 0; font: inherit;
  color: var(--ink); background: transparent;
}
.dash-input-container.input input.dash-input-element:invalid { color: var(--ink); }

/* Choice groups (toggle buttons) */
.group-label { font-weight: 600; margin-bottom: 4px; }
.choice-group { margin-bottom: 16px; }
.choices { display: flex; flex-direction: column; gap: 6px; }
.page > .choice-group .choices { flex-direction: row; flex-wrap: wrap; }
.choice {
  min-height: 44px; padding: 8px 12px; text-align: left; font: inherit; cursor: pointer;
  color: var(--ink); background: var(--surface); border: 1px solid var(--control); border-radius: var(--radius);
}
.choice[aria-pressed="true"] { border: 2px solid var(--ink); font-weight: 600; box-shadow: inset 4px 0 0 var(--ink); }

*, *::before, *::after { box-sizing: border-box; }
html { font-size: 100%; }
body {
  margin: 0; background: var(--ground); color: var(--ink);
  font-family: var(--font); font-size: 1rem; line-height: 1.5;
  font-variant-numeric: tabular-nums;
}
h1 { font-size: 1.75rem; line-height: 1.2; margin: 0 0 8px; }
h2 { font-size: 1.1875rem; line-height: 1.3; margin: 0 0 8px; }
p { margin: 0 0 8px; }
a { color: var(--focus); }
.lede { color: var(--muted); max-width: 72ch; margin-bottom: 24px; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* Focus: always visible, never removed */
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
main:focus { outline: none; } /* programmatic focus target of the skip link only */
main:focus-visible { outline: 3px solid var(--focus); }

.skip-link {
  position: absolute; left: 16px; top: -64px; z-index: 10;
  background: var(--surface); color: var(--ink); padding: 12px 16px; border-radius: var(--radius);
}
.skip-link:focus { top: 8px; }
/* On the green shell the blue focus colour is too faint (2.09:1): use the shell's text colour. */
.shell :focus-visible, .site-nav :focus-visible { outline-color: var(--on-shell); }
.skip-link:focus-visible { outline-color: var(--ink); }

/* Shell */
.shell {
  background: var(--shell); color: var(--on-shell);
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 24px;
}
.brand { margin: 0; font-weight: 600; font-size: 1.1875rem; }
.site-nav { background: var(--shell); padding: 0 16px 8px; }
.site-nav ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px; }
.nav-link {
  display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 8px 14px;
  color: var(--on-shell); text-decoration: none; border-radius: var(--radius);
}
.nav-link:hover { background: rgba(255, 255, 255, 0.1); }
.nav-link[aria-current="page"] { background: var(--ground); color: var(--ink); font-weight: 600; }
.chip {
  display: inline-block; font-size: 0.75rem; font-weight: 600; padding: 1px 8px;
  border: 1px solid currentColor; border-radius: 999px; vertical-align: middle;
}
h1 .chip { font-size: 0.875rem; }

main { display: block; padding: 24px; max-width: 1440px; margin: 0 auto; }
.page.narrow { max-width: 960px; }

/* Buttons and inputs: 44px targets */
.button {
  min-height: 44px; padding: 8px 16px; border-radius: var(--radius); cursor: pointer;
  font: inherit; font-weight: 600; background: var(--ink); color: var(--ground);
  border: 1px solid var(--ink);
}
.button.secondary { background: transparent; color: var(--ink); border-color: var(--control); }
.button.on-shell { background: transparent; color: var(--on-shell); border-color: var(--on-shell); }
.button-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0 8px; }

.field { margin-bottom: 12px; }
.field label { display: block; font-weight: 600; margin-bottom: 4px; }
.input {
  width: 100%; max-width: 12rem; min-height: 44px; padding: 8px 10px; font: inherit;
  color: var(--ink); background: var(--surface);
  border: 1px solid var(--control); border-radius: var(--radius);
}
.input[aria-invalid="true"] { border: 2px solid var(--error); }
.field-error { color: var(--error); font-size: 0.875rem; margin: 4px 0 0; min-height: 0; }
.field-error:empty { display: none; }

.fieldset { border: 0; padding: 0; margin: 0 0 16px; }
.fieldset legend { font-weight: 600; margin-bottom: 4px; padding: 0; }
.fieldset.inline { margin-bottom: 16px; }
.radios label { display: flex; align-items: center; gap: 8px; min-height: 44px; cursor: pointer; }
.radios.inline { display: flex; flex-wrap: wrap; gap: 0 24px; }
.radios input { width: 20px; height: 20px; accent-color: var(--focus); }
.total-readout { font-weight: 600; }
.status { color: var(--muted); font-size: 0.875rem; min-height: 1.5em; }

/* Layout */
.layout-rail { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 24px; align-items: start; }
.rail { background: var(--rail); border-radius: var(--radius); padding: 16px; }
/* Sticky only where the whole rail fits, so its buttons never end up off-screen. */
@media (min-height: 900px) and (min-width: 901px) {
  .rail { position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow-y: auto; }
}
.results { display: grid; gap: 16px; min-width: 0; }
.two-col { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }

.card {
  background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius);
  padding: 16px; min-width: 0;
}
.page.narrow .card { margin-bottom: 16px; }
.verdict { border-top: 4px solid var(--ink); }
.verdict-text { font-size: 1.1875rem; font-weight: 600; max-width: 70ch; }
.summary { color: var(--muted); max-width: 90ch; }
.caption { color: var(--muted); font-size: 0.875rem; }
.card-actions { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 8px 16px; margin-top: 8px; }
.card-actions details { flex: 1 1 320px; }
.card-actions summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; font-weight: 600; }
.table-wrap { overflow-x: auto; }

.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.tile { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: 12px 16px; }
.tile-label { color: var(--muted); font-size: 0.875rem; font-weight: 600; margin-bottom: 4px; }
.tile-value { font-size: 1.4375rem; font-weight: 700; margin-bottom: 4px; }
.tile-note { color: var(--muted); font-size: 0.875rem; margin: 0; }

.assumptions {
  border-left: 4px solid var(--control); padding: 8px 12px; background: var(--surface);
  color: var(--muted); font-size: 0.875rem;
}
.alert {
  border: 2px solid var(--error); border-radius: var(--radius); padding: 12px 16px;
  background: var(--surface); color: var(--ink);
}

.data-table { border-collapse: collapse; width: 100%; font-size: 0.875rem; margin-top: 8px; }
.data-table caption { text-align: left; font-weight: 600; padding-bottom: 4px; }
.data-table th, .data-table td { border-bottom: 1px solid var(--rule); padding: 6px 8px; text-align: right; }
.data-table th[scope="row"], .data-table th:first-child { text-align: left; }
.data-table td:only-child { text-align: left; }
.page.narrow .data-table td { text-align: left; }

.equation {
  background: var(--rail); padding: 12px; border-radius: var(--radius); overflow-x: auto;
  font-size: 0.875rem; white-space: pre;
}

/* Recompute: keep the old results visible, dimmed, while the model runs (aria-busy set in JS) */
.graph[data-dash-is-loading="true"], .results[aria-busy="true"] .graph { opacity: 0.5; }
.graph { transition: opacity 150ms ease-out; }
/* Results that belong to earlier settings (invalid input or failed run) */
.results.is-stale .card, .results.is-stale .tile { opacity: 0.6; }
.stale-note:empty { display: none; }
.stale-note { font-weight: 600; border-left: 4px solid var(--error); padding: 4px 12px; margin: 0; }

/* Charts keep a usable plot width: below 480px the chart scrolls sideways instead */
.graph-scroll { overflow-x: auto; }
.graph-scroll .graph { min-width: 480px; }

/* Placeholders before the first run, so nothing shifts when values arrive */
.tile-value:empty::before, .summary:empty::before, .verdict-text:empty::before { content: "\2014"; }

/* Dash's own startup text uses "..." */
._dash-loading { font-size: 0; }
._dash-loading::after { content: "Loading\2026"; font-size: 1rem; padding: 24px; display: block; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0ms !important; animation-duration: 0ms !important; }
}

/* Reflow */
@media (max-width: 1100px) {
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .two-col { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 900px) {
  .layout-rail { grid-template-columns: minmax(0, 1fr); }
  .rail { position: static; }
}
@media (max-width: 600px) {
  main { padding: 16px; }
  .shell { padding: 12px 16px; flex-wrap: wrap; }
  .tiles { grid-template-columns: minmax(0, 1fr); }
  .input { max-width: none; }
}
