:root {
  --teal: #006b84; --teal-dark: #00566a; --green: #a6c953;
  --ok: #1a9a48; --err: #d32f2f; --warn: #ef9a00;
  --bg: #f3f6f7; --card: #fff; --text: #1d2a2e; --muted: #6b7b80; --line: #dce5e8;
}
* { box-sizing: border-box; }
/* L'attributo hidden deve vincere sui display impostati dalle classi (es. .result, .btn) */
[hidden] { display: none !important; }
body { margin: 0; font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--teal); }
h1 { font-size: 1.5rem; margin: .2em 0 .6em; color: var(--teal); }
h2 { font-size: 1.15rem; margin: 1.2em 0 .5em; }
.card h2 { margin-top: 0; }
code, .mono { font-family: ui-monospace, Consolas, "Courier New", monospace; }
.muted { color: var(--muted); }

.top { background: var(--teal); color: #fff; padding: .6rem 1rem; display: flex; flex-wrap: wrap; gap: .5rem 1.5rem; align-items: center; border-bottom: 4px solid var(--green); }
.top nav { display: flex; flex-wrap: wrap; gap: .25rem; }
.top nav a { color: #fff; text-decoration: none; padding: .3rem .6rem; border-radius: 6px; }
.top nav a.active, .top nav a:hover { background: rgba(255,255,255,.18); }
.top nav a.logout { opacity: .8; }
main { max-width: 1100px; margin: 0 auto; padding: 1rem; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 1rem 1.2rem; margin: 0 0 1rem; }
.card.narrow { max-width: 380px; margin: 3rem auto; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1rem; }
label { display: block; margin: 0 0 .8rem; font-weight: 600; font-size: .9rem; }
input, select { display: block; width: 100%; margin-top: .25rem; padding: .55rem .6rem; font: inherit; border: 1px solid #b9c7cb; border-radius: 6px; background: #fff; }
form.inline, .filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
form.inline input, .filters input, .filters select { width: auto; flex: 1 1 180px; margin: 0; }
.actions form { display: flex; flex-wrap: wrap; gap: .3rem; }

.btn { display: inline-block; padding: .5rem .9rem; font: inherit; font-weight: 600; border: 1px solid #b9c7cb; border-radius: 6px; background: #fff; color: var(--text); cursor: pointer; text-decoration: none; }
.btn:hover { border-color: var(--teal); }
.btn.primary { background: var(--teal); border-color: var(--teal); color: #fff; }
.btn.primary:hover { background: var(--teal-dark); }
.btn.danger { color: var(--err); border-color: #e7b3b3; }
.btn.small { padding: .25rem .55rem; font-size: .85rem; }
.btn.big { padding: .8rem 1.4rem; font-size: 1.05rem; }
.btn:disabled { opacity: .5; cursor: default; }

.flash { padding: .6rem .9rem; border-radius: 6px; margin: 0 0 1rem; background: #e5f4ea; border: 1px solid #b7dfc3; white-space: pre-line; overflow-wrap: anywhere; }
.flash.error { background: #fdeaea; border-color: #f1b9b9; }
.flash.warn { background: #fff4df; border-color: #f3d193; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .7rem; margin-bottom: .8rem; }
.stat { background: #fff; border: 1px solid var(--line); border-left: 5px solid var(--teal); border-radius: 8px; padding: .6rem .8rem; color: var(--muted); font-size: .85rem; }
.stat b { display: block; font-size: 1.8rem; color: var(--text); line-height: 1.1; }
.stat.green { border-left-color: var(--ok); } .stat.red { border-left-color: var(--err); }
.stat.orange { border-left-color: var(--warn); } .stat.grey { border-left-color: #a8b4b8; }

.table-wrap { overflow-x: auto; background: #fff; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 1rem; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: #f7fafb; font-size: .85rem; color: var(--muted); }
.badge { display: inline-block; padding: .1rem .5rem; border-radius: 99px; font-size: .8rem; font-weight: 600; color: #fff; background: #93a1a5; white-space: nowrap; }
.badge.green { background: var(--ok); } .badge.red { background: var(--err); } .badge.orange { background: var(--warn); }
.pager { display: flex; flex-wrap: wrap; gap: .3rem; }
.progress { height: 10px; background: var(--line); border-radius: 99px; overflow: hidden; margin: 1rem 0 .5rem; }
.progress div { height: 100%; width: 0; background: var(--ok); transition: width .3s; }
.log { max-height: 260px; overflow: auto; background: #10272d; color: #d8f1e0; padding: .7rem; border-radius: 6px; font-size: .8rem; white-space: pre-wrap; }

/* ---------------------------------------------------------------- scanner */
body.scanner { background: #0d1f24; color: #fff; min-height: 100vh; }
body.scanner a { color: #9fd9e6; }
.scan-top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .5rem; background: var(--teal); border-bottom: 4px solid var(--green); }
body.mode-out .scan-top { background: #8a4b00; border-bottom-color: var(--warn); }
.modes { display: flex; gap: .3rem; }
.mode { font: 700 1rem system-ui, sans-serif; padding: .6rem .9rem; border-radius: 8px; border: 2px solid rgba(255,255,255,.5); background: transparent; color: #fff; }
.mode.active { background: #fff; color: var(--teal); border-color: #fff; }
body.mode-out .mode.active { color: #8a4b00; }
.counter { font-size: .9rem; text-align: right; }
.counter b { font-size: 1.3rem; }
#reader { width: 100%; max-width: 560px; margin: 0 auto; }
#reader video { border-radius: 0; }
.cam-msg { margin: 1rem; padding: .8rem; background: #5a1d1d; border-radius: 8px; }
#cam-start { display: block; margin: 1rem auto; }
.manual { max-width: 560px; margin: 0 auto; padding: .8rem; }
#manual-form { display: flex; gap: .4rem; }
#manual-form input { margin: 0; font-size: 1rem; }
#results { list-style: none; padding: 0; margin: .6rem 0; }
#results li { display: flex; justify-content: space-between; align-items: center; gap: .5rem; background: #183840; padding: .6rem; border-radius: 8px; margin-bottom: .4rem; }
#results small { color: #b7cdd2; }
.scan-foot { color: #9ab; font-size: .85rem; margin-top: 1.2rem; }

.result { position: fixed; inset: 0; z-index: 20; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 1.5rem; color: #fff; cursor: pointer; }
.result.ok { background: var(--ok); }
.result.error { background: var(--err); }
.result.warn { background: var(--warn); }
.r-mode { font-weight: 700; letter-spacing: .15em; opacity: .85; }
.r-title { font-size: clamp(2rem, 9vw, 3.4rem); font-weight: 800; line-height: 1.1; margin: .3rem 0 .8rem; }
.r-name { font-size: clamp(1.4rem, 6vw, 2.2rem); font-weight: 700; }
.r-msg { font-size: 1.15rem; margin-top: .6rem; max-width: 30em; }
.r-detail { font-size: .9rem; opacity: .85; margin-top: 1rem; }
.r-tap { position: absolute; bottom: 1.5rem; font-size: .85rem; opacity: .75; }

/* ---------------------------------------------------------------- categorie di ingresso */
/* L'arancione e' quello della mappa degli ingressi, non l'ambra degli avvisi: sul
   cartellino, sulla mappa e sul cartello all'arrivo deve essere lo stesso colore. */
:root { --cat-verde: #a6c953; --cat-arancione: #c8472a; }
.badge.cat-verde { background: var(--cat-verde); color: #33421a; }
.badge.cat-arancione { background: var(--cat-arancione); }
.stat.cat-v { border-left-color: var(--cat-verde); }
.stat.cat-a { border-left-color: var(--cat-arancione); }
.stat small { font-size: .8em; }

/* Interruttore "speciale": si usa 1200 volte di fila, deve essere grande e immediato */
.switch { position: relative; display: inline-block; width: 44px; height: 24px; margin: 0; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 2; }
.switch .slider { position: absolute; inset: 0; background: #c3ced1; border-radius: 99px; transition: background .15s; }
.switch .slider::before { content: ''; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform .15s; }
.switch input:checked + .slider { background: var(--cat-arancione); }
.switch input:checked + .slider::before { transform: translateX(20px); }
.switch input:focus-visible + .slider { outline: 2px solid var(--teal); outline-offset: 2px; }
.switch input:disabled + .slider { opacity: .5; }

/* Riga appena salvata: conferma senza spostare niente e senza far aspettare */
tr.saved > td { animation: saved 1.2s ease-out; }
@keyframes saved { from { background: #d8f0dd; } to { background: transparent; } }

/* Intestazioni ordinabili. Sono collegamenti: l'ordinamento lo fa il database su tutte
   le righe che corrispondono al filtro, non sulle sole righe stampate in questa pagina. */
.filters .chk { display: flex; align-items: center; gap: .35rem; margin: 0; font-weight: 600; font-size: .9rem; white-space: nowrap; }
.filters .chk input { width: auto; margin: 0; }
th.sort a { display: block; color: inherit; text-decoration: none; white-space: nowrap; }
th.sort a:hover { color: var(--teal); text-decoration: underline; }
th.sort.active a { color: var(--teal); }

/* ---------------------------------------------------------------- scanner: categoria */
.r-cat { font: 800 1.1rem/1 system-ui, sans-serif; letter-spacing: .12em; padding: .55rem 1.1rem; border-radius: 99px; margin-bottom: .8rem; border: 3px solid rgba(255,255,255,.85); }
.scan-warn { background: #7a1f1f; color: #fff; padding: .6rem .8rem; text-align: center; font-weight: 700; }
.scan-warn a { color: #fff; text-decoration: underline; }

/* ---------------------------------------------------------------- scheda ordine */
.chk { display: inline-flex; align-items: center; gap: .3rem; margin: 0; font-weight: 600; font-size: .85rem; white-space: nowrap; }
.chk input { width: auto; margin: 0; }
.page-head { margin-bottom: .8rem; }
.page-head h1 { margin-bottom: .1em; }
.page-head p { margin: 0; }
.grid2.tight { gap: .6rem; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
.btn-row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }

/* Due colonne con due mestieri diversi: a sinistra si modifica e si salva, a destra si
   agisce subito. Tenerle mescolate rendeva difficile capire cosa richiedesse un Salva. */
.card h3 { font-size: .95rem; margin: 1.2em 0 .4em; padding-top: .8rem; border-top: 1px solid var(--line); }
.tk-row { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; padding: .45rem 0; }
.tk-row + .tk-row { border-top: 1px dashed var(--line); }
.tk-row:target { background: #fffbe6; }
.save-row { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; margin-top: 1.2rem; padding-top: .9rem; border-top: 1px solid var(--line); }

.tk-op { padding: .5rem 0; }
.tk-op + .tk-op { border-top: 1px dashed var(--line); }
.tk-op.annullato { opacity: .6; }
.tk-op-head { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.tk-op-btns { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .45rem; }

.storico summary { cursor: pointer; font-weight: 600; padding: .5rem 0; color: var(--teal); }

/* Stampa: serve solo per il foglio delle password dei varchi, da consegnare a mano */
@media print {
  .top, .filters, .pager, .no-print, form.inline, .live-row { display: none !important; }
  body { background: #fff; }
  .card { border: none; }
  .table-wrap { overflow: visible; border: none; }
}

/* ---------------------------------------------------------------- targhetta ambiente */
/* Sapere sempre dove si sta lavorando e con che versione. Non intercetta i clic e sta
   sotto l'esito dello scanner, che deve restare leggibile da lontano. */
.envtag { position: fixed; right: .5rem; bottom: .5rem; z-index: 3; pointer-events: none;
  font: 600 .72rem/1 ui-monospace, Consolas, "Courier New", monospace; letter-spacing: .03em;
  padding: .35rem .55rem; border-radius: 6px; background: #55666b; color: #fff; opacity: .8; }
.envtag b { letter-spacing: .09em; }
.envtag.env-prod { background: var(--err); opacity: 1; }
.envtag.env-locale { background: #4a5ba8; }
@media print { .envtag { display: none; } }

/* ---------------------------------------------------------------- filtri e ricerca */
/* Due cose diverse, quindi due blocchi diversi: sopra si restringe l'elenco, sotto si
   cerca una persona. Le tendine si applicano al cambio, la ricerca parte da sola:
   tenerle nella stessa riga faceva sembrare che il pulsante servisse anche a lei. */
.filters-label { font-weight: 600; font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
#filtri .filters { margin-bottom: .7rem; }
.cerca { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: .7rem .9rem .8rem; margin: 0 0 1rem; }
.cerca-head { display: flex; gap: .6rem; align-items: baseline; }
.cerca label { margin: 0; font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.cerca input { font-size: 1.05rem; padding: .6rem .7rem; }
.cerca p { margin: .5rem 0 0; font-size: .85rem; }

/* Indirizzi email che non possono funzionare: devono saltare all'occhio in elenco,
   non essere scoperti fra gli errori dopo l'invio. */
.btn.alert { background: var(--err); border-color: var(--err); color: #fff; }
.btn.alert:hover { background: #b62626; border-color: #b62626; }
.email-bad { color: var(--err); font-weight: 600; overflow-wrap: anywhere; }
