/* White theme throughout — no dark mode. */
:root {
  color-scheme: light;
  --bg: #ffffff;
  --surface: #ffffff;
  --subtle: #f7f8fb;
  --text: #1b2236;
  --muted: #6b7489;
  --border: #e4e7ee;
  --primary: #1f4fd1;
  --primary-2: #183fa8;
  --primary-soft: #eef3ff;
  --accent: #d4a017;
  --ok: #157f4b;
  --ok-soft: #e8f6ee;
  --warn: #9a6400;
  --warn-soft: #fdf5e1;
  --err: #b42318;
  --err-soft: #fdeeed;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 30, 60, .04), 0 8px 24px rgba(20, 30, 60, .06);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--primary); }
h1 { font-size: 1.6rem; margin: 0 0 .3rem; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 0 0 .8rem; }
code { font-family: ui-monospace, Consolas, monospace; }
hr { border: 0; border-top: 1px solid var(--border); margin: 1.2rem 0; }
[hidden] { display: none !important; }

.container { max-width: 880px; margin: 0 auto; padding: 0 16px; }
.container.narrow { max-width: 480px; }
.container.medium { max-width: 640px; }
.container.wide { max-width: 1200px; }
main.container { padding-top: 28px; padding-bottom: 60px; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.print-only { display: none; }

/* ---------- Header ---------- */
.hero, .topbar {
  background: var(--surface);
  color: var(--text);
  border-bottom: 1px solid var(--border);
}
.hero .container, .topbar .container {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  min-height: 64px;
}
.brand { font-weight: 700; font-size: 1.05rem; display: flex; align-items: center; gap: 8px; }
.logo { color: var(--accent); font-size: 1.3rem; }
.link-light { color: var(--muted); }

.topbar nav { display: flex; gap: 4px; flex-wrap: wrap; }
.topbar nav a {
  color: var(--muted); text-decoration: none; padding: 8px 12px; border-radius: 8px; font-size: .92rem;
}
.topbar nav a:hover { background: var(--subtle); color: var(--text); }
.topbar nav a.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav-toggle { display: none; background: none; border: 0; color: var(--text); font-size: 1.5rem; cursor: pointer; }

/* ---------- Cards, alerts ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 18px;
}
.alert { padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; border: 1px solid transparent; }
.alert.ok { background: var(--ok-soft); color: var(--ok); border-color: #bfe5cf; }
.alert.warn { background: var(--warn-soft); color: var(--warn); border-color: #f1dca6; }
.alert.err { background: var(--err-soft); color: var(--err); border-color: #f5c6c2; }

/* ---------- Forms & buttons ---------- */
input, textarea, select {
  font: inherit; color: var(--text); background: #fff;
  border: 1px solid var(--border); border-radius: 9px; padding: 9px 12px; width: 100%;
}
input:focus, textarea:focus { outline: 2px solid #c7d6fb; border-color: var(--primary); }
input[type=checkbox], input[type=radio] { width: auto; }
label { display: block; font-weight: 500; font-size: .92rem; }
label > input, label > textarea { margin-top: 6px; font-weight: 400; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.radio-line { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; cursor: pointer; }
.radio-line input { margin-top: 4px; }
.radio-line.sub { margin-left: 26px; }
.inline { display: inline-flex; gap: 6px; align-items: center; margin: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: end; }
.grid-2.top { align-items: start; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--primary); color: #fff; border: 1px solid var(--primary);
  padding: 9px 16px; border-radius: 9px; font: inherit; font-weight: 600;
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background .15s, opacity .15s, transform .05s;
}
.btn:hover { background: var(--primary-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.ghost { background: #fff; color: var(--primary); border-color: var(--border); }
.btn.ghost:hover { background: var(--primary-soft); }
.btn.danger { background: #fff; color: var(--err); border-color: #f0c4c0; }
.btn.danger:hover { background: var(--err-soft); }
.btn.big { padding: 13px 24px; font-size: 1.02rem; }
.btn.sm { padding: 5px 10px; font-size: .85rem; border-radius: 7px; }

.pill {
  display: inline-block; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  padding: 2px 8px; border-radius: 99px; background: var(--ok-soft); color: var(--ok); vertical-align: middle;
}
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.muted-pill { background: var(--subtle); color: var(--muted); }
.chip { padding: 6px 12px; border-radius: 99px; border: 1px solid var(--border); text-decoration: none; color: var(--text); font-size: .88rem; }
.chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ---------- Voter: code entry ---------- */
.code-input { font-size: 1.4rem; letter-spacing: .25em; text-transform: uppercase; text-align: center; font-family: ui-monospace, Consolas, monospace; }

/* ---------- Voter: wizard ---------- */


.stepper { margin-bottom: 16px; }
.stepper-top { display: flex; justify-content: space-between; gap: 12px; font-weight: 600; font-size: .9rem; margin-bottom: 8px; }
.progress { height: 6px; background: var(--subtle); border: 1px solid var(--border); border-radius: 99px; overflow: hidden; }
.progress .bar { height: 100%; width: 0; background: var(--primary); transition: width .3s; }
.dots { list-style: none; display: flex; justify-content: center; gap: 8px; padding: 0; margin: 12px 0 0; }
.dots li { width: 8px; height: 8px; border-radius: 50%; background: var(--border); transition: all .2s; }
.dots li.done { background: var(--primary); }
.dots li.active { background: var(--primary); width: 22px; border-radius: 99px; }

.step { animation: stepIn .25s ease; }
@keyframes stepIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.kicker { margin: 0 0 4px; font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--primary); }
.step-title { font-size: 1.5rem; margin: 0 0 4px; }
.step > .muted { margin: 0 0 18px; }

.choices { display: grid; gap: 10px; }
.choice {
  position: relative; display: flex; align-items: center; gap: 14px;
  padding: 14px 16px; border: 1.5px solid var(--border); border-radius: 12px; background: #fff;
  cursor: pointer; font-weight: 500; font-size: 1.02rem; transition: border-color .15s, background .15s;
}
.choice:hover { border-color: #b9c9f5; background: var(--subtle); }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice .avatar {
  flex: none; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center;
  background: var(--subtle); border: 1px solid var(--border); color: var(--primary); font-weight: 700; font-size: .92rem;
}
.choice .cname { flex: 1; }
.choice .tick {
  width: 24px; height: 24px; border-radius: 50%; border: 1.5px solid var(--border);
  display: grid; place-items: center; color: transparent; font-size: .78rem;
}
.choice:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.choice:has(input:checked) .avatar { background: var(--primary); border-color: var(--primary); color: #fff; }
.choice:has(input:checked) .tick { background: var(--primary); border-color: var(--primary); color: #fff; }
.choice:has(input:focus-visible) { outline: 2px solid var(--primary); outline-offset: 2px; }

.step-nav { display: flex; justify-content: space-between; gap: 10px; margin-top: 24px; padding-top: 18px; border-top: 1px solid var(--border); }

.review-list { list-style: none; padding: 0; margin: 8px 0 0; }
.review-list li {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.review-list li:last-child { border-bottom: 0; }
.review-list li div { display: flex; flex-direction: column; }
.review-pos { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.review-list strong { font-size: 1.05rem; }
.missing-text { color: var(--err); }

.big-check {
  width: 72px; height: 72px; margin: 6px auto 14px; border-radius: 50%;
  display: grid; place-items: center; background: var(--ok-soft); color: var(--ok); font-size: 2rem; font-weight: 700;
}

/* ---------- Admin ---------- */
body.admin { background: var(--subtle); }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head p { margin: 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 2px;
}
.kpi .label { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.kpi .value { font-size: 1.9rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: .82rem; color: var(--muted); }
.kpi.open .value { color: var(--ok); }
.kpi.closed .value { color: var(--err); }
.meter { display: block; height: 6px; background: var(--subtle); border-radius: 99px; overflow: hidden; margin-top: 6px; }
.meter span { display: block; height: 100%; background: var(--primary); }

.results-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 18px; }
.result-card { margin: 0; }
.result-card header { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 12px; }
.result-card h2 { margin: 0; text-transform: uppercase; letter-spacing: .04em; font-size: .95rem; }
.result-row { margin-bottom: 12px; }
.result-label { display: flex; justify-content: space-between; gap: 8px; font-size: .92rem; margin-bottom: 4px; }
.result-num { font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; }
.result-num b { color: var(--text); }
.track { height: 10px; background: var(--subtle); border-radius: 99px; overflow: hidden; }
.fill { height: 100%; background: #9fb6ef; border-radius: 99px; transition: width .5s ease; }
.result-row.lead .fill { background: var(--primary); }
.adj { color: var(--warn); font-weight: 700; cursor: help; }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; margin-bottom: 14px; }
.table th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--border); }
.table td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table td.pos { color: var(--ok); font-weight: 600; }
.table td.neg { color: var(--err); font-weight: 600; }
.table td.muted { color: var(--muted); }
.num-input { width: 90px; }
.code { background: var(--primary-soft); color: var(--primary); padding: 2px 8px; border-radius: 6px; font-weight: 700; letter-spacing: .08em; }
.picks { line-height: 1.6; }

.pos-head { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.title-input { font-weight: 700; font-size: 1.05rem; min-width: 240px; }
.add-row input { min-width: 240px; }
.filters { flex-wrap: wrap; margin-bottom: 12px; }
.filters input[type=search] { width: 220px; margin-left: auto; }

.log { list-style: none; padding: 0; margin: 0; max-height: 640px; overflow: auto; }
.log li { padding: 9px 0; border-bottom: 1px solid var(--border); }
.danger-zone { border-color: #f0c4c0; }

/* Settings: equal-size cards, action button pinned to the bottom of each. */
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); grid-auto-rows: 1fr; gap: 18px; }
.settings-grid .card { margin: 0; display: flex; flex-direction: column; }
.settings-grid .card > form:last-child { flex: 1; display: flex; flex-direction: column; gap: 14px; }
.settings-grid .card > form:last-child > .btn { margin-top: auto; align-self: flex-start; }

/* ---------- Admin login ---------- */
.login-shell { min-height: 100vh; display: grid; grid-template-columns: 1fr 1fr; }
.login-side {
  background: linear-gradient(160deg, #f5f8ff 0%, #e9efff 100%);
  border-right: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center; padding: 48px;
  position: relative; overflow: hidden;
}
.login-side::after { /* soft dotted texture */
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background-image: radial-gradient(#c9d6f8 1px, transparent 1px);
  background-size: 22px 22px; opacity: .55;
  mask-image: linear-gradient(to top, #000, transparent 70%);
}
.login-side-inner { max-width: 380px; position: relative; z-index: 1; }
.ballot-art { width: 108px; color: var(--primary); margin-bottom: 26px; }
.login-side h1 { font-size: 1.85rem; line-height: 1.2; margin: 0 0 22px; }
.login-features { list-style: none; padding: 0; margin: 0; }
.login-features li { display: flex; align-items: center; gap: 12px; padding: 7px 0; color: #3d4760; }
.login-features .dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--primary); box-shadow: 0 0 0 4px #d9e3fd; }

.login-main { display: flex; align-items: center; justify-content: center; padding: 48px 24px; }
.login-box { width: 100%; max-width: 360px; animation: stepIn .35s ease; }
.login-box h2 { font-size: 1.6rem; margin: 0 0 4px; }
.login-box > .muted { margin: 0 0 24px; }
.pw-wrap { position: relative; display: block; margin-top: 6px; }
.pw-wrap input { margin-top: 0; padding-right: 64px; }
.pw-toggle {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  background: none; border: 0; color: var(--primary); font: inherit; font-size: .82rem; font-weight: 600;
  padding: 6px 8px; border-radius: 6px; cursor: pointer;
}
.pw-toggle:hover { background: var(--primary-soft); }
.login-box .btn.big { width: 100%; margin-top: 4px; }
.login-foot { margin-top: 24px; text-align: center; }
.login-foot a { color: var(--muted); text-decoration: none; }
.login-foot a:hover { color: var(--primary); }

/* ---------- Voter welcome (reuses the admin login layout) ---------- */
.on-welcome .hero { display: none; }
.on-welcome main.container { max-width: none; padding: 0; }
.on-welcome .alert { display: none; }
.welcome.login-shell { animation: none; }
.welcome .login-box > .login-foot { margin: 14px 0 0; }
.voter .hero .container { max-width: 640px; }
.ballot-outline { list-style: none; padding: 0; margin: 0 0 24px; border-top: 1px solid var(--border); }
.ballot-outline li { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--border); font-weight: 500; }
.ballot-outline span {
  flex: none; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center;
  background: var(--primary-soft); color: var(--primary); font-size: .76rem; font-weight: 700;
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
  .settings-grid { grid-template-columns: 1fr; grid-auto-rows: auto; }
  .login-shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .login-side { border-right: 0; border-bottom: 1px solid var(--border); padding: 28px 24px; justify-content: flex-start; }
  .login-side .ballot-art { width: 56px; margin-bottom: 12px; }
  .login-side h1 { font-size: 1.3rem; margin: 0; }
  .login-features { display: none; }
  .login-main { align-items: flex-start; padding-top: 32px; }
  .nav-toggle { display: block; }
  .topbar .container { flex-wrap: wrap; }
  .topbar nav { display: none; width: 100%; flex-direction: column; padding-bottom: 12px; }
  .nav-open .topbar nav { display: flex; }
}
@media (max-width: 520px) {
  h1 { font-size: 1.35rem; }
  .card { padding: 18px; }
  .step-title { font-size: 1.3rem; }
  .step-nav .btn { flex: 1; }
  .results-grid { grid-template-columns: 1fr; }
  .title-input, .add-row input { min-width: 0; }
  .filters input[type=search] { width: 100%; margin-left: 0; }
}

/* ---------- Print ---------- */
@media print {
  .topbar, .actions, .no-print, .nav-toggle { display: none !important; }
  body, body.admin { background: #fff; color: #000; }
  .card, .kpi { box-shadow: none; break-inside: avoid; }
  .print-only { display: inline; }
  .print-codes .voters-table tbody tr { border: 1px dashed #999; }
  .print-codes .voters-table td { padding: 14px 10px; }
  .print-codes .code { font-size: 1.3rem; }
}
