/* Waltham Forest SEND data. Light and dark themes share one set of roles.
   Echoes the borough's feel (forest green, heather accent) but deliberately
   avoids the council's exact colours, typefaces and logo: this is an independent site. */
:root {
  color-scheme: light;
  --page: #f7f6f1;
  --surface: #ffffff;
  --ink: #1c211e;
  --ink-2: #49524c;
  --muted: #646d67;
  --grid: #e8e7e0;
  --axis: #bdbcb0;
  --border: #dcdcd2;
  --link: #1d5ea6;
  --forest: #24543a;      /* brand: masthead band */
  --forest-ink: #1f5a3c;  /* green used as text */
  --forest-tint: #e4efe6;
  --on-forest: #ffffff;
  --heather: #8a4b7d;     /* accent: Independent badge, focus ring */
  --amber: #e3a032;       /* attention: current nav, callout bar. Never text */
  --s1: #2c7a4b;   /* Waltham Forest */
  --s2: #cc5f22;   /* London */
  --s3: #56688f;   /* England */
  --s5: #7c4f9f;   /* Similar areas (statistical neighbours' average) */
  --other: #8e9089;   /* ranked bars: 3:1 on surface */
  --good: #2c7a4b;
  --warning: #e3a032;
  --serious: #e0814f;
  --critical: #c23b3b;
  --good-text: #1f5a3c;
  --critical-text: #a52c2c;
  --callout: #fbf1de;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #111412;
    --surface: #1b1f1c;
    --ink: #eef0ec;
    --ink-2: #c3c9c3;
    --muted: #959d96;
    --grid: #262b27;
    --axis: #3d443f;
    --border: #2f3531;
    --link: #8cb8ef;
    --forest-ink: #86c79c;
    --forest-tint: #1c2e22;
    --heather: #d49fc6;
    --s1: #5fb47e;
    --s2: #e5824b;
    --s3: #93a2c8;
    --s5: #c19ae0;
    --other: #6b726c;
    --good: #4fae6e;
    --critical: #e36464;
    --good-text: #86c79c;
    --critical-text: #f08a8a;
    --callout: #2a2416;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #111412;
  --surface: #1b1f1c;
  --ink: #eef0ec;
  --ink-2: #c3c9c3;
  --muted: #959d96;
  --grid: #262b27;
  --axis: #3d443f;
  --border: #2f3531;
  --link: #8cb8ef;
  --forest-ink: #86c79c;
  --forest-tint: #1c2e22;
  --heather: #d49fc6;
  --s1: #5fb47e;
  --s2: #e5824b;
  --s3: #93a2c8;
  --s5: #c19ae0;
  --other: #6b726c;
  --good: #4fae6e;
  --critical: #e36464;
  --good-text: #86c79c;
  --critical-text: #f08a8a;
  --callout: #2a2416;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--page); color: var(--ink);
  font: 16px/1.55 "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
}
a { color: var(--link); }
a:focus-visible, [tabindex]:focus-visible, summary:focus-visible { outline: 3px solid var(--heather); outline-offset: 2px; }
.wrap { max-width: 980px; margin: 0 auto; padding: 0 16px; }
.skip { position: absolute; left: -999px; }
.vh { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip:focus { left: 16px; top: 8px; background: var(--surface); padding: 8px; z-index: 10; }

.masthead { background: var(--forest); color: var(--on-forest); padding: 18px 0 0; }
.masthead .row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.brand { font-weight: 700; font-size: 1.4rem; color: var(--on-forest); text-decoration: none; }
.brand b { border-bottom: 3px solid var(--amber); }
.badge-independent { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px; border: 1.5px solid currentColor; font-size: 0.8rem; font-weight: 700; letter-spacing: .02em; white-space: nowrap; }
.badge-independent::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--amber); }
.tagline { margin: 4px 0 12px; opacity: .92; }
nav ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 2px 4px; }
nav a { display: block; padding: 8px 10px; color: var(--on-forest); opacity: .85; text-decoration: none; border-bottom: 4px solid transparent; font-size: 0.95rem; }
nav a:hover { opacity: 1; }
nav a[aria-current] { opacity: 1; border-bottom-color: var(--amber); font-weight: 700; }
.masthead a:focus-visible { outline-color: var(--on-forest); }

main { padding: 24px 16px 48px; }
h1 { font-size: 1.9rem; line-height: 1.2; margin: 8px 0 12px; }
h2 { font-size: 1.35rem; margin: 40px 0 8px; padding-top: 8px; border-top: 1px solid var(--border); }
h3 { font-size: 1.1rem; margin: 0 0 4px; }
h4.sub { font-size: 0.95rem; margin: 20px 0 6px; color: var(--ink-2); }
p, li { max-width: 72ch; }
.lede { font-size: 1.1rem; color: var(--ink-2); }

.callout { background: var(--callout); border-left: 4px solid var(--warning); padding: 12px 16px; margin: 20px 0; border-radius: 4px; }
.callout p { margin: 6px 0; }

/* stat tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; margin: 20px 0; padding: 0; list-style: none; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px; display: flex; flex-direction: column; }
.tiles > .tile:nth-child(-n+2) { border-top: 4px solid var(--forest); }
.tile .label { font-size: 0.9rem; color: var(--ink-2); margin: 0 0 6px; }
.tile .value { font-size: 2rem; font-weight: 700; line-height: 1.1; }
.tile .compare { font-size: 0.88rem; color: var(--ink-2); margin: 6px 0 0; }
.tile .rank { font-size: 0.85rem; color: var(--muted); margin: 4px 0 0; }
.tile .more { margin-top: auto; padding-top: 8px; font-size: 0.88rem; }

/* figures */
figure.metric { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; margin: 20px 0; padding: 16px; }
.explain { color: var(--ink-2); margin: 0 0 8px; font-size: 0.95rem; }
.note { font-size: 0.9rem; color: var(--ink-2); }
.source { font-size: 0.82rem; color: var(--muted); margin: 10px 0 0; }
.cite { color: var(--ink-2); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 0.88rem; color: var(--ink-2); margin: 6px 0; }
.key { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 14px; height: 3px; border-radius: 2px; background: currentColor; display: inline-block; }
.swatch.s1 { background: var(--s1); height: 4px; } .swatch.s2 { background: var(--s2); } .swatch.s3 { background: var(--s3); } .swatch.s5 { background: var(--s5); }
/* s4: a second local series (e.g. North East London next to NELFT), dashed in the local colour */
.swatch.s4 { background: repeating-linear-gradient(90deg, var(--s1) 0 5px, transparent 5px 8px); }

svg.chart { width: 100%; height: auto; display: block; overflow: visible; }
svg .grid { stroke: var(--grid); stroke-width: 1; }
svg .axis { stroke: var(--axis); stroke-width: 1; }
svg .tick { fill: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
svg .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
svg .line.s1 { stroke: var(--s1); stroke-width: 3; } svg .line.s2 { stroke: var(--s2); } svg .line.s3 { stroke: var(--s3); } svg .line.s5 { stroke: var(--s5); }
svg .line.s4 { stroke: var(--s1); stroke-dasharray: 6 4; }
svg .dot { stroke: var(--surface); stroke-width: 2; }
svg .dot.s1 { fill: var(--s1); } svg .dot.s2 { fill: var(--s2); } svg .dot.s3 { fill: var(--s3); } svg .dot.s5 { fill: var(--s5); }
svg .dot.s4 { fill: var(--surface); stroke: var(--s1); }
svg .hit { fill: transparent; cursor: pointer; }
svg .endlabel { font-size: 12px; fill: var(--ink-2); }
svg .endname { fill: var(--ink); font-weight: 600; }

/* ranked bars */
.ranked { position: relative; font-size: 0.85rem; }
.ranked ol { list-style: none; margin: 0; padding: 0; }
.rb { display: grid; grid-template-columns: 2em 11em 1fr; align-items: center; gap: 6px; min-height: 20px; }
.rb .rn { color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.rb .an { color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rb .bar { position: relative; height: 10px; margin-right: 3.6em; }
.rb .fill { display: block; height: 100%; background: var(--other); border-radius: 0 4px 4px 0; }
.rb.hl .fill { background: var(--s1); }
.rb.hl .an, .rb.hl .rn { color: var(--ink); font-weight: 700; }
.rb .fill { position: relative; }
.rb .val { position: absolute; left: calc(100% + 6px); top: -4px; white-space: nowrap; font-weight: 700; }
.rb:hover .fill, .rb:focus .fill { filter: brightness(0.9); }
.refline { position: absolute; top: -5px; bottom: -5px; width: 0; border-left: 2px solid var(--muted); }
.refline.s2 { border-color: var(--s2); } .refline.s3 { border-color: var(--s3); } .refline.s5 { border-color: var(--s5); }
.rhead { min-height: 34px; }
.rhead .bar { height: 34px; }
.rhead .refline { top: auto; bottom: -5px; height: 12px; }
.reflabel { position: absolute; top: 0; transform: translateX(-50%); font-size: 0.75rem; color: var(--ink-2); white-space: nowrap; }
.reflabel.s3 { top: 15px; }
.ranked { padding: 20px 0; }

/* tables */
details { margin: 10px 0 0; }
summary { cursor: pointer; color: var(--link); font-size: 0.92rem; }
.tablewrap { overflow-x: auto; margin: 8px 0; }
.tablewrap:focus-visible { outline: 3px solid var(--heather); outline-offset: 2px; }
table { border-collapse: collapse; font-size: 0.9rem; font-variant-numeric: tabular-nums; min-width: 100%; }
caption { text-align: left; font-weight: 600; padding: 4px 0; }
th, td { padding: 6px 10px; border-bottom: 1px solid var(--grid); text-align: right; vertical-align: top; }
th:first-child, td.text { text-align: left; }
thead th { color: var(--ink-2); font-weight: 600; border-bottom-color: var(--axis); }
tbody th { font-weight: 600; text-align: left; }
table.wide td, table.wide th { text-align: left; }
.hlcol { font-weight: 700; background: var(--forest-tint); }

/* deadlines calculator */
.calc { display: grid; gap: 4px; max-width: 32rem; margin: 12px 0; padding: 12px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; }
.calc label { font-weight: 600; margin-top: 6px; }
.calc input { font: inherit; padding: 6px 8px; border: 1px solid var(--axis); border-radius: 4px; background: var(--page); color: var(--ink); max-width: 14rem; }
.calc input:focus-visible { outline: 3px solid var(--heather); outline-offset: 2px; }
.deadlines td.when { white-space: nowrap; color: var(--muted); }
.deadlines td.when.set { color: var(--ink); }
.deadlines .rel { font-size: 0.85rem; color: var(--ink-2); }
.deadlines .past .rel { color: var(--critical-text); }

/* status (always with icon + label) */
.status { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; font-weight: 600; }
.status::before { content: ""; width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.status.met::before { background: var(--good); }
.status.behind::before { background: var(--critical); }
.status.improving::before { background: var(--warning); }
.status.nodata::before, .status.unclear::before { background: var(--muted); }
.notarget { color: var(--critical-text); font-weight: 600; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; padding: 0; list-style: none; }
.cards li { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 12px 16px; }
.cards a { font-weight: 600; }
blockquote { margin: 12px 0; padding: 8px 16px; border-left: 4px solid var(--axis); color: var(--ink-2); }
.footer { border-top: 1px solid var(--border); padding: 16px; font-size: 0.85rem; color: var(--ink-2); }
.footer .disclaimer { color: var(--ink); }
.footer .disclaimer strong { color: var(--heather); }

#tip { position: absolute; z-index: 20; background: var(--ink); color: var(--surface); padding: 4px 8px; border-radius: 4px; font-size: 0.82rem; pointer-events: none; max-width: 260px; }

@media (max-width: 560px) {
  h1 { font-size: 1.5rem; }
  .rb { grid-template-columns: 1.6em 8.5em 1fr; }
  .refs { left: calc(10.1em + 12px); }
  .tile .value { font-size: 1.7rem; }
}
@media (forced-colors: active) {
  svg .line, .rb .fill { forced-color-adjust: none; }
}
@media print {
  nav, details summary, #tip { display: none; }
  details > *:not(summary) { display: block; }
  figure.metric { break-inside: avoid; border: 0; }
}
