/* ============================================================================
   civic.css — the canonical civic-plain token + accessibility layer.
   Loaded by every page (AFTER styles.css where both are present, so these
   rules win by source order — do not reorder the <link> tags).

   Audience: precinct chairs 60+ on iPads. Non-negotiables encoded here:
   - 18px body floor (20px with the text-size toggle), 1.5 line-height;
   - 7:1 (WCAG AAA) contrast for text tokens — enforced by
     tests/civicTokens.test.js, do not eyeball changes;
   - gold 3px :focus-visible everywhere;
   - 44px touch targets on interactive chrome;
   - solid backplates behind text that sits over the map (no glass/blur);
   - glossary terms open on tap, never hover.
   ============================================================================ */

/* ---------------------------------------------------------------------------
   1) TOKENS
   --------------------------------------------------------------------------- */
:root {
  /* Warm-paper surfaces (shared with styles.css / page inlines) */
  --civic-paper: #fffdf9;
  --civic-paper-shade: #f4f1ea;
  --civic-paper-inset: #e7e2d7;
  --civic-line: #d8d2c6;

  /* Text inks — every *-aaa token is >= 7:1 on --civic-paper */
  --ink-aaa: #1c2733; /* 12.9:1 primary text */
  --ink-dim-aaa: #44505c; /* 8.1:1  secondary text — use instead of #5F6B76 */
  --accent-aaa: #0b4da2; /* 8.1:1  civic blue as text; white on it is 8.1:1 */
  --rep-text-aaa: #a01218; /* 8.0:1  Republican as text (party fill stays #E81B23) */
  --dem-text-aaa: #005c82; /* 7.3:1  Democratic as text (party fill stays #00AEF3) */

  --focus-gold: #ffc800;

  /* Type scale (rem so the text-size toggle scales everything) */
  --fs-small: 0.889rem; /* 16px — the floor; nothing renders smaller */
  --fs-body: 1rem; /* 18px */
  --fs-big: 1.167rem; /* 21px */
  --fs-h2: 1.5rem;
  --fs-h1: 1.889rem;

  --civic-display: "Fraunces", Georgia, "Times New Roman", serif;
  --civic-body: "Public Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  --civic-shadow: 0 1px 3px rgba(28, 39, 51, 0.1), 0 8px 24px rgba(28, 39, 51, 0.12);
  --tap: 44px;
}

/* ---------------------------------------------------------------------------
   2) BASE ENFORCEMENT — wins over styles.css by source order
   --------------------------------------------------------------------------- */
html {
  font-size: 112.5%; /* 18px large-print floor */
}
html.text-large {
  font-size: 125%; /* 20px via the header Text size toggle */
}
body {
  font-size: 1rem;
  line-height: 1.5;
}

/* Visible keyboard focus, everywhere, on gold (never color-only) */
:focus-visible {
  outline: 3px solid var(--focus-gold);
  outline-offset: 2px;
  border-radius: 4px;
}

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

/* Solid backplate for anything textual floating over the map */
.backplate {
  background: var(--civic-paper);
  border: 1px solid var(--civic-line);
  box-shadow: var(--civic-shadow);
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}

/* Two-finger pan hint (mobile scroll-trap fix, js/map/mapView.js). Opaque
   backplate — never a blurred glass overlay — centered, flashed on a one-finger
   drag and fading out. pointer-events:none so it never blocks a real gesture. */
.map-pan-hint {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 30;
  padding: 12px 18px;
  border-radius: 12px;
  font-size: var(--fs-body);
  font-weight: 600;
  color: var(--ink-aaa, #1a1a1a);
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.18s ease;
}
.map-pan-hint.show { opacity: 1; }
@media (prefers-reduced-motion: reduce) {
  .map-pan-hint { transition: none; }
}

.skip-link {
  position: absolute;
  left: 12px;
  top: -100px;
  z-index: 100;
  padding: 12px 18px;
  min-height: var(--tap);
  background: var(--civic-paper);
  border: 2px solid var(--accent-aaa);
  border-radius: 10px;
  color: var(--accent-aaa);
  font-family: var(--civic-body);
  font-size: var(--fs-body);
  font-weight: 600;
  text-decoration: none;
}
.skip-link:focus-visible {
  top: 12px;
}

/* ---------------------------------------------------------------------------
   3) SHARED HEADER (rendered by js/siteNav.js)
   --------------------------------------------------------------------------- */
.site-header-bar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 24px;
  background: var(--civic-paper);
  border-bottom: 1px solid var(--civic-line);
  font-family: var(--civic-body);
}
.site-brand {
  font-family: var(--civic-display);
  font-weight: 700;
  font-size: var(--fs-big);
  color: var(--ink-aaa);
  white-space: nowrap;
}
.site-nav {
  display: flex;
  align-items: stretch;
  flex-wrap: wrap;
  gap: 4px;
  flex: 1;
  min-width: 0;
}
/* The tab row gets its OWN full-width line under the brand + controls at every
   width above the phone breakpoint. A single flex row can't hold brand + badge +
   up to six tabs + the View switcher + Text size/Help/Sign out on a laptop, and
   the nav (the only shrinkable item) collapses into an ugly multi-row stack.
   Dropping it to its own row keeps the tabs on one clean line for every persona.
   (≤760px has its own reflow below; ultrawide keeps the two rows too — cleaner
   and consistent than a width-dependent single row.) */
@media (min-width: 761px) {
  .site-header-bar {
    flex-wrap: wrap;
    row-gap: 10px;
  }
  .site-view-switch {
    margin-left: auto;
  }
  .site-nav {
    order: 3;
    flex-basis: 100%;
    flex-grow: 0;
  }
}
/* Phones only: single scrollable row beats a four-row stack of tabs */
@media (max-width: 480px) {
  .site-nav {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}
.site-nav a {
  display: flex;
  align-items: center;
  min-height: var(--tap);
  padding: 8px 14px;
  border-radius: 10px;
  border-bottom: 3px solid transparent;
  font-size: var(--fs-body);
  font-weight: 600;
  color: var(--ink-dim-aaa);
  text-decoration: none;
  white-space: nowrap;
}
.site-nav a:hover,
.site-nav a:focus-visible {
  color: var(--ink-aaa);
  background: var(--civic-paper-shade);
}
/* Open page: color + weight + a solid underline bar (not color alone) */
.site-nav a[aria-current="page"] {
  color: var(--accent-aaa);
  font-weight: 700;
  border-bottom-color: var(--accent-aaa);
  border-radius: 10px 10px 0 0;
}
#nav-text-size,
#nav-help,
#nav-signout {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 8px 16px;
  border: 2px solid var(--civic-line);
  border-radius: 10px;
  background: var(--civic-paper);
  color: var(--ink-aaa);
  font-family: var(--civic-body);
  font-size: var(--fs-body);
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
#nav-text-size span[aria-hidden],
#nav-help span[aria-hidden] {
  font-family: var(--civic-display);
  font-size: var(--fs-big);
  line-height: 1;
}
#nav-text-size[aria-pressed="true"] {
  background: var(--accent-aaa);
  border-color: var(--accent-aaa);
  color: #ffffff;
}
/* Persona (view mode) chrome (js/lib/persona.js + js/ui/personaLayouts.js). The
   active persona is stamped as html[data-persona="public|chair|campaign"]. The
   badge names the non-public view in plain words next to the brand; the View
   switcher (.site-view-switch) is the always-visible control that lets anyone
   move between Public, Simple (chair), and Detailed (campaign) — the only
   discoverable path to those dashboards. */
.site-persona-badge {
  padding: 4px 12px;
  border: 2px solid var(--accent-aaa);
  border-radius: 10px;
  background: var(--civic-paper);
  color: var(--accent-aaa);
  font-family: var(--civic-body);
  font-size: var(--fs-body);
  font-weight: 700;
  white-space: nowrap;
}
.site-view-switch {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}
.site-view-label {
  font-family: var(--civic-body);
  font-size: var(--fs-body);
  font-weight: 600;
  color: var(--ink-dim-aaa);
}
#nav-persona {
  min-height: var(--tap);
  padding: 8px 12px;
  border: 2px solid var(--civic-line);
  border-radius: 10px;
  background: var(--civic-paper);
  color: var(--ink-aaa);
  font-family: var(--civic-body);
  font-size: var(--fs-body);
  font-weight: 600;
  cursor: pointer;
}

/* ---------------------------------------------------------------------------
   4) GLOSSARY — tappable terms + the definition popover
   --------------------------------------------------------------------------- */
button.term {
  appearance: none;
  background: none;
  border: none;
  padding: 4px 2px; /* inline in prose: comfortable without breaking flow */
  margin: -4px 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
  text-decoration: underline dotted;
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}
.term-mark {
  color: var(--accent-aaa);
  font-size: var(--fs-small);
}
.glossary-pop {
  position: fixed;
  z-index: 200;
  max-width: min(360px, calc(100vw - 24px));
  padding: 18px 20px;
  border-radius: 12px;
  background: var(--civic-paper);
  border: 1px solid var(--civic-line);
  box-shadow: 0 18px 44px rgba(28, 39, 51, 0.2);
  font-family: var(--civic-body);
  color: var(--ink-aaa);
}
.glossary-pop-title {
  font-family: var(--civic-display);
  font-weight: 700;
  font-size: var(--fs-big);
  margin-bottom: 8px;
}
.glossary-pop-body {
  font-size: var(--fs-body);
  line-height: 1.5;
  color: var(--ink-dim-aaa);
  margin: 0 0 14px;
}
.glossary-pop-close {
  width: 100%;
  min-height: var(--tap);
  border: none;
  border-radius: 10px;
  background: var(--accent-aaa);
  color: #ffffff;
  font-family: var(--civic-body);
  font-size: var(--fs-body);
  font-weight: 600;
  cursor: pointer;
}

/* ---------------------------------------------------------------------------
   5) WELCOME PANEL (first visit only; js/siteNav.js)
   --------------------------------------------------------------------------- */
.welcome-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(28, 39, 51, 0.45);
}
.welcome-card {
  max-width: 560px;
  padding: 28px 30px;
  border-radius: 14px;
  background: var(--civic-paper);
  border: 1px solid var(--civic-line);
  box-shadow: 0 18px 44px rgba(28, 39, 51, 0.3);
  font-family: var(--civic-body);
  color: var(--ink-aaa);
  font-size: var(--fs-body);
  line-height: 1.5;
}
.welcome-card h2 {
  font-family: var(--civic-display);
  font-size: var(--fs-h2);
  margin: 0 0 10px;
}
.welcome-card p,
.welcome-card ul {
  margin: 0 0 12px;
  color: var(--ink-dim-aaa);
}
.welcome-card ul {
  padding-left: 22px;
}
.welcome-card li {
  margin-bottom: 6px;
}
.welcome-dismiss {
  width: 100%;
  min-height: var(--tap);
  margin-top: 6px;
  border: none;
  border-radius: 10px;
  background: var(--accent-aaa);
  color: #ffffff;
  font-family: var(--civic-body);
  font-size: var(--fs-big);
  font-weight: 600;
  cursor: pointer;
}

/* Welcome primary action: "Find your precinct" — the first thing every new
   chair does (REDESIGN §3.2). Same visual weight as the old dismiss button;
   the dismiss becomes the quiet secondary. */
.welcome-primary {
  display: flex; align-items: center; justify-content: center;
  width: 100%;
  min-height: var(--tap);
  margin-top: 10px;
  border-radius: 10px;
  background: var(--accent-aaa);
  color: #ffffff;
  font-family: var(--civic-body);
  font-size: var(--fs-big);
  font-weight: 700;
  text-decoration: none;
}
.welcome-overlay .welcome-dismiss {
  background: transparent;
  color: var(--accent-aaa);
  border: 2px solid var(--accent-aaa);
}
.welcome-mine {
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px solid #d8d2c6;
  border-radius: 10px;
  font-weight: 600;
}

/* Help panel (js/helpPanel.js) reuses the welcome card; these are its extras */
.help-card {
  max-height: 84vh;
  overflow-y: auto;
}
.help-card h3 {
  font-family: var(--civic-display);
  font-size: var(--fs-big);
  margin: 16px 0 8px;
  color: var(--ink-aaa);
}
.help-card a {
  color: var(--accent-aaa);
  font-weight: 600;
}
.help-glossary {
  margin: 0 0 12px;
  padding-left: 22px;
  color: var(--ink-dim-aaa);
}
.help-glossary li {
  margin-bottom: 8px;
}

/* ---------------------------------------------------------------------------
   6) SYSTEM PREFERENCES
   --------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
@media (prefers-contrast: more) {
  :root {
    --ink-dim-aaa: #1c2733;
    --civic-line: #44505c;
  }
}
@media (pointer: coarse) {
  .site-nav a,
  #nav-text-size,
  #nav-help,
  #nav-signout,
  #nav-persona,
  .site-view-switch,
  .glossary-pop-close,
  .welcome-dismiss {
    min-height: 48px;
  }
}

/* Narrow screens: the text-size toggle must NEVER scroll off the edge behind
   the nav tabs. Brand + toggle share the first row; the nav gets its own
   full-width scrollable row below. */
@media (max-width: 760px) {
  .site-header-bar {
    flex-wrap: wrap;
    gap: 8px 12px;
    padding: 8px 12px;
  }
  #nav-text-size {
    order: 2;
    margin-left: auto;
  }
  #nav-help,
  #nav-signout,
  .site-view-switch {
    order: 2;
  }
  .site-nav {
    order: 3;
    flex-basis: 100%;
  }
}

/* ---------------------------------------------------------------------------
   Shared race-picker component (js/ui/racePicker.js) — the searchable,
   category-grouped race menu used by the Map and the Forecast. Class names
   are the Map's originals (cc-*); index.html carries its own copies until
   Phase 4 moves the map page onto this block. */
.cc-county-select { position: relative; }
.cc-county-btn {
  display: flex; align-items: center; gap: 9px;
  background: var(--bg-raise);
  border: 1px solid var(--line);
  color: var(--ink);
  font-family: var(--body); font-weight: 600;
  font-size: 1rem;
  padding: 9px 14px; min-height: 44px;
  border-radius: 10px;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
}
.cc-county-btn:hover { border-color: var(--accent); box-shadow: var(--shadow); }
.cc-county-menu {
  position: absolute; top: calc(100% + 8px); left: 0;
  width: 300px; max-height: 52vh; overflow-y: auto;
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px;
  display: none;
  z-index: 60;
  box-shadow: var(--shadow-pop);
}
.cc-county-menu.open { display: block; }
.cc-county-search {
  width: 100%; background: var(--bg-inset);
  border: 1px solid var(--line); color: var(--ink);
  padding: 11px 12px; border-radius: 9px; font-family: var(--body);
  font-size: 1rem; margin-bottom: 6px;
}
.cc-county-search:focus { border-color: var(--accent); }
.cc-county-opt {
  padding: 10px 12px; border-radius: 8px; cursor: pointer;
  font-size: 1rem; color: var(--ink-dim);
  display: flex; justify-content: space-between; align-items: center;
}
.cc-county-opt:hover { background: var(--bg-raise); color: var(--ink); }
.cc-county-opt.active { color: var(--accent); font-weight: 600; }
.cc-county-opt small { font-family: var(--mono); font-size: 0.889rem; color: var(--ink-faint); }
.cc-race-group {
  width: 100%; display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 10px 12px; margin-top: 4px; min-height: 44px;
  border: 0; border-radius: 8px;
  background: var(--bg-inset); color: var(--ink);
  font: inherit; font-weight: 700; text-align: left; cursor: pointer;
}
.cc-race-group:hover { background: var(--bg-raise); }
.cc-race-group small { font-family: var(--mono); font-size: 0.889rem; color: var(--ink-faint); white-space: nowrap; }
