:root {
  --paper: #f3efe6;
  --surface: #fffdf9;
  --surface-2: #f7f3ea;
  --ink: #1b1916;
  --muted: #534e46;
  --line: #ddd4c6;
  --accent: #1b4332;
  --accent-hover: #132f24;
  --on-accent: #f7f4ee;
  --accent-soft: #e7f2ec;
  --accent-line: #b7d4c6;
  --danger: #7a2926;
  --danger-soft: #f8ecea;
  --danger-line: #e4c4c0;
  --ok-soft: #e7f2ec;
  --shadow: 0 1px 2px rgba(27, 25, 22, 0.05);
  --radius: 12px;
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", sans-serif;
  --serif: "Iowan Old Style", Palatino, "Palatino Linotype", "Book Antiqua", Georgia, serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 3rem;
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-md: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.5rem;
  --text-2xl: 1.875rem;
  --text-3xl: 2.5rem;
  --topbar: 4rem;
  color-scheme: light;
}

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

html { scroll-padding-top: calc(var(--topbar) + 1rem); }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--text-md);
  line-height: 1.5;
}

:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

a { color: var(--accent); }
h1, h2, h3 { font-weight: 600; line-height: 1.2; margin: 0; }
h1 { font-family: var(--serif); font-size: var(--text-2xl); letter-spacing: -0.02em; }
h2 { font-size: var(--text-lg); }
p { margin: 0; }

.skip {
  position: absolute;
  left: var(--space-4);
  top: -4rem;
  background: var(--surface);
  color: var(--ink);
  padding: var(--space-2) var(--space-3);
  z-index: 30;
}
.skip:focus { top: var(--space-2); }

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: var(--space-5);
  min-height: var(--topbar);
  padding: var(--space-2) var(--space-5);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  color: var(--ink);
  text-decoration: none;
  margin-right: auto;
}
.brand-mark {
  width: 2rem;
  height: 2rem;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: var(--on-accent);
  border-radius: 7px;
  font-family: var(--serif);
  font-size: 1.15rem;
}
.brand-lockup { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text { font-family: var(--serif); font-size: 1.25rem; }
.brand-org { color: var(--muted); font-size: var(--text-xs); letter-spacing: 0.04em; text-transform: uppercase; }

.nav { display: flex; gap: var(--space-1); }
.nav a {
  color: var(--ink);
  text-decoration: none;
  padding: 0.55rem 0.8rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: var(--text-sm);
}
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.nav a:hover { background: var(--surface-2); }

.menu { position: relative; flex-shrink: 0; }
.menu summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
  padding: 0.25rem 0.4rem 0.25rem 0.25rem;
  border-radius: 999px;
}
.menu summary::-webkit-details-marker { display: none; }
.avatar {
  width: 2rem;
  height: 2rem;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: var(--text-xs);
  font-weight: 700;
}
.menu-email { font-size: var(--text-sm); white-space: nowrap; }
.menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 0.4rem);
  width: 16rem;
  padding: var(--space-4);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.menu-role { color: var(--muted); font-size: var(--text-sm); margin-bottom: var(--space-3); }
.menu-panel .button { width: 100%; }

.content {
  width: min(1120px, calc(100% - 2rem));
  margin: 0 auto;
  padding: var(--space-6) 0 var(--space-7);
}

.footer {
  width: min(1120px, calc(100% - 2rem));
  margin: 0 auto var(--space-6);
  color: var(--muted);
  font-size: var(--text-sm);
}

.page-head { margin-bottom: var(--space-5); }
.lede-sm { color: var(--muted); margin-top: var(--space-2); max-width: 46rem; }
.fine { color: var(--muted); font-size: var(--text-sm); margin-top: var(--space-3); }
.fine.block { display: block; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: var(--text-sm); }
.num { font-variant-numeric: tabular-nums; }
.eyebrow {
  margin: 0 0 var(--space-2);
  color: var(--accent);
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.button, button, .nav a, summary, input, select {
  font: inherit;
}
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.75rem;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  border: 1px solid transparent;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 650;
  text-decoration: none;
  cursor: pointer;
}
.button:hover { background: var(--accent-hover); }
.button.secondary {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--line);
}
.button.secondary:hover { background: var(--surface-2); }
.button.danger { background: var(--danger); color: #fff; }
.button.danger:hover { background: #641f1c; }
.button:disabled { opacity: 0.45; cursor: not-allowed; }

label { display: flex; flex-direction: column; gap: 0.35rem; font-size: var(--text-sm); font-weight: 600; }
input, select {
  min-height: 2.75rem;
  padding: 0.45rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 450;
}
input::placeholder { color: var(--muted); }
.banner {
  padding: var(--space-3) var(--space-4);
  border-radius: 8px;
  margin-bottom: var(--space-4);
  border: 1px solid var(--line);
}
.banner-error { background: var(--danger-soft); border-color: var(--danger-line); color: var(--danger); }
.banner-ok { background: var(--ok-soft); border-color: var(--accent-line); color: var(--accent); }

.filters {
  display: grid;
  grid-template-columns: 1.4fr repeat(4, minmax(0, 1fr)) 0.7fr 0.7fr;
  gap: var(--space-3);
  align-items: end;
  padding: var(--space-4);
  margin-bottom: var(--space-4);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.filter-actions { display: flex; gap: var(--space-2); align-items: center; }

.table-scroll {
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.staff-scroll { max-height: none; }
table.roster { width: 100%; border-collapse: collapse; font-size: 0.9375rem; }
.roster th, .roster td {
  text-align: left;
  padding: 0.7rem 0.85rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.roster thead th {
  background: var(--surface-2);
  font-size: var(--text-xs);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.roster-table { overflow: visible; }
.roster-table thead th {
  position: sticky;
  top: var(--topbar);
  z-index: 2;
}
.roster tbody tr { position: relative; }
.roster tbody tr:hover { background: #fbf8f2; }
.row-link { color: var(--ink); font-weight: 650; text-decoration: none; }
.row-link::after { content: ""; position: absolute; inset: 0; }
.roster-cards { display: none; }

.result-meta { color: var(--muted); font-size: var(--text-sm); margin-bottom: var(--space-3); }
.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-top: var(--space-4);
}
.pager a, .pager span {
  min-height: 2.75rem;
  display: inline-flex;
  align-items: center;
  padding: 0 0.8rem;
  border-radius: 8px;
  text-decoration: none;
}
.pager a { border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-weight: 600; }
.pager .is-disabled, .is-disabled { color: var(--muted); }

.empty {
  padding: var(--space-7) var(--space-5);
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  text-align: center;
}
.empty h1, .empty h2 { margin-bottom: var(--space-2); }
.empty p { color: var(--muted); margin-bottom: var(--space-4); }
.loading-status:empty { display: none; }
.loading-status { color: var(--accent); font-weight: 650; margin-bottom: var(--space-3); }
body.is-loading::before {
  content: "";
  position: fixed;
  inset: 0 0 auto 0;
  height: 3px;
  background: var(--accent);
  z-index: 40;
}

.chip {
  display: inline-flex;
  align-items: center;
  padding: 0.12rem 0.5rem;
  border-radius: 999px;
  border: 1px solid transparent;
  font-size: var(--text-xs);
  font-weight: 700;
  line-height: 1.4;
  white-space: nowrap;
}
.chip-democratic { background: #e4edf6; color: #16365a; border-color: #c5d4e6; }
.chip-republican { background: #f8e8e5; color: #6a2420; border-color: #e7cdc8; }
.chip-independent { background: #eeeae3; color: #3d3832; border-color: #ddd4c8; }
.chip-libertarian { background: #f6f0e2; color: #5a4012; border-color: #e6d7b8; }
.chip-green { background: #e5f2ea; color: #1a4a32; border-color: #c5dfd0; }
.chip-other { background: #eeeae3; color: #3d3832; border-color: #ddd4c8; }
.chip-row { display: flex; flex-wrap: wrap; gap: var(--space-2); margin: var(--space-3) 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--space-5);
  box-shadow: var(--shadow);
}
.card + .card, .import-grid, .admin-grid, .danger-zone, .stats { margin-top: var(--space-4); }
.profile-toolbar {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--space-3) var(--space-4);
  align-items: center;
  margin-bottom: var(--space-4);
}
.back { font-weight: 650; text-decoration: none; }
.neighbor { display: flex; gap: var(--space-2); justify-content: flex-end; }
.neighbor-link {
  display: flex;
  flex-direction: column;
  min-width: 9rem;
  max-width: 16rem;
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  text-decoration: none;
}
.neighbor-link.is-disabled { color: var(--muted); }
.pager-kicker { color: var(--muted); font-size: var(--text-xs); font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; }
.copy-link { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }
.copy-link input {
  flex: 1 1 16rem;
  font-family: var(--mono);
  font-size: var(--text-xs);
}
.copy-status { font-size: var(--text-sm); color: var(--accent); font-weight: 650; }

.profile-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
}
.profile-grid .raw-record { grid-column: 1 / -1; }
.card-persona {
  background: var(--accent-soft);
  border-color: var(--accent-line);
}
.persona-lead {
  font-family: var(--serif);
  font-size: var(--text-xl);
  line-height: 1.45;
}
.place { color: var(--muted); margin-top: var(--space-2); }
.facts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3) var(--space-4);
  margin: var(--space-4) 0 0;
}
.facts div { min-width: 0; }
.facts .span-2 { grid-column: 1 / -1; }
.facts dt { color: var(--muted); font-size: var(--text-xs); font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; }
.facts dd { margin: 0.15rem 0 0; }
.timeline { list-style: none; margin: var(--space-4) 0 0; padding: 0; }
.timeline li {
  position: relative;
  padding: 0 0 var(--space-4) 1.4rem;
  border-left: 2px solid var(--accent-line);
}
.timeline li:last-child { border-left-color: transparent; padding-bottom: 0; }
.timeline li::before {
  content: "";
  position: absolute;
  left: -5px;
  top: 0.35rem;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}
.raw-record summary { cursor: pointer; font-weight: 650; }
.raw-json {
  margin: var(--space-4) 0 0;
  padding: var(--space-4);
  background: var(--surface-2);
  border-radius: 8px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--mono);
  font-size: var(--text-xs);
  line-height: 1.45;
}

.import-grid, .admin-grid { display: grid; grid-template-columns: 20rem 1fr; gap: var(--space-4); }
.import-grid { grid-template-columns: 1.4fr 0.8fr; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-3); }
.stat {
  padding: var(--space-3);
  background: var(--surface-2);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
}
.stat-value { font-family: var(--serif); font-size: var(--text-xl); }
.stat-label { color: var(--muted); font-size: var(--text-xs); font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; }
.note-list { margin: var(--space-4) 0 0; padding-left: 1.1rem; color: var(--muted); font-size: var(--text-sm); }
.progress { margin-top: var(--space-4); }
progress { width: 100%; height: 0.6rem; accent-color: var(--accent); }
.quota { max-width: 46rem; }
.subnav { display: flex; gap: var(--space-2); margin-bottom: var(--space-4); flex-wrap: wrap; }
.subnav a {
  text-decoration: none;
  color: var(--ink);
  font-weight: 650;
  padding: 0.4rem 0.7rem;
  border-radius: 999px;
}
.subnav a[aria-current="page"] { background: var(--accent); color: var(--on-accent); }
.inline-form { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }
.inline-form input, .inline-form select { min-width: 8rem; }
.danger-zone { border-color: var(--danger-line); background: var(--danger-soft); }
.danger-zone h2 { color: var(--danger); }
.danger-zone form { margin-top: var(--space-4); display: grid; gap: var(--space-3); max-width: 28rem; }

.auth-body { background: var(--paper); }
.auth-layout { min-height: 100vh; display: grid; grid-template-columns: minmax(18rem, 0.9fr) 1.1fr; }
.auth-brand {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: var(--space-4);
  padding: var(--space-7);
  background: var(--accent);
  color: var(--on-accent);
}
.auth-brand .eyebrow { color: #d5e8de; }
.auth-brand h1 { font-size: var(--text-3xl); }
.auth-brand .lede { font-size: var(--text-lg); max-width: 26rem; }
.auth-note { margin-top: auto; font-size: var(--text-sm); letter-spacing: 0.04em; text-transform: uppercase; color: #d5e8de; }
.auth-panel { display: grid; place-items: center; padding: var(--space-6); }
.auth-card {
  width: min(26rem, 100%);
  display: grid;
  gap: var(--space-4);
  padding: var(--space-6);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.auth-card h2 { font-family: var(--serif); font-size: var(--text-xl); }
.auth-card .button { width: 100%; }

.print-only { display: none; }

@media (max-width: 980px) {
  .filters { grid-template-columns: 1fr 1fr; }
  .import-grid, .admin-grid, .profile-grid { grid-template-columns: 1fr; }
  .profile-grid .raw-record { grid-column: auto; }
  .stats { grid-template-columns: 1fr 1fr; }
  .brand-org { display: none; }
}

@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; padding: var(--space-3); gap: var(--space-2); }
  .nav { order: 3; width: 100%; }
  .nav a { flex: 1; text-align: center; }
  .menu-email { display: none; }
  .content { width: min(1120px, calc(100% - 1.5rem)); padding-top: var(--space-5); }
  .roster-table { display: none; }
  .roster-cards { display: flex; flex-direction: column; gap: var(--space-2); }
  .voter-card {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    padding: var(--space-4);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    color: var(--ink);
    text-decoration: none;
  }
  .voter-card-name { font-weight: 700; }
  .voter-card-meta { color: var(--muted); font-size: var(--text-sm); }
  .filters { grid-template-columns: 1fr; }
  .profile-toolbar, .neighbor { display: flex; flex-direction: column; align-items: stretch; }
  .neighbor-link { max-width: none; }
  .facts { grid-template-columns: 1fr; }
  .auth-layout { grid-template-columns: 1fr; }
  .auth-brand { padding: var(--space-6) var(--space-5); min-height: auto; }
  .auth-brand h1 { font-size: var(--text-2xl); }
  .auth-note { margin-top: var(--space-5); }
  .auth-panel { padding: var(--space-5) var(--space-4) var(--space-7); }
  .menu-email { max-width: 8rem; }
  .staff-scroll { overflow: visible; border: 0; background: transparent; max-height: none; }
  .staff-table, .staff-table tbody, .staff-table tr, .staff-table th, .staff-table td { display: block; width: auto; }
  .staff-table thead { display: none; }
  .staff-table tr {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    margin-bottom: var(--space-3);
    padding: var(--space-3);
  }
  .staff-table th, .staff-table td { border: 0; padding: 0.35rem 0; }
  .inline-form { display: grid; }
  .inline-form .button, .inline-form input, .inline-form select { width: 100%; min-width: 0; }
}

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

@media print {
  .no-print, .topbar, .footer, .skip, .profile-toolbar { display: none !important; }
  .print-only { display: block !important; }
  body { background: #fff; color: #000; }
  .content { width: auto; margin: 0; padding: 0; }
  .card, .card-persona { background: #fff; box-shadow: none; break-inside: avoid; }
  .profile-grid { display: block; }
  .card { margin-bottom: 1rem; }
  .raw-record > :not(summary) { display: block !important; }
  a { color: #000; text-decoration: none; }
  .print-banner { font-size: 0.8rem; letter-spacing: 0.06em; text-transform: uppercase; margin-bottom: 1rem; }
  @page { margin: 0.6in; }
}
