:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --text: #17202b;
  --muted: #5d6b7a;
  --border: #dde3ea;
  --primary: #0b4f8a;
  --primary-text: #ffffff;
  --ok-bg: #e3f5ea; --ok: #17663a;
  --bad-bg: #fde8e8; --bad: #a3231f;
  --warn-bg: #fff4dc; --warn: #8a5a00;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11161d; --surface: #1a212b; --text: #e6ebf1; --muted: #9aa7b5; --border: #2c3643;
    --primary: #4b9be0; --primary-text: #0b1520;
    --ok-bg: #173826; --ok: #7fd9a2; --bad-bg: #44191b; --bad: #ff9c97; --warn-bg: #3f3214; --warn: #f4c96b;
    --shadow: none; color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--primary); }
h1 { font-size: 1.45rem; margin: .2em 0 .4em; }
h2 { font-size: 1.1rem; margin: 0 0 .8em; }
code { font-family: ui-monospace, Consolas, monospace; font-size: .92em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
[hidden] { display: none !important; }

/* barra superiore */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 1rem;
  background: var(--primary); color: var(--primary-text); padding: .6rem 1rem;
  padding-top: calc(.6rem + env(safe-area-inset-top));
}
.brand { display: flex; align-items: center; gap: .5rem; color: inherit; text-decoration: none; font-weight: 700; font-size: 1.1rem; }
.menu { display: flex; align-items: center; gap: .3rem; margin-left: auto; }
.menu a, .menu .linklike { white-space: nowrap; color: inherit; text-decoration: none; padding: .45rem .7rem; border-radius: 8px; opacity: .9; }
.menu a.active, .menu a:hover, .menu .linklike:hover { background: rgba(255,255,255,.15); opacity: 1; }
.menu form { margin: 0; }
.menu-btn { display: none; margin-left: auto; background: none; border: 0; color: inherit; font-size: 1.5rem; padding: .2rem .5rem; cursor: pointer; }
.linklike { background: none; border: 0; font: inherit; cursor: pointer; color: var(--primary); padding: 0; }

.container { max-width: 1200px; margin: 0 auto; padding: 1rem; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem; margin-bottom: 1rem; box-shadow: var(--shadow); }
.card.narrow { max-width: 480px; margin: 1rem auto; }
.ok-card { border-color: var(--ok); background: var(--ok-bg); color: var(--ok); }
.grid-2 { display: grid; gap: 1rem; grid-template-columns: 1fr 1fr; align-items: start; }
.grid-2 > .card { margin: 0; }
.danger-zone { margin-top: 1rem; border-color: var(--bad-bg); }

/* form */
label { display: block; margin-bottom: .85rem; font-weight: 600; font-size: .92rem; }
input:not([type=checkbox]):not([type=file]):not([type=radio]), textarea, select {
  display: block; width: 100%; margin-top: .3rem; padding: .7rem .8rem; font: inherit; font-weight: 400;
  font-size: 16px; /* evita lo zoom automatico su iOS */
  color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
}
input:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: transparent; }
.field-error { display: block; color: var(--bad); font-weight: 400; font-size: .85rem; margin-top: .25rem; }
.errorlist { color: var(--bad); padding-left: 1.1rem; margin: 0 0 .8rem; }
.otp-input { text-align: center; letter-spacing: .4em; font-size: 1.6rem !important; font-variant-numeric: tabular-nums; }
.check { display: flex; align-items: center; gap: .4rem; font-weight: 400; margin: 0; }
.form-actions { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: .5rem; }
.form-actions form { margin: 0; }
.inline-form { display: flex; gap: .7rem; align-items: center; flex-wrap: wrap; }
.inline-form input { flex: 1 1 200px; margin: 0 !important; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .65rem 1.1rem; min-height: 44px; font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
}
.btn:hover { border-color: var(--primary); }
.btn-primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-danger { color: var(--bad); border-color: var(--bad); }
.btn-warn { background: var(--warn-bg); color: var(--warn); border-color: var(--warn); }
.banner-manutenzione { background: var(--warn-bg); color: var(--warn); text-align: center; padding: .55rem 1rem; font-weight: 600; border-bottom: 1px solid var(--warn); }
.banner-manutenzione a { color: inherit; margin-left: .5rem; }
.card.narrow-left { max-width: 640px; }
.grid-2.compatta { gap: 0 1rem; margin-top: .8rem; }
.check input { width: 1.2rem; height: 1.2rem; }
form.form-actions { align-items: center; margin-top: .8rem; }
.stato-manutenzione { border-radius: 8px; padding: .8rem 1rem; margin: 1rem 0; }
.stato-manutenzione.on { background: var(--warn-bg); color: var(--warn); }
.stato-manutenzione.off { background: var(--ok-bg); color: var(--ok); }
.btn-block { width: 100%; }
.btn-big { min-height: 64px; font-size: 1.05rem; flex: 1 1 240px; }
.btn-small { min-height: 34px; padding: .3rem .65rem; font-size: .85rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.alert { padding: .8rem 1rem; border-radius: 8px; margin-bottom: 1rem; background: var(--surface); border: 1px solid var(--border); }
.alert-success { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.alert-error { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.alert-warning { background: var(--warn-bg); color: var(--warn); border-color: transparent; }

.badge { display: inline-block; padding: .15rem .55rem; margin: .1rem .2rem .1rem 0; border-radius: 99px; font-size: .78rem; font-weight: 600; background: var(--bg); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.badge-ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.badge-bad { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.badge-warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.badges { margin-bottom: .8rem; }

/* ricerca + filtri */
.search { display: flex; gap: .5rem; margin-bottom: .8rem; }
.search input { margin: 0 !important; flex: 1; }
.filtri-form { flex-wrap: wrap; align-items: flex-end; }
.filtri-form input[type=search] { flex: 1 1 240px; }
.filtri-form .mese { margin: 0; font-size: .8rem; font-weight: 600; color: var(--muted); }
.filtri-form .mese input { margin-top: .2rem; }
.azioni-elenco { display: flex; flex-wrap: wrap; gap: .4rem; margin: 0 0 .8rem; }
.chips { display: flex; gap: .4rem; overflow-x: auto; padding-bottom: .3rem; margin-bottom: .8rem; scrollbar-width: none; }
.chip { flex: none; padding: .4rem .8rem; border-radius: 99px; border: 1px solid var(--border); background: var(--surface); color: var(--text); text-decoration: none; font-size: .9rem; }
.chip .count { color: var(--muted); margin-left: .2rem; font-variant-numeric: tabular-nums; }
.chip.active { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.chip.active .count { color: inherit; opacity: .8; }

/* tabella che diventa schede su smartphone */
table.list { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); margin-bottom: 1rem; }
.list th { text-align: left; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); padding: .7rem .8rem; border-bottom: 1px solid var(--border); }
.list td { padding: .7rem .8rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.list tbody tr:last-child td { border-bottom: 0; }
.list tr[data-href] { cursor: pointer; }
.list tr[data-href]:hover td { background: var(--bg); }
.cell-main a { font-weight: 600; text-decoration: none; color: var(--text); }
.actions { display: flex; flex-wrap: wrap; gap: .3rem; }
.actions form { margin: 0; }

.facts { display: grid; grid-template-columns: max-content 1fr; gap: .45rem 1rem; margin: 0 0 1rem; }
.facts dt { color: var(--muted); font-size: .9rem; }
.facts dd { margin: 0; font-weight: 600; word-break: break-word; }

/* login */
body.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(160deg, var(--primary) 0%, var(--bg) 55%); }
body.auth .container { width: 100%; max-width: 440px; }
.auth-card { background: var(--surface); border-radius: 14px; padding: 1.6rem; box-shadow: 0 10px 30px rgba(0,0,0,.15); }
.auth-card.wide { max-width: 520px; }
.auth-card h1 { margin-top: 0; }
.auth-logo { text-align: center; }
.auth-card .auth-logo + h1, .auth-card .auth-logo ~ p { text-align: center; }
.steps { padding-left: 1.2rem; }
.steps li { margin-bottom: .4rem; }
.qr-box { background: #fff; border-radius: 10px; padding: .6rem; width: 220px; margin: .8rem auto; }
.qr-box svg { width: 100%; height: auto; display: block; }
.secret { display: block; margin: .5rem 0 1rem; padding: .6rem; background: var(--bg); border-radius: 6px; font-size: 1.05rem; letter-spacing: .08em; word-break: break-all; user-select: all; }
details summary { cursor: pointer; color: var(--primary); margin: .5rem 0; }

/* scansione QR */
.scan-actions { display: flex; gap: .7rem; flex-wrap: wrap; margin: 1rem 0; }
#reader { width: 100%; max-width: 520px; margin: 0 auto .7rem; border-radius: 10px; overflow: hidden; background: #000; }
#reader video { width: 100% !important; display: block; }
.manual { margin-top: .5rem; }
.manual .search { margin-top: .6rem; }

/* pulsante flottante per aggiungere da smartphone */
.fab { display: none; }

/* check list online */
.scelte { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: .8rem; }
.scelta { display: flex; align-items: center; gap: .4rem; font-weight: 600; margin: 0; padding: .55rem .8rem; border: 1px solid var(--border); border-radius: 8px; cursor: pointer; }
.scelta:has(input:checked) { border-color: var(--primary); background: var(--bg); }
.coppia { display: flex; gap: .4rem; }
.prove-online { display: flex; flex-direction: column; gap: .5rem; }
.gruppo-online { background: var(--bg); padding: .6rem .8rem; border-radius: 6px; margin-top: .4rem; }
.prova-online { border: 1px solid var(--border); border-radius: 8px; padding: .7rem .8rem; display: grid; grid-template-columns: 1fr auto; gap: .5rem 1rem; align-items: center; }
.prova-online .grid-2 { grid-column: 1 / -1; order: 2; }
.prova-online.manca { border-color: var(--bad); box-shadow: 0 0 0 2px var(--bad-bg); }
.testo-prova { font-size: .92rem; }
.si-no { display: flex; gap: .4rem; }
.si-no input, .scelta input { width: 1.2rem; height: 1.2rem; margin: 0; }
.si-no label { display: flex; align-items: center; justify-content: center; gap: .3rem; margin: 0; min-width: 64px; min-height: 44px; border: 1px solid var(--border); border-radius: 8px; cursor: pointer; }
.si-no .si:has(input:checked) { background: var(--ok-bg); color: var(--ok); border-color: var(--ok); }
.si-no .no:has(input:checked) { background: var(--bad-bg); color: var(--bad); border-color: var(--bad); }
.firme { margin-top: .8rem; }
.firma { display: flex; flex-direction: column; gap: .4rem; }
.firma canvas { width: 100%; height: auto; aspect-ratio: 3 / 1; background: #fff; border: 1px dashed var(--muted); border-radius: 8px; touch-action: none; }
.etichetta-firma { font-weight: 600; font-size: .9rem; }
.firma .btn { align-self: flex-start; }
.barra-salva { position: sticky; bottom: 0; display: flex; gap: .6rem; justify-content: flex-end; padding: .8rem 0; background: var(--bg); z-index: 5; }
.candidato { justify-content: flex-start; text-align: left; margin-top: .4rem; font-weight: 400; }
.storico td { vertical-align: middle; }
.sottotitolo { font-size: 1rem; margin: 1.2rem 0 .6rem; }
.calendari summary { cursor: pointer; }
.banner-app { display: flex; align-items: center; gap: .7rem; padding: .7rem 1rem; padding-top: calc(.7rem + env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--border); box-shadow: var(--shadow); width: 100%; }
.banner-app img { border-radius: 9px; flex: none; }
.banner-app .icona-banner { font-size: 1.6rem; }
.testo-banner { display: flex; flex-direction: column; flex: 1; line-height: 1.3; }
.chiudi-banner { color: var(--muted); font-size: 1.1rem; padding: .3rem; }
body.auth .banner-app { position: fixed; top: 0; left: 0; z-index: 40; }
.separatore { display: flex; align-items: center; gap: .6rem; color: var(--muted); font-size: .85rem; margin: 1rem 0; }
.separatore::before, .separatore::after { content: ""; flex: 1; border-top: 1px solid var(--border); }
.piede a { color: inherit; }
.novita { max-width: 900px; }
.novita section { scroll-margin-top: 70px; }
.titolo-versione { font-weight: 600; margin: -.4rem 0 .6rem; }
.elenco-novita { padding-left: 1.1rem; margin: 0; }
.elenco-novita li { margin-bottom: .45rem; }
.elenco-novita .badge { min-width: 6.5rem; text-align: center; margin-right: .3rem; }
.list.compatta td { padding: .3rem .6rem; font-size: .85rem; }
.interventi { display: flex; flex-direction: column; gap: .2rem; }
.intervento { margin-bottom: .6rem; }
.intervento-testa { display: flex; flex-wrap: wrap; gap: .4rem .6rem; align-items: center; margin-bottom: .6rem; }
.intervento .facts { margin-bottom: .5rem; }
.note-intervento { white-space: pre-line; font-size: .92rem; margin: .3rem 0 .6rem; }
.miniature { display: flex; flex-wrap: wrap; gap: .6rem; }
.miniature a { display: block; border: 1px solid var(--border); border-radius: 6px; padding: .3rem; text-decoration: none; font-size: .8rem; max-width: 160px; word-break: break-all; }
.miniature img { display: block; max-width: 150px; max-height: 150px; }
@media (max-width: 760px) {
  .prova-online { grid-template-columns: 1fr; }
  .si-no label { flex: 1; }
  .barra-salva { justify-content: stretch; }
  .barra-salva .btn { flex: 1; }
}
pre.codice { background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: .7rem; font-size: .8rem; white-space: pre-wrap; word-break: break-all; }
.check { margin-bottom: .5rem; align-items: flex-start; }
fieldset.senza-bordo { border: 0; padding: 0; margin: 0; min-width: 0; }
.piede { text-align: right; color: var(--muted); font-size: .8rem; padding: .8rem 1rem 1.2rem; max-width: 1200px; margin: 0 auto; }
body.auth { flex-direction: column; }
body.auth .piede { position: fixed; right: 0; bottom: 0; padding: .6rem 1rem; }
.guida { max-width: 860px; }
.guida .indice ol { margin: .5rem 0 0; padding-left: 1.3rem; columns: 2; }
.guida section { scroll-margin-top: 70px; }
.guida li { margin-bottom: .35rem; }
.guida .nota { background: var(--bg); border-left: 3px solid var(--primary); padding: .6rem .8rem; border-radius: 4px; font-size: .92rem; }
.faq dt { font-weight: 700; margin-top: .8rem; }
.faq dd { margin: .2rem 0 0; color: var(--muted); }
kbd { border: 1px solid var(--border); border-radius: 4px; padding: 0 .3rem; font-size: .85em; }
@media (max-width: 760px) { .guida .indice ol { columns: 1; } }
.log { font-size: .85rem; max-height: 360px; overflow: auto; }
.log div { padding: .3rem 0; border-bottom: 1px solid var(--border); }

@media (max-width: 760px) {
  .container { padding: .8rem; }
  .hide-mobile { display: none; }
  .grid-2 { grid-template-columns: 1fr; }
  .menu-btn { display: block; }
  .menu { display: none; position: absolute; top: 100%; left: 0; right: 0; flex-direction: column; align-items: stretch; background: var(--primary); padding: .5rem; }
  .menu.open { display: flex; }
  .menu a, .menu .linklike { padding: .8rem; width: 100%; text-align: left; }

  table.list, .list tbody, .list tr, .list td { display: block; width: 100%; }
  .list thead { display: none; }
  table.list { background: none; border: 0; box-shadow: none; }
  .list tr { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: .6rem; padding: .7rem .9rem; box-shadow: var(--shadow); }
  .list td { border: 0; padding: .15rem 0; display: flex; gap: .6rem; }
  .list td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: .85rem; min-width: 7.5rem; flex: none; }
  .list td[data-label="Stato"] { flex-wrap: wrap; align-items: flex-start; }
  .list .badge { white-space: normal; }
  .list td.cell-main { display: block; font-size: 1.05rem; padding-bottom: .35rem; }
  .list td.actions { flex-wrap: wrap; }
  .list td.actions::before { width: 100%; }

  .fab {
    display: flex; align-items: center; justify-content: center; position: fixed; z-index: 20;
    right: 1rem; bottom: calc(1rem + env(safe-area-inset-bottom)); width: 60px; height: 60px; border-radius: 50%;
    background: var(--primary); color: var(--primary-text); box-shadow: 0 6px 18px rgba(0,0,0,.3);
  }
  body { padding-bottom: 90px; }
  body.auth { padding-bottom: 0; }
  .form-actions .btn, .form-actions form { flex: 1 1 auto; }
  .form-actions form .btn { width: 100%; }
}
