/* Wanasiasa design system.
 *
 * This replaces the inline <style> block that used to live in base.html. That
 * block was justified by a round-trip argument: roughly 4KB of rules was not
 * worth an extra request on 3G. The full token set plus component recipes is
 * several times that, and it is identical on every page, so one cacheable
 * request now beats re-sending the block on every navigation.
 *
 * Tokens come from ui-designs/design_handoff_wanasiasa/BRAND.md. Keep them in
 * sync with that file rather than tuning values here.
 */

:root {
  /* Core palette. Blue leads; green and gold are accents. */
  --blue-900: #0B4C6B;
  --blue-600: #0E7FA8;
  --green-700: #1B6B33;
  --green-600: #1E8E3E;
  --red-700: #A3301D;

  /* Gold contrast rule, from BRAND.md section 2. --gold-500 fails contrast as
   * text on light grounds. It is for fills, borders and rules only. Gold text
   * is --gold-700 on light and --gold-300 on dark blue. Do not set --gold-500
   * on a colour property. */
  --gold-500: #E3B429;
  --gold-700: #8A6206;
  --gold-300: #F2C14E;

  /* Ground and structure. */
  --ground: #F2F7F3;
  --surface: #FFFFFF;
  --band: #E7EFE9;
  --rule: #D6E2DA;
  --hairline: #E3ECE6;
  --fill: #DDE8E0;

  /* Text. Contrast ratios on --ground are in BRAND.md. */
  --ink: #10151A;
  --ink-body: #3A3F45;
  --ink-2: #474C52;
  --muted: #5A6068;
  --placeholder: #7B818A;

  /* Semantic figure colours. --amber-700 is the mid band shared by attendance,
   * promises and fund absorption. */
  --amber-700: #B8890F;

  /* Party tints. Legibility tints, deliberately not party brand colours. */
  --party-ccm-bg: #DCEEDF;
  --party-ccm-ink: #1B6B33;
  --party-chadema-bg: #D6EAF6;
  --party-chadema-ink: #0B4C6B;
  --party-act-bg: #FBEBC9;
  --party-act-ink: #7A5405;
  --party-cuf-bg: #E8E7F0;
  --party-cuf-ink: #3F3F73;

  /* Cartogram ramp, low to high absorption. */
  --ramp-1: #E7EFE9;
  --ramp-2: #CFE3EC;
  --ramp-3: #A6CFE0;
  --ramp-4: #6FB3CE;
  --ramp-5: #3C90B4;

  /* Spacing scale. */
  --s-2: 2px;   --s-4: 4px;   --s-6: 6px;   --s-8: 8px;
  --s-10: 10px; --s-12: 12px; --s-14: 14px; --s-16: 16px;
  --s-18: 18px; --s-20: 20px; --s-22: 22px; --s-26: 26px;
  --s-30: 30px; --s-34: 34px; --s-40: 40px; --s-44: 44px;
  --s-48: 48px; --s-52: 52px; --s-56: 56px; --s-64: 64px;
  --s-72: 72px;

  /* Radii. Nothing is fully rounded except proportion tracks. */
  --r-chip: 3px;
  --r-btn: 4px;
  --r-card: 6px;
  --r-track: 99px;

  --page-max: 1240px;
  --gutter: 32px;
  --measure: 62ch;

  /* Type families. --font-serif carries the human record, --font-mono the
   * machine record: a person's name is serif, a number or label is mono. */
  --font-serif: "Newsreader", Georgia, "Times New Roman", serif;
  --font-sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  /* Minimum type size anywhere in live UI is 11.5px (BRAND.md section 3). */
  --t-min: 11.5px;
}

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

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

body {
  margin: 0;
  font: 400 15.5px/1.6 var(--font-sans);
  color: var(--ink-body);
  background: var(--ground);
}

/* Structure comes from 1px rules and white-on-green, not elevation. */

h1, h2, h3, h4 {
  font-family: var(--font-serif);
  font-weight: 600;
  color: var(--ink);
  margin: 0 0 var(--s-12);
  text-wrap: balance;
}

h1 { font-size: 42px; line-height: 1.1; letter-spacing: -0.015em; }
h2 { font-size: 26px; line-height: 1.2; letter-spacing: -0.01em; margin-top: var(--s-40); }
h3 { font-size: 20px; line-height: 1.25; }

/* A 2px ink rule under section h2s, per BRAND.md section 4. */
h2.ruled {
  border-bottom: 2px solid var(--ink);
  padding-bottom: var(--s-8);
}

p { margin: 0 0 var(--s-16); text-wrap: pretty; }

a { color: var(--blue-900); }
a:hover { color: var(--blue-600); }

.wrap {
  max-width: var(--page-max);
  margin: 0 auto;
  padding-inline: var(--gutter);
}

/* Focus ring, ACCESSIBILITY.md section 3. Never remove it. */
:focus-visible {
  outline: 3px solid var(--blue-600);
  outline-offset: 2px;
}

/* Visible to screen readers only. Used where a control shows a short label for
 * layout but needs a full accessible name, such as the EN/SW toggle. */
.visually-hidden {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ---- Skip link ---------------------------------------------------------- */

.skip {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
}
.skip:focus {
  left: var(--s-8);
  top: var(--s-8);
  background: var(--blue-900);
  color: var(--ground);
  padding: var(--s-10) var(--s-18);
  border-radius: var(--r-track);
  font: 600 12px/1 var(--font-mono);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  text-decoration: none;
}

/* ---- Status strip ------------------------------------------------------- */

.statusbar {
  background: var(--blue-900);
  color: var(--ground);
  font: 400 var(--t-min)/1.2 var(--font-mono);
}
.statusbar .wrap {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-8) var(--s-20);
  align-items: center;
  padding-block: var(--s-8);
}
.statusbar .dot {
  display: inline-block;
  inline-size: var(--s-6);
  block-size: var(--s-6);
  border-radius: var(--r-track);
  background: var(--gold-500);
  margin-inline-end: var(--s-6);
}

/* ---- Header ------------------------------------------------------------- */

header.site {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--surface);
  border-bottom: 1px solid var(--rule);
}
header.site .wrap {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-16);
  align-items: center;
  justify-content: space-between;
  padding-block: var(--s-12);
}

/* Bracket lockup: mono brackets, serif wordmark, never capitalised. */
.brand {
  display: inline-flex;
  align-items: baseline;
  gap: 9px;
  text-decoration: none;
  color: var(--ink);
}
.brand .mark {
  font: 700 21px/1 var(--font-mono);
  color: var(--blue-900);
}
.brand .word {
  font: 600 20px/1 var(--font-serif);
  color: var(--ink);
}

nav.site {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-18);
}
nav.site a {
  font: 600 var(--t-min)/1 var(--font-mono);
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-2);
  text-decoration: none;
  padding-block: var(--s-6);
  border-bottom: 2px solid transparent;
}
nav.site a:hover { color: var(--blue-900); }
nav.site a[aria-current="page"] {
  color: var(--blue-900);
  border-bottom-color: var(--gold-500);
}

/* ---- Language toggle ---------------------------------------------------- */

.langs {
  display: inline-flex;
  border: 1px solid var(--rule);
  border-radius: var(--r-chip);
  overflow: hidden;
}
.langs form { display: inline-flex; margin: 0; }
.langs button {
  background: var(--surface);
  border: 0;
  color: var(--ink-2);
  cursor: pointer;
  font: 600 var(--t-min)/1 var(--font-mono);
  letter-spacing: 0.05em;
  padding: var(--s-8) var(--s-12);
  min-block-size: var(--s-34);
}
.langs button:hover { background: var(--band); color: var(--blue-900); }
.langs [aria-pressed="true"] {
  background: var(--blue-900);
  color: var(--ground);
}

/* ---- Search ------------------------------------------------------------- */

.searchbox { display: flex; gap: var(--s-6); align-items: center; }
.searchbox input[type="search"] {
  inline-size: 200px;
  padding: var(--s-8) var(--s-10);
  border: 1px solid var(--rule);
  border-radius: var(--r-chip);
  font: 400 13.5px/1.4 var(--font-sans);
  background: var(--surface);
  color: var(--ink);
}
.searchbox input::placeholder { color: var(--placeholder); }
.searchbox button {
  background: var(--band);
  border: 1px solid var(--rule);
  border-radius: var(--r-chip);
  color: var(--ink-2);
  cursor: pointer;
  font-size: 15px;
  /* 34px matches the language toggle beside it; the mobile block below takes
     both to 44px for touch. */
  min-inline-size: var(--s-34);
  min-block-size: var(--s-34);
}
.searchbox button:hover { background: var(--blue-900); color: var(--ground); }

/* Results page. The form here is the page's main control rather than a header
   affordance, so it sits on its own row and the input takes the space. */
.searchform { margin-block: var(--s-20) var(--s-30); }
.searchform label { display: block; font-weight: 600; margin-block-end: var(--s-8); }
.searchrow { display: flex; gap: var(--s-8); max-inline-size: 34rem; }
.searchrow input[type="search"] {
  flex: 1 1 auto;
  min-inline-size: 0;
  padding: var(--s-10) var(--s-12);
  border: 1px solid var(--rule);
  border-radius: var(--r-chip);
  font: 400 16px/1.4 var(--font-sans);
  background: var(--surface);
  color: var(--ink);
}

/* Cartogram. Equal-weight tiles, one per region, laid out on their grid.
   Flex rows rather than CSS grid: the server already emits a dense row-major
   layout with explicit gaps, so the rows only need to stay in order. */
.cartogram { margin-block: var(--s-16) var(--s-30); overflow-x: auto; }
.cartorow { display: flex; gap: var(--s-6); margin-block-end: var(--s-6); }
.tile {
  flex: 0 0 auto;
  inline-size: 84px;
  min-block-size: var(--s-44);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--s-6);
  text-align: center;
  border: 1px solid var(--rule);
  border-radius: var(--r-chip);
  background: var(--band);
  color: var(--ink);
  text-decoration: none;
  font-size: var(--t-min);
  line-height: 1.15;
}
a.tile:hover { background: var(--blue-900); border-color: var(--blue-900); color: var(--ground); }
/* Empty cells hold the grid's shape. No border: a visible box reads as a
   region with no data rather than as sea. */
.tile.empty { background: transparent; border-color: transparent; }
.tname { overflow-wrap: anywhere; }

/* Directory filter. Wraps to its own rows on narrow screens rather than
   shrinking the select below a usable touch target. */
.filterbar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-10);
  align-items: center;
  margin-block: var(--s-24) var(--s-16);
  padding-block-end: var(--s-16);
  border-bottom: 1px solid var(--hairline);
}
.filterbar label { font-weight: 600; }
.filterbar select {
  padding: var(--s-8) var(--s-10);
  border: 1px solid var(--rule);
  border-radius: var(--r-chip);
  background: var(--surface);
  color: var(--ink);
  font: 400 15px/1.4 var(--font-sans);
  min-block-size: var(--s-44);
}

ul.results { list-style: none; margin: 0 0 var(--s-30); padding: 0; }
ul.results li {
  border-bottom: 1px solid var(--hairline);
  padding-block: var(--s-12);
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-10);
  align-items: baseline;
}
ul.results a { font-weight: 600; }

/* ---- Main --------------------------------------------------------------- */

main { display: block; padding-block: var(--s-40) var(--s-72); }

.eyebrow {
  font: 600 var(--t-min)/1.2 var(--font-mono);
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--gold-700);
  margin: 0 0 var(--s-8);
}
.on-dark .eyebrow, .eyebrow.on-dark { color: var(--gold-300); }

.lede {
  font: 400 21px/1.5 var(--font-serif);
  font-style: italic;
  color: var(--ink-2);
  margin: 0 0 var(--s-26);
  max-inline-size: var(--measure);
}

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

/* Data tables may scroll horizontally inside a labelled region rather than
 * shrinking type below the 11.5px floor (ACCESSIBILITY.md section 7). */
.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--rule);
  border-radius: var(--r-card);
  background: var(--surface);
}

table {
  border-collapse: collapse;
  inline-size: 100%;
  background: var(--surface);
}
caption {
  text-align: start;
  font: 600 var(--t-min)/1.4 var(--font-mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  padding: var(--s-12) var(--s-14);
}
th, td {
  text-align: start;
  padding: var(--s-12) var(--s-14);
  border-bottom: 1px solid var(--hairline);
  vertical-align: top;
}
thead th {
  background: var(--band);
  font: 600 var(--t-min)/1.4 var(--font-mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--rule);
}
/* The identifying cell is the human record, so it is serif. */
tbody th[scope="row"] {
  font: 600 16.5px/1.3 var(--font-serif);
  color: var(--ink);
}
tbody tr:last-child th, tbody tr:last-child td { border-bottom: 0; }

.num {
  text-align: end;
  font: 600 13px/1.4 var(--font-mono);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  color: var(--ink);
}

/* ---- Cards and callouts ------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-card);
  padding: var(--s-22);
  margin-block: var(--s-16);
}
/* Internal rows separate by hairline, never by margin. */
.card .row { padding-block: var(--s-12); border-bottom: 1px solid var(--hairline); }
.card .row:last-child { border-bottom: 0; padding-bottom: 0; }
.card .row:first-child { padding-top: 0; }

.note {
  background: var(--band);
  border-inline-start: 4px solid var(--blue-900);
  padding: var(--s-14) var(--s-18);
  margin-block: var(--s-16);
  font-size: 13.5px;
}
.warn {
  background: #FDF6E3;
  border-inline-start: 4px solid var(--gold-500);
  padding: var(--s-14) var(--s-18);
  margin-block: var(--s-16);
  font-size: 13.5px;
}

.cite, .muted {
  font: 400 var(--t-min)/1.5 var(--font-mono);
  color: var(--muted);
}
.cite { display: block; margin-top: var(--s-8); }

/* ---- Buttons ------------------------------------------------------------ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-6);
  background: var(--blue-900);
  color: var(--ground);
  padding: 13px var(--s-22);
  border: 1px solid var(--blue-900);
  border-radius: var(--r-btn);
  font: 600 12px/1 var(--font-mono);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  text-decoration: none;
  cursor: pointer;
  min-block-size: var(--s-44);
}
.btn:hover { background: var(--blue-600); border-color: var(--blue-600); color: var(--ground); }
.btn-secondary {
  background: transparent;
  color: var(--blue-900);
  border-color: var(--blue-900);
}
.btn-secondary:hover { background: var(--band); color: var(--blue-900); }
.btn-accent {
  background: var(--gold-500);
  color: var(--ink);
  border-color: var(--gold-500);
}
.btn-accent:hover { background: var(--gold-300); border-color: var(--gold-300); color: var(--ink); }

/* ---- Chips -------------------------------------------------------------- */

.chip {
  display: inline-flex;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-chip);
  color: var(--ink-2);
  font: 600 var(--t-min)/1 var(--font-mono);
  padding: var(--s-6) 11px;
  cursor: pointer;
  min-block-size: var(--s-30);
}
.chip[aria-pressed="true"] {
  background: var(--blue-900);
  border-color: var(--blue-900);
  color: var(--ground);
}

/* Party tints. Legibility tints, not party brand colours. */
.tint-ccm { background: var(--party-ccm-bg); color: var(--party-ccm-ink); }
.tint-chadema { background: var(--party-chadema-bg); color: var(--party-chadema-ink); }
.tint-act { background: var(--party-act-bg); color: var(--party-act-ink); }
.tint-cuf { background: var(--party-cuf-bg); color: var(--party-cuf-ink); }

/* ---- Proportion track --------------------------------------------------- */

/* Decorative: the bar is aria-hidden and the number is always present in text,
 * so colour is never the only encoding. */
.track {
  background: var(--fill);
  border-radius: var(--r-track);
  block-size: var(--s-8);
  overflow: hidden;
  margin-block: var(--s-6);
}
.track > span {
  display: block;
  block-size: 100%;
  background: var(--blue-900);
  border-radius: var(--r-track);
}
.is-good > span { background: var(--green-700); }
.is-mid > span { background: var(--amber-700); }
.is-low > span { background: var(--red-700); }

.status-good { color: var(--green-700); }
.status-mid { color: var(--amber-700); }
.status-low { color: var(--red-700); }

/* ---- Bar chart ---------------------------------------------------------- */

.bars { display: flex; align-items: flex-end; gap: var(--s-6); block-size: 160px; }
.bars .bar {
  flex: 1;
  background: var(--blue-900);
  border-radius: var(--r-chip) var(--r-chip) 0 0;
  min-block-size: var(--s-2);
}
.bars .bar.latest { background: var(--gold-500); }

/* ---- Avatar ------------------------------------------------------------- */

/* Small avatars are initials tiles, never photography. Deliberate: it avoids
 * the rights and cost problems of sourcing hundreds of portraits. */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  inline-size: var(--s-44);
  block-size: var(--s-44);
  background: var(--fill);
  color: var(--muted);
  border-radius: var(--r-chip);
  font: 600 14px/1 var(--font-mono);
}

/* ---- Big figure --------------------------------------------------------- */

.figure-big {
  font: 600 34px/1 var(--font-serif);
  letter-spacing: -0.01em;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

/* ---- Forms -------------------------------------------------------------- */

label {
  display: block;
  margin: var(--s-16) 0 var(--s-6);
  font: 600 var(--t-min)/1.4 var(--font-mono);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-2);
}
select, input[type=text], input[type=email], input[type=search], textarea {
  inline-size: 100%;
  padding: var(--s-10) var(--s-12);
  border: 1px solid var(--rule);
  border-radius: var(--r-chip);
  font: 400 15.5px/1.5 var(--font-sans);
  background: var(--surface);
  color: var(--ink);
  min-block-size: var(--s-44);
}
textarea { min-block-size: 120px; }

.errorlist {
  color: var(--red-700);
  font: 600 13.5px/1.5 var(--font-sans);
  list-style: none;
  padding: 0;
  margin: var(--s-6) 0;
}

/* ---- Footer ------------------------------------------------------------- */

footer.site {
  background: var(--blue-900);
  color: var(--ground);
  padding-block: var(--s-48) var(--s-40);
  margin-top: var(--s-72);
}
footer.site .cols {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--s-34);
}
footer.site h2 {
  font: 600 var(--t-min)/1.2 var(--font-mono);
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--gold-300);
  margin: 0 0 var(--s-12);
  border: 0;
  padding: 0;
}
footer.site a { color: var(--ground); text-decoration: underline; }
footer.site a:hover { color: var(--gold-300); }
footer.site ul { list-style: none; margin: 0; padding: 0; }
footer.site li { margin-bottom: var(--s-8); font-size: 13.5px; }
footer.site .colophon {
  border-top: 1px solid rgba(242, 247, 243, 0.2);
  margin-top: var(--s-34);
  padding-top: var(--s-20);
  font-size: 13.5px;
  max-inline-size: var(--measure);
}
footer.site .brand .mark,
footer.site .brand .word { color: var(--ground); }

/* ---- Compare -------------------------------------------------------------
   Two office_cost() results side by side. Neither column carries a "winner"
   treatment - same border, same weight, same colour - because the guardrail
   this screen exists under (docs/05-RISKS-AND-GUARDRAILS.md section 4 rule 2)
   is what forbids a composite score in the first place. Columns stack under
   the mobile breakpoint rather than scrolling horizontally, since a reader
   comparing two full tables side by side at 390px would lose the row labels
   off one side. -------------------------------------------------------- */

.compare-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s-34);
  align-items: start;
}
.compare-col {
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  padding: var(--s-20);
}

/* ---- Mobile ------------------------------------------------------------- */

@media (max-width: 760px) {
  :root { --gutter: 16px; }
  h1 { font-size: 30px; }
  h2 { font-size: 22px; }
  .lede { font-size: 18px; }
  header.site .wrap { gap: var(--s-10); }
  nav.site { gap: var(--s-12); order: 3; inline-size: 100%; }
  .searchbox input[type="search"] { inline-size: 100%; }
  .searchbox { order: 4; inline-size: 100%; }
  /* Desktop row buttons run ~31px; they must reach 44px on touch. */
  .chip { min-block-size: var(--s-44); padding-inline: var(--s-14); }
  .compare-cols { grid-template-columns: 1fr; }
}

/* ---- Motion ------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---- Print -------------------------------------------------------------- */

@media print {
  .statusbar, nav.site, .langs, .searchbox, .skip { display: none; }
  body { background: #fff; }
  header.site { position: static; }
}
