/*
 * The UK Dashboard — Design Tokens & Base Styles
 * Version: 1.0  ·  Operated by Intelligentae Ltd
 *
 * Derived from the ROSA Cars token structure (navy + cream base, mono type carrying the
 * data) and re-coloured. It shares no palette with any other portfolio brand.
 *
 * THREE DELIBERATE CHOICES, each with a reason:
 *
 * 1. NO WEBFONTS, NO EXTERNAL REQUESTS. ROSA Cars pulls Outfit/Inter/JetBrains Mono from
 *    Google Fonts. This site does not, because every visitor would then announce their IP
 *    address to a third party on every page load. For a site whose whole claim is
 *    independence, that is both a bad look and a live GDPR question. A system font stack
 *    costs nothing, renders instantly, and lets the About page truthfully say the site
 *    calls nobody and tracks nothing.
 *
 * 2. BRONZE ACCENT, NOT RED OR BLUE. Red reads as alarm on a page of indicators, and in a
 *    British political context both red and blue read as party allegiance. Bronze is not
 *    a UK party colour and carries an archival, reference-work register, which is the
 *    tone this site wants.
 *
 * 3. DIRECTION COLOURS ARE NOT GOOD/BAD. --rise and --fall are a desaturated slate/clay
 *    pair, never green/red. "Higher" is not morally comparable across indicators — lower
 *    migration and higher FTSE cannot share a colour language. Pass/fail styling exists
 *    only in the pledge tracker, where a real target exists. Blue/orange is also the
 *    safest pair for the most common forms of colour blindness.
 *
 * Theme: system preference is the default; an explicit data-theme on <html> overrides it
 * in BOTH directions, so the toggle always wins.
 */

:root {
  /* ---- Surfaces & ink (light is the default) ---- */
  --bg: #f7f4ec; /* Page. Warm cream, not white. */
  --surface: #fdfcf8; /* Cards, panels. */
  --surface-2: #f1ede1; /* Recessed rows, table stripes. */
  --text: #16283f;
  --heading: #0d1b2e;
  --muted: #5c6779; /* Secondary text, captions. */
  --muted-2: #838c9c; /* Tertiary, timestamps, units. */
  --hair: #dfd8c8; /* Dividers, card borders. */

  /* ---- Accent ---- */
  --accent: #9a6b1f; /* Links, active state, wordmark rule. */
  --accent-deep: #7b5416; /* Hover / pressed. */
  --accent-wash: #9a6b1f14; /* Tinted background at ~8% */

  /* ---- Data direction. Neutral by design — see note 3 above. ---- */
  --rise: #3e6e9e; /* Value went up. Not "good". */
  --fall: #a8663f; /* Value went down. Not "bad". */
  --flat: #6b7280; /* No material change. */

  /* ---- Pledge tracker only, where a real target exists ---- */
  --met: #2e7d5b;
  --partial: #b8791c;
  --missed: #9e2a38;

  /* ---- Caveat / data-quality signal ---- */
  --caveat: #8a6d3b; /* Series breaks, approximate figures, estimated values. */

  /* ---- Type. System stack — no webfonts, see note 1. ---- */
  --f-display:
    ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --f-body:
    ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --f-mono:
    ui-monospace, "Cascadia Mono", "Segoe UI Mono", Menlo, Consolas, "Liberation Mono", monospace;

  /* ---- Scale ---- */
  --text-xs: 12px;
  --text-sm: 13.5px;
  --text-base: 15.5px;
  --text-lg: 18px;
  --text-xl: 21px;
  --text-2xl: 25px;
  --text-3xl: 31px;
  --text-4xl: 38px;
  --text-5xl: 46px;

  /* ---- Spacing (8px unit) ---- */
  --space-1: 8px;
  --space-2: 16px;
  --space-3: 24px;
  --space-4: 32px;
  --space-6: 48px;
  --space-8: 64px;

  /* ---- Layout ---- */
  --container-max: 1180px;
  --reading-max: 700px;
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --shadow-card: 0 1px 2px rgba(13, 27, 46, 0.05), 0 1px 3px rgba(13, 27, 46, 0.04);
}

/* Dark by system preference. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c1626;
    --surface: #121f33;
    --surface-2: #172741;
    --text: #e6ecf5;
    --heading: #f2f6fb;
    --muted: #94a1b6;
    --muted-2: #6e7c93;
    --hair: #22304a;

    --accent: #d9a441;
    --accent-deep: #ebbb63;
    --accent-wash: #d9a4411f;

    --rise: #6fa3d0;
    --fall: #d08c5e;
    --flat: #8a94a6;

    --met: #4fb488;
    --partial: #e0a94a;
    --missed: #ec6b7b;

    --caveat: #c9a567;

    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.28), 0 1px 3px rgba(0, 0, 0, 0.22);
  }
}

/* Explicit override — the toggle wins over the system preference, both directions. */
:root[data-theme="dark"] {
  --bg: #0c1626;
  --surface: #121f33;
  --surface-2: #172741;
  --text: #e6ecf5;
  --heading: #f2f6fb;
  --muted: #94a1b6;
  --muted-2: #6e7c93;
  --hair: #22304a;

  --accent: #d9a441;
  --accent-deep: #ebbb63;
  --accent-wash: #d9a4411f;

  --rise: #6fa3d0;
  --fall: #d08c5e;
  --flat: #8a94a6;

  --met: #4fb488;
  --partial: #e0a94a;
  --missed: #ec6b7b;

  --caveat: #c9a567;

  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.28), 0 1px 3px rgba(0, 0, 0, 0.22);
}

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

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--f-body);
  font-size: var(--text-base);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1,
h2,
h3,
h4 {
  font-family: var(--f-display);
  color: var(--heading);
  line-height: 1.2;
  letter-spacing: -0.015em;
  margin: 0 0 var(--space-2) 0;
  font-weight: 600;
}
h1 {
  font-size: var(--text-4xl);
  letter-spacing: -0.025em;
  line-height: 1.1;
}
h2 {
  font-size: var(--text-2xl);
}
h3 {
  font-size: var(--text-lg);
}
h4 {
  font-size: var(--text-base);
}

p {
  margin: 0 0 var(--space-2) 0;
}
p.lead {
  font-size: var(--text-lg);
  color: var(--text);
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
  text-underline-offset: 2px;
}
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

small,
.caption {
  font-size: var(--text-xs);
  color: var(--muted-2);
}

hr {
  border: 0;
  border-top: 1px solid var(--hair);
  margin: var(--space-4) 0;
}

/* ---------- Shared components ---------- */

.container {
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 0 var(--space-3);
}
.reading {
  max-width: var(--reading-max);
}

/* Small uppercase label — category headers, field names. */
.lbl {
  font-family: var(--f-mono);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 10.5px;
  color: var(--muted-2);
}

/* Figures. Tabular numerals so columns align. */
.num {
  font-family: var(--f-mono);
  font-variant-numeric: tabular-nums;
}

.card {
  background: var(--surface);
  border: 1px solid var(--hair);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  box-shadow: var(--shadow-card);
}

/* Caveat marker — attached to any figure that is estimated, approximate, or sits
   across a definition break. Deliberately visible rather than a footnote nobody reads. */
.caveat {
  color: var(--caveat);
  font-family: var(--f-mono);
  font-size: var(--text-xs);
  cursor: help;
  border-bottom: 1px dotted currentColor;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  font-family: var(--f-body);
  font-size: var(--text-sm);
  font-weight: 500;
  line-height: 1;
  border: 1px solid var(--hair);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.btn[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
}

/* ---------- Site chrome ---------- */

.site-header {
  border-bottom: 1px solid var(--hair);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 20;
}
.site-header .container {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 58px;
  flex-wrap: wrap;
}
.wordmark {
  font-family: var(--f-display);
  font-weight: 700;
  font-size: var(--text-lg);
  color: var(--heading);
  letter-spacing: -0.02em;
  white-space: nowrap;
}
.wordmark .the {
  color: var(--accent);
}
.site-nav {
  display: flex;
  gap: var(--space-2);
  margin-left: auto;
  align-items: center;
  flex-wrap: wrap;
}
.site-nav a {
  color: var(--muted);
  font-size: var(--text-sm);
}
.site-nav a:hover,
.site-nav a[aria-current="page"] {
  color: var(--accent);
  text-decoration: none;
}
.site-nav a[aria-current="page"] {
  font-weight: 600;
}

.site-footer {
  border-top: 1px solid var(--hair);
  margin-top: var(--space-8);
  padding: var(--space-4) 0;
  font-size: var(--text-sm);
  color: var(--muted);
}
.site-footer a {
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.site-footer a:hover {
  color: var(--accent);
}
.footer-grid {
  display: flex;
  gap: var(--space-4);
  flex-wrap: wrap;
  justify-content: space-between;
}
.attribution {
  font-size: var(--text-xs);
  color: var(--muted-2);
  max-width: 62ch;
}

/* Theme toggle. A half-filled circle: the near-universal contrast glyph, so it needs no
   label, and unlike a sun/moon pair it does not have to flip to show current state. */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  background: none;
  border: 1px solid var(--hair);
  border-radius: 50%;
  color: var(--muted);
  cursor: pointer;
}
.theme-toggle svg {
  display: block;
}
.theme-toggle:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.theme-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Accessibility ---------- */

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

.skip-link {
  position: absolute;
  left: -9999px;
  background: var(--accent);
  color: var(--bg);
  padding: 10px 16px;
  z-index: 100;
  border-radius: 0 0 var(--radius-sm) 0;
}
.skip-link:focus {
  left: 0;
  top: 0;
}

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

/* Print — the source list matters more than the chrome. */
@media print {
  .site-header,
  .site-nav,
  .theme-toggle,
  .btn {
    display: none !important;
  }
  body {
    background: #fff;
    color: #000;
  }
  a::after {
    content: " (" attr(href) ")";
    font-size: 10px;
    word-break: break-all;
  }
}

/* ============================================================================
   RESPONSIVE — site chrome and content pages
   ========================================================================== */

/* There is deliberately NO overflow-x backstop on html or body.
 *
 * There was one, and it caused a worse bug than it prevented. Any overflow value other than
 * visible on an ancestor makes that element a scroll container, and a sticky header then
 * sticks to it rather than to the viewport, so the navigation scrolled away. `clip` is the
 * documented fix, but browsers propagate the html overflow value to the viewport and the
 * behaviour persisted.
 *
 * The backstop is unnecessary now in any case: every real overflow has been fixed at source,
 * and scripts/test-* plus the documented responsive check verify zero horizontal overflow at
 * 320, 375, 414, 667, 768 and 1024 with nothing suppressing it. A test that proves the
 * absence of overflow is worth more than a rule that hides it.
 *
 * If overflow ever reappears, fix the element that causes it. Do not reinstate this. */
img,
svg,
table {
  max-width: 100%;
}

/* Tables in content pages scroll inside their own container. */
.tablewrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.tablewrap .srctable {
  min-width: 560px;
}

@media (max-width: 900px) {
  :root {
    --text-4xl: 33px;
    --text-3xl: 27px;
    --text-2xl: 22px;
  }
  .container {
    padding: 0 20px;
  }
}

@media (max-width: 640px) {
  :root {
    --text-4xl: 28px;
    --text-3xl: 24px;
    --text-2xl: 20px;
    --text-lg: 17px;
  }
  .container {
    padding: 0 16px;
  }

  /* The header becomes two rows: wordmark and theme control on the first, the
     nav links beneath. Keeps every tap target full size instead of shrinking
     them to fit one line. */
  .site-header .container {
    min-height: 0;
    padding-top: 10px;
    padding-bottom: 10px;
    row-gap: 8px;
  }
  .wordmark {
    font-size: 17px;
  }
  .site-nav {
    margin-left: 0;
    width: 100%;
    gap: var(--space-2);
    order: 3;
  }
  .theme-toggle {
    margin-left: auto;
    order: 2;
  }

  .footer-grid {
    flex-direction: column;
    gap: var(--space-3);
  }
  .attribution {
    max-width: none;
  }
}

@media (max-width: 420px) {
  :root {
    --text-4xl: 25px;
    --text-base: 15px;
  }
  .container {
    padding: 0 13px;
  }
  .site-nav {
    gap: 14px;
    font-size: var(--text-sm);
  }
  .wordmark {
    font-size: 16px;
  }
}

/* Touch targets. Pointer-coarse devices get a comfortable minimum without
   inflating the same controls on a mouse-driven screen. */
@media (pointer: coarse) {
  .site-nav a {
    padding: 4px 0;
    display: inline-block;
  }
  .theme-toggle {
    width: 36px;
    height: 36px;
  }
  .btn {
    padding: 10px 18px;
  }
}

/* ============================================================================
   SHORT VIEWPORTS (mostly handhelds in landscape)
   ----------------------------------------------------------------------------
   Width-only breakpoints miss this entirely. A phone in landscape is around
   667-932px wide but only 320-430px tall, so it matches the tablet rules while
   having barely any vertical room. The sticky header then consumes 15% of the
   screen and generous vertical padding eats most of the rest.

   Keyed on height, not on orientation, because that is what actually matters:
   a short window on a desktop has the same problem and benefits from the same
   treatment.
   ========================================================================== */

@media (max-height: 500px) {
  /* Give the content the screen back. Header still reachable by scrolling up. */
  .site-header {
    position: static;
  }
  .site-header .container {
    min-height: 0;
    padding-top: 7px;
    padding-bottom: 7px;
  }
  .site-footer {
    margin-top: var(--space-4);
    padding: var(--space-3) 0;
  }
}

/* Short AND wide: a handheld in landscape. Keep the header on one row, since
   there is width to spare, and pull vertical spacing right in. */
@media (max-height: 500px) and (min-width: 480px) {
  .site-header .container {
    flex-wrap: nowrap;
  }
  .site-nav {
    margin-left: auto;
    width: auto;
    order: 0;
  }
  .theme-toggle {
    order: 0;
    margin-left: 0;
  }
}
