/* ==========================================================================
   Plataforma de Pesquisa Eleitoral — design system
   --------------------------------------------------------------------------
   Hand-written, zero-build, zero-CDN. That is a deliberate architectural
   choice, not a shortcut: the interviewer app must run from a service-worker
   cache with no network at all, and a stylesheet fetched from a CDN is the one
   asset most likely to be missing at that moment.

   Structure:  1. tokens  ·  2. reset  ·  3. layout  ·  4. components
               5. field app (mobile-first)  ·  6. utilities  ·  7. print
   ========================================================================== */

/* 1. TOKENS ============================================================== */

:root {
  /* Neutrals — a single slate ramp keeps surfaces coherent in both themes */
  --c-slate-50:  #f8fafc;
  --c-slate-100: #f1f5f9;
  --c-slate-200: #e2e8f0;
  --c-slate-300: #cbd5e1;
  --c-slate-400: #94a3b8;
  --c-slate-500: #64748b;
  --c-slate-600: #475569;
  --c-slate-700: #334155;
  --c-slate-800: #1e293b;
  --c-slate-900: #0f172a;
  --c-slate-950: #020617;

  /* Brand + status. Chosen for ≥4.5:1 contrast on their paired surfaces. */
  --c-brand:      #2563eb;
  --c-brand-dark: #1d4ed8;
  --c-brand-soft: #dbeafe;
  --c-success:    #16a34a;
  --c-success-soft:#dcfce7;
  --c-warning:    #d97706;
  --c-warning-soft:#fef3c7;
  --c-danger:     #dc2626;
  --c-danger-soft:#fee2e2;
  --c-info:       #0891b2;
  --c-info-soft:  #cffafe;

  /* Categorical chart palette.
     ------------------------------------------------------------------------
     Slot ORDER is the colour-blind-safety mechanism, not decoration: hues are
     assigned in this fixed order and never cycled. Validated in both modes on
     the adjacent pairlist — worst adjacent CVD ΔE 9.1 light / 8.4 dark,
     normal-vision ΔE 19.6 / 19.3, against surfaces #ffffff and #0f172a.

     Three light slots (aqua, yellow, magenta) fall below 3:1 against white, so
     the relief rule applies: every chart in this system ships visible direct
     value labels (see .result-row__pct and the chart label marks). Do not use
     these in a chart that hides its numbers.

     Scatter/bubble/map forms compare ALL pairs, not just neighbours — cap those
     at the first three slots and fold the rest into "Outros". */
  --chart-1: #2a78d6;  /* blue    */
  --chart-2: #eb6834;  /* orange  */
  --chart-3: #1baf7a;  /* aqua    */
  --chart-4: #eda100;  /* yellow  */
  --chart-5: #e87ba4;  /* magenta */
  --chart-6: #008300;  /* green   */
  --chart-7: #4a3aa7;  /* violet  */
  --chart-8: #e34948;  /* red     */

  /* Semantic surfaces (light theme) */
  --bg:          var(--c-slate-100);
  --bg-elevated: #ffffff;
  --bg-sunken:   var(--c-slate-50);
  --bg-hover:    var(--c-slate-100);
  --surface-nav: var(--c-slate-900);

  --text:        var(--c-slate-900);
  --text-muted:  var(--c-slate-500);
  --text-subtle: var(--c-slate-400);
  --text-invert: #ffffff;

  --border:        var(--c-slate-200);
  --border-strong: var(--c-slate-300);

  --ring: 0 0 0 3px rgb(37 99 235 / 0.35);

  /* Elevation — low-spread shadows read as "crisp" rather than "fuzzy" */
  --shadow-sm: 0 1px 2px rgb(15 23 42 / 0.06);
  --shadow:    0 1px 3px rgb(15 23 42 / 0.10), 0 1px 2px rgb(15 23 42 / 0.06);
  --shadow-md: 0 4px 12px rgb(15 23 42 / 0.08), 0 2px 4px rgb(15 23 42 / 0.04);
  --shadow-lg: 0 12px 32px rgb(15 23 42 / 0.12), 0 4px 8px rgb(15 23 42 / 0.06);

  --radius-sm: 6px;
  --radius:    10px;
  --radius-lg: 16px;
  --radius-full: 999px;

  /* 4px base scale */
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
  --sp-5: 20px; --sp-6: 24px; --sp-8: 32px; --sp-10: 40px; --sp-12: 48px;

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
  /* Tabular figures everywhere numbers are compared column-to-column */
  --font-num: var(--font);

  --nav-w: 248px;
  --header-h: 60px;

  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --dur: 160ms;
}

:root[data-theme="dark"] {
  --bg:          var(--c-slate-950);
  --bg-elevated: var(--c-slate-900);
  --bg-sunken:   #0b1220;
  --bg-hover:    var(--c-slate-800);
  --surface-nav: #060b18;

  --text:        var(--c-slate-100);
  --text-muted:  var(--c-slate-400);
  --text-subtle: var(--c-slate-500);

  --border:        #1e293b;
  --border-strong: #334155;

  --c-brand-soft:  #14294d;
  --c-success-soft:#0d2818;
  --c-warning-soft:#3a2a08;
  --c-danger-soft: #3b1414;
  --c-info-soft:   #0a2b33;

  /* Same eight hues, re-stepped for the dark surface — not a different palette.
     Selected for the dark band (OKLCH L 0.48–0.67) and ≥3:1 on #0f172a. */
  --chart-1: #3987e5;
  --chart-2: #d95926;
  --chart-3: #199e70;
  --chart-4: #c98500;
  --chart-5: #d55181;
  --chart-6: #008300;
  --chart-7: #9085e9;
  --chart-8: #e66767;

  --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.4);
  --shadow:    0 1px 3px rgb(0 0 0 / 0.5);
  --shadow-md: 0 4px 12px rgb(0 0 0 / 0.5);
  --shadow-lg: 0 12px 32px rgb(0 0 0 / 0.6);
}

/* Respect the OS preference until the user picks explicitly. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: var(--c-slate-950);
    --bg-elevated: var(--c-slate-900);
    --bg-sunken: #0b1220;
    --bg-hover: var(--c-slate-800);
    --surface-nav: #060b18;
    --text: var(--c-slate-100);
    --text-muted: var(--c-slate-400);
    --text-subtle: var(--c-slate-500);
    --border: #1e293b;
    --border-strong: #334155;
    --c-brand-soft: #14294d;
    --c-success-soft: #0d2818;
    --c-warning-soft: #3a2a08;
    --c-danger-soft: #3b1414;
    --c-info-soft: #0a2b33;
    --chart-1: #3987e5; --chart-2: #d95926; --chart-3: #199e70; --chart-4: #c98500;
    --chart-5: #d55181; --chart-6: #008300; --chart-7: #9085e9; --chart-8: #e66767;
  }
}

/* 2. RESET =============================================================== */

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

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

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 { margin: 0; font-weight: 650; line-height: 1.25; letter-spacing: -0.011em; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
h4 { font-size: 13px; }
p  { margin: 0 0 var(--sp-3); }

a { color: var(--c-brand); text-decoration: none; }
a:hover { text-decoration: underline; }

img, svg { max-width: 100%; display: block; }

button, input, select, textarea { font: inherit; color: inherit; }

:focus-visible { outline: none; box-shadow: var(--ring); border-radius: var(--radius-sm); }

::selection { background: var(--c-brand); color: #fff; }

/* Scrollbars — thin and neutral so panels don't look like they have gutters */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: var(--radius-full); border: 3px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-track { background: transparent; }

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

/* 3. LAYOUT ============================================================== */

.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--nav-w);
  flex-shrink: 0;
  background: var(--surface-nav);
  color: var(--c-slate-300);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 40;
}

.sidebar__brand {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-5) var(--sp-5) var(--sp-4);
  color: #fff; font-weight: 700; font-size: 15px; letter-spacing: -0.02em;
}
.sidebar__mark {
  width: 30px; height: 30px; border-radius: 8px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--c-brand), #7c3aed);
  display: grid; place-items: center; font-size: 14px;
}
.sidebar__group { padding: var(--sp-2) var(--sp-3); }
.sidebar__label {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.09em;
  color: var(--c-slate-500); font-weight: 700;
  padding: var(--sp-3) var(--sp-3) var(--sp-2);
}
.sidebar__link {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: 9px var(--sp-3); border-radius: var(--radius-sm);
  color: var(--c-slate-300); font-size: 13.5px; font-weight: 500;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.sidebar__link:hover { background: rgb(255 255 255 / 0.07); color: #fff; text-decoration: none; }
.sidebar__link.is-active { background: var(--c-brand); color: #fff; box-shadow: var(--shadow-sm); }
.sidebar__link .icon { width: 17px; height: 17px; flex-shrink: 0; opacity: 0.85; }
.sidebar__link.is-active .icon { opacity: 1; }
.sidebar__footer { margin-top: auto; padding: var(--sp-4); border-top: 1px solid rgb(255 255 255 / 0.08); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: var(--header-h);
  display: flex; align-items: center; gap: var(--sp-4);
  padding: 0 var(--sp-6);
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 30;
}
.topbar__title { font-size: 15px; font-weight: 650; }
.topbar__spacer { flex: 1; }

.content { padding: var(--sp-6); flex: 1; }
.content--narrow { max-width: 880px; }

.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: var(--sp-4); margin-bottom: var(--sp-5); flex-wrap: wrap;
}
.page-head__sub { color: var(--text-muted); font-size: 13px; margin-top: 2px; }

.grid { display: grid; gap: var(--sp-4); }
.grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid--auto { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }

@media (max-width: 1100px) {
  .grid--4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid--3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .grid--2, .grid--3, .grid--4 { grid-template-columns: 1fr; }
  .content { padding: var(--sp-4); }
}

/* Mobile navigation: the sidebar becomes an off-canvas drawer. */
.nav-toggle { display: none; }
@media (max-width: 960px) {
  .sidebar {
    position: fixed; inset: 0 auto 0 0;
    transform: translateX(-100%);
    transition: transform var(--dur) var(--ease);
    box-shadow: var(--shadow-lg);
  }
  .shell.is-nav-open .sidebar { transform: translateX(0); }
  .nav-toggle { display: inline-flex; }
  .nav-scrim {
    position: fixed; inset: 0; background: rgb(2 6 23 / 0.5);
    opacity: 0; pointer-events: none; transition: opacity var(--dur) var(--ease); z-index: 35;
  }
  .shell.is-nav-open .nav-scrim { opacity: 1; pointer-events: auto; }
}

/* 4. COMPONENTS ========================================================== */

/* --- Card --- */
.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card__head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border);
}
.card__title { font-size: 14px; font-weight: 650; }
.card__sub { font-size: 12px; color: var(--text-muted); margin-top: 1px; }
.card__body { padding: var(--sp-5); }
.card__body--flush { padding: 0; }
.card__foot { padding: var(--sp-3) var(--sp-5); border-top: 1px solid var(--border); background: var(--bg-sunken); border-radius: 0 0 var(--radius) var(--radius); }

/* --- Stat tile --- */
.stat {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-4) var(--sp-5);
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}
.stat__label {
  font-size: 11px; font-weight: 650; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--text-muted);
}
.stat__value {
  font-size: 27px; font-weight: 700; line-height: 1.15; margin-top: var(--sp-2);
  font-variant-numeric: tabular-nums; letter-spacing: -0.02em;
}
.stat__meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.stat__accent { position: absolute; inset: 0 auto 0 0; width: 3px; background: var(--c-brand); }
.stat--success .stat__accent { background: var(--c-success); }
.stat--warning .stat__accent { background: var(--c-warning); }
.stat--danger  .stat__accent { background: var(--c-danger); }

/* --- Buttons --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--c-brand); color: #fff;
  font-size: 13px; font-weight: 600; white-space: nowrap;
  cursor: pointer; text-decoration: none;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease),
              transform var(--dur) var(--ease), opacity var(--dur) var(--ease);
}
.btn:hover { background: var(--c-brand-dark); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn.is-disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn--ghost { background: transparent; color: var(--text); border-color: var(--border-strong); }
.btn--ghost:hover { background: var(--bg-hover); }
.btn--subtle { background: var(--bg-sunken); color: var(--text); border-color: var(--border); }
.btn--subtle:hover { background: var(--bg-hover); }
.btn--danger { background: var(--c-danger); }
.btn--danger:hover { background: #b91c1c; }
.btn--success { background: var(--c-success); }
.btn--success:hover { background: #15803d; }
.btn--sm { padding: 5px 10px; font-size: 12px; }
.btn--lg { padding: 12px 22px; font-size: 15px; }
.btn--block { width: 100%; }
.btn--icon { padding: 7px; }

/* --- Badges --- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: var(--radius-full);
  font-size: 11px; font-weight: 650; letter-spacing: 0.01em;
  background: var(--bg-sunken); color: var(--text-muted);
  border: 1px solid var(--border);
}
.badge--brand   { background: var(--c-brand-soft);   color: var(--c-brand);   border-color: transparent; }
.badge--success { background: var(--c-success-soft); color: var(--c-success); border-color: transparent; }
.badge--warning { background: var(--c-warning-soft); color: var(--c-warning); border-color: transparent; }
.badge--danger  { background: var(--c-danger-soft);  color: var(--c-danger);  border-color: transparent; }
.badge--info    { background: var(--c-info-soft);    color: var(--c-info);    border-color: transparent; }
.badge__dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* --- Tables --- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { padding: 10px var(--sp-4); text-align: left; }
.table thead th {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em;
  font-weight: 700; color: var(--text-muted);
  background: var(--bg-sunken); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 1; white-space: nowrap;
}
.table tbody tr { border-bottom: 1px solid var(--border); }
.table tbody tr:last-child { border-bottom: none; }
.table tbody tr:hover { background: var(--bg-hover); }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table--compact th, .table--compact td { padding: 6px var(--sp-3); }
/* First column of a crosstab stays visible while the banner scrolls */
.table--sticky-first td:first-child, .table--sticky-first th:first-child {
  position: sticky; left: 0; background: var(--bg-elevated); z-index: 2;
}
.table--sticky-first thead th:first-child { background: var(--bg-sunken); z-index: 3; }

/* --- Forms --- */
.field { margin-bottom: var(--sp-4); }
.field__label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 5px; }
.field__hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.field__error { font-size: 12px; color: var(--c-danger); margin-top: 4px; font-weight: 500; }

.input, .select, .textarea {
  width: 100%; padding: 8px 11px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--c-brand); box-shadow: var(--ring);
}
.input:disabled, .select:disabled { background: var(--bg-sunken); color: var(--text-muted); cursor: not-allowed; }
.textarea { resize: vertical; min-height: 76px; }
.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%2364748b'%3E%3Cpath d='M4.5 6.5 8 10l3.5-3.5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 9px center; background-size: 16px;
  padding-right: 30px;
}
.checkbox-row { display: flex; align-items: center; gap: var(--sp-2); font-size: 13.5px; }
.checkbox-row input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--c-brand); }

.filters {
  display: flex; gap: var(--sp-3); flex-wrap: wrap; align-items: flex-end;
  padding: var(--sp-4) var(--sp-5);
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--radius); margin-bottom: var(--sp-4);
}
.filters .field { margin-bottom: 0; min-width: 165px; flex: 1 1 165px; }

/* --- Progress --- */
.progress { height: 7px; background: var(--bg-sunken); border-radius: var(--radius-full); overflow: hidden; }
.progress__bar {
  height: 100%; background: var(--c-brand); border-radius: var(--radius-full);
  transition: width 400ms var(--ease);
}
.progress__bar--success { background: var(--c-success); }
.progress__bar--warning { background: var(--c-warning); }
.progress__bar--danger  { background: var(--c-danger); }
.progress--lg { height: 11px; }

/* --- Avatar --- */
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--c-brand); color: #fff;
  display: grid; place-items: center;
  font-size: 12px; font-weight: 700; flex-shrink: 0;
}
.avatar--sm { width: 25px; height: 25px; font-size: 10px; }
.avatar--lg { width: 46px; height: 46px; font-size: 16px; }

/* --- Empty state --- */
.empty { text-align: center; padding: var(--sp-12) var(--sp-6); color: var(--text-muted); }
.empty__icon { font-size: 34px; opacity: 0.4; margin-bottom: var(--sp-3); }
.empty__title { font-size: 15px; font-weight: 650; color: var(--text); margin-bottom: 4px; }

/* --- Tabs --- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: var(--sp-5); overflow-x: auto; }
.tab {
  padding: 9px var(--sp-4); font-size: 13.5px; font-weight: 550;
  color: var(--text-muted); border-bottom: 2px solid transparent;
  white-space: nowrap; cursor: pointer; background: none; border-top: 0; border-left: 0; border-right: 0;
}
.tab:hover { color: var(--text); text-decoration: none; }
.tab.is-active { color: var(--c-brand); border-bottom-color: var(--c-brand); }

/* --- Alerts / messages --- */
.alert {
  display: flex; gap: var(--sp-3); align-items: flex-start;
  padding: var(--sp-3) var(--sp-4); border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--bg-sunken);
  font-size: 13px; margin-bottom: var(--sp-3);
}
.alert--success { background: var(--c-success-soft); border-color: transparent; color: var(--c-success); }
.alert--warning { background: var(--c-warning-soft); border-color: transparent; color: var(--c-warning); }
.alert--danger  { background: var(--c-danger-soft);  border-color: transparent; color: var(--c-danger); }
.alert--info    { background: var(--c-info-soft);    border-color: transparent; color: var(--c-info); }

/* --- Toasts --- */
.toasts { position: fixed; bottom: var(--sp-5); right: var(--sp-5); z-index: 100; display: flex; flex-direction: column; gap: var(--sp-2); }
.toast {
  background: var(--c-slate-900); color: #fff;
  padding: 10px var(--sp-4); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg); font-size: 13px; font-weight: 500;
  max-width: 340px; animation: toast-in 200ms var(--ease);
}
.toast--success { background: var(--c-success); }
.toast--danger  { background: var(--c-danger); }
.toast--warning { background: var(--c-warning); }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* --- Skeleton loading --- */
.skeleton {
  background: linear-gradient(90deg, var(--bg-sunken) 25%, var(--bg-hover) 50%, var(--bg-sunken) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite linear;
  border-radius: var(--radius-sm);
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* --- Charts --- */
.chart { width: 100%; }
.chart svg { width: 100%; height: auto; overflow: visible; }
.chart__legend { display: flex; flex-wrap: wrap; gap: var(--sp-3); margin-top: var(--sp-3); font-size: 12px; }
.chart__legend-item { display: inline-flex; align-items: center; gap: 6px; color: var(--text-muted); }
.chart__swatch { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.chart-tooltip {
  position: fixed; pointer-events: none; z-index: 200;
  background: var(--c-slate-900); color: #fff;
  padding: 6px 10px; border-radius: var(--radius-sm);
  font-size: 12px; box-shadow: var(--shadow-lg); white-space: nowrap;
  opacity: 0; transition: opacity 100ms var(--ease);
}
.chart-tooltip.is-visible { opacity: 1; }

/* --- Result bars (candidate results) --- */
.result-row { display: flex; align-items: center; gap: var(--sp-3); padding: 9px 0; }
.result-row + .result-row { border-top: 1px solid var(--border); }
.result-row__name { flex: 0 0 155px; font-weight: 600; font-size: 13px; }
.result-row__party { font-size: 11px; color: var(--text-muted); font-weight: 500; }
.result-row__track { flex: 1; height: 22px; background: var(--bg-sunken); border-radius: var(--radius-sm); overflow: hidden; position: relative; }
.result-row__fill { height: 100%; border-radius: var(--radius-sm); transition: width 500ms var(--ease); min-width: 2px; }
.result-row__pct { flex: 0 0 96px; text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; font-size: 14px; }
.result-row__moe { font-size: 11px; color: var(--text-muted); font-weight: 500; }
@media (max-width: 620px) {
  .result-row { flex-wrap: wrap; }
  .result-row__name { flex: 1 1 100%; }
  .result-row__pct { flex: 0 0 80px; }
}

/* --- Map --- */
.map {
  position: relative; width: 100%; aspect-ratio: 16 / 10;
  background: var(--bg-sunken); border-radius: var(--radius);
  overflow: hidden; border: 1px solid var(--border);
}
.map svg { width: 100%; height: 100%; }
.map__point { cursor: pointer; transition: r 120ms var(--ease); }
.map__legend {
  position: absolute; left: var(--sp-3); bottom: var(--sp-3);
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: var(--sp-2) var(--sp-3);
  font-size: 11px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 4px;
}

/* 5. FIELD APP (mobile first) ============================================ */

/* Everything below targets a phone held one-handed on a street corner:
   large hit targets (>=48px), high contrast, no hover dependence. */

.field-app {
  min-height: 100vh; min-height: 100dvh;
  background: var(--bg);
  display: flex; flex-direction: column;
}

.field-header {
  position: sticky; top: 0; z-index: 20;
  background: var(--bg-elevated); border-bottom: 1px solid var(--border);
  padding: var(--sp-3) var(--sp-4);
  display: flex; align-items: center; gap: var(--sp-3);
  padding-top: max(var(--sp-3), env(safe-area-inset-top));
}
.field-header__title { font-size: 15px; font-weight: 650; flex: 1; min-width: 0; }
.field-header__title small { display: block; font-size: 11px; color: var(--text-muted); font-weight: 500; }

.sync-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: var(--radius-full);
  font-size: 11px; font-weight: 700;
  background: var(--c-success-soft); color: var(--c-success);
}
.sync-pill--offline { background: var(--c-warning-soft); color: var(--c-warning); }
.sync-pill--error   { background: var(--c-danger-soft);  color: var(--c-danger); }
.sync-pill--syncing { background: var(--c-brand-soft);   color: var(--c-brand); }
.sync-pill__dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.sync-pill--syncing .sync-pill__dot { animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.3; } }

.field-progress { height: 3px; background: var(--bg-sunken); }
.field-progress__bar { height: 100%; background: var(--c-brand); transition: width 250ms var(--ease); }

.field-body { flex: 1; padding: var(--sp-4); padding-bottom: 108px; max-width: 720px; width: 100%; margin: 0 auto; }

.survey-card {
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--radius); padding: var(--sp-4);
  margin-bottom: var(--sp-3); box-shadow: var(--shadow-sm);
  display: block; color: inherit;
}
.survey-card:hover { text-decoration: none; border-color: var(--c-brand); }
.survey-card__title { font-size: 15px; font-weight: 650; margin-bottom: 2px; }
.survey-card__meta { font-size: 12px; color: var(--text-muted); margin-bottom: var(--sp-3); }

/* --- Question --- */
.question { animation: q-in 200ms var(--ease); }
@keyframes q-in { from { opacity: 0; transform: translateX(12px); } to { opacity: 1; transform: none; } }

.question__section {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.07em; color: var(--c-brand); margin-bottom: var(--sp-2);
}
.question__code { font-size: 12px; color: var(--text-subtle); font-weight: 700; }
.question__text { font-size: 19px; font-weight: 650; line-height: 1.35; margin: var(--sp-2) 0 var(--sp-3); }
.question__note {
  font-size: 12px; font-weight: 650; color: var(--c-warning);
  background: var(--c-warning-soft); padding: 7px 11px;
  border-radius: var(--radius-sm); margin-bottom: var(--sp-4);
  display: flex; gap: 6px; align-items: flex-start;
}
.question__help { font-size: 13px; color: var(--text-muted); margin-bottom: var(--sp-3); }

/* Big tap targets. 56px min height is above the 48px accessibility floor
   because interviewers tap while walking and holding a clipboard. */
.option {
  display: flex; align-items: center; gap: var(--sp-3);
  width: 100%; min-height: 56px;
  padding: var(--sp-3) var(--sp-4); margin-bottom: var(--sp-2);
  background: var(--bg-elevated);
  border: 2px solid var(--border); border-radius: var(--radius);
  font-size: 15.5px; font-weight: 550; text-align: left;
  cursor: pointer;
  transition: border-color 100ms var(--ease), background 100ms var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.option:active { transform: scale(0.99); }
.option.is-selected { border-color: var(--c-brand); background: var(--c-brand-soft); color: var(--c-brand); }
.option.is-selected .option__marker { background: var(--c-brand); border-color: var(--c-brand); color: #fff; }
.option__marker {
  width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0;
  border: 2px solid var(--border-strong);
  display: grid; place-items: center; font-size: 13px; font-weight: 700;
}
.option--multi .option__marker { border-radius: 7px; }
.option__body { flex: 1; min-width: 0; }
.option__label { display: block; }
.option__sub { display: block; font-size: 12px; color: var(--text-muted); font-weight: 500; margin-top: 1px; }
.option.is-selected .option__sub { color: var(--c-brand); opacity: 0.8; }
.option__photo { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; flex-shrink: 0; background: var(--bg-sunken); }
.option__stripe { width: 5px; align-self: stretch; border-radius: 3px; flex-shrink: 0; }
.option--dk { min-height: 48px; font-size: 14px; opacity: 0.85; }

/* Scale question: a row of numbered buttons */
.scale { display: flex; gap: 5px; flex-wrap: wrap; margin-bottom: var(--sp-3); }
.scale__btn {
  flex: 1 1 52px; min-width: 46px; min-height: 52px;
  border: 2px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg-elevated); font-size: 16px; font-weight: 700; cursor: pointer;
}
.scale__btn.is-selected { background: var(--c-brand); border-color: var(--c-brand); color: #fff; }
.scale__labels { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--text-muted); }

.field-input {
  width: 100%; padding: var(--sp-4);
  font-size: 17px; border: 2px solid var(--border);
  border-radius: var(--radius); background: var(--bg-elevated);
}
.field-input:focus { outline: none; border-color: var(--c-brand); }

/* Sticky footer navigation */
.field-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 25;
  background: var(--bg-elevated); border-top: 1px solid var(--border);
  padding: var(--sp-3) var(--sp-4);
  padding-bottom: max(var(--sp-3), env(safe-area-inset-bottom));
  display: flex; gap: var(--sp-3); align-items: center;
  box-shadow: 0 -2px 12px rgb(15 23 42 / 0.06);
}
.field-nav .btn { min-height: 50px; flex: 1; font-size: 15px; }
.field-nav__meta {
  position: absolute; top: -22px; left: 50%; transform: translateX(-50%);
  font-size: 11px; color: var(--text-muted); background: var(--bg);
  padding: 2px 10px; border-radius: var(--radius-full); font-variant-numeric: tabular-nums;
}

.field-fullscreen .field-header__nav,
.field-fullscreen .sidebar { display: none; }

/* 6. UTILITIES =========================================================== */

.u-flex { display: flex; }
.u-inline-flex { display: inline-flex; }
.u-col { flex-direction: column; }
.u-center { align-items: center; }
.u-between { justify-content: space-between; }
.u-end { justify-content: flex-end; }
.u-wrap { flex-wrap: wrap; }
.u-gap-1 { gap: var(--sp-1); } .u-gap-2 { gap: var(--sp-2); }
.u-gap-3 { gap: var(--sp-3); } .u-gap-4 { gap: var(--sp-4); }
.u-grow { flex: 1; }

.u-mt-1 { margin-top: var(--sp-1); } .u-mt-2 { margin-top: var(--sp-2); }
.u-mt-3 { margin-top: var(--sp-3); } .u-mt-4 { margin-top: var(--sp-4); }
.u-mt-5 { margin-top: var(--sp-5); } .u-mt-6 { margin-top: var(--sp-6); }
.u-mb-0 { margin-bottom: 0; } .u-mb-2 { margin-bottom: var(--sp-2); }
.u-mb-3 { margin-bottom: var(--sp-3); } .u-mb-4 { margin-bottom: var(--sp-4); }
.u-mb-5 { margin-bottom: var(--sp-5); }

.u-muted { color: var(--text-muted); }
.u-subtle { color: var(--text-subtle); }
.u-danger { color: var(--c-danger); }
.u-success { color: var(--c-success); }
.u-warning { color: var(--c-warning); }
.u-brand { color: var(--c-brand); }

.u-xs { font-size: 11px; } .u-sm { font-size: 12.5px; } .u-lg { font-size: 16px; }
.u-bold { font-weight: 700; } .u-semi { font-weight: 600; }
.u-num { font-variant-numeric: tabular-nums; }
.u-mono { font-family: var(--font-mono); font-size: 12px; }
.u-upper { text-transform: uppercase; letter-spacing: 0.05em; }
.u-right { text-align: right; } .u-center-text { text-align: center; }
.u-truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.u-hidden { display: none !important; }
.u-sr {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
@media (max-width: 720px) { .u-hide-mobile { display: none !important; } }
@media (min-width: 721px) { .u-hide-desktop { display: none !important; } }

/* --- Auth screen --- */
.auth {
  min-height: 100vh; min-height: 100dvh;
  display: grid; place-items: center; padding: var(--sp-5);
  background: linear-gradient(160deg, var(--c-slate-900), var(--c-slate-950));
}
.auth__card {
  width: 100%; max-width: 400px;
  background: var(--bg-elevated); border-radius: var(--radius-lg);
  padding: var(--sp-8); box-shadow: var(--shadow-lg);
}
.auth__brand { display: flex; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-6); }
.auth__title { font-size: 19px; font-weight: 700; }
.auth__sub { font-size: 13px; color: var(--text-muted); }

/* 7. PRINT =============================================================== */

@media print {
  .sidebar, .topbar, .field-nav, .filters, .btn, .toasts { display: none !important; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .card { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
  .content { padding: 0; }
  a { color: #000; text-decoration: none; }
}
