:root {
  --az: #2ea7e0;
  --az-d: #1583bb;
  --navy: #0d2b45;
  --bg: #f3f8fc;
  --card: #fff;
  --ink: #16202c;
  --muted: #607083;
  --line: #dbe6ef;
  --ok: #1d8a4e;
  --warn: #b86a00;
  --err: #c0392b;
  --r: 14px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg); }
a { color: var(--az-d); }
img { max-width: 100%; }
.wrap { max-width: 1040px; margin: 0 auto; padding: 0 16px; }
h1 { font-size: 1.7rem; line-height: 1.2; margin: .2em 0 .5em; color: var(--navy); }
h2 { font-size: 1.25rem; margin: 0 0 .4em; color: var(--navy); }
h3 { margin: 0 0 .3em; font-size: 1.08rem; }
.muted { color: var(--muted); }
.center { text-align: center; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.inline { display: inline; }

/* Header */
.top { background: linear-gradient(135deg, var(--az), var(--az-d)); color: #fff; box-shadow: 0 2px 10px rgba(13,43,69,.15); }
.top-in { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding-top: 10px; padding-bottom: 10px; }
.brand { display: flex; align-items: center; gap: 12px; color: #fff; text-decoration: none; font-weight: 700; font-size: 1.1rem; }
.brand img { width: 52px; height: 52px; border-radius: 50%; background: #fff; box-shadow: 0 0 0 2px rgba(255,255,255,.6); object-fit: contain; }
.brand small { display: block; font-weight: 400; font-size: .8rem; opacity: .9; }
.adm-nav { display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: center; font-size: .92rem; }
.adm-nav a, .adm-nav .linkbtn { color: #fff; text-decoration: none; opacity: .92; }
.adm-nav a:hover { opacity: 1; text-decoration: underline; }

main { padding-top: 24px; padding-bottom: 32px; }
.foot { color: var(--muted); font-size: .82rem; padding-bottom: 32px; text-align: center; }

/* Blocks */
.hero, .panel, .privacy-box { background: var(--card); border-radius: var(--r); padding: 22px; margin-bottom: 20px; box-shadow: 0 1px 3px rgba(13,43,69,.08); }
.hero { border-top: 5px solid var(--az); }
.hero-cta { margin-top: 14px; }
.narrow { max-width: 560px; margin-left: auto; margin-right: auto; }
.privacy-box { background: #e8f5fc; border: 1px solid #bfe3f5; box-shadow: none; }
.privacy-box ul { margin: 0; padding-left: 1.2em; }
.privacy-box li { margin: .35em 0; }
.info { background: #e8f5fc; border-left: 4px solid var(--az); padding: 12px 14px; border-radius: 8px; margin-bottom: 18px; font-size: .95rem; }
.position { margin: 30px 0; }

.badge { display: inline-block; padding: 3px 12px; border-radius: 99px; font-size: .8rem; font-weight: 600; background: #e3e9ef; color: var(--muted); }
.badge.st-aperta { background: #dcf3e6; color: var(--ok); }
.badge.st-chiusa { background: #fbe3e0; color: var(--err); }
.badge.st-attesa { background: #fff1d6; color: var(--warn); }

/* Candidate cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.card { background: var(--card); border-radius: var(--r); overflow: hidden; box-shadow: 0 1px 3px rgba(13,43,69,.1); display: flex; flex-direction: column; }
.card .photo { width: 100%; aspect-ratio: 1; object-fit: cover; background: #dbeef8; display: block; }
.card-body { padding: 14px 16px 18px; }
.bio { font-size: .93rem; color: #34414f; }

/* Buttons */
.btn { display: inline-block; border: 0; border-radius: 10px; background: var(--az-d); color: #fff; padding: 10px 18px; font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; }
.btn:hover { background: #0f6c9c; }
.btn.big { padding: 14px 28px; font-size: 1.08rem; }
.btn.block { display: block; width: 100%; text-align: center; }
.btn.small { padding: 6px 12px; font-size: .88rem; }
.btn.ghost { background: transparent; color: var(--az-d); box-shadow: inset 0 0 0 2px var(--az-d); }
.btn.ghost:hover { background: #e8f5fc; }
.btn.danger { background: var(--err); }
.linkbtn { background: none; border: 0; padding: 0; font: inherit; color: var(--az-d); cursor: pointer; text-decoration: underline; }
.linkbtn.danger { color: var(--err); }

/* Forms */
.form label { display: block; margin-bottom: 14px; font-weight: 600; font-size: .93rem; }
input:not([type=checkbox]):not([type=radio]):not([type=file]), select, textarea {
  display: block; width: 100%; margin-top: 5px; padding: 11px 12px; font: inherit; border: 1.5px solid var(--line); border-radius: 9px; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--az); box-shadow: 0 0 0 3px rgba(46,167,224,.2); }
.form .check-row, .check-row { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; }
.check-row input { margin-top: 4px; width: 18px; height: 18px; flex: none; }
.row-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 10px; }
.row-form label { flex: 1 1 150px; font-size: .88rem; font-weight: 600; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.photo-edit { display: flex; gap: 16px; align-items: center; margin-bottom: 14px; }
.photo-edit img { width: 96px; height: 96px; object-fit: cover; border-radius: 12px; }
input.num { width: 80px; display: inline-block; text-align: right; padding: 6px 8px; margin: 0; }
input.filter { margin: 0 0 12px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.field-label { display: block; font-weight: 600; font-size: .93rem; margin-bottom: 6px; }
.photo-field { margin-bottom: 16px; }
.form label.photo-drop, .photo-drop { display: flex; align-items: center; gap: 16px; padding: 14px; margin: 0; border: 2px dashed #bfe3f5; border-radius: 12px; background: #f5fbfe; cursor: pointer; }
.photo-drop:hover, .photo-drop:focus-within { border-color: var(--az); background: #e8f5fc; }
.photo-drop img { width: 120px; height: 120px; object-fit: cover; border-radius: 12px; flex: none; background: #dbeef8; }
.photo-drop-txt { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; font-weight: 400; font-size: .88rem; }
.photo-field .check-row { margin: 10px 0 0; }
p.small { font-size: .84rem; margin: 8px 0 0; }
code { background: #eef3f7; padding: 1px 5px; border-radius: 4px; }

/* Voting */
.steps { list-style: none; display: flex; gap: 8px; padding: 0; margin: 0 0 18px; font-size: .85rem; flex-wrap: wrap; }
.steps li { padding: 6px 12px; border-radius: 99px; background: #e3e9ef; color: var(--muted); }
.steps li.on { background: var(--az-d); color: #fff; font-weight: 600; }
.steps li.past { background: #cfe9f6; color: var(--az-d); }
.who { font-size: .9rem; color: var(--muted); margin-bottom: 8px; }
.ballot-group { border: 1.5px solid var(--line); border-radius: var(--r); padding: 14px; margin: 0 0 20px; }
.ballot-group legend { font-weight: 700; padding: 0 6px; color: var(--navy); font-size: 1.1rem; }
.choice { display: flex; align-items: center; gap: 12px; padding: 10px; border-radius: 10px; border: 1.5px solid transparent; cursor: pointer; margin-bottom: 6px; background: #f7fafc; }
.choice:hover { border-color: #bfe3f5; }
.choice:has(input:checked) { border-color: var(--az); background: #e8f5fc; }
.choice input { width: 22px; height: 22px; flex: none; accent-color: var(--az-d); }
.choice img { width: 52px; height: 52px; border-radius: 50%; object-fit: cover; flex: none; }
.choice span { font-weight: 600; }
.choice.blank span { font-weight: 400; color: var(--muted); }
.choice:has(input:disabled) { opacity: .5; cursor: not-allowed; }
.summary { margin: 16px 0; }
.sum-row { border-bottom: 1px solid var(--line); padding: 10px 0; }
.sum-row p { margin: 4px 0; }
.sum-cand { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.sum-cand img { width: 38px; height: 38px; border-radius: 50%; object-fit: cover; }
.actions { display: flex; gap: 10px; justify-content: space-between; flex-wrap: wrap; }
.done .check { width: 72px; height: 72px; margin: 0 auto 10px; border-radius: 50%; background: var(--ok); color: #fff; font-size: 40px; line-height: 72px; }

/* Alerts */
.alert { padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; }
.alert.ok { background: #dcf3e6; color: #125c33; }
.alert.err { background: #fbe3e0; color: #8a2419; }
.alert.warn { background: #fff1d6; color: #7a4800; }

/* Admin */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--card); border-radius: var(--r); padding: 14px 16px; box-shadow: 0 1px 3px rgba(13,43,69,.08); text-decoration: none; color: inherit; border: 2px solid transparent; }
.stat.sel { border-color: var(--az); }
.stat span { display: block; color: var(--muted); font-size: .84rem; }
.stat strong { font-size: 1.6rem; color: var(--navy); }
.state-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.tbl { width: 100%; border-collapse: collapse; font-size: .93rem; }
.tbl th { text-align: left; color: var(--muted); font-weight: 600; font-size: .82rem; border-bottom: 2px solid var(--line); padding: 8px 6px; }
.tbl td { border-bottom: 1px solid var(--line); padding: 8px 6px; vertical-align: middle; }
.tbl .thumb img { width: 48px; height: 48px; border-radius: 50%; object-fit: cover; display: block; }
.tbl tr.elected td { background: #e8f5fc; }
.tag { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: .75rem; font-weight: 700; background: #dcf3e6; color: var(--ok); vertical-align: middle; }
.tag.warn, .tag.st-astenuto { background: #fff1d6; color: var(--warn); }
.tag.st-assente { background: #fbe3e0; color: var(--err); }
.tag.st-sala { background: #d9ecf7; color: var(--az-d); }
.todo li { margin: 6px 0; }
.todo li.ok::marker { content: "✓  "; color: var(--ok); }
.danger-zone { border: 1.5px solid #f2c4bd; }

/* Public results */
.results { background: var(--card); border-radius: var(--r); padding: 12px 18px; box-shadow: 0 1px 3px rgba(13,43,69,.08); }
.res-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.res-row img { width: 48px; height: 48px; border-radius: 50%; object-fit: cover; }
.res-main { flex: 1; }
.res-name { font-weight: 600; }
.bar { height: 8px; background: #e3eef6; border-radius: 99px; overflow: hidden; margin-top: 6px; }
.bar span { display: block; height: 100%; background: var(--az); }
.res-row.elected .bar span { background: var(--az-d); }
.res-n { font-size: 1.4rem; font-weight: 700; color: var(--navy); min-width: 40px; text-align: right; }

details.panel summary { cursor: pointer; }
.tbl td[data-l]::before { display: none; }

@media (max-width: 640px) {
  body { font-size: 16px; }
  h1 { font-size: 1.4rem; }
  main { padding-top: 16px; }
  .hero, .panel, .privacy-box { padding: 16px; border-radius: 12px; margin-bottom: 14px; }
  .grid2 { grid-template-columns: 1fr; }
  .brand { font-size: 1rem; }
  .brand img { width: 44px; height: 44px; }
  .actions { flex-direction: column-reverse; }
  .actions .btn { width: 100%; text-align: center; }
  .hero-cta .btn, p.center .btn { display: block; text-align: center; }
  .btn { min-height: 44px; }
  .btn.small { min-height: 36px; }

  /* Menu admin: barra scorrevole orizzontale */
  .top-in { flex-direction: column; flex-wrap: nowrap; align-items: stretch; gap: 8px; }
  .adm-nav { min-width: 0; flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; gap: 6px; margin: 0 -16px; padding: 0 16px 4px; scrollbar-width: none; }
  .adm-nav::-webkit-scrollbar { display: none; }
  .adm-nav a, .adm-nav .linkbtn { white-space: nowrap; background: rgba(255,255,255,.18); padding: 7px 12px; border-radius: 99px; text-decoration: none; font-size: .88rem; }
  .adm-nav form { flex: none; }

  /* Candidati: schede a 2 colonne con foto più compatte */
  .cards { grid-template-columns: 1fr; gap: 12px; }
  .card { flex-direction: row; }
  .card .photo { width: 110px; min-width: 110px; aspect-ratio: auto; height: auto; min-height: 130px; }
  .card-body { padding: 12px 14px; }
  .bio { font-size: .9rem; }

  .ballot-group { padding: 10px; }
  .choice { padding: 10px 8px; }
  .steps { gap: 4px; font-size: .78rem; }
  .steps li { padding: 5px 9px; }

  .stats { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat { padding: 10px 12px; }
  .stat strong { font-size: 1.35rem; }
  .state-btns .btn { flex: 1 1 100%; }
  .row-form label { flex-basis: 100%; }
  .row-form .btn { width: 100%; }
  .photo-edit img { width: 72px; height: 72px; }

  /* Tabelle impilate come schede */
  .tbl { font-size: .9rem; }
  .tbl.stack, .tbl.stack tbody, .tbl.stack tr, .tbl.stack td { display: block; width: 100%; }
  .tbl.stack tr:first-child { display: none; }
  .tbl.stack tr { border-bottom: 1px solid var(--line); padding: 10px 0; }
  .tbl.stack tr[hidden] { display: none; }
  .tbl.stack td { border: 0; padding: 2px 0; text-align: left; }
  .tbl.stack td[data-l]::before { display: inline; content: attr(data-l) ": "; color: var(--muted); font-size: .82rem; }
  .tbl.cands td { display: block; border: 0; padding: 2px 0; }
  .tbl.cands tr { display: grid; grid-template-columns: 56px 1fr; gap: 0 10px; border-bottom: 1px solid var(--line); padding: 10px 0; }
  .tbl.cands td.right { grid-column: 2; text-align: left; padding-top: 6px; }
  .results-tbl th, .results-tbl td { padding: 6px 3px; }
  .results-tbl th { font-size: .72rem; }
  input.num { width: 58px; }
  .res-row img { width: 40px; height: 40px; }
}
@media print {
  .top, .foot, .noprint, .btn, .linkbtn { display: none !important; }
  body { background: #fff; }
  .panel { box-shadow: none; border: 1px solid #ccc; }
}
