/* ═══════════════════════════════════════════════════
   THEME PALETTE (CSS custom properties)
   Light is the default; [data-theme="dark"] overrides.
   ═══════════════════════════════════════════════════ */
:root {
  /* Surfaces */
  --bg: #f0f2f5;
  --surface: #ffffff;
  --card: #ffffff;
  --header-bg: #1a1a2e;
  --header-text: #ffffff;
  --header-sub: #a0aec0;

  /* Text */
  --text: #1a1a2e;
  --text-strong: #2d3748;
  --text-body: #4a5568;
  --text-muted: #718096;
  --text-faint: #a0aec0;

  /* Borders / dividers */
  --border: #e2e8f0;
  --border-strong: #cbd5e0;
  --border-faint: #edf2f7;
  --divider: #f0f2f5;

  /* Brand / interactive */
  --primary: #2b6cb0;
  --primary-hover: #2c5282;
  --primary-soft: rgba(43, 108, 176, 0.15);
  --accent: #c53030;
  --accent-hover: #9b2c2c;
  --success: #48bb78;
  --success-text: #276749;
  --danger-text: #c53030;
  --disabled-bg: #a0aec0;

  /* Subtle fills */
  --fill-soft: #f7fafc;
  --fill-head: #edf2f7;
  --secondary-bg: #e2e8f0;
  --secondary-bg-hover: #cbd5e0;
  --secondary-text: #4a5568;

  /* Tinted badges / heatmap */
  --dem-bg: #bee3f8;       --dem-text: #2a4365;
  --rep-bg: #fed7d7;       --rep-text: #742a2a;
  --other-bg: #e2e8f0;     --other-text: #4a5568;
  --statewide-bg: #d6bcfa; --statewide-text: #44337a;
  --state-bg: #c6f6d5;     --state-text: #22543d;
  --local-bg: #fefcbf;     --local-text: #744210;
  --warn-bg: #fefcbf;      --warn-text: #744210;  --warn-border: #ecc94b;
  --incumbent-bg: #f0fff4; --incumbent-border: #c6f6d5;
  --score-pos-bg: #c6f6d5; --score-pos-text: #22543d;
  --score-neg-bg: #fed7d7; --score-neg-text: #742a2a;
  --score-zero-bg: #f7fafc;
  --top-tint: rgba(72, 187, 120, 0.04);
  --why-pos-tint: rgba(72, 187, 120, 0.08);
  --why-neg-tint: rgba(252, 129, 129, 0.08);

  /* Effects */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.08);
  --overlay: rgba(0, 0, 0, 0.6);
}

[data-theme="dark"] {
  /* Surfaces */
  --bg: #0f1419;
  --surface: #1a212e;
  --card: #1a212e;
  --header-bg: #0a0e14;
  --header-text: #f7fafc;
  --header-sub: #8b98ad;

  /* Text */
  --text: #e8edf4;
  --text-strong: #dbe3ee;
  --text-body: #c2ccd9;
  --text-muted: #97a3b4;
  --text-faint: #6b7686;

  /* Borders / dividers */
  --border: #2c3644;
  --border-strong: #3a4654;
  --border-faint: #242d3a;
  --divider: #242d3a;

  /* Brand / interactive — brighter so they pop on dark */
  --primary: #5b9bd5;
  --primary-hover: #74acdf;
  --primary-soft: rgba(91, 155, 213, 0.22);
  --accent: #f56565;
  --accent-hover: #fc8181;
  --success: #5fcf8f;
  --success-text: #9ae6b4;
  --danger-text: #fc8181;
  --disabled-bg: #3a4654;

  /* Subtle fills */
  --fill-soft: #222b38;
  --fill-head: #232d3b;
  --secondary-bg: #2c3644;
  --secondary-bg-hover: #3a4654;
  --secondary-text: #c2ccd9;

  /* Tinted badges / heatmap — darker tints, light text for contrast */
  --dem-bg: #1e3a5f;       --dem-text: #aaccf0;
  --rep-bg: #4a2222;       --rep-text: #f2b8b8;
  --other-bg: #2c3644;     --other-text: #c2ccd9;
  --statewide-bg: #3a2f5a; --statewide-text: #d2c2f0;
  --state-bg: #1f3d2a;     --state-text: #a8e6bd;
  --local-bg: #45390f;     --local-text: #ecd98a;
  --warn-bg: #3a3210;      --warn-text: #f0dd9a;  --warn-border: #8a7420;
  --incumbent-bg: #163524; --incumbent-border: #2a5a3c;
  --score-pos-bg: #1f3d2a; --score-pos-text: #a8e6bd;
  --score-neg-bg: #4a2222; --score-neg-text: #f2b8b8;
  --score-zero-bg: #222b38;
  --top-tint: rgba(95, 207, 143, 0.10);
  --why-pos-tint: rgba(95, 207, 143, 0.12);
  --why-neg-tint: rgba(252, 129, 129, 0.12);

  /* Effects */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 2px 10px rgba(0, 0, 0, 0.5);
  --overlay: rgba(0, 0, 0, 0.72);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* Prevent layout viewport inflation on narrow phones.
   overflow-x:hidden on body alone does NOT constrain the layout viewport in
   Chrome/WebKit; adding it to html as well + max-width:100% is the reliable fix. */
html {
  overflow-x: hidden;
  max-width: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  transition: background-color 0.2s ease, color 0.2s ease;
  /* Belt-and-suspenders: overflow-x hidden on both html+body is the standard
     pattern to truly prevent layout viewport inflation from overflowing children. */
  overflow-x: hidden;
  max-width: 100%;
}

header {
  background: var(--header-bg);
  color: var(--header-text);
  padding: 1.5rem 2rem;
  text-align: center;
  position: relative;
  /* Prevent the tagline from inflating the layout viewport on narrow phones */
  overflow: hidden;
}

header h1 {
  font-size: 1.8rem;
  font-weight: 700;
  letter-spacing: 0.05em;
}

header p {
  color: var(--header-sub);
  font-size: 0.9rem;
  margin-top: 0.25rem;
}

/* Theme toggle */
.theme-toggle {
  position: absolute;
  top: 1rem;
  right: 1rem;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: rgba(255, 255, 255, 0.1);
  color: var(--header-text);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 999px;
  padding: 0.4rem 0.8rem;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
  line-height: 1;
}

.theme-toggle:hover {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.45);
}

.theme-toggle:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.theme-toggle .theme-icon {
  font-size: 0.95rem;
}

@media (max-width: 600px) {
  .theme-toggle {
    top: 0.6rem;
    right: 0.6rem;
    padding: 0.35rem 0.6rem;
  }
  .theme-toggle .theme-label { display: none; }

  /* Reduce header padding so tagline doesn't push layout viewport wide */
  header {
    padding: 1rem 1rem;
  }

  header p {
    font-size: 0.8rem;
    /* Allow the tagline to wrap rather than overflow */
    word-break: break-word;
    overflow-wrap: break-word;
  }
}

main {
  max-width: 960px;
  margin: 2rem auto;
  padding: 0 1rem;
  /* Belt-and-suspenders: clip any child that tries to widen past the
     viewport (mirrors body overflow-x: hidden for the content layer). */
  overflow-x: hidden;
}

/* Navigation tabs */
.tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  border-bottom: 2px solid var(--border);
  padding-bottom: 0;
}

.tab-btn {
  padding: 0.75rem 1.25rem;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 0.95rem;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color 0.2s, border-color 0.2s;
}

.tab-btn:hover {
  color: var(--text-strong);
}

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}

/* Panels */
.panel {
  display: none;
  background: var(--surface);
  border-radius: 8px;
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
}

.panel.active {
  display: block;
}

/* Forms */
.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.25rem;
  font-size: 0.9rem;
  color: var(--text-body);
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  font-size: 0.95rem;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.2s;
}

.form-group input::placeholder {
  color: var(--text-faint);
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.form-row {
  display: flex;
  gap: 1rem;
}

.form-row .form-group {
  flex: 1;
}

button[type="submit"],
.btn {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 0.6rem 1.5rem;
  border-radius: 6px;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.2s;
}

button[type="submit"]:hover,
.btn:hover {
  background: var(--primary-hover);
}

button[type="submit"]:disabled,
.btn:disabled {
  background: var(--disabled-bg);
  cursor: not-allowed;
}

/* Results tables */
.results-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1.5rem;
  font-size: 0.9rem;
}

.results-table th {
  background: var(--fill-head);
  text-align: left;
  padding: 0.75rem;
  font-weight: 600;
  color: var(--text-body);
  border-bottom: 2px solid var(--border);
}

.results-table td {
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.results-table tr:hover {
  background: var(--fill-soft);
}

.results-table a {
  color: var(--primary);
  text-decoration: none;
}

.results-table a:hover {
  text-decoration: underline;
}

/* Official cards (for representatives view) */
.official-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 0.75rem;
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  background: var(--card);
}

.official-card img {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--fill-head);
}

.official-card .info {
  flex: 1;
}

.official-card .name {
  font-weight: 600;
  font-size: 1.05rem;
}

.official-card .office {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.official-card .party {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.8rem;
  font-weight: 600;
  margin-top: 0.25rem;
}

.party-democratic { background: var(--dem-bg); color: var(--dem-text); }
.party-republican { background: var(--rep-bg); color: var(--rep-text); }
.party-other { background: var(--other-bg); color: var(--other-text); }

.official-card .contact {
  font-size: 0.85rem;
  color: var(--text-body);
  margin-top: 0.5rem;
}

.official-card .contact a {
  color: var(--primary);
}

/* Source line */
.source-line {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

/* District map */
.district-map {
  background: var(--fill-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 1.25rem;
}

.district-map-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-strong);
  margin-bottom: 0.5rem;
}

.district-row {
  display: flex;
  justify-content: space-between;
  padding: 0.3rem 0;
  border-bottom: 1px solid var(--border-faint);
  font-size: 0.85rem;
}

.district-row:last-child {
  border-bottom: none;
}

.district-label {
  color: var(--text-muted);
  font-weight: 500;
}

.district-value {
  color: var(--text-strong);
  font-weight: 600;
  text-align: right;
}

/* Level headings (Federal / State / Local) */
.level-heading {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-strong);
  margin: 1.25rem 0 0.5rem;
  padding-bottom: 0.25rem;
  border-bottom: 2px solid var(--border);
}

/* Status messages */
.status {
  text-align: center;
  padding: 2rem;
  color: var(--text-muted);
}

.status.error {
  color: var(--danger-text);
}

.loading-spinner {
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-right: 0.5rem;
  vertical-align: middle;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Vote position badges */
.vote-yes { color: var(--success-text); font-weight: 600; }
.vote-no { color: var(--danger-text); font-weight: 600; }
.vote-other { color: var(--text-muted); font-weight: 600; }

/* ═══════════════════════════════════════════════════
   FUNNEL UI
   ═══════════════════════════════════════════════════ */

/* Progress bar */
.progress-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  margin-bottom: 1.5rem;
  padding: 1rem 0;
  /* Viewport-independent hardening (does NOT depend on any media query):
     the 6-step stepper must never push the page wider than its container.
     If the row genuinely can't fit (e.g. a browser that reports a wide
     layout viewport so the ≤480px shrink rules never fire), contain it and
     let it scroll horizontally inside its own box instead of clipping the
     last step off the edge of the screen. */
  max-width: 100%;
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;            /* Firefox: hide the scrollbar track */
  -webkit-overflow-scrolling: touch;
}
.progress-bar::-webkit-scrollbar { display: none; }  /* WebKit: hide track */

.progress-dot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  position: relative;
  /* Keep each step at its natural size inside the (now scrollable) bar so the
     dots never get squished; horizontal scroll is the overflow escape hatch. */
  flex-shrink: 0;
}

.dot-num {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--secondary-bg);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  transition: background 0.3s, color 0.3s;
}

.dot-label {
  font-size: 0.7rem;
  color: var(--text-faint);
  font-weight: 500;
  transition: color 0.3s;
}

.progress-dot.active .dot-num {
  background: var(--primary);
  color: #fff;
}

.progress-dot.active .dot-label {
  color: var(--primary);
  font-weight: 600;
}

.progress-dot.done .dot-num {
  background: var(--success);
  color: #fff;
}

.progress-dot.done .dot-label {
  color: var(--success);
}

.progress-connector {
  width: 40px;
  height: 2px;
  background: var(--secondary-bg);
  margin: 0 0.25rem;
  margin-bottom: 1.1rem;
  flex-shrink: 0;
}

/* Funnel steps */
.funnel-step {
  display: none;
}

.funnel-step.active {
  display: block;
}

.step-card {
  background: var(--card);
  border-radius: 10px;
  padding: 2rem;
  box-shadow: var(--shadow-md);
  max-width: 700px;
  margin: 0 auto;
}

.step-card h2 {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0.25rem;
}

.step-desc {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 1.25rem;
}

.step-status {
  margin-top: 0.75rem;
  font-size: 0.9rem;
}

.step-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  margin-top: 1.5rem;
}

.btn-secondary {
  background: var(--secondary-bg);
  color: var(--secondary-text);
}

.btn-secondary:hover {
  background: var(--secondary-bg-hover);
}

.error-text {
  color: var(--danger-text);
}

.address-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  /* Prevent any child from bleeding outside the card on narrow viewports */
  overflow-x: hidden;
}
.address-actions button[type="submit"] {
  /* Let the primary CTA grow to fill available space */
  flex: 1 1 12rem;
  min-width: 0;
}
.address-actions .btn-secondary {
  /* Viewport-independent hardening: each action demands a real flex-basis so
     three side-by-side buttons can't fit on one narrow row — they WRAP to the
     next line instead of clipping "Pick on Map" off the right edge. This no
     longer relies on the ≤480px media query firing (which never happens when a
     browser reports a wider layout viewport than the physical window). */
  flex: 1 1 12rem;
  font-size: 0.85rem;
  padding: 0.6rem 1rem;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  cursor: pointer;
  white-space: normal;
  min-width: 0;
}

/* On narrow phones (≤480px) stack every address-action button full-width so
   "Pick on Map" is never clipped off the right edge.  480px covers 320/375/390/
   414/420px devices — the threshold where three side-by-side buttons overflow. */
@media (max-width: 480px) {
  .address-actions {
    flex-direction: column;
    overflow-x: hidden;
  }
  .address-actions button[type="submit"],
  .address-actions .btn-secondary {
    flex: 1 1 auto;
    width: 100%;
    box-sizing: border-box;
    white-space: normal;
    text-align: center;
  }

}

.precision-note {
  background: var(--warn-bg);
  color: var(--warn-text);
  border: 1px solid var(--warn-border);
  border-radius: 6px;
  padding: 0.6rem 1rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.privacy-note {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
}

/* Map picker modal */
.map-modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--overlay);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.map-modal.hidden { display: none; }
.map-modal-content {
  background: var(--surface);
  color: var(--text);
  border-radius: 12px;
  width: 90vw;
  max-width: 700px;
  max-height: 85vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.map-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.2rem 0.5rem;
}
.map-header h3 { margin: 0; }
.btn-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-body);
  padding: 0 0.3rem;
}
.map-hint {
  padding: 0 1.2rem 0.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}
#map-container {
  height: 400px;
  width: 100%;
}
.map-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.8rem 1.2rem;
  border-top: 1px solid var(--border);
}
#map-coords {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-family: monospace;
}
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.6rem 1.2rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
}
.btn-primary:disabled {
  background: var(--border-strong);
  cursor: default;
}
.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

/* Confirm step — officials table grouped by level */
.confirm-reps {
  margin-top: 1rem;
}

.confirm-level-group {
  margin-bottom: 1.25rem;
}

.confirm-level-heading {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  padding: 0.4rem 0.75rem;
  background: var(--fill-head);
  border-radius: 6px 6px 0 0;
  margin-bottom: 0;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.8rem;
}

.confirm-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 6px 6px;
  overflow: hidden;
}

.confirm-table thead th {
  text-align: left;
  padding: 0.4rem 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.confirm-table td {
  padding: 0.4rem 0.75rem;
  border-bottom: 1px solid var(--divider);
  vertical-align: middle;
}

.confirm-table tr:last-child td {
  border-bottom: none;
}

.confirm-office {
  font-weight: 600;
  color: var(--text-strong);
  font-size: 0.82rem;
  border-right: 1px solid var(--border-faint);
}

.confirm-name {
  color: var(--text);
  font-weight: 500;
}

.party-badge {
  display: inline-block;
  padding: 0.1rem 0.45rem;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.party-democratic .party-badge,
.party-badge.party-democratic {
  background: var(--dem-bg);
  color: var(--dem-text);
}

.party-republican .party-badge,
.party-badge.party-republican {
  background: var(--rep-bg);
  color: var(--rep-text);
}

.party-other .party-badge,
.party-badge.party-other {
  background: var(--other-bg);
  color: var(--other-text);
}

.confirm-note {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-style: italic;
  margin-top: 0.75rem;
}

/* Issue chips (step 3) */
.issues-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.issue-chip {
  display: inline-flex;
  align-items: center;
  padding: 0.5rem 1rem;
  border: 2px solid var(--border);
  border-radius: 20px;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-body);
  background: var(--surface);
  transition: all 0.2s;
  user-select: none;
}

.issue-chip:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.issue-chip.selected {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.issue-chip input[type="checkbox"] {
  display: none;
}

#issues-count {
  font-weight: 600;
  color: var(--primary);
}

/* Slider items (steps 4 & 5) */
.slider-item {
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border-faint);
}

.slider-item:last-child {
  border-bottom: none;
}

.slider-item label {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-strong);
  margin-bottom: 0.35rem;
}

.position-reminder {
  font-weight: 400;
  color: var(--text-faint);
  font-size: 0.8rem;
}

.slider-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.slider-end {
  font-size: 0.75rem;
  color: var(--text-faint);
  font-weight: 600;
  min-width: 1.5rem;
  text-align: center;
}

.slider-row input[type="range"] {
  flex: 1;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--secondary-bg);
  border-radius: 3px;
  outline: none;
}

.slider-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  background: var(--primary);
  border-radius: 50%;
  cursor: pointer;
}

.slider-row input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  background: var(--primary);
  border-radius: 50%;
  cursor: pointer;
  border: none;
}

.slider-value {
  min-width: 2rem;
  text-align: center;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--primary);
}

.slider-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.7rem;
  color: var(--text-faint);
  margin-top: 0.15rem;
  padding: 0 1.5rem;
}

/* Results (step 6) */
.results-summary {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

/* All-neutral positions notice — shown in Step 6 when the user left every slider at 0.
   Uses warn colours (already defined for light + dark mode) so it reads as informational
   rather than an error. Does NOT change slider defaults — neutrality is preserved. */
.neutral-positions-notice {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  background: var(--warn-bg);
  color: var(--warn-text);
  border: 1px solid var(--warn-border);
  border-radius: 8px;
  padding: 0.85rem 1rem;
  margin-bottom: 1.1rem;
  font-size: 0.9rem;
  line-height: 1.5;
}
.neutral-positions-icon {
  font-size: 1.15rem;
  flex-shrink: 0;
  margin-top: 0.05rem;
}
.neutral-positions-body {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
.neutral-positions-back {
  align-self: flex-start;
  margin-top: 0.1rem;
  font-size: 0.85rem;
  padding: 0.35rem 0.85rem;
  cursor: pointer;
  border-radius: 5px;
}

/* Race group */
.race-group {
  margin-bottom: 1.5rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--card);
}

.race-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.65rem 1rem;
  background: var(--header-bg);
}

.race-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: #fff;
  margin: 0;
}

[data-theme="dark"] .race-title { color: var(--header-text); }

.race-level-badge {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.15rem 0.5rem;
  border-radius: 3px;
  white-space: nowrap;
}

.race-level-federal { background: var(--dem-bg); color: var(--dem-text); }
.race-level-statewide { background: var(--statewide-bg); color: var(--statewide-text); }
.race-level-state { background: var(--state-bg); color: var(--state-text); }
.race-level-local { background: var(--local-bg); color: var(--local-text); }
.race-level-other { background: var(--other-bg); color: var(--other-text); }

.race-ballot-note {
  font-size: 0.78rem;
  color: var(--text-muted, #a0aec0);
  font-style: italic;
  padding: 0.25rem 0.75rem 0;
  margin: 0;
}

.race-ballot-year {
  font-size: 0.65rem;
  font-weight: 700;
  background: var(--success, #5fcf8f);
  color: #000;
  border-radius: 3px;
  padding: 1px 4px;
  margin-left: 4px;
  vertical-align: middle;
}

.race-election-dates {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-body, #c2ccd9);
  padding: 0.2rem 0.75rem 0.1rem;
  margin: 0;
}

.ballot-measures-section {
  margin: 1.5rem 0 0;
  padding: 1rem;
  background: var(--card-bg, #1a202c);
  border-radius: 8px;
  border: 1px solid var(--border, #2d3748);
}

.ballot-measures-header {
  font-size: 1rem;
  font-weight: 600;
  margin: 0 0 0.35rem;
  color: var(--text, #e2e8f0);
}

.ballot-measures-desc {
  font-size: 0.78rem;
  color: var(--text-muted, #a0aec0);
  margin: 0 0 0.75rem;
}

.measure-card {
  background: var(--card-inner-bg, #2d3748);
  border-radius: 6px;
  padding: 0.75rem;
  margin-bottom: 0.5rem;
}

.measure-title {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text, #e2e8f0);
  margin-bottom: 0.25rem;
}

.measure-subtitle {
  font-size: 0.8rem;
  color: var(--text-secondary, #cbd5e0);
  margin-bottom: 0.25rem;
}

.measure-text {
  font-size: 0.78rem;
  color: var(--text-muted, #a0aec0);
  line-height: 1.4;
}

.measure-research-link {
  display: inline-block;
  margin-top: 0.4rem;
  font-size: 0.75rem;
  color: var(--primary, #2b6cb0);
  text-decoration: none;
}

.measure-research-link a,
.measure-research-link a:visited {
  font-size: 0.75rem;
  color: var(--text-secondary, #cbd5e0);
  text-decoration: none;
  opacity: 0.8;
}

.measure-research-link:hover,
.measure-research-link a:hover {
  text-decoration: underline;
  opacity: 1;
}

.ballot-measures-pending {
  font-size: .8rem;
  color: var(--text-muted, #a0aec0);
  font-style: italic;
  padding: .75rem;
  background: var(--fill-soft, #f7fafc);
  border-radius: 6px;
  margin-top: 1rem;
}

.ballot-empty-info {
  padding: .5rem .75rem;
}

.ballot-empty-info p {
  font-size: .82rem;
  color: var(--text-muted);
  margin-bottom: .25rem;
}

.race-candidates {
  padding: 0.5rem;
}

/* Unmatched section */
.unmatched-section {
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 2px solid var(--border);
}

.unmatched-header {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-body);
  margin-bottom: 0.25rem;
}

.unmatched-desc {
  font-size: 0.82rem;
  color: var(--text-faint);
  margin-bottom: 0.75rem;
}

/* Divider between scored and unscored candidates within a race */
.not-yet-scored-divider {
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-faint);
  margin: 0.5rem 0;
  padding: 0.25rem 0;
  border-top: 1px solid var(--border-faint);
  border-bottom: 1px solid var(--border-faint);
  letter-spacing: 0.04em;
}

/* Ballotpedia external link on candidate cards — pill button, clearly visible */
.candidate-bp-link {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--primary, #5b9bd5);
  text-decoration: none;
  border: 1px solid var(--primary, #5b9bd5);
  border-radius: 4px;
  padding: 1px 5px;
  margin-left: 4px;
  opacity: 0.85;
  white-space: nowrap;
  vertical-align: middle;
}
.candidate-bp-link:hover {
  opacity: 1;
  background: var(--primary-soft, rgba(91,155,213,0.15));
}

/* OpenSecrets donor-industry row — shown only when data is present */
.candidate-donors {
  font-size: 0.72rem;
  color: var(--text-faint);
  margin-top: 0.3rem;
}
.candidate-source-link {
  color: var(--text-faint);
  text-decoration: none;
}
.candidate-source-link:hover {
  color: var(--accent);
  text-decoration: underline;
}

/* Ballotpedia candidate profile enrichments */
.candidate-photo { width:32px; height:32px; border-radius:50%; object-fit:cover; margin-right:6px; vertical-align:middle; border:1px solid var(--border); }
.candidate-bio { font-size:.75rem; color:var(--text-muted); margin:.25rem 0; line-height:1.4; }
.candidate-survey { margin:.5rem 0; padding:.5rem; background:var(--fill-soft); border-radius:6px; font-size:.75rem; }
.survey-q { font-weight:600; color:var(--text-body); margin-top:.4rem; }
.survey-a { color:var(--text-muted); margin-bottom:.25rem; }
.btn-survey { font-size:.7rem; background:none; border:1px solid var(--border); border-radius:4px; padding:2px 6px; cursor:pointer; color:var(--primary); margin-top:.25rem; }

/* Stated positions — verbatim public-record text for executives/officeholders who
   have real documented positions but no vote-based alignment score. Neutral styling:
   no color coding, no endorsement framing, same rules for every candidate/party.
   Skill rule 6b: executives must NEVER be blank; surface facts, not a blank card. */
.result-card-stated {
  opacity: 1; /* full opacity — this card HAS real content */
}
.stated-positions {
  margin: 0.5rem 0 0.25rem;
  padding: 0.6rem 0.75rem;
  background: var(--fill-soft);
  border-left: 3px solid var(--border);
  border-radius: 0 6px 6px 0;
}
.stated-positions-heading {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}
.stated-pos-item {
  margin-bottom: 0.5rem;
}
.stated-pos-item:last-child {
  margin-bottom: 0;
}
.stated-pos-topic {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-body);
  margin-bottom: 0.15rem;
}
.stated-pos-text {
  font-size: 0.73rem;
  color: var(--text-muted);
  line-height: 1.5;
}
.stated-pos-other {
  margin-top: 0.4rem;
}
.stated-pos-other-toggle {
  font-size: 0.68rem;
  color: var(--primary);
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.stated-pos-other-toggle::-webkit-details-marker { display: none; }
.stated-pos-more {
  font-size: 0.65rem;
  color: var(--text-faint);
  margin-top: 0.25rem;
}
.result-score.stated-positions-available {
  color: var(--text-muted);
  font-style: normal;
}

/* Neutral fact-only candidate meta (occupation / education / Wikipedia). Public
   record only — no scoring, no endorsement styling. */
.candidate-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.75rem;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin: 0.2rem 0 0.35rem;
  line-height: 1.4;
}
.candidate-meta-label { color: var(--text-faint); font-weight: 600; }
.candidate-meta-link { color: var(--text-faint); text-decoration: none; }
.candidate-meta-link:hover { color: var(--accent); text-decoration: underline; }

/* Neutral "Factual data score" — distinct from the user-alignment match score,
   muted and clearly labeled so it is never read as an endorsement. */
.candidate-insight {
  display: flex;
  align-items: baseline;
  gap: 0.3rem;
  white-space: nowrap;
}
.insight-label {
  font-size: 0.7rem;
  color: var(--text-faint);
  font-weight: 500;
}
.insight-value {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-muted);
}
.insight-coverage {
  font-size: 0.68rem;
  color: var(--text-faint);
}

/* Neutral "Factual data" block — public-record data points (campaign finance,
   years in office, attendance, etc.) shown as FACTS. Deliberately monochrome/muted:
   no green/red, no bars, no ranking cue, so it can never read as good/bad or as an
   endorsement. Each row is a label + its raw value with the data source. */
.candidate-facts {
  margin-top: 0.4rem;
  padding: 0.4rem 0.5rem;
  background: var(--fill-soft);
  border: 1px solid var(--border-faint);
  border-radius: 6px;
}
.candidate-facts-heading {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-faint);
  margin-bottom: 0.25rem;
}
.candidate-fact {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  font-size: 0.74rem;
  line-height: 1.5;
  color: var(--text-muted);
}
.fact-label { color: var(--text-faint); }
.fact-value { font-weight: 700; color: var(--text-body); }
.fact-source { color: var(--text-faint); font-size: 0.66rem; }

/* Result card */
.result-card {
  padding: 0.75rem;
  border: 1px solid var(--border-faint);
  border-radius: 8px;
  margin-bottom: 0.4rem;
  background: var(--card);
  transition: border-color 0.2s;
}

.result-card:hover {
  border-color: var(--border-strong);
}

.result-card-top {
  border-color: var(--success);
  background: var(--top-tint);
}

.result-info {
  flex: 1;
}

.result-name-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.result-name {
  font-weight: 600;
  font-size: 1rem;
  color: var(--text);
}

.incumbent-badge {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
  background: var(--incumbent-bg);
  color: var(--success-text);
  border: 1px solid var(--incumbent-border);
}

/* Scores row — match bar + confidence side by side */
.result-scores-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin: 0.35rem 0;
}

.result-match {
  flex: 1;
}

.result-bar-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.result-bar {
  height: 8px;
  border-radius: 4px;
  transition: width 0.5s ease;
  flex: 1;
  background: var(--secondary-bg);
}

.result-score {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-strong);
  white-space: nowrap;
  min-width: 5.5rem;
}

/* Confidence indicator */
.result-confidence {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  white-space: nowrap;
}

.confidence-label {
  font-size: 0.7rem;
  color: var(--text-faint);
  font-weight: 500;
}

.confidence-value {
  font-size: 0.85rem;
  font-weight: 700;
}

.confidence-sd {
  font-size: 0.7rem;
  color: var(--text-faint);
  font-family: 'SF Mono', 'Menlo', monospace;
}

.result-breakdown {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.breakdown-chip {
  font-size: 0.7rem;
  padding: 0.15rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-body);
  white-space: nowrap;
}

/* Ballot race title */
.ballot-race-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
  margin: 1rem 0 0.3rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* Result card header (name + Why button) */
.result-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

/* Learn Why button */
.btn-why {
  background: none;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  padding: 0.15rem 0.5rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
}

.btn-why:hover {
  border-color: var(--primary);
  color: var(--primary);
}

/* Learn Why detail table */
.why-detail {
  margin-top: 0.5rem;
  border-top: 1px solid var(--border-faint);
  padding-top: 0.5rem;
}

.why-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.why-table th {
  text-align: left;
  padding: 0.25rem 0.5rem;
  color: var(--text-muted);
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  font-size: 0.75rem;
}

.why-table td {
  padding: 0.25rem 0.5rem;
  border-bottom: 1px solid var(--fill-soft);
}

.why-num {
  text-align: center;
  font-family: 'SF Mono', 'Menlo', monospace;
  font-size: 0.8rem;
}

.why-pos td { background: var(--why-pos-tint); }
.why-neg td { background: var(--why-neg-tint); }

/* Post-results action buttons */
.post-results-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 2px solid var(--border);
}

.btn-action {
  font-size: 0.85rem;
  padding: 0.5rem 1rem;
}

.btn-sm {
  font-size: 0.8rem;
  padding: 0.35rem 0.75rem;
}

/* Sample Ballot */
.sample-ballot {
  background: var(--card);
  border: 2px solid var(--header-bg);
  border-radius: 10px;
  padding: 2rem;
  margin-top: 1.5rem;
  max-width: 700px;
  margin-left: auto;
  margin-right: auto;
}

.ballot-header {
  text-align: center;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid var(--border);
}

.ballot-header h2 {
  font-size: 1.4rem;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.ballot-header p {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.ballot-header button {
  margin: 0.5rem 0.25rem 0;
}

.ballot-meta {
  font-size: 0.85rem;
  color: var(--text-body);
  margin-bottom: 1rem;
}

.ballot-meta p {
  margin-bottom: 0.15rem;
}

.ballot-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.ballot-table th {
  background: var(--header-bg);
  color: var(--header-text);
  padding: 0.5rem 0.75rem;
  text-align: left;
  font-weight: 600;
}

.ballot-table td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

.ballot-table tr:nth-child(even) {
  background: var(--fill-soft);
}

.ballot-score {
  font-weight: 700;
  text-align: right;
}

.ballot-footer {
  text-align: center;
  margin-top: 1rem;
  font-size: 0.8rem;
  color: var(--text-faint);
}

.ballot-nodata td {
  color: var(--text-faint);
  font-style: italic;
}

.ballot-empty {
  color: var(--text-faint);
  font-style: italic;
  font-size: 0.9rem;
  padding: 0.5rem 0;
}

.result-card-nodata {
  opacity: 0.75;
}

.result-score.no-data {
  color: var(--text-faint);
  font-style: italic;
}

/* Print styles — force light palette so ballots print cleanly on paper */
@media print {
  :root, [data-theme="dark"] {
    --bg: #ffffff;
    --card: #ffffff;
    --surface: #ffffff;
    --text: #1a1a2e;
    --text-strong: #2d3748;
    --text-body: #4a5568;
    --text-muted: #718096;
    --text-faint: #a0aec0;
    --border: #e2e8f0;
    --header-bg: #1a1a2e;
    --header-text: #ffffff;
    --fill-soft: #f7fafc;
  }
  body > * { display: none !important; }
  .sample-ballot { display: block !important; border: none; box-shadow: none; }
  .ballot-header button { display: none; }
  .post-results-actions { display: none; }
}

/* Research tools section */
.tools-section {
  margin-top: 3rem;
  border-top: 2px solid var(--border);
  padding-top: 1rem;
}

.tools-toggle {
  cursor: pointer;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-muted);
  padding: 0.5rem 0;
  list-style: none;
}

.tools-toggle::-webkit-details-marker {
  display: none;
}

.tools-toggle::before {
  content: '+ ';
}

details[open] > .tools-toggle::before {
  content: '- ';
}

/* Scorecard heatmap colors */
.scorecard td { text-align: center; font-size: 0.8rem; min-width: 40px; }
.scorecard .candidate-name { text-align: left; font-weight: 500; white-space: nowrap; }
.score-pos { background: var(--score-pos-bg); color: var(--score-pos-text); }
.score-neg { background: var(--score-neg-bg); color: var(--score-neg-text); }
.score-zero { background: var(--score-zero-bg); color: var(--text-faint); }

/* Responsive */
@media (max-width: 600px) {
  .form-row {
    flex-direction: column;
    gap: 0;
  }

  .tabs {
    flex-wrap: wrap;
  }

  .official-card {
    flex-direction: column;
    align-items: center;
    text-align: center;
  }

  .progress-bar {
    gap: 0;
  }

  .progress-connector {
    width: 16px;
  }

  .dot-label {
    font-size: 0.6rem;
  }

  .dot-num {
    width: 26px;
    height: 26px;
    font-size: 0.75rem;
  }

  .step-card {
    padding: 1.25rem;
  }

  .step-card h2 {
    font-size: 1.15rem;
  }

  .issue-chip {
    font-size: 0.8rem;
    padding: 0.4rem 0.75rem;
  }

  .step-actions {
    flex-direction: column;
  }

  .result-scores-row {
    flex-direction: column;
    gap: 0.25rem;
  }

  .result-confidence {
    justify-content: flex-start;
  }

  .confirm-table {
    font-size: 0.78rem;
  }

  .race-header {
    flex-wrap: wrap;
  }
}

/* ══ Extra condensed stepper for phones ≤480px ══════════════════════════════
   This MUST come AFTER the @media (max-width:600px) block so source-order
   cascade ensures these narrower overrides win (both blocks match at ≤480px;
   same specificity → last-defined wins).

   Goal: keep the 6-step progress bar inside the viewport so it never inflates
   the layout viewport past the physical device width, which would prevent
   the @media (max-width:480px) .address-actions stacking rule from firing.

   Critical fix: the progress bar must be width-constrained with overflow:hidden
   so that no child (incl. the active step label) can widen the layout viewport.
   The active label is positioned absolutely so it contributes zero flex-row width.
   ════════════════════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
  /* Contain the progress bar strictly within the viewport width.
     overflow:hidden + width:100% prevents any child from inflating the
     layout viewport, which would stop the @media (max-width:480px)
     address-button stacking rule from firing. */
  .progress-bar {
    width: 100%;
    overflow: hidden;
    box-sizing: border-box;
    /* Reserve space below for the absolutely-positioned active label */
    padding-bottom: 1.4rem;
    margin-bottom: 0.5rem;
  }

  /* Each dot needs relative positioning so the label can anchor to it. */
  .progress-dot {
    position: relative;
    flex-shrink: 0;
  }

  /* Dots at 20px: 6*20 + 5*(6+4) = 120+50 = 170px — fits in 288px (320-2*16) */
  .dot-num {
    width: 20px;
    height: 20px;
    font-size: 0.65rem;
  }

  .progress-connector {
    width: 6px;
    margin: 0 2px;
    flex-shrink: 0;
  }

  /* Hide all labels — they do NOT contribute to flex-row width at all. */
  .dot-label {
    display: none;
  }

  /* Active step label: absolutely positioned BELOW its dot, zero flex width. */
  .progress-dot.active .dot-label {
    display: block;
    position: absolute;
    top: calc(100% + 2px);
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.58rem;
    white-space: nowrap;
    /* Clip if still too wide rather than widening the row */
    overflow: hidden;
    max-width: 60px;
    text-overflow: ellipsis;
  }
}

/* ══ Address button stacking for all narrow phones ════════════════════════
   NOTE: this block is at the same breakpoint but defined AFTER the stepper
   block. Both apply at <=480px. The stacking fix depends on the stepper
   fix above ensuring the layout viewport is not inflated past 480px.
   (The stacking block was already at line ~664 — this comment is a reminder.)
   ════════════════════════════════════════════════════════════════════════ */
