/* ===================================================
   STILE GLOBALE - Protezione Civile V.A.E.
   Versione moderna con sidebar collassabile
   =================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ?? Variabili ?? */
:root {
  --pc-blu:          #1b3d6e;
  --pc-blu-scuro:    #112a50;
  --pc-blu-chiaro:   #2980b9;
  --pc-arancione:    #e67e22;
  --pc-rosso:        #c0392b;
  --pc-verde:        #2e7d32;
  --pc-sfondo:       #f0f2f7;
  --pc-bordo:        #d6dde6;
  --pc-giallo:       #f4c20d;
  --pc-bianco:       #ffffff;
  --pc-testo:        #1e2d3d;
  --pc-testo-light:  #5a6a7e;

  --sidebar-w:       240px;
  --sidebar-w-mini:  0px;
  --header-h:        64px;
  --raggio:          12px;
  --ombra:           0 2px 12px rgba(0,0,0,.08);
  --ombra-hover:     0 6px 24px rgba(0,0,0,.14);
  --transizione:     .25s ease;
}

/* ?? Reset ?? */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Inter', Helvetica, Arial, sans-serif;
  background: var(--pc-sfondo);
  color: var(--pc-testo);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

h1, h2, h3, h4 { color: var(--pc-blu); font-weight: 700; line-height: 1.3; }
h1 { font-size: 1.8rem; }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.15rem; margin-bottom: 12px; }
h4 { font-size: 1rem; }

a { color: var(--pc-blu-chiaro); text-decoration: none; transition: color var(--transizione); }
a:hover { color: var(--pc-blu); }

/* ??????????????????????????????????????????
   LAYOUT PRINCIPALE (sidebar + contenuto)
   ?????????????????????????????????????????? */

.layout {
  display: flex;
  min-height: 100dvh;
}

/* ?? SIDEBAR ?? */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100dvh;
  background: var(--pc-blu);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 200;
  transition: width var(--transizione), transform var(--transizione);
  overflow: hidden;
  box-shadow: 3px 0 16px rgba(0,0,0,.18);
  /* PWA: rispetta la safe area in alto */
  padding-top: env(safe-area-inset-top);
}

/* Logo / brand */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 22px 20px 18px;
  border-bottom: 1px solid rgba(255,255,255,.12);
  min-height: var(--header-h);
  white-space: nowrap;
  overflow: hidden;
}

.sidebar-brand .brand-icon {
  width: 38px; height: 38px;
  background: var(--pc-arancione);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.sidebar-brand .brand-testo {
  display: flex;
  flex-direction: column;
}

.sidebar-brand .brand-nome {
  font-weight: 700;
  font-size: 15px;
  color: #fff;
  line-height: 1.2;
}

.sidebar-brand .brand-sub {
  font-size: 11px;
  color: rgba(255,255,255,.55);
  font-weight: 400;
  margin-top: 2px;
}

/* Toggle button (hamburger) */
.sidebar-toggle {
  position: fixed;
  top: 14px;
  left: calc(var(--sidebar-w) - 18px);
  z-index: 300;
  width: 34px; height: 34px;
  background: var(--pc-arancione);
  border: none;
  border-radius: 50%;
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
  transition: left var(--transizione), background var(--transizione);
  padding: 0;
  min-height: unset;
}

.sidebar-toggle:hover { background: var(--pc-blu-chiaro); }

/* Voce di navigazione */
.sidebar-nav {
  flex: 1;
  padding: 16px 10px;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-nav a,
.sidebar-nav a:link,
.sidebar-nav a:visited {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: 10px;
  color: #eef3fa;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  transition: background var(--transizione), color var(--transizione);
  margin-bottom: 4px;
}

.sidebar-nav a .nav-icon {
  font-size: 18px;
  flex-shrink: 0;
  width: 24px;
  text-align: center;
}

.sidebar-nav a:hover {
  background: rgba(255,255,255,.16);
  color: #ffffff;
}

.sidebar-nav a.attiva,
.sidebar-nav a.attiva:link,
.sidebar-nav a.attiva:visited {
  background: var(--pc-arancione);
  color: #ffffff;
  font-weight: 600;
}

/* Separatore nav */
.sidebar-nav .nav-sep {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: rgba(255,255,255,.35);
  padding: 14px 14px 6px;
  white-space: nowrap;
}

/* Footer sidebar (utente + logout) */
.sidebar-footer {
  padding: 14px 12px;
  border-top: 1px solid rgba(255,255,255,.12);
  display: flex;
  align-items: center;
  gap: 10px;
  overflow: hidden;
  white-space: nowrap;
  /* PWA + browser: rispetta la safe area in basso */
  padding-bottom: max(14px, env(safe-area-inset-bottom));
  /* Sempre visibile anche con barra browser Safari */
  flex-shrink: 0;
}

.sidebar-footer .avatar {
  width: 36px; height: 36px;
  background: var(--pc-blu-chiaro);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.sidebar-footer .utente-info {
  flex: 1;
  overflow: hidden;
}

.sidebar-footer .utente-nome {
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-footer .utente-ruolo {
  font-size: 11px;
  color: rgba(255,255,255,.5);
}

.btn-logout {
  background: none;
  border: 1px solid rgba(255,255,255,.25);
  color: rgba(255,255,255,.75);
  border-radius: 8px;
  padding: 5px 9px;
  font-size: 13px;
  cursor: pointer;
  flex-shrink: 0;
  min-height: unset;
  width: auto;
  transition: background var(--transizione), color var(--transizione);
}
.btn-logout:hover {
  background: var(--pc-rosso);
  border-color: var(--pc-rosso);
  color: #fff;
}

/* ?? STATO COLLASSATO (desktop) ?? */
body.sidebar-chiusa .sidebar        { width: 0; }
body.sidebar-chiusa .sidebar-toggle { left: 10px; }
body.sidebar-chiusa .main-content   { margin-left: 0; }

/* ?? OVERLAY mobile ?? */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 190;
}

/* ?? CONTENUTO PRINCIPALE ?? */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-w);
  transition: margin-left var(--transizione);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  /* PWA: safe area in basso */
  padding-bottom: env(safe-area-inset-bottom);
}

/* Header superiore (topbar mobile) */
.topbar {
  display: none;
  align-items: center;
  gap: 14px;
  background: var(--pc-bianco);
  padding: 0 20px;
  height: var(--header-h);
  border-bottom: 1px solid var(--pc-bordo);
  box-shadow: var(--ombra);
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar .topbar-titolo {
  font-weight: 700;
  font-size: clamp(14px, 4vw, 17px);
  color: var(--pc-blu);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  text-align: center;
}

/* Area pagina */
.pagina {
  padding: 28px 32px;
  flex: 1;
}

/* ??????????????????????????????????????????
   PAGINA DI LOGIN (index.html)
   ?????????????????????????????????????????? */

.login-wrap {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--pc-blu-scuro) 0%, var(--pc-blu) 50%, #1a5276 100%);
  padding: 24px;
  /* PWA safe area */
  padding-top: max(24px, env(safe-area-inset-top));
  padding-bottom: max(24px, env(safe-area-inset-bottom));
}

.login-card {
  background: var(--pc-bianco);
  border-radius: 20px;
  padding: 48px 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 24px 60px rgba(0,0,0,.3);
  text-align: center;
}

.login-card .login-icon { font-size: 48px; margin-bottom: 12px; }
.login-card h1          { font-size: 1.5rem; margin-bottom: 6px; }
.login-card .login-sub  { color: var(--pc-testo-light); font-size: 14px; margin-bottom: 32px; }

/* ??????????????????????????????????????????
   CONTAINER / GRIGLIE
   ?????????????????????????????????????????? */

.container-stretto { max-width: 480px; }
.container-medio   { max-width: 760px; }
.container-largo   { max-width: 1140px; }

/* ?? CARD ?? */
.card {
  background: var(--pc-bianco);
  border-radius: var(--raggio);
  border: 1px solid var(--pc-bordo);
  box-shadow: var(--ombra);
  padding: 22px 24px;
  margin-bottom: 20px;
  transition: box-shadow var(--transizione);
}
.card:hover { box-shadow: var(--ombra-hover); }
.card-titolo {
  font-size: 15px;
  font-weight: 700;
  color: var(--pc-blu);
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--pc-bordo);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ?? STAT CARD (dashboard / statistiche) ?? */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--pc-bianco);
  border-radius: var(--raggio);
  border: 1px solid var(--pc-bordo);
  box-shadow: var(--ombra);
  padding: 20px;
  text-align: center;
  transition: box-shadow var(--transizione), transform var(--transizione);
}
.stat-card:hover { box-shadow: var(--ombra-hover); transform: translateY(-2px); }
.stat-card .numero   { font-size: 2rem; font-weight: 700; color: var(--pc-blu); }
.stat-card .etichetta { font-size: 13px; color: var(--pc-testo-light); margin-top: 4px; }

/* ??????????????????????????????????????????
   PULSANTI
   ?????????????????????????????????????????? */

button, .btn {
  background: var(--pc-blu);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  cursor: pointer;
  font-size: 14px;
  font-family: 'Inter', sans-serif;
  font-weight: 600;
  transition: background var(--transizione), box-shadow var(--transizione), transform var(--transizione);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  -webkit-tap-highlight-color: transparent;
}
button:hover, .btn:hover {
  background: var(--pc-blu-scuro);
  box-shadow: 0 4px 12px rgba(27,61,110,.3);
  transform: translateY(-1px);
}

.btn-arancione       { background: var(--pc-arancione); color: #fff; }
.btn-arancione:hover { background: #ca6f1e; box-shadow: 0 4px 12px rgba(230,126,34,.35); }

.btn-rosso       { background: var(--pc-rosso); color: #fff; }
.btn-rosso:hover { background: #a93226; box-shadow: 0 4px 12px rgba(192,57,43,.35); }

.btn-verde       { background: var(--pc-verde); color: #fff; }
.btn-verde:hover { background: #1b5e20; }

.btn-grigio       { background: #95a5a6; color: #fff; }
.btn-grigio:hover { background: #7f8c8d; }

.btn-outline {
  background: transparent;
  border: 2px solid var(--pc-blu);
  color: var(--pc-blu);
}
.btn-outline:hover { background: var(--pc-blu); color: #fff; }

.piccolo {
  background: #95a5a6;
  color: #fff;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 500;
  border-radius: 6px;
  min-height: unset;
  width: auto;
}
.piccolo:hover { background: #7f8c8d; transform: none; box-shadow: none; }

/* ??????????????????????????????????????????
   FORM / INPUT
   ?????????????????????????????????????????? */

form {
  background: var(--pc-bianco);
  padding: 24px;
  border-radius: var(--raggio);
  margin: 16px 0;
  border: 1px solid var(--pc-bordo);
  box-shadow: var(--ombra);
}

label {
  display: block;
  margin: 12px 0 5px;
  font-weight: 600;
  font-size: 13px;
  color: var(--pc-testo-light);
  text-transform: uppercase;
  letter-spacing: .04em;
}

input, select, textarea {
  width: 100%;
  padding: 10px 14px;
  box-sizing: border-box;
  font-family: 'Inter', sans-serif;
  font-size: 15px;
  border: 1.5px solid var(--pc-bordo);
  border-radius: 8px;
  background: #fafbfc;
  color: var(--pc-testo);
  transition: border-color var(--transizione), box-shadow var(--transizione);
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--pc-blu-chiaro);
  box-shadow: 0 0 0 3px rgba(41,128,185,.15);
  background: var(--pc-bianco);
}

textarea { resize: vertical; min-height: 80px; }

input[type="checkbox"] {
  width: 18px; height: 18px;
  accent-color: var(--pc-blu);
  cursor: pointer;
  vertical-align: middle;
  margin-right: 6px;
}

/* ??????????????????????????????????????????
   TABELLE
   ?????????????????????????????????????????? */

.tabella-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--raggio);
  box-shadow: var(--ombra);
}

table { width: 100%; border-collapse: collapse; background: var(--pc-bianco); }

th {
  background: var(--pc-blu);
  color: #fff;
  padding: 12px 14px;
  text-align: left;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .03em;
  white-space: nowrap;
}
th:first-child { border-radius: var(--raggio) 0 0 0; }
th:last-child  { border-radius: 0 var(--raggio) 0 0; }

td {
  border-bottom: 1px solid #eef1f6;
  padding: 11px 14px;
  text-align: left;
  font-size: 14px;
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: #f6f8fc; }

.si { color: var(--pc-verde); font-weight: 700; }
.no { color: #bdc3c7; }

/* ?? Pattuglie ?? */
#griglia th { text-align: center; vertical-align: middle; border-bottom: none; }
#griglia td { text-align: center; }
#griglia td.giorno { text-align: left; }
th.aib  { background: var(--pc-arancione); color: #fff; }
th.avv  { background: var(--pc-blu-chiaro); color: #fff; }
th.giorno, td.giorno { background: #f4f6fa; font-weight: 700; white-space: nowrap; }
#griglia th.giorno { background: #f4f6fa !important; color: var(--pc-blu) !important; text-align: center !important; }
td.cella-aib { background: #fff8f0; }
td.cella-avv { background: #eef4fb; }
td.libera    { color: #bbb; }
.occupante   { font-weight: 700; display: block; font-size: 12px; }
.weekend td.giorno { background: #e8eef5; }

/* ??????????????????????????????????????????
   BADGE / TAG
   ?????????????????????????????????????????? */

.badge {
  background: var(--pc-blu-chiaro);
  color: #fff;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  display: inline-block;
}

.tag-vae {
  background: #fef3cd;
  color: #7d5a00;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  border: 1px solid #f4c20d;
}

.tag-ar {
  background: #fde8d8;
  color: #a04000;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  border: 1px solid var(--pc-arancione);
}

.tag-nos {
  background: #ede9fe;
  color: #5b21b6;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  border: 1px solid #7c3aed;
}

.tag-emergenza {
  display: inline-block;
  background: #fee2e2;
  color: #991b1b;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  margin-left: 4px;
}

.tag-rischio {
  background: var(--pc-arancione);
  color: #fff;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
}

.badge-stato {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}
.badge-stato.completo { background: #e6f4ea; color: #1e7e34; border: 1px solid #a8d5b0; }
.badge-stato.mancano  { background: #fdecea; color: #c0392b; border: 1px solid #f5b7b1; }

/* ??????????????????????????????????????????
   CARD SERVIZIO / IMPEGNO
   ?????????????????????????????????????????? */

.servizio {
  border: 1px solid var(--pc-bordo);
  border-radius: var(--raggio);
  padding: 18px 20px;
  margin: 12px 0;
  background: var(--pc-bianco);
  box-shadow: var(--ombra);
  transition: box-shadow var(--transizione);
}
.servizio:hover { box-shadow: var(--ombra-hover); }
.servizio.alto-rischio {
  border-left: 5px solid var(--pc-arancione);
  background: #fffaf6;
}

.servizio.emergenza-card {
  border-left: 4px solid #dc2626;
  background: #fff5f5;
}

.servizio.nos-card,
.nos-card {
  border-left: 4px solid #7c3aed;
  background: #faf5ff;
}

.sezione-emergenza-titolo {
  margin: 24px 0 10px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.sezione-emergenza-titolo h3 { margin: 0; color: #991b1b; }

.impegno {
  border: 1px solid var(--pc-bordo);
  border-radius: var(--raggio);
  padding: 16px 18px;
  margin: 10px 0;
  background: var(--pc-bianco);
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--ombra);
  transition: box-shadow var(--transizione);
}
.impegno:hover { box-shadow: var(--ombra-hover); }
.impegno.aib          { border-left: 5px solid var(--pc-arancione); }
.impegno.avv          { border-left: 5px solid var(--pc-blu-chiaro); }
.impegno.servizio-ar  { border-left: 5px solid var(--pc-arancione); }
.impegno.servizio-vae { border-left: 5px solid var(--pc-verde); }

.data-box {
  text-align: center;
  min-width: 56px;
  background: rgba(255,255,255,0.22);
  border-radius: 10px;
  padding: 6px 10px;
  flex-shrink: 0;
}
.data-box .giorno {
  font-size: 26px;
  font-weight: 800;
  color: #fff;
  line-height: 1;
  text-shadow: 0 1px 3px rgba(0,0,0,0.25);
}
.data-box .mese {
  font-size: 11px;
  text-transform: uppercase;
  color: rgba(255,255,255,0.85);
  letter-spacing: .08em;
  margin-top: 2px;
  font-weight: 600;
}
.impegno.servizio-vae .data-box,
.impegno.servizio-ar  .data-box {
  background: var(--pc-sfondo);
}
.impegno.servizio-vae .data-box .giorno,
.impegno.servizio-ar  .data-box .giorno {
  color: var(--pc-blu);
  text-shadow: none;
}
.impegno.servizio-vae .data-box .mese,
.impegno.servizio-ar  .data-box .mese {
  color: var(--pc-testo-light);
}

.vuoto {
  text-align: center;
  color: var(--pc-testo-light);
  padding: 32px 20px;
  background: var(--pc-bianco);
  border-radius: var(--raggio);
  border: 2px dashed var(--pc-bordo);
  font-size: 15px;
}

/* ??????????????????????????????????????????
   CALENDARIO
   ?????????????????????????????????????????? */

.cal-nav {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  margin: 16px 0;
}
.cal-nav button { width: auto; padding: 8px 18px; }
.cal-nav #titoloMese { font-weight: 700; font-size: 18px; min-width: 190px; text-align: center; }

.calendario { width: 100%; border-collapse: collapse; table-layout: fixed; border-radius: var(--raggio); overflow: hidden; box-shadow: var(--ombra); }
.calendario th { background: var(--pc-blu); color: #fff; padding: 10px 4px; font-size: 13px; }
.calendario td { border: 1px solid #eef1f6; vertical-align: top; height: 94px; padding: 6px; background: var(--pc-bianco); }
.calendario td.vuota { background: #f7f8fa; }
.calendario td.oggi  { outline: 2px solid var(--pc-arancione); outline-offset: -2px; }
.cal-giorno { font-weight: 700; font-size: 13px; color: #333; }
.calendario td.weekend .cal-giorno { color: var(--pc-rosso); }

.ev { display: block; font-size: 11px; line-height: 1.3; border-radius: 6px; padding: 2px 5px; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: default; }
.ev-vae { background: #ffff00; color: #4d3a00; }
.ev-ar  { background: #c0392b; color: #fff; }
.ev-nos { background: #7c3aed; color: #fff; }
.ev-emg { background: #dc2626; color: #fff; }
.ev-aib { background: #e67e22; color: #fff; }
.ev-avv { background: #2980b9; color: #fff; }

.legenda { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; margin: 16px 0 4px; font-size: 13px; color: var(--pc-testo-light); }
.legenda span { display: inline-flex; align-items: center; gap: 6px; }
.punto { width: 13px; height: 13px; border-radius: 4px; display: inline-block; }

#dettaglioGiorno {
  margin-top: 20px;
  background: var(--pc-bianco);
  border: 1px solid var(--pc-bordo);
  border-radius: var(--raggio);
  padding: 20px;
  box-shadow: var(--ombra);
}
#dettaglioGiorno.nascosto { display: none; }

/* ??????????????????????????????????????????
   PATTUGLIE ? navigazione mesi
   ?????????????????????????????????????????? */

.mesi-nav {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  margin: 16px 0;
}
.mesi-nav button { width: auto; padding: 8px 18px; }
.mesi-nav span   { font-weight: 700; font-size: 18px; min-width: 160px; text-align: center; }

.mesi { text-align: center; margin: 16px 0; display: flex; gap: 8px; justify-content: center; }
.mesi button { background: var(--pc-bianco); color: var(--pc-blu); border: 2px solid var(--pc-bordo); font-weight: 600; }
.mesi button:hover { border-color: var(--pc-blu); transform: none; }
.mesi button.attivo { background: var(--pc-blu); color: #fff; border-color: var(--pc-blu); }

.tabella-pattuglie-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--raggio); box-shadow: var(--ombra); }

/* ??????????????????????????????????????????
   HEADER LEGACY (compatibilità)
   ?????????????????????????????????????????? */

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 0;
  border-bottom: 2px solid var(--pc-bordo);
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 8px;
}
header h2 { font-size: 1.25rem; }

.header nav { margin-top: 0; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.header nav a {
  color: var(--pc-blu);
  font-weight: 600;
  font-size: 14px;
  padding: 7px 14px;
  border-radius: 8px;
  background: var(--pc-bianco);
  border: 1.5px solid var(--pc-bordo);
  transition: background var(--transizione), color var(--transizione), border-color var(--transizione);
}
.header nav a:hover { background: var(--pc-blu); color: #fff; border-color: var(--pc-blu); }

/* ??????????????????????????????????????????
   VARIE
   ?????????????????????????????????????????? */

.nascosto { display: none !important; }
.errore   { color: var(--pc-rosso); font-weight: 600; font-size: 14px; }

.cessato-banner {
  background: #fdecea;
  color: var(--pc-rosso);
  padding: 10px 16px;
  border-radius: 8px;
  font-weight: 600;
  margin: 8px 0;
  border-left: 4px solid var(--pc-rosso);
}

/* Grafici */
.box-grafico {
  background: var(--pc-bianco);
  border: 1px solid var(--pc-bordo);
  border-radius: var(--raggio);
  padding: 20px;
  margin: 16px 0;
  box-shadow: var(--ombra);
}
.box-grafico h4 { margin: 0 0 14px; color: var(--pc-blu); }
canvas { max-height: 320px; }

/* Cards statistiche */
.cards { display: flex; gap: 14px; flex-wrap: wrap; margin: 16px 0; }
.cards .card { flex: 1; min-width: 140px; text-align: center; }
.cards .card .numero   { font-size: 2rem; font-weight: 800; color: var(--pc-blu); }
.cards .card .etichetta { font-size: 13px; color: var(--pc-testo-light); margin-top: 4px; }

/* Scheda volontario */
.box { background: var(--pc-bianco); border: 1px solid var(--pc-bordo); border-radius: var(--raggio); padding: 20px; margin: 16px 0; box-shadow: var(--ombra); }
.box h3 { margin-top: 0; }
.riga-due { display: flex; gap: 12px; flex-wrap: wrap; }
.riga-due > div { flex: 1; min-width: 140px; }
.info-vol { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 8px 0 16px; }
.restituita { color: #999; text-decoration: line-through; }
.azioni-cella { white-space: nowrap; }

/* Schede pattuglie mobile */
#schede { display: none; }
.scheda-giorno { background: var(--pc-bianco); border: 1px solid var(--pc-bordo); border-radius: var(--raggio); margin: 12px 0; padding: 16px; box-shadow: var(--ombra); }
.scheda-giorno.weekend { border-left: 5px solid var(--pc-rosso); }
.scheda-giorno h4 { margin: 0 0 10px; font-size: 16px; color: var(--pc-blu); }
.gruppo-titolo { font-size: 12px; font-weight: 700; margin: 12px 0 6px; color: var(--pc-testo-light); text-transform: uppercase; letter-spacing: .05em; }
.slot-riga { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; border-radius: 8px; margin: 4px 0; background: #f7f8fa; }
.slot-riga.aib { background: #fff8f0; }
.slot-riga.avv { background: #eef4fb; }
.slot-riga .etichetta { font-size: 13px; font-weight: 600; }
.slot-riga .occupante { font-size: 14px; }
.slot-riga button { width: auto; padding: 8px 14px; font-size: 14px; }
.slot-riga select { width: auto; max-width: 55%; }
.slot-libero-testo { color: #aaa; font-style: italic; font-size: 13px; }

/* ??????????????????????????????????????????
   SCROLLBAR
   ?????????????????????????????????????????? */
::-webkit-scrollbar       { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #c0c9d8; border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: #a0aab8; }

/* ??????????????????????????????????????????
   MODAL GLOBALI
   Sistema unico: classList.add/remove('aperto')
   ?????????????????????????????????????????? */
.modale-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .55);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 16px;
  padding-top: max(16px, env(safe-area-inset-top));
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  animation: modaleFade .18s ease;
}
.modale-overlay.aperto { display: flex; }

.modale-box {
  background: var(--pc-bianco);
  border-radius: 16px;
  max-width: 600px;
  width: 100%;
  /* Altezza massima calcolata sulla viewport reale, rispettando le safe area */
  max-height: calc(100dvh - 32px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 24px;
  box-shadow: 0 18px 50px rgba(0,0,0,.30);
  animation: modaleSu .22s ease;
  /* Centra verticalmente anche quando l'overlay fa overflow */
  margin: auto;
}
.modale-box.stretto { max-width: 460px; }
.modale-box.largo   { max-width: 820px; }

.modale-box form {
  background: none;
  border: none;
  box-shadow: none;
  padding: 0;
  margin: 0;
}

.modale-chiudi {
  float: right;
  cursor: pointer;
  font-size: 26px;
  line-height: 1;
  color: var(--pc-testo-light);
  background: none;
  border: none;
  width: auto;
  min-height: unset;
  padding: 0 0 0 12px;
  transition: color var(--transizione);
}
.modale-chiudi:hover { background: none; color: var(--pc-rosso); box-shadow: none; transform: none; }

.modale-titolo { margin: 0 0 16px; padding-right: 30px; }

@keyframes modaleFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes modaleSu   { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

.modale-azioni {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--pc-bordo);
}

/* Righe cliccabili nelle tabelle */
table tbody tr.cliccabile { cursor: pointer; }
table tbody tr.cliccabile:hover td { background: #f5f7fa; }

/* ??????????????????????????????????????????
   PROFILO VAE ? SOLA LETTURA
   ?????????????????????????????????????????? */
body.sola-lettura .azione,
body.sola-lettura .btn-azione,
body.sola-lettura button.btn-iscrivi,
body.sola-lettura .form-modifica,
body.sola-lettura [data-azione] {
  display: none !important;
}

body.sola-lettura .pagina::before {
  content: "?? Modalità sola lettura ? puoi consultare i dati ma non modificarli";
  display: block;
  background: #fff4e0;
  color: #8a5200;
  border: 1px solid #f0c987;
  border-radius: 10px;
  padding: 10px 16px;
  margin-bottom: 18px;
  font-size: 13px;
  font-weight: 600;
}

/* ??????????????????????????????????????????
   PATTUGLIE ? griglia
   ?????????????????????????????????????????? */
#griglia thead th { border-radius: 0; border: none; }
#griglia thead tr:first-child th.aib,
#griglia thead tr:nth-child(2) th.aib { background: var(--pc-arancione); }
#griglia thead tr:first-child th.avv,
#griglia thead tr:nth-child(2) th.avv { background: var(--pc-blu-chiaro); }
#griglia thead tr:first-child th.avv:last-child { border-radius: 0 var(--raggio) 0 0; }

#griglia { border-collapse: separate; border-spacing: 0; width: 100%; }
#griglia th, #griglia td { border: 1px solid rgba(0,0,0,.08); }
#griglia td.cella-aib  { border-color: rgba(230,126,34,.25); }
#griglia td.cella-avv  { border-color: rgba(41,128,185,.25); }
#griglia thead th      { border-color: rgba(255,255,255,.25); }
#griglia td.giorno     { border-color: rgba(0,0,0,.10); }

#griglia th, #griglia td {
  padding: 8px 10px;
  font-size: 13px;
}
#griglia th { font-size: 12px; font-weight: 600; letter-spacing: .03em; }
#griglia td.giorno       { min-width: 90px; padding: 8px 12px; }
#griglia td.cella-aib,
#griglia td.cella-avv    { min-width: 100px; height: 46px; }

#griglia button {
  font-size: 11px;
  padding: 4px 10px;
  min-height: unset;
  height: 28px;
  border-radius: 6px;
  white-space: nowrap;
}

/* ??????????????????????????????????????????
   RESPONSIVE ? 900px (tablet / sidebar mobile)
   ?????????????????????????????????????????? */
@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-100%);
    width: var(--sidebar-w);
    /* Su browser mobile la sidebar deve coprire tutto lo schermo visibile */
    height: 100dvh;
    min-height: unset;
  }
  body.sidebar-aperta .sidebar         { transform: translateX(0); }
  body.sidebar-aperta .sidebar-overlay { display: block; }

  .sidebar-toggle { left: 10px; top: 14px; }
  body.sidebar-aperta .sidebar-toggle { left: calc(var(--sidebar-w) - 18px); }

  .main-content { margin-left: 0; }
  .topbar { display: flex; }
  .pagina { padding: 20px 16px; }
}

/* ??????????????????????????????????????????
   RESPONSIVE ? 600px (smartphone)
   ?????????????????????????????????????????? */
@media (max-width: 600px) {
  button, .btn { width: auto; min-height: 44px; font-size: 15px; }
  button.piccolo { min-height: 34px; font-size: 12px; }

  form button[type="submit"],
  .modale-box form button[type="submit"],
  .btn-largo { width: 100%; min-height: 46px; }

  /* FIX MODALI MOBILE: centrati e contenuti nella viewport */
  .modale-overlay {
    padding: 8px;
    padding-top: max(8px, env(safe-area-inset-top));
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    align-items: center;
  }

  .modale-box {
    padding: 18px;
    border-radius: 14px;
    max-height: calc(100dvh - 16px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    width: 100%;
  }

  .container-medio,
  .container-stretto,
  .container-largo { width: 100%; max-width: 100%; }

  header { flex-wrap: wrap; gap: 8px; }
  nav { gap: 4px; }
  nav a { flex: 1 1 auto; text-align: center; padding: 10px 8px; font-size: 13px; }

  .impegno { flex-direction: column; align-items: flex-start; gap: 10px; }

  input, select, textarea { font-size: 16px; }

  h1 { font-size: 1.4rem; }
  h2 { font-size: 1.2rem; }
  h3 { font-size: 1.05rem; }

  form > div[style*="display:flex"] { flex-direction: column !important; gap: 0 !important; }

  .tabella-scroll th,
  .tabella-scroll td { font-size: 13px; padding: 8px; }
  .tabella-scroll table { min-width: 640px; }

  .servizio select { width: 100% !important; margin-bottom: 8px; }

  .servizio .tag-vae,
  .servizio .tag-ar,
  .servizio .tag-nos,
  .servizio .badge-stato { display: inline-block; margin-top: 4px; }

  .servizio button { margin-bottom: 6px; }

  .mesi { flex-direction: column; align-items: center; }
  .mesi button { width: 100%; max-width: 220px; }

  #vistaTabella { display: none; }
  #schede       { display: block; }

  .calendario td { height: 64px; }
  .ev { font-size: 10px; }

  .tabella-pattuglie-wrapper table { min-width: 600px; }

  .stat-grid { grid-template-columns: repeat(2, 1fr); }

  .azioni-cella { white-space: nowrap; }
}

/* ??????????????????????????????????????????
   TAP HIGHLIGHT ? niente highlight blu su mobile
   ?????????????????????????????????????????? */
button, .btn, a, .servizio, tr.cliccabile {
  -webkit-tap-highlight-color: transparent;
}
