/* public/css/style.css — single stylesheet, mobile first. */
:root {
  --voted: #2e7d4f;
  --vbm: #c77d0a;
  --notv: #b3202a;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1c2430;
  --muted: #5d6878;
  --border: #d7dce3;
  --primary: #b3202a;
  --primary-dark: #8d1820;
  --navy: #1d2f4f;
  --ok-bg: #e7f5ea;
  --ok-text: #1d6b33;
  --err-bg: #fdecec;
  --err-text: #9b1c1c;
  --radius: 8px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1 { font-size: 1.4rem; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
p { margin: 0 0 .75rem; }
a { color: var(--navy); }

/* --- Top bar --- */
#topbar {
  background: var(--navy);
  color: #fff;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  padding: .5rem 1rem;
  gap: .5rem;
}
#topbar .brand { font-weight: 700; letter-spacing: .03em; flex: 1; white-space: nowrap; }
#topbar .brand span { font-weight: 400; opacity: .75; margin-left: .25rem; }
#topbar nav { display: none; width: 100%; flex-direction: column; gap: .25rem; padding: .5rem 0; }
#topbar.open nav { display: flex; }
#topbar nav a, #topbar nav .link, #topbar nav .who {
  color: #fff;
  text-decoration: none;
  padding: .5rem .25rem;
  font-size: 1rem;
}
#topbar nav a.current { font-weight: 700; text-decoration: underline; }
#topbar nav .who { opacity: .75; }
.nav-toggle {
  background: none;
  border: 1px solid rgba(255, 255, 255, .4);
  color: #fff;
  font-size: 1.25rem;
  border-radius: var(--radius);
  padding: .25rem .6rem;
  cursor: pointer;
}
button.link {
  background: none;
  border: none;
  text-align: left;
  cursor: pointer;
  font: inherit;
}

@media (min-width: 720px) {
  #topbar { flex-wrap: nowrap; }
  .nav-toggle { display: none; }
  #topbar nav { display: flex; flex-direction: row; width: auto; align-items: center; gap: .75rem; padding: 0; }
}

/* --- Layout --- */
main { max-width: 960px; margin: 0 auto; padding: 1rem; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}
.muted { color: var(--muted); font-size: .9rem; }

/* --- Forms --- */
label { display: block; font-weight: 600; margin: .75rem 0 .25rem; }
input, select, textarea {
  width: 100%;
  font: inherit;
  padding: .6rem .7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  min-height: 44px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--navy); outline-offset: 1px; }
.btn {
  display: inline-block;
  font: inherit;
  font-weight: 600;
  padding: .6rem 1.1rem;
  min-height: 44px;
  border-radius: var(--radius);
  border: 1px solid var(--primary);
  background: var(--primary);
  color: #fff;
  cursor: pointer;
}
.btn:hover { background: var(--primary-dark); }
.btn:disabled { opacity: .6; cursor: default; }
.btn.secondary { background: #fff; color: var(--navy); border-color: var(--border); }
.btn.secondary:hover { background: var(--bg); }
.btn.small { padding: .35rem .7rem; min-height: 36px; font-size: .9rem; }
.form-actions { margin-top: 1rem; display: flex; gap: .5rem; flex-wrap: wrap; }
.grid-2 { display: grid; gap: 0 1rem; }
@media (min-width: 720px) { .grid-2 { grid-template-columns: 1fr 1fr; } }

.msg { padding: .6rem .8rem; border-radius: var(--radius); margin: .75rem 0; }
.msg.error { background: var(--err-bg); color: var(--err-text); }
.msg.ok { background: var(--ok-bg); color: var(--ok-text); }

/* --- Login --- */
.login-wrap { max-width: 380px; margin: 3rem auto; padding: 0 1rem; }
.login-wrap h1 { text-align: center; }
.login-wrap .sub { text-align: center; color: var(--muted); margin-bottom: 1.25rem; }
.login-wrap .btn { width: 100%; margin-top: 1.25rem; }

/* --- Stats --- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .75rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem; }
.stat .num { font-size: 1.6rem; font-weight: 700; }
.stat .lbl { color: var(--muted); font-size: .85rem; }

/* --- User list: cards on phones, table on wider screens --- */
.user-list { list-style: none; margin: 0; padding: 0; }
.user-row {
  border-top: 1px solid var(--border);
  padding: .75rem 0;
  display: grid;
  gap: .4rem;
}
.user-row:first-child { border-top: none; }
.user-row .name { font-weight: 600; }
.user-row .email { color: var(--muted); font-size: .9rem; word-break: break-all; }
.user-row .controls { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.user-row .controls select { width: auto; min-height: 36px; padding: .3rem .5rem; }
.user-row.inactive .name, .user-row.inactive .email { text-decoration: line-through; opacity: .6; }
.badge {
  display: inline-block;
  font-size: .75rem;
  padding: .1rem .45rem;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
  margin-left: .35rem;
  font-weight: 600;
}
@media (min-width: 720px) {
  .user-row { grid-template-columns: 1.2fr 1.4fr auto; align-items: center; }
}

/* --- Tables (imports) --- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { text-align: left; padding: .4rem .5rem; border-top: 1px solid var(--border); vertical-align: top; white-space: nowrap; }
.table th { border-top: none; color: var(--muted); font-weight: 600; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .wrap { white-space: normal; word-break: break-word; min-width: 10rem; }
.badge.new { background: var(--ok-bg); color: var(--ok-text); border-color: transparent; }
.result-list { list-style: none; margin: .5rem 0 0; padding: 0; }
.result-list li { padding: .5rem 0; border-top: 1px solid var(--border); word-break: break-word; }
.result-list li.fail { color: var(--err-text); }
code { background: var(--bg); padding: 0 .25rem; border-radius: 4px; font-size: .9em; }

/* --- Voter status --- */
.badge.st-voted { background: var(--voted); color: #fff; border-color: transparent; }
.badge.st-vbm { background: var(--vbm); color: #fff; border-color: transparent; }
.badge.st-not { background: var(--notv); color: #fff; border-color: transparent; }
.badge.party-rep { border-color: #b3202a; color: #8d1820; }
.badge.party-dem { border-color: #1d4f9c; color: #1d3f7c; }
.link-stat { color: inherit; text-decoration: none; display: block; }
.link-stat:hover { border-color: var(--navy); }
.st-voted-edge { border-left: 4px solid var(--voted); }
.st-vbm-edge { border-left: 4px solid var(--vbm); }
.st-not-edge { border-left: 4px solid var(--notv); }
.stats + .card, .card + .stats { margin-top: 1rem; }
.bar-col { width: 30%; min-width: 90px; }
.bar { display: flex; height: .8rem; border-radius: 4px; overflow: hidden; background: var(--bg); margin-top: .25rem; }
.bar span { display: block; height: 100%; }
.bar .st-voted { background: var(--voted); }
.bar .st-vbm { background: var(--vbm); }
.bar .st-not { background: var(--notv); opacity: .75; }

/* --- Voter search --- */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.filter-main { display: flex; gap: .5rem; }
.filter-main input { flex: 1; }
.filter-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 .75rem; }
.filter-grid label { font-size: .85rem; margin-top: .6rem; }
.filter-grid select { min-height: 40px; padding: .4rem .5rem; }
.filter-grid .check { grid-column: 1 / -1; }
.filter-grid .check label { display: flex; align-items: center; gap: .5rem; font-weight: 500; font-size: .95rem; }
.filter-grid .check input { width: auto; min-height: 0; }
@media (min-width: 720px) { .filter-grid { grid-template-columns: repeat(4, 1fr); } }
.voter-list { list-style: none; margin: 0; padding: 0; }
.voter-row { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: .5rem; }
.voter-row a { display: block; padding: .65rem .8rem; color: inherit; text-decoration: none; }
.voter-row a:hover { background: #fafbfc; }
.voter-row.same-door { margin-top: -.45rem; border-top-left-radius: 0; border-top-right-radius: 0; border-left: 4px solid var(--border); }
.voter-list.compact .voter-row { border: none; border-top: 1px solid var(--border); border-radius: 0; margin: 0; }
.vr-top { display: flex; justify-content: space-between; align-items: flex-start; gap: .5rem; }
.vr-top h1 { margin: 0; }
.vr-name { font-weight: 700; }
.vr-addr { margin-top: .1rem; }
.vr-meta { display: flex; flex-wrap: wrap; gap: .25rem .75rem; align-items: center; font-size: .85rem; margin-top: .3rem; }
.vr-meta .badge { margin-left: 0; }
.vr-contact { margin-top: .25rem; }
.pager { display: flex; justify-content: space-between; align-items: center; margin: 1rem 0; gap: .5rem; }

/* --- Voter detail --- */
.big-addr { font-size: 1.1rem; font-weight: 600; margin: .5rem 0; }
.contact-links { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: .75rem; }
.contact-links .btn { text-decoration: none; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1rem; margin: 0; }
.facts dt { color: var(--muted); font-size: .9rem; }
.facts dd { margin: 0; }
.seg { display: flex; gap: .5rem; }
.seg label { display: flex; align-items: center; gap: .4rem; margin: 0; padding: .5rem .9rem; border: 1px solid var(--border); border-radius: var(--radius); font-weight: 600; cursor: pointer; }
.seg input { width: auto; min-height: 0; }
.seg label:has(input:checked) { border-color: var(--navy); background: #eef1f6; }
textarea { resize: vertical; }
.mt { margin-top: 1.25rem; }
.contact-list { list-style: none; margin: 0; padding: 0; }
.contact-list li { padding: .6rem 0; border-top: 1px solid var(--border); }
.contact-list li:first-child { border-top: none; }
.contact-list .badge { font-weight: 500; }
.contact-list .note { margin-top: .25rem; white-space: pre-wrap; }
.small-link { color: var(--err-text); font-size: .85rem; padding: .25rem 0; text-decoration: underline; }
.more-filters { margin-top: .6rem; }
.more-filters summary { cursor: pointer; font-weight: 600; color: var(--navy); padding: .35rem 0; }

/* --- Lists --- */
.btn.disabled { opacity: .5; pointer-events: none; }
a.btn { text-decoration: none; }
.filter-grid .check label + label { margin-top: .25rem; }

/* --- Printable sheets --- */
.sheet { max-width: 1100px; }
.sheet-head h1 { margin-bottom: .25rem; }
.sheet-head p { margin: 0 0 .35rem; }
.legend { font-size: .85rem; }
.street { margin-top: 1.25rem; }
.street h2 { font-size: 1.05rem; margin: 0 0 .35rem; }
.street h2 .side { font-weight: 400; color: var(--muted); font-size: .9rem; }
.print-table { width: 100%; border-collapse: collapse; font-size: .9rem; background: #fff; }
.print-table th, .print-table td { border: 1px solid #9aa3ae; padding: .3rem .4rem; vertical-align: top; text-align: left; }
.print-table th { background: #eef1f6; font-size: .8rem; }
.print-table .c { text-align: center; white-space: nowrap; }
.print-table .door, .print-table .phone { white-space: nowrap; font-weight: 700; }
.print-table .unit { font-weight: 400; }
.print-table .door-more td { border-top-style: dotted; }
.print-table .door-more .door, .print-table .door-more .phone { border-top-color: transparent; }
.print-table .write { min-width: 4rem; }
.print-table .write.wide { min-width: 9rem; }
.print-table .prev { font-size: .75rem; color: var(--muted); }
.print-table .tag { font-size: .7rem; border: 1px solid #9aa3ae; border-radius: 4px; padding: 0 .2rem; white-space: nowrap; }
.print-table .addr { font-size: .8rem; }
.foot { margin-top: 1rem; }

@media print {
  @page { margin: 12mm; }
  body.print-page { background: #fff; font-size: 10pt; }
  .no-print, #topbar { display: none !important; }
  .sheet { max-width: none; padding: 0; }
  .muted { color: #333; }
  .print-table { font-size: 9pt; }
  .print-table th { background: #e6e6e6; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .print-table tr { break-inside: avoid; }
  .street h2 { break-after: avoid; }
  .page-break { break-before: page; }
}
.count-row { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin-bottom: .5rem; }
.count-row p { margin: 0; }
.user-row .precincts { font-size: .9rem; }
.user-row.unassigned .precincts { color: var(--notv); font-weight: 600; }
.user-row .phone { font-size: .9rem; margin-top: .15rem; }
