:root {
  --bg: #f2f4f8;
  --card: #ffffff;
  --ink: #1a2332;
  --ink-soft: #5a6577;
  --accent: #1d4ed8;
  --accent-ink: #ffffff;
  --line: #dde3ec;
  --dem: #2563eb;
  --rep: #dc2626;
  --ind: #7c3aed;
  --other: #64748b;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 4px 14px rgba(16, 24, 40, .06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1420;
    --card: #1a2130;
    --ink: #e8ecf3;
    --ink-soft: #9aa5b8;
    --accent: #3b6ef6;
    --line: #2a3348;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4), 0 4px 14px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

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

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
}

.site-header {
  background: linear-gradient(135deg, #1e3a8a, #1d4ed8);
  color: #fff;
  text-align: center;
  padding: 28px 16px 22px;
}

.site-header h1 {
  margin: 0;
  font-size: 1.45rem;
  letter-spacing: -.01em;
}

.tagline {
  margin: 6px 0 0;
  font-size: .92rem;
  opacity: .85;
}

main {
  max-width: 960px;
  margin: 0 auto;
  padding: 16px;
}

/* ---------- address form ---------- */

.address-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 16px;
  margin: -34px auto 20px;
  max-width: 560px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.address-card label {
  font-weight: 600;
  font-size: .95rem;
}

.mode-toggle {
  display: flex;
  gap: 3px;
  padding: 3px;
  background: var(--bg);
  border: 1.5px solid var(--line);
  border-radius: 999px;
}

.mode-toggle label {
  flex: 1;
  text-align: center;
  font-size: .88rem;
  padding: 8px 10px;
  border-radius: 999px;
  cursor: pointer;
  color: var(--ink-soft);
  transition: background .15s, color .15s;
}

.mode-toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.mode-toggle label:has(input:checked) {
  background: var(--accent);
  color: var(--accent-ink);
}

.mode-toggle label:has(input:focus-visible) {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

#input-row, #browse-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.field {
  font: inherit;
  font-size: 1.05rem;
  padding: 13px 14px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--ink);
  min-height: 48px;
  width: 100%;
}

.field:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: transparent;
}

/* ---------- name typeahead ---------- */

.input-wrap { position: relative; }

.suggest {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 20;
  margin-top: 4px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  max-height: 320px;
  overflow-y: auto;
}

.suggest-item {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  background: none;
  border: 0;
  font: inherit;
  text-align: left;
  cursor: pointer;
  color: var(--ink);
}

.suggest-item:hover, .suggest-item.active { background: var(--bg); }

.s-name { font-weight: 600; }

.s-ctx {
  color: var(--ink-soft);
  font-size: .82rem;
  white-space: nowrap;
}

#search-btn {
  font: inherit;
  font-size: 1.05rem;
  font-weight: 600;
  padding: 13px;
  min-height: 48px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
  transition: filter .15s;
}

#search-btn:hover { filter: brightness(1.1); }
#search-btn:disabled { opacity: .6; cursor: wait; }

.ghost-btn {
  font: inherit;
  font-size: .95rem;
  font-weight: 600;
  padding: 10px;
  min-height: 44px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: none;
  color: var(--accent);
  cursor: pointer;
  transition: border-color .15s;
}

.ghost-btn:hover { border-color: var(--accent); }
.ghost-btn:disabled { opacity: .6; cursor: wait; }

.privacy-note {
  margin: 0;
  font-size: .78rem;
  color: var(--ink-soft);
  text-align: center;
}

/* ---------- status / errors ---------- */

#status {
  max-width: 560px;
  margin: 0 auto 16px;
  text-align: center;
  font-size: .95rem;
}

#status .error {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
  border-radius: 10px;
  padding: 12px 14px;
}

@media (prefers-color-scheme: dark) {
  #status .error {
    background: #3b1215;
    color: #fca5a5;
    border-color: #7f1d1d;
  }
}

#status .loading { color: var(--ink-soft); }

.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  margin-right: 8px;
  vertical-align: -3px;
  border: 2.5px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

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

/* ---------- results ---------- */

.matched-address {
  text-align: center;
  color: var(--ink-soft);
  font-size: .9rem;
  margin-bottom: 18px;
}

.rep-section h2 {
  font-size: 1.15rem;
  margin: 22px 4px 12px;
}

.card-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

@media (min-width: 720px) {
  .card-list { grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }
}

.rep-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 5px solid var(--party, var(--other));
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
}

.rep-card.party-democratic { --party: var(--dem); }
.rep-card.party-republican { --party: var(--rep); }
.rep-card.party-independent { --party: var(--ind); }

.rep-head {
  display: flex;
  gap: 12px;
  align-items: center;
}

.rep-photo, .rep-photo-fallback {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  object-fit: cover;
  object-position: top;
  flex-shrink: 0;
  border: 2px solid var(--line);
  background: var(--bg);
}

.rep-photo-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.3rem;
  color: var(--ink-soft);
}

.rep-name {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 700;
}

.rep-role {
  margin: 2px 0 0;
  font-size: .85rem;
  color: var(--ink-soft);
}

.party-badge {
  display: inline-block;
  font-size: .72rem;
  font-weight: 700;
  padding: 1px 8px;
  border-radius: 999px;
  color: #fff;
  background: var(--party, var(--other));
  margin-top: 4px;
}

.rep-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.action-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 14px;
  min-height: 42px;
  border-radius: 999px;
  border: 1.5px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  font-size: .88rem;
  font-weight: 600;
  text-decoration: none;
  transition: border-color .15s, background .15s;
}

.action-btn:hover { border-color: var(--accent); }

button.action-btn { cursor: pointer; }

.action-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.rep-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.tag {
  font-size: .72rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--ink-soft);
}

.rep-offices {
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
  font-size: .85rem;
  color: var(--ink-soft);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.rep-offices li {
  padding-left: 22px;
  position: relative;
}

.rep-offices .office-icon {
  position: absolute;
  left: 0;
  top: 1px;
}

.office-label {
  font-weight: 600;
  color: var(--ink);
}

.rep-offices a { color: var(--accent); text-decoration: none; }

.office-dist { color: var(--ink-soft); }
.office-dist.nearest { color: var(--accent); font-weight: 600; }
.office-main { color: var(--accent); font-weight: 600; }
.office-hours { color: var(--ink-soft); font-style: italic; }

/* ---------- call script ---------- */

.call-script {
  margin-top: 12px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
  font-size: .88rem;
}

.call-script summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--accent);
  list-style-position: inside;
}

.script-body { margin-top: 8px; }

.script-text {
  margin: 0 0 8px;
  padding: 10px 12px;
  background: var(--bg);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
}

.script-tips {
  margin: 0 0 10px;
  padding-left: 18px;
  color: var(--ink-soft);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* ---------- QR panel ---------- */

.qr-panel {
  margin-top: 10px;
  text-align: center;
}

.qr-panel svg {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.qr-caption {
  margin: 6px 0 0;
  font-size: .8rem;
  color: var(--ink-soft);
}

.no-match {
  background: var(--card);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 16px;
  color: var(--ink-soft);
  font-size: .92rem;
}

.no-match a { color: var(--accent); }

.hours-note {
  max-width: 640px;
  margin: 26px auto 8px;
  font-size: .85rem;
  color: var(--ink-soft);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
}

/* ---------- footer ---------- */

.site-footer {
  text-align: center;
  font-size: .78rem;
  color: var(--ink-soft);
  padding: 24px 16px 32px;
}

.site-footer a { color: var(--ink-soft); }

/* ---------- print ---------- */

@media print {
  .site-header, .address-card, #status, .site-footer,
  .rep-actions, .hours-note { display: none !important; }
  body { background: #fff; color: #000; }
  .matched-address, .rep-role, .rep-offices, .office-label, .s-ctx { color: #000; }
  .card-list { display: block; }
  .card-list > * { margin-bottom: 12px; }
  .rep-card {
    box-shadow: none;
    border: 1px solid #bbb;
    break-inside: avoid;
    page-break-inside: avoid;
  }
  .rep-offices a, .no-match a { color: #000; }
}
