:root {
  --forest: #1f5135;
  --forest-dark: #143824;
  --leaf: #8bc34a;
  --gold: #c9a227;
  --paper: #f4f1ea;
  --card: #ffffff;
  --ink: #1d2a22;
  --muted: #66746b;
  --line: #e2ddd1;
  --danger: #b23b3b;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(20, 40, 30, .06), 0 12px 32px rgba(20, 40, 30, .08);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  color: var(--ink);
  background: var(--paper);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
body.voter {
  background:
    radial-gradient(1200px 500px at 50% -200px, rgba(139, 195, 74, .18), transparent 70%),
    var(--paper);
}
h1, h2, h3 { line-height: 1.2; }
code { background: #eee9dd; padding: 1px 6px; border-radius: 6px; }
.center { text-align: center; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 28px;
  background: var(--forest);
  color: #fff;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { width: 48px; height: 48px; flex: none; display: block; object-fit: contain; }
.topbar .logo { width: 62px; height: 62px; background: #fff; border-radius: 50%; padding: 2px; box-shadow: 0 0 0 2px rgba(255,255,255,.35); }
.brand-org { font-weight: 600; font-size: 15px; letter-spacing: .2px; }
.brand-fund { font-size: 13px; opacity: .8; }
.secret-badge {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 600; letter-spacing: .3px;
  padding: 7px 14px; border-radius: 999px;
  background: rgba(255, 255, 255, .12); border: 1px solid rgba(255, 255, 255, .25);
}
.secret-badge svg { width: 18px; height: 18px; }

/* ---------- Voter stage ---------- */
.stage { flex: 1; width: 100%; max-width: 1040px; margin: 0 auto; padding: 32px 20px 48px; }
.election-title {
  text-align: center; margin: 4px 0 28px;
  font-size: clamp(22px, 3.2vw, 34px); font-weight: 700; color: var(--forest-dark);
}
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 40px 36px;
}
.narrow { max-width: 520px; margin: 0 auto; }
.narrow-block { max-width: 640px; margin: 0 auto 18px; }
.card h2, .ballot h2 { margin: 6px 0 8px; font-size: 26px; }
.lead { color: var(--muted); font-size: 17px; margin: 0 0 22px; }
.hint { color: var(--muted); font-size: 14px; margin: 18px 0 0; }
.step-label {
  display: inline-block; font-size: 12px; font-weight: 700; letter-spacing: 1.4px; text-transform: uppercase;
  color: var(--forest); background: rgba(139, 195, 74, .2); padding: 5px 12px; border-radius: 999px;
}
.ballot .step-label { display: block; width: max-content; margin: 0 auto; }

.code-form { display: flex; flex-direction: column; gap: 14px; }
.code-input {
  font-family: Consolas, "Courier New", monospace;
  font-size: 34px; letter-spacing: 6px; text-align: center; text-transform: uppercase;
  padding: 16px; border: 2px solid var(--line); border-radius: 14px; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.code-input:focus { border-color: var(--forest); box-shadow: 0 0 0 4px rgba(31, 81, 53, .15); }

/* ---------- Buttons ---------- */
.btn {
  font: inherit; font-weight: 600; cursor: pointer; border: 0; border-radius: 12px;
  padding: 11px 20px; transition: transform .08s, background .15s, opacity .15s;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--forest); color: #fff; }
.btn.primary:hover { background: var(--forest-dark); }
.btn.primary:disabled { opacity: .45; cursor: not-allowed; }
.btn.big { font-size: 19px; padding: 16px 34px; border-radius: 14px; }
.btn.ghost { background: #efebe2; color: var(--ink); }
.btn.ghost:hover { background: #e5dfd2; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.gold { background: var(--gold); color: #fff; }
.btn.link { background: none; color: var(--muted); text-decoration: underline; padding: 8px; }
.btn.small { padding: 7px 12px; font-size: 14px; border-radius: 9px; }

.alert { padding: 12px 16px; border-radius: 12px; margin: 0 0 16px; font-weight: 500; text-align: left; }
.alert.error { background: #fbeaea; color: #8a2424; border: 1px solid #f0c9c9; }
.alert.ok { background: #e9f5e3; color: #2a5e1f; border: 1px solid #cde6c0; }
.alert.info { background: #fff7e0; color: #6b5310; border: 1px solid #f0e0a8; }

/* ---------- Ballot ---------- */
.ballot-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 28px;
  margin: 26px 0 30px;
}
.candidate {
  position: relative; cursor: pointer; background: var(--card);
  border-radius: 22px; box-shadow: var(--shadow); border: 3px solid transparent;
  padding: 26px 22px 28px; display: flex; flex-direction: column; align-items: center; text-align: center;
  transition: transform .15s, border-color .15s, box-shadow .15s;
}
.candidate:hover { transform: translateY(-3px); }
.candidate input { position: absolute; opacity: 0; pointer-events: none; }
.candidate:has(input:checked) {
  border-color: var(--forest);
  box-shadow: 0 0 0 6px rgba(31, 81, 53, .12), var(--shadow);
}
.candidate:has(input:focus-visible) { outline: 3px solid var(--gold); outline-offset: 4px; }
.cand-num {
  position: absolute; top: 16px; left: 16px; width: 38px; height: 38px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 700; font-size: 18px;
  background: var(--paper); color: var(--forest);
}
.cand-check {
  position: absolute; top: 14px; right: 14px; width: 42px; height: 42px; border-radius: 50%;
  display: grid; place-items: center; border: 3px solid var(--line); color: transparent; background: #fff;
  transition: all .15s;
}
.cand-check svg { width: 24px; height: 24px; }
.candidate:has(input:checked) .cand-check { background: var(--forest); border-color: var(--forest); color: #fff; }
.cand-photo-wrap { margin: 12px 0 18px; }
.cand-photo {
  width: 210px; height: 250px; border-radius: 16px; object-fit: cover; object-position: center top;
  display: block; background: #eae5d8;
}
.cand-photo.initials, .photo.initials, .thumb.initials {
  display: grid; place-items: center; color: #fff; font-weight: 700;
  background: linear-gradient(135deg, var(--forest), #3f7d4f);
}
.cand-photo.initials { font-size: 72px; }
.cand-name { font-size: 22px; font-weight: 700; color: var(--forest-dark); }
.cand-title { margin-top: 4px; color: var(--muted); font-size: 15px; }
.ballot-actions { display: flex; justify-content: center; }

/* ---------- Dialog ---------- */
.dialog {
  border: 0; border-radius: 20px; padding: 30px 32px; max-width: 420px; width: calc(100% - 40px);
  text-align: center; box-shadow: 0 30px 80px rgba(0, 0, 0, .3);
}
.dialog::backdrop { background: rgba(10, 25, 15, .55); backdrop-filter: blur(3px); }
.dialog h3 { margin: 0 0 16px; font-size: 22px; }
.dialog p { margin: 4px 0; }
.confirm-photo { display: flex; justify-content: center; margin-bottom: 12px; }
.confirm-photo .cand-photo { width: 120px; height: 140px; }
.confirm-photo .cand-photo.initials { font-size: 42px; }
.confirm-name { font-size: 22px; font-weight: 700; color: var(--forest-dark); }
.dialog-actions { display: flex; gap: 12px; justify-content: center; margin-top: 22px; flex-wrap: wrap; }

.big-icon { width: 84px; height: 84px; margin: 0 auto 10px; }
.big-icon svg { width: 100%; height: 100%; }
.big-icon.success { color: #2f8f46; }
.big-icon.muted { color: var(--muted); }
.done h2 { color: var(--forest-dark); }

.foot { text-align: center; color: var(--muted); font-size: 13px; padding: 16px; }

/* ---------- Admin ---------- */
body.admin { background: #f1efe9; }
.admin-nav { display: flex; gap: 6px; flex-wrap: wrap; }
.admin-nav a {
  color: #fff; text-decoration: none; padding: 8px 14px; border-radius: 10px; font-size: 14px; font-weight: 500; opacity: .85;
}
.admin-nav a:hover { background: rgba(255, 255, 255, .1); opacity: 1; }
.admin-nav a.active { background: rgba(255, 255, 255, .18); opacity: 1; }
.admin-main { flex: 1; width: 100%; max-width: 1100px; margin: 0 auto; padding: 28px 20px 48px; }
.admin-main h1 { margin: 0 0 20px; font-size: 26px; }
.panel { background: #fff; border-radius: 16px; box-shadow: var(--shadow); padding: 22px 24px; margin-bottom: 22px; }
.panel h2 { margin: 0 0 14px; font-size: 18px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.panel-head h2 { margin: 0; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 16px; margin-bottom: 22px; }
.stat { background: #fff; border-radius: 16px; box-shadow: var(--shadow); padding: 18px 20px; }
.stat .label { font-size: 13px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .6px; }
.stat .value { font-size: 32px; font-weight: 700; margin-top: 6px; color: var(--forest-dark); }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 999px; font-weight: 700; font-size: 13px; }
.pill.open { background: #e2f3dc; color: #24661c; }
.pill.closed { background: #f6e3e3; color: #8a2424; }
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }

.result-row { display: grid; grid-template-columns: 56px 1fr; gap: 14px; align-items: center; padding: 12px 0; border-top: 1px solid var(--line); }
.result-row:first-child { border-top: 0; }
.thumb { width: 56px; height: 56px; border-radius: 12px; object-fit: cover; object-position: center top; }
.thumb.initials { font-size: 20px; }
.result-top { display: flex; justify-content: space-between; gap: 10px; font-weight: 600; }
.bar { height: 14px; background: #eee9dd; border-radius: 999px; overflow: hidden; margin-top: 8px; }
.bar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--forest), #4f9a5f); border-radius: 999px; }
.results-wrap { position: relative; }
.results-wrap.hidden .results-body { filter: blur(9px); user-select: none; pointer-events: none; }
.results-cover {
  display: none; position: absolute; inset: 0; align-items: center; justify-content: center;
}
.results-wrap.hidden .results-cover { display: flex; }

table.tbl { width: 100%; border-collapse: collapse; font-size: 15px; }
.tbl th, .tbl td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); }
.tbl th { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }

.form-row { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field label { font-size: 13px; font-weight: 600; color: var(--muted); }
.field input[type=text], .field input[type=number], .field input[type=password] {
  font: inherit; padding: 10px 12px; border: 1.5px solid var(--line); border-radius: 10px; min-width: 220px;
}
.field input:focus { outline: none; border-color: var(--forest); }
.cand-edit { display: grid; grid-template-columns: 160px 1fr; gap: 22px; align-items: start; }
.cand-edit .photo { width: 160px; height: 190px; border-radius: 14px; object-fit: cover; object-position: center top; }
.cand-edit .photo.initials { font-size: 52px; }
.danger-zone { border: 1.5px dashed #e3b9b9; }
.login-box { max-width: 380px; margin: 60px auto; }

/* ---------- Voter login ---------- */
.login-form { margin-top: 6px; }
.login-form .field label { font-size: 14px; color: var(--ink); }
.big-input, .dob select {
  font: inherit; font-size: 18px; padding: 13px 14px; border: 2px solid var(--line); border-radius: 12px;
  background: #fff; color: var(--ink); width: 100%; outline: none;
}
.big-input:focus, .dob select:focus { border-color: var(--forest); box-shadow: 0 0 0 4px rgba(31, 81, 53, .15); }
.dob { display: grid; grid-template-columns: 1fr 1.6fr 1.2fr; gap: 8px; }
.btn.full { width: 100%; margin-top: 8px; }
.cand-text { display: flex; flex-direction: column; }

/* ---------- Admin: voters ---------- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.badge.yes { background: #e2f3dc; color: #24661c; }
.badge.no { background: #efebe2; color: var(--muted); }
.badge.lock { background: #f6e3e3; color: #8a2424; }
.field select { font: inherit; padding: 10px 12px; border: 1.5px solid var(--line); border-radius: 10px; background: #fff; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
.share-link {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
}
.share-link input {
  flex: 1; min-width: 240px; font: inherit; font-family: Consolas, monospace; padding: 10px 12px;
  border: 1.5px solid var(--line); border-radius: 10px; background: #faf8f3;
}
.tbl-wrap { max-height: 560px; overflow: auto; }

@media (max-width: 640px) {
  .topbar { padding: 12px 16px; }
  .brand-org { font-size: 13px; }
  .secret-badge { display: none; }
  .stage { padding: 20px 14px 32px; }
  .election-title { margin-bottom: 18px; }
  .card { padding: 26px 18px; }
  .card h2, .ballot h2 { font-size: 22px; }
  .lead { font-size: 15px; }
  /* Ballot cards side-by-side layout on phones: photo left, name right, so both fit on screen */
  .ballot-grid { grid-template-columns: 1fr; gap: 14px; margin: 18px 0 22px; }
  .candidate { flex-direction: row; text-align: left; padding: 14px 56px 14px 14px; gap: 14px; }
  .candidate:hover { transform: none; }
  .cand-photo-wrap { margin: 0; flex: none; }
  .cand-photo { width: 92px; height: 110px; border-radius: 12px; }
  .cand-photo.initials { font-size: 34px; }
  .cand-num { top: auto; bottom: 10px; left: 10px; width: 28px; height: 28px; font-size: 14px; box-shadow: 0 0 0 2px #fff; }
  .cand-check { top: 50%; transform: translateY(-50%); right: 12px; width: 36px; height: 36px; }
  .cand-name { font-size: 18px; }
  .ballot-actions .btn { width: 100%; }
  .cand-edit, .grid-2 { grid-template-columns: 1fr; }
}
