/*
 * One stylesheet, tokens first.
 *
 * Light and dark are both chosen, not flipped: the dark values are their own
 * steps against the dark surface rather than an inversion of the light ones.
 * They are declared twice on purpose - once for the operating system's
 * setting, once for the toggle - so that a visitor who picks light on a dark
 * machine gets light.
 *
 * The chart reads its colours from these same properties, so the figures and
 * the prose never drift apart.
 */

:root {
  color-scheme: light;

  --page: #f4f3f0;
  --surface-1: #fcfcfb;
  --surface-sunken: #f0efec;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #77756f;
  --border: #e3e2dd;
  --grid: #e8e7e2;
  --series-1: #2a78d6;

  /* Status colours are fixed in both modes and never used as a series. */
  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-critical: #d03b3b;

  --radius: 10px;
  --gap: 1.5rem;
  --measure: 68ch;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #121211;
    --surface-1: #1a1a19;
    --surface-sunken: #222220;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #8f8e85;
    --border: #33332f;
    --grid: #2b2b28;
    --series-1: #3987e5;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #121211;
  --surface-1: #1a1a19;
  --surface-sunken: #222220;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #8f8e85;
  --border: #33332f;
  --grid: #2b2b28;
  --series-1: #3987e5;
}

/* --- Base ---------------------------------------------------------------- */

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font: 16px/1.6 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
}

.wrap {
  max-width: 62rem;
  margin: 0 auto;
  padding: 0 1.25rem;
}

h1, h2, h3 {
  line-height: 1.25;
  margin: 0 0 0.5rem;
  font-weight: 650;
}

h1 { font-size: clamp(1.75rem, 4vw, 2.5rem); }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; }

p { max-width: var(--measure); margin: 0 0 1rem; }
p:last-child { margin-bottom: 0; }

a { color: var(--series-1); }

/* --- Header and footer --------------------------------------------------- */

.site-header {
  padding: 3rem 0 2rem;
  border-bottom: 1px solid var(--border);
}

.lead {
  font-size: 1.1rem;
  color: var(--text-secondary);
}

.privacy {
  padding: 0.85rem 1rem;
  border-left: 3px solid var(--status-good);
  background: var(--surface-1);
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--text-secondary);
}

.privacy strong { color: var(--text-primary); }

.theme-toggle {
  float: right;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-secondary);
  border-radius: 999px;
  padding: 0.3rem 0.85rem;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

.theme-toggle:hover { color: var(--text-primary); }

.site-footer {
  margin-top: 3rem;
  padding: 2rem 0 3rem;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* --- Panels -------------------------------------------------------------- */

main { padding: 2rem 0; }

.panel {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: var(--gap);
}

.panel > p { color: var(--text-secondary); }

.panel.is-blocking { border-left: 3px solid var(--status-critical); }

.disclaimer { background: var(--surface-sunken); }

.notice {
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  border-left: 3px solid var(--status-warning);
  background: var(--surface-sunken);
  border-radius: 0 var(--radius) var(--radius) 0;
}

/* --- Choosing a file ----------------------------------------------------- */

.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2rem 1.5rem;
  text-align: center;
  transition: border-color 120ms ease, background 120ms ease;
}

.drop-zone[data-dragging] {
  border-color: var(--series-1);
  background: var(--surface-sunken);
}

.drop-label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.75rem;
}

.drop-zone input[type="file"] { font: inherit; max-width: 100%; }
.drop-zone input[type="file"]:disabled { opacity: 0.5; }

.file-name {
  margin: 0.75rem auto 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.status {
  margin-top: 1rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.status[data-state="ready"] { color: var(--text-secondary); }
.status[data-state="failed"] { color: var(--status-critical); }

/* --- The form ------------------------------------------------------------ */

.assumptions {
  display: grid;
  gap: 1.25rem;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
  margin: 0;
}

.field { min-width: 0; border: 0; padding: 0; margin: 0; }

.field > label, .field > legend {
  display: block;
  font-weight: 600;
  margin-bottom: 0.35rem;
  padding: 0;
}

.input-row { display: flex; align-items: stretch; }

.prefix {
  display: flex;
  align-items: center;
  padding: 0 0.6rem;
  border: 1px solid var(--border);
  border-right: 0;
  border-radius: 6px 0 0 6px;
  background: var(--surface-sunken);
  color: var(--text-muted);
}

.input-row input { border-radius: 0 6px 6px 0; }

input, select {
  width: 100%;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-1);
  color: var(--text-primary);
  font: inherit;
  font-variant-numeric: tabular-nums;
}

input:focus-visible, select:focus-visible, .theme-toggle:focus-visible,
summary:focus-visible, .chart-hit:focus-visible {
  outline: 2px solid var(--series-1);
  outline-offset: 2px;
}

.input-pair {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.4rem 0.6rem;
  align-items: center;
}

.input-pair label { color: var(--text-secondary); font-size: 0.9rem; }

.hint {
  margin: 0.4rem 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* --- Figures ------------------------------------------------------------- */

.hero { margin: 0.5rem 0 1.5rem; }

.hero-figure {
  display: block;
  font-size: clamp(2.75rem, 7vw, 3.5rem);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -0.02em;
}

.label {
  display: block;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.stat-row {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  margin-bottom: 1.25rem;
}

.stat {
  padding: 0.85rem 1rem;
  background: var(--surface-sunken);
  border-radius: var(--radius);
}

.stat-value {
  display: block;
  font-size: 1.35rem;
  font-weight: 650;
  margin-top: 0.15rem;
}

/* --- Alternatives -------------------------------------------------------- */

.card-row {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(19rem, 1fr));
  margin-top: 1.5rem;
}

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem;
}

.card h3 { color: var(--text-muted); font-size: 0.85rem; text-transform: none; }

.card-subject {
  display: block;
  font-weight: 650;
  margin-bottom: 0.75rem;
}

.card dl {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.3rem 1rem;
  margin: 0 0 0.9rem;
  font-variant-numeric: tabular-nums;
}

.card dt { color: var(--text-secondary); font-size: 0.9rem; }
.card dd { margin: 0; text-align: right; font-weight: 600; }
.card p { font-size: 0.9rem; color: var(--text-muted); }

/* --- Tables -------------------------------------------------------------- */

.data-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

.data-table th, .data-table td {
  text-align: right;
  padding: 0.45rem 0.6rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table thead th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.8rem;
}

.data-table th:first-child,
.data-table td:last-child {
  text-align: left;
  white-space: normal;
}

.data-table tbody th { font-weight: 500; }
.data-table tbody tr:hover { background: var(--surface-sunken); }

.data-table tr.is-recommended {
  background: var(--surface-sunken);
}

.data-table tr.is-recommended th:first-child {
  font-weight: 700;
  box-shadow: inset 3px 0 0 var(--series-1);
}

/* --- The chart ----------------------------------------------------------- */

.chart-figure { margin: 1.25rem 0 0; }

.chart-holder { position: relative; }

.chart { width: 100%; height: auto; display: block; overflow: visible; }

.chart-column { fill: var(--series-1); }
.chart-column.is-below { fill: var(--series-1); opacity: 0.35; }

.chart-grid { stroke: var(--grid); stroke-width: 1; }

.chart-threshold {
  stroke: var(--text-secondary);
  stroke-width: 2;
  stroke-linecap: round;
}

.chart-marker { stroke: var(--text-muted); stroke-width: 1; }

.chart-annotation {
  fill: var(--text-secondary);
  font-size: 12px;
}

.chart-tick {
  fill: var(--text-muted);
  font-size: 11px;
  text-anchor: middle;
  font-variant-numeric: tabular-nums;
}

.chart-tick.is-vertical { text-anchor: end; }

.chart-axis-title {
  fill: var(--text-muted);
  font-size: 12px;
  text-anchor: middle;
}

.chart-hit { fill: transparent; cursor: default; }
.chart-hit:hover { fill: var(--text-primary); fill-opacity: 0.04; }

.chart-tooltip {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  max-width: 17rem;
  padding: 0.5rem 0.7rem;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 2px 10px rgb(0 0 0 / 12%);
  font-size: 0.82rem;
  color: var(--text-secondary);
  pointer-events: none;
}

.chart-tooltip strong { display: block; color: var(--text-primary); }

/* --- Caveats ------------------------------------------------------------- */

.caveat {
  padding: 0.85rem 1rem;
  margin-bottom: 0.75rem;
  border-left: 3px solid var(--border);
  background: var(--surface-sunken);
  border-radius: 0 var(--radius) var(--radius) 0;
}

.caveat:last-child { margin-bottom: 0; }
.caveat.is-blocking { border-left-color: var(--status-critical); }
.caveat.is-warning { border-left-color: var(--status-warning); }
.caveat.is-context { border-left-color: var(--text-muted); }

.caveat-tag {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.2rem;
}

.caveat h3 { font-size: 1rem; }
.caveat p { font-size: 0.92rem; color: var(--text-secondary); }

/* --- Disclosure ---------------------------------------------------------- */

details { margin-top: 1.25rem; }

summary {
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 600;
}

details ul { color: var(--text-secondary); font-size: 0.9rem; }

details pre {
  white-space: pre-wrap;
  font-size: 0.8rem;
  color: var(--text-muted);
  background: var(--surface-sunken);
  padding: 0.6rem;
  border-radius: 6px;
}

/* Scrolling belongs to the table, not to the page. */
.panel > .data-table,
details > .data-table {
  display: block;
  overflow-x: auto;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}

/* --- What the contract changes ------------------------------------------- */

.contract {
  margin: 1.5rem 0 0;
  padding: 1.1rem 1.25rem;
  background: var(--surface-sunken);
  border-radius: var(--radius);
}

.contract h3 { font-size: 1rem; margin-bottom: 0.75rem; }

.contract-rows {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem 1.5rem;
  align-items: baseline;
  margin: 0 0 1rem;
}

.contract-rows dt { color: var(--text-secondary); }

.contract-rows dd {
  margin: 0;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.contract-amount {
  font-size: 1.2rem;
  font-weight: 650;
  margin-right: 0.5rem;
}

.contract-rows .label { display: inline; font-size: 0.82rem; }

.contract p { font-size: 0.9rem; color: var(--text-muted); }

/* --- Repeatable periods -------------------------------------------------- */

/* The pairs of dates need the full width of the form, not one column. */
.field-wide { grid-column: 1 / -1; }

.exclusion {
  margin-bottom: 0.5rem;
  grid-template-columns: auto 1fr auto 1fr;
}

.secondary {
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-secondary);
  border-radius: 6px;
  padding: 0.4rem 0.8rem;
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}

.secondary:hover:not(:disabled) { color: var(--text-primary); }
.secondary:disabled { opacity: 0.5; cursor: default; }

.recognised h4 {
  margin: 1rem 0 0.25rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

@media (max-width: 30rem) {
  .exclusion { grid-template-columns: auto 1fr; }
}

/* --- The bill ------------------------------------------------------------ */

.bill tr.is-total th,
.bill tr.is-total td {
  border-top: 2px solid var(--border);
  border-bottom: 0;
  font-weight: 700;
  padding-top: 0.6rem;
}

/* A line that got cheaper is the point of the table, so it is marked - but
   the sign in front of the number is what says so, not the colour. */
.bill .is-cheaper { color: var(--status-good); }
