/* Warehouse Math — shared styles for every tool. Plain CSS, no build step. */

:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --surface-2: #f0f1f2;
  --ink: #1b1d1f;
  --ink-2: #4a5057;
  --line: #d3d7dc;
  /* Form-control boundary: at least 3:1 against surface, bg and button fill (WCAG 1.4.11). */
  --control-border: #7c828a;
  --accent: #1f4e8c;
  --focus: #1f6feb;

  --green: #17692e;
  --green-bg: #e8f5ec;
  --amber: #7a4f00;
  --amber-bg: #fff4d9;
  --red: #b42318;
  --red-bg: #fdecea;
  --neutral: #555b62;
  --neutral-bg: #eef0f2;

  /* Plan-view colours, read by app.js */
  --draw-building: #dfe3e8;
  --draw-building-line: #545d68;
  --draw-court: #cbd9ec;
  --draw-min: #b42318;
  --draw-door: #1b1d1f;
  --draw-grade: #9a6400;
  --draw-stall: #6f7c8b;
  --draw-col: #6f7c8b;
  --draw-dim: #3f454c;

  /* Chart series (categorical slots 1-2), validated for CVD and 3:1 against --surface in both modes */
  --series-1: #2a78d6;
  --series-2: #eb6834;

  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121416;
    --surface: #1a1d20;
    --surface-2: #23272b;
    --ink: #e8eaed;
    --ink-2: #aab1b8;
    --line: #363c43;
    --control-border: #737b85;
    --accent: #8ab4f8;
    --focus: #8ab4f8;

    --green: #56c271;
    --green-bg: #132a1b;
    --amber: #e8b949;
    --amber-bg: #2f2510;
    --red: #ff8a80;
    --red-bg: #361719;
    --neutral: #a3abb4;
    --neutral-bg: #24282c;

    --draw-building: #2b3139;
    --draw-building-line: #9ba5b0;
    --draw-court: #233850;
    --draw-min: #ff8a80;
    --draw-door: #eef0f2;
    --draw-grade: #e8b949;
    --draw-stall: #8d9aa8;
    --draw-col: #7d8792;
    --draw-dim: #c3c9cf;

    --series-1: #3987e5;
    --series-2: #d95926;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
}

.wrap { max-width: 1240px; margin: 0 auto; padding: 0 16px; }

a { color: var(--accent); }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

.skip-link {
  position: absolute; left: 8px; top: -48px;
  background: var(--surface); color: var(--ink);
  padding: 8px 12px; border-radius: 6px; z-index: 10;
}
.skip-link:focus { top: 8px; }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------- Breadcrumb (tool pages) ---------- */
.crumbs ol { list-style: none; margin: 0 0 10px; padding: 0; display: flex; flex-wrap: wrap; gap: 4px; font-size: 0.9rem; }
.crumbs li + li::before { content: "/"; margin-right: 4px; color: var(--ink-2); }
.crumbs a { color: var(--ink-2); text-decoration: none; }
.crumbs a:hover { text-decoration: underline; }
.crumbs a[aria-current="page"] { color: var(--ink); }

/* ---------- Home: tool cards ---------- */
.tools {
  list-style: none; margin: 20px 0 40px; padding: 0;
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr));
}
.tool-card {
  display: flex; flex-direction: column; gap: 8px; height: 100%;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 16px;
}
.tool-card h2 { margin: 0; font-size: 1.2rem; }
.tool-card h2 a { color: var(--ink); text-decoration: none; }
.tool-card h2 a::after { content: ""; position: absolute; inset: 0; } /* whole card is the link target */
.tool-card { position: relative; }
.tool-card:hover { border-color: var(--control-border); }
.tool-card:focus-within { outline: 3px solid var(--focus); outline-offset: 2px; }
.tool-card p { margin: 0; color: var(--ink-2); }
.tool-card .checks { margin: 4px 0 0; padding-left: 18px; color: var(--ink-2); font-size: 0.92rem; }
.tool-card .go { margin-top: auto; padding-top: 6px; font-weight: 600; color: var(--accent); }
.home-intro { max-width: 70ch; }

/* ---------- Header ---------- */
.site-header { padding: 28px 0 8px; }
.site-header h1 { margin: 0 0 6px; font-size: clamp(1.6rem, 4vw, 2.2rem); line-height: 1.2; letter-spacing: -0.01em; }
.lede { margin: 0 0 6px; max-width: 70ch; color: var(--ink-2); font-size: 1.05rem; }
.screening-note { margin: 0; font-size: 0.9rem; color: var(--ink-2); }

.noscript { padding: 12px 16px; background: var(--amber-bg); border-radius: var(--radius); }

/* ---------- Tool layout ---------- */
.tool-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  margin: 20px 0 32px;
}
@media (min-width: 760px) {
  .tool-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .results { grid-column: 1 / -1; }
}
@media (min-width: 1180px) {
  .tool-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1.2fr); align-items: start; }
  .results { grid-column: auto; }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 16px 12px;
  min-width: 0;
}
.panel h2 {
  display: flex; align-items: center; gap: 10px;
  margin: 0 0 14px; font-size: 1.15rem;
}
.step {
  display: inline-grid; place-items: center;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--surface-2); border: 1px solid var(--line);
  font-size: 0.85rem; font-weight: 700;
}

/* ---------- Fields ---------- */
/* align-content: start keeps label and input together when a neighbouring field in the same row is taller. */
.field { display: grid; gap: 4px; margin: 0 0 14px; min-width: 0; align-content: start; }
fieldset.field { border: 0; padding: 0; }
.field label, .field legend { font-weight: 600; font-size: 0.95rem; padding: 0; }
.hint { margin: 0; font-size: 0.85rem; color: var(--ink-2); }
/* A helper line inside a field ends the field (the field's 14px margin follows it); a helper line that
   stands on its own in a panel or fieldset gets the same 14px before the next label. */
.panel > .hint, fieldset > .hint { margin-bottom: 14px; }
fieldset > legend + .hint { margin-top: 2px; }

input[type="number"], input[type="text"], select {
  font: inherit;
  width: 100%;
  min-height: 44px;
  padding: 9px 11px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--control-border);
  border-radius: 8px;
}
input[type="number"]:hover, input[type="text"]:hover, select:hover { border-color: var(--ink-2); }
/* Placeholders get an explicit token instead of the browser default, which is faint on dark panels. */
input::placeholder { color: var(--ink-2); opacity: 1; }
input[aria-invalid="true"] { border: 2px solid var(--red); }
input[type="range"] { width: 100%; min-height: 32px; accent-color: var(--accent); }
.range-out { font-size: 0.9rem; color: var(--ink-2); }

.radios { display: flex; gap: 20px; }
.radio {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 44px; font-weight: 400 !important; cursor: pointer;
}
.radio input { width: 20px; height: 20px; margin: 0; accent-color: var(--accent); }

.field-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
.field-row .field { margin-bottom: 0; }
.field-row--by { grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: end; }
.field-row--by .field label { font-weight: 400; font-size: 0.9rem; }
.by { padding-bottom: 11px; color: var(--ink-2); }
fieldset.field .field-row { margin-top: 4px; }
.field-row + .field, .field-row { margin-bottom: 14px; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 6px; }
.btn {
  font: inherit; font-size: 0.9rem;
  min-height: 40px; padding: 8px 12px;
  color: var(--ink); background: var(--surface-2);
  border: 1px solid var(--control-border); border-radius: 8px; cursor: pointer;
}
.btn:hover { border-color: var(--ink-2); }

/* ---------- Results ---------- */
.overall {
  display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; align-items: start;
  padding: 14px; margin: 8px 0 14px;
  border-radius: var(--radius); border: 2px solid var(--st); background: var(--st-bg);
}
.overall .icon { grid-row: span 2; width: 34px; height: 34px; color: var(--st); }
.overall .headline { margin: 0; font-size: 1.2rem; font-weight: 700; line-height: 1.3; }
.overall .reason { margin: 0; font-size: 0.95rem; }

[data-status="green"] { --st: var(--green); --st-bg: var(--green-bg); }
[data-status="amber"] { --st: var(--amber); --st-bg: var(--amber-bg); }
[data-status="red"] { --st: var(--red); --st-bg: var(--red-bg); }
[data-status="pending"] { --st: var(--neutral); --st-bg: var(--neutral-bg); }

.cards { display: grid; gap: 12px; }
.card {
  border: 1px solid var(--line);
  border-left: 6px solid var(--st);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 12px 14px;
}
.card-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.card-head h3 { margin: 0; font-size: 1.02rem; }
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px 2px 6px; border-radius: 999px;
  background: var(--st-bg); color: var(--st);
  font-size: 0.82rem; font-weight: 700;
  border: 1px solid var(--st);
}
.badge .icon { width: 16px; height: 16px; }
.card-sentence { margin: 0 0 8px; }

.nums { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 2px 12px; margin: 0 0 8px; font-size: 0.9rem; }
.nums dt { color: var(--ink-2); }
.nums dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

.notes { margin: 0 0 8px; padding-left: 18px; font-size: 0.9rem; }
.notes li { margin: 2px 0; }

details.why { border-top: 1px solid var(--line); padding-top: 6px; }
details.why summary {
  cursor: pointer; font-weight: 600; font-size: 0.9rem; color: var(--accent);
  min-height: 32px; display: flex; align-items: center; gap: 6px; list-style: none;
}
details.why summary::-webkit-details-marker { display: none; }
details.why summary::before {
  content: ""; width: 0; height: 0;
  border-left: 6px solid currentColor; border-top: 5px solid transparent; border-bottom: 5px solid transparent;
  transition: transform 0.15s;
}
details.why[open] summary::before { transform: rotate(90deg); }
.why-body { font-size: 0.88rem; color: var(--ink-2); }
.why-body p { margin: 4px 0; }
.why-body code, .why-body .calc { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 0.85rem; color: var(--ink); }

.unscored { margin-top: 12px; font-size: 0.88rem; color: var(--ink-2); }
.unscored p { margin: 4px 0; }
.fine { margin: 12px 0 4px; font-size: 0.82rem; color: var(--ink-2); }

/* ---------- Plan ---------- */
.plan, .lead, .guide { margin: 0 0 36px; }
.plan h2, .lead h2 { font-size: 1.35rem; margin: 0 0 10px; }
.plan-figure { margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.canvas-wrap { width: 100%; }
#plan { display: block; width: 100%; }
.plan-desc { margin: 10px 0 8px; font-size: 0.92rem; }
.legend { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 0.85rem; color: var(--ink-2); }
.legend li { display: inline-flex; align-items: center; gap: 6px; }
.sw { display: inline-block; width: 18px; height: 12px; border-radius: 2px; }
.sw-building { background: var(--draw-building); border: 1px solid var(--draw-building-line); }
.sw-court { background: var(--draw-court); }
.sw-min { height: 0; border-top: 2px dashed var(--draw-min); border-radius: 0; }
.sw-door { width: 6px; background: var(--draw-door); }
.sw-grade { width: 12px; border: 2px solid var(--draw-grade); background: transparent; }
.sw-stall { border: 1px solid var(--draw-stall); background: transparent; }
.sw-col { width: 6px; height: 6px; border-radius: 50%; background: var(--draw-col); }

/* ---------- Lead ---------- */
.lead { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 16px; }
.lead > p { margin: 0 0 12px; max-width: 70ch; }
.tally-placeholder {
  border: 2px dashed var(--line); border-radius: var(--radius);
  padding: 16px; background: var(--surface-2); font-size: 0.92rem;
}
.tally-placeholder p { margin: 0 0 6px; }
.tally-embed iframe { display: block; width: 100%; border: 0; }
.form-card {
  background: #ffffff; border-radius: 12px; padding: 20px;
  color-scheme: light; /* the embedded form renders in its light scheme, matching the card */
}
@media (prefers-color-scheme: dark) { .form-card { border: 1px solid var(--line); } }
@media (max-width: 420px) { .form-card { padding: 14px; } }

/* ---------- Guide ---------- */
.guide { max-width: 760px; }
.guide h2 { font-size: 1.3rem; margin: 30px 0 8px; line-height: 1.3; }
.guide p, .guide li { max-width: 70ch; }
.guide li { margin: 6px 0; }
.byline { color: var(--ink-2); font-size: 0.9rem; margin: 0; }
.table-wrap { overflow-x: auto; margin: 12px 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { border-collapse: collapse; width: 100%; min-width: 560px; font-size: 0.92rem; }
caption { text-align: left; padding: 10px 12px 4px; font-weight: 600; }
th, td { text-align: left; padding: 8px 12px; border-top: 1px solid var(--line); vertical-align: top; }
thead th { background: var(--surface-2); font-size: 0.85rem; }

/* ---------- Footer ---------- */
.site-footer {
  border-top: 1px solid var(--line);
  background: var(--surface);
  padding: 18px 0 22px;
  font-size: 0.9rem;
  color: var(--ink-2);
}
.site-footer p { margin: 0; }

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

/* ==================== Renew or Relocate ==================== */
.tool-grid--inputs { margin-bottom: 16px; }
@media (min-width: 760px) {
  .tool-grid--inputs { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .tool-grid--inputs > :nth-child(3) { grid-column: 1 / -1; }
}
@media (min-width: 1180px) {
  .tool-grid--inputs { grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: stretch; }
  .tool-grid--inputs > :nth-child(3) { grid-column: auto; }
}
.field.check { margin-bottom: 8px; }
.rr-moving { margin: 0 0 16px; }
.rr-moving-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0 20px; }
.rr-moving-grid .sub-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0 20px; }
@media (min-width: 760px) {
  .rr-moving-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .rr-moving-grid .span-all { grid-column: 1 / -1; }
  .rr-moving-grid .span-2 { grid-column: span 2; }
  .rr-moving-grid .span-all .sub-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .rr-moving-grid .span-2 .sub-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.rr-moving-grid fieldset.field { margin-bottom: 0; }
.rr-moving-grid legend { margin-bottom: 6px; }
.rr-settings { margin: 0 0 20px; }
@media (min-width: 760px) {
  .rr-settings { display: grid; grid-template-columns: minmax(0, 22rem) 1fr; gap: 4px 24px; align-items: end; }
  .rr-settings .actions { margin: 0 0 14px; }
  .rr-settings .hint { grid-column: 1 / -1; }
}
.rr-results { margin: 0 0 36px; }
.rr-headline {
  margin: 8px 0 14px; padding: 14px;
  border: 2px solid var(--accent); border-radius: var(--radius); background: var(--surface-2);
}
.rr-headline[data-status="pending"] { border-color: var(--neutral); }
.rr-headline .headline { margin: 0; font-size: 1.2rem; font-weight: 700; line-height: 1.35; }
.rr-headline .note { margin: 8px 0 0; font-size: 0.95rem; }
.rr-warning {
  display: flex; gap: 10px; align-items: flex-start;
  margin: 10px 0 0; padding: 10px 12px; border-radius: 8px;
  background: var(--amber-bg); border-left: 6px solid var(--amber);
}
.rr-warning .icon { width: 22px; height: 22px; flex: none; color: var(--amber); }
.rr-warning p { margin: 0; }
.rr-paths { display: grid; gap: 12px; }
@media (min-width: 760px) { .rr-paths { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }
.rr-path { border: 1px solid var(--line); border-top: 5px solid var(--series-1); border-radius: var(--radius); padding: 12px 14px; background: var(--surface); }
.rr-path[data-path="relocate"] { border-top-color: var(--series-2); }
.rr-path-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.rr-path-head h3 { margin: 0; font-size: 1.1rem; }
.rr-lower {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px 2px 6px; border-radius: 999px;
  border: 1px solid var(--ink-2); color: var(--ink); font-size: 0.82rem; font-weight: 700;
}
.rr-lower .icon { width: 16px; height: 16px; }
.rr-figs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 10px 0; }
@media (max-width: 420px) { .rr-figs { grid-template-columns: minmax(0, 1fr); } }
.rr-fig { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; min-width: 0; }
.rr-fig.is-lead { box-shadow: inset 0 0 0 2px var(--accent); }
.rr-fig .k { display: block; font-size: 0.8rem; color: var(--ink-2); }
.rr-fig .v { display: block; font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.rr-fig .u { font-size: 0.8rem; font-weight: 400; color: var(--ink-2); }
.rr-path .sub { margin: 0 0 6px; font-size: 0.88rem; color: var(--ink-2); }
.rr-breakeven { margin: 16px 0; padding: 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.rr-breakeven .k { margin: 0; font-weight: 600; }
.rr-be-value { margin: 4px 0; font-size: clamp(2rem, 7vw, 2.8rem); font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.rr-be-value .u { font-size: 1rem; font-weight: 600; color: var(--ink-2); }
.rr-breakeven p { margin: 4px 0; }
.rr-h3 { font-size: 1.05rem; margin: 22px 0 8px; }
.rr-assumptions { margin: 0; padding-left: 18px; font-size: 0.9rem; color: var(--ink-2); }
.rr-assumptions li { margin: 3px 0; }
#rr-years td.num, #rr-years th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
#rr-years tfoot td, #rr-years tfoot th { font-weight: 700; border-top: 2px solid var(--control-border); }
.rr-chart .legend { margin-bottom: 8px; }
.sw-series1 { background: var(--series-1); }
.sw-series2 { background: var(--series-2); }
#chart-wrap { position: relative; }
#chart { display: block; width: 100%; }
.chart-tip {
  position: absolute; z-index: 2; pointer-events: none; white-space: nowrap;
  background: var(--surface); color: var(--ink); border: 1px solid var(--control-border);
  border-radius: 6px; padding: 6px 8px; font-size: 0.85rem; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}
.chart-tip strong { display: block; }
