/* ==========================================================================
   ALBATRASPORTI — DESIGN SYSTEM CONDIVISO
   Tema "Hub Logistico" allineato a GestionaleDistribuzione.html
   Usato da tutte le pagine Flask (home, viaggi, mezzi, calendario, grafico).

   Indice:
     1.  Token / variabili tema (light + dark)
     2.  Reset e base
     3.  Layout (shell, container, page-header)
     4.  Topbar + navigazione responsive
     5.  Card e sezioni
     6.  Pulsanti
     7.  Form
     8.  Tabelle (con modalita' "card" su mobile)
     9.  Badge, pill, stati
     10. Statistiche / contatori
     11. Flash messages
     12. Modale
     13. Utility
     14. Stampa
   ========================================================================== */

/* ==========================================================================
   1. TOKEN
   ========================================================================== */
:root {
  /* Superfici */
  --bg:            #eef2f7;
  --surface:       #ffffff;
  --surface-2:     #f8fafc;
  --surface-3:     #f1f5f9;
  --border:        #e2e8f0;
  --border-strong: #cbd5e1;

  /* Testo */
  --text:       #1e293b;
  --text-muted: #64748b;
  --text-soft:  #94a3b8;

  /* Accenti */
  --primary:      #4f46e5;
  --primary-2:    #6366f1;
  --primary-hover:#4338ca;
  --primary-soft: #eef2ff;
  --primary-ink:  #3730a3;

  --accent:       #3b82f6;

  --success:      #10b981;
  --success-soft: #dcfce7;
  --success-ink:  #166534;

  --danger:       #ef4444;
  --danger-soft:  #fee2e2;
  --danger-ink:   #991b1b;

  --warn:         #f59e0b;
  --warn-soft:    #fef3c7;
  --warn-ink:     #92400e;

  --info:         #0ea5e9;
  --info-soft:    #e0f2fe;
  --info-ink:     #075985;

  /* Header scuro (come l'hub) */
  --header-bg:    linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  --header-text:  #f8fafc;

  /* Forme */
  --radius:    14px;
  --radius-sm: 10px;
  --radius-xs: 8px;
  --pill:      999px;

  --shadow-xs: 0 1px 2px rgba(15, 23, 42, .05);
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, .07), 0 1px 2px rgba(15, 23, 42, .04);
  --shadow:    0 4px 12px -2px rgba(15, 23, 42, .08), 0 2px 4px -2px rgba(15, 23, 42, .04);
  --shadow-lg: 0 14px 30px -8px rgba(15, 23, 42, .12), 0 4px 8px -2px rgba(15, 23, 42, .05);

  /* Misure */
  --topbar-h: 62px;
  --tap:      44px;   /* area minima tocco su mobile */
}

/* Dark mode: attivata da <html class="dark"> (stessa chiave dell'hub) */
html.dark {
  --bg:            #0b1220;
  --surface:       #151e30;
  --surface-2:     #1b2740;
  --surface-3:     #22304c;
  --border:        #29364f;
  --border-strong: #3b4a68;

  --text:       #e2e8f0;
  --text-muted: #94a3b8;
  --text-soft:  #64748b;

  --primary-soft: #1e1b4b;
  --primary-ink:  #c7d2fe;

  --success-soft: #052e1b;
  --success-ink:  #6ee7b7;
  --danger-soft:  #3f1414;
  --danger-ink:   #fca5a5;
  --warn-soft:    #3b2705;
  --warn-ink:     #fcd34d;
  --info-soft:    #082f49;
  --info-ink:     #7dd3fc;

  --header-bg:   linear-gradient(135deg, #111a2c 0%, #0a1120 100%);

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, .35);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, .45);
  --shadow:    0 4px 12px -2px rgba(0, 0, 0, .5);
  --shadow-lg: 0 14px 30px -8px rgba(0, 0, 0, .6);
}

/* ==========================================================================
   2. RESET E BASE
   ========================================================================== */
*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;   /* niente zoom automatico testo su iOS */
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background-color: var(--bg);
  background-image:
    radial-gradient(ellipse at 0% 0%, rgba(99, 102, 241, .05) 0, transparent 60%),
    radial-gradient(ellipse at 100% 100%, rgba(16, 185, 129, .04) 0, transparent 60%);
  background-attachment: fixed;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;                /* mai scroll orizzontale di pagina */
}

img, svg, video { max-width: 100%; height: auto; }

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }

h1, h2, h3, h4 { margin: 0 0 .35em; font-weight: 700; letter-spacing: -.01em; line-height: 1.25; }
h1 { font-size: clamp(20px, 4.5vw, 28px); }
h2 { font-size: clamp(18px, 3.5vw, 22px); }
h3 { font-size: clamp(16px, 3vw, 18px); }
p  { margin: 0 0 1em; }

:focus-visible {
  outline: 2px solid var(--primary-2);
  outline-offset: 2px;
}

::selection { background: rgba(99, 102, 241, .18); }

/* Scrollbar sottile (come l'hub) */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: var(--pill); }
::-webkit-scrollbar-thumb:hover { background: var(--text-soft); }

/* ==========================================================================
   3. LAYOUT
   ========================================================================== */
.container {
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 16px;
}
.container-narrow { max-width: 920px; }
.container-wide   { max-width: 1600px; }

.page {
  padding: 20px 0 56px;
  /* rispetta le zone sicure di iPhone (notch / barra gesti) */
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  padding-bottom: calc(56px + env(safe-area-inset-bottom));
}

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}
.page-header .page-title { display: flex; align-items: center; gap: 10px; margin: 0; }
.page-header .page-subtitle { color: var(--text-muted); font-size: 14px; margin: 4px 0 0; }
.page-actions { display: flex; flex-wrap: wrap; gap: 10px; }

.stack   { display: flex; flex-direction: column; gap: 18px; }
.row-gap { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }

.grid { display: grid; gap: 18px; }
.grid-auto  { grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); }
.grid-tiles { grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr)); }

/* ==========================================================================
   4. TOPBAR + NAVIGAZIONE
   ========================================================================== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 200;
  background: var(--header-bg);
  color: var(--header-text);
  box-shadow: 0 2px 10px rgba(15, 23, 42, .18);
  padding-top: env(safe-area-inset-top);
}

.topbar-inner {
  max-width: 1280px;
  margin: 0 auto;
  min-height: var(--topbar-h);
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--header-text);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -.01em;
  white-space: nowrap;
  margin-right: auto;
}
.brand:hover { color: #fff; }
.brand img { height: 30px; width: auto; display: block; }
.brand-sub {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: rgba(255, 255, 255, .55);
  letter-spacing: .02em;
}

.nav {
  display: flex;
  align-items: center;
  gap: 4px;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  color: rgba(255, 255, 255, .55);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  transition: background .18s ease, color .18s ease;
}
.nav-link:hover { background: rgba(255, 255, 255, .07); color: rgba(255, 255, 255, .9); }
.nav-link.is-active {
  background: rgba(255, 255, 255, .12);
  border-color: rgba(255, 255, 255, .15);
  color: #fff;
  font-weight: 700;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .2), inset 0 1px 0 rgba(255, 255, 255, .08);
}

/* Pulsanti icona nella topbar (tema + menu) */
.topbar-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--tap);
  height: var(--tap);
  flex: 0 0 auto;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, .15);
  background: rgba(255, 255, 255, .07);
  color: #fff;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.topbar-btn:hover { background: rgba(255, 255, 255, .16); }
.nav-toggle { display: none; }

/* Icona del tema: luna con tema chiaro, sole con tema scuro */
.icon-sun { display: none; }
html.dark .icon-sun { display: block; }
html.dark .icon-moon { display: none; }

/* --- Mobile: menu a scomparsa --- */
@media (max-width: 900px) {
  .nav-toggle { display: inline-flex; }

  .nav {
    position: fixed;
    /* sopra il contenuto della pagina: senza z-index il menu finiva sotto
       le tabelle e le intestazioni appiccicate in alto */
    z-index: 199;
    inset: calc(var(--topbar-h) + env(safe-area-inset-top)) 0 auto 0;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    padding: 12px 16px calc(16px + env(safe-area-inset-bottom));
    background: #0f172a;
    border-top: 1px solid rgba(255, 255, 255, .08);
    box-shadow: 0 16px 30px rgba(0, 0, 0, .4);
    max-height: calc(100dvh - var(--topbar-h));
    overflow-y: auto;
    transform: translateY(-8px);
    opacity: 0;
    visibility: hidden;
    transition: opacity .18s ease, transform .18s ease, visibility .18s;
  }
  .nav.is-open { transform: translateY(0); opacity: 1; visibility: visible; }

  .nav-link {
    min-height: var(--tap);
    font-size: 15px;
    padding: 12px 14px;
    background: rgba(255, 255, 255, .04);
  }
}

/* ==========================================================================
   5. CARD
   ========================================================================== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 20px;
}
.card + .card { margin-top: 18px; }
.card-pad-sm { padding: 14px; }

.card-hover { transition: transform .25s cubic-bezier(.4, 0, .2, 1), box-shadow .25s, border-color .25s; }
.card-hover:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: var(--border-strong);
}

.card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.card-title .hint { margin-left: auto; font-size: 12px; font-weight: 500; color: var(--text-muted); }

.section-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-soft);
}

/* Card di navigazione della home */
.tile {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  color: var(--text);
  overflow: hidden;
  min-height: 128px;
  transition: transform .25s cubic-bezier(.4, 0, .2, 1), box-shadow .25s, border-color .25s;
}
.tile::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  background: var(--tile-accent, var(--primary));
}
.tile:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); color: var(--text); border-color: var(--border-strong); }
.tile-icon { font-size: 26px; line-height: 1; }
.tile-name { font-size: 16px; font-weight: 700; }
.tile-desc { font-size: 13px; color: var(--text-muted); }

/* ==========================================================================
   6. PULSANTI
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 9px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: var(--shadow-xs);
  transition: background .18s ease, border-color .18s ease, transform .08s ease, box-shadow .18s ease;
}
.btn:hover { background: var(--surface-2); border-color: var(--border-strong); color: var(--text); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .55; pointer-events: none; }

.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: #fff; }

.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-success:hover { background: #059669; border-color: #059669; color: #fff; }

.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; border-color: #dc2626; color: #fff; }

.btn-warn { background: var(--warn); border-color: var(--warn); color: #fff; }
.btn-warn:hover { background: #d97706; border-color: #d97706; color: #fff; }

.btn-soft { background: var(--surface-3); border-color: var(--border); color: var(--text); }
.btn-soft:hover { background: var(--border); }

.btn-soft-danger { background: var(--danger-soft); border-color: transparent; color: var(--danger-ink); }
.btn-soft-danger:hover { background: var(--danger-soft); border-color: var(--danger); color: var(--danger-ink); }

.btn-sm { min-height: 34px; padding: 6px 12px; font-size: 13px; }
.btn-lg { min-height: 50px; padding: 13px 22px; font-size: 16px; }
.btn-block { width: 100%; }
.btn-icon { width: 40px; padding: 0; }

/* Su mobile i pulsanti diventano comodi da toccare */
@media (max-width: 640px) {
  .btn { min-height: var(--tap); }
  .btn-sm { min-height: 38px; }
  .btn-stack-mobile { width: 100%; }
}

/* ==========================================================================
   7. FORM
   ========================================================================== */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}
.form-grid-1 { grid-template-columns: minmax(0, 1fr); }
.field-full { grid-column: 1 / -1; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label,
.form-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}
.field-hint { font-size: 12px; color: var(--text-soft); }

input[type="text"], input[type="number"], input[type="date"], input[type="time"],
input[type="search"], input[type="email"], input[type="password"], input[type="tel"],
select, textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  font-family: inherit;
  font-size: 16px;              /* 16px: evita lo zoom automatico su iOS */
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xs);
  transition: border-color .18s ease, box-shadow .18s ease;
  -webkit-appearance: none;
  appearance: none;
}
textarea { min-height: 96px; resize: vertical; }

select {
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 34px;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary-2);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, .15);
}
input::placeholder, textarea::placeholder { color: var(--text-soft); }
input[readonly] { background: var(--surface-3); color: var(--text-muted); cursor: not-allowed; }

input[type="checkbox"], input[type="radio"] {
  width: 18px; height: 18px;
  accent-color: var(--primary);
  cursor: pointer;
}

.check-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: var(--tap);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

/* Barra filtri */
.filter-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 170px), 1fr));
  gap: 10px;
  align-items: end;
}

/* Zona upload file */
.file-drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 18px;
  text-align: center;
  background: var(--surface-2);
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  transition: background .2s, border-color .2s;
}
.file-drop:hover { background: var(--primary-soft); border-color: var(--primary-2); }
.file-current {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  background: var(--info-soft);
  border: 1px solid transparent;
  border-radius: var(--radius-xs);
  color: var(--info-ink);
  font-size: 14px;
}

/* Footer sticky del form (salva sempre raggiungibile) */
.form-footer {
  position: sticky;
  bottom: 0;
  z-index: 20;
  padding: 12px 0 calc(12px + env(safe-area-inset-bottom));
  margin-top: 4px;
  background: linear-gradient(to top, var(--bg) 60%, transparent);
}

@media (max-width: 640px) {
  .form-grid { grid-template-columns: minmax(0, 1fr); }
}

/* ==========================================================================
   8. TABELLE
   ========================================================================== */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
table.data-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.data-table tbody td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  color: var(--text);
}
table.data-table tbody tr:last-child td { border-bottom: none; }
table.data-table tbody tr:hover { background: var(--surface-2); }
table.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }
table.data-table .center { text-align: center; }
.cell-strong { font-weight: 600; }
.cell-muted  { color: var(--text-muted); }

.table-empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
}

/*
   Modalita' CARD su mobile.
   Ogni <td> deve avere data-label="Nome colonna": l'intestazione
   viene ricreata dentro la riga e la tabella diventa una lista di schede.
*/
@media (max-width: 820px) {
  table.data-table.as-cards { min-width: 0 !important; border-collapse: separate; }
  table.data-table.as-cards thead { display: none; }
  table.data-table.as-cards,
  table.data-table.as-cards tbody,
  table.data-table.as-cards tr,
  table.data-table.as-cards td { display: block; width: 100%; }

  table.data-table.as-cards tr {
    margin: 0 0 12px;
    padding: 6px 4px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-xs);
    overflow: hidden;
  }
  table.data-table.as-cards tbody tr:hover { background: var(--surface); }

  table.data-table.as-cards td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 9px 12px;
    border: none;
    border-bottom: 1px dashed var(--border);
    text-align: right;
    min-height: 42px;
  }
  table.data-table.as-cards td:last-child { border-bottom: none; }
  table.data-table.as-cards td::before {
    content: attr(data-label);
    flex: 0 0 40%;
    text-align: left;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-soft);
  }
  /* Celle senza etichetta (checkbox, azioni) restano centrate */
  table.data-table.as-cards td[data-label=""]::before { display: none; }
  table.data-table.as-cards td.cell-hidden-mobile { display: none; }
  table.data-table.as-cards .table-empty { text-align: center; }
  table.data-table.as-cards .table-empty::before { display: none; }
}

/* ==========================================================================
   9. BADGE / STATI
   ========================================================================== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: var(--pill);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .03em;
  white-space: nowrap;
}
.badge-success { background: var(--success-soft); color: var(--success-ink); }
.badge-warn    { background: var(--warn-soft);    color: var(--warn-ink); }
.badge-danger  { background: var(--danger-soft);  color: var(--danger-ink); }
.badge-info    { background: var(--info-soft);    color: var(--info-ink); }
.badge-primary { background: var(--primary-soft); color: var(--primary-ink); }
.badge-muted   { background: var(--surface-3);    color: var(--text-muted); }

/* Stati viaggio (mappati dai valori del database) */
.st-Completato,     .st-completato     { background: var(--success-soft); color: var(--success-ink); }
.st-In-Corso,       .st-in-corso       { background: var(--warn-soft);    color: var(--warn-ink); }
.st-Non-Effettuato, .st-non-effettuato { background: var(--surface-3);    color: var(--text-muted); }
.st-Solo-Carico,    .st-solo-carico    { background: #ffedd5;             color: #9a3412; }
html.dark .st-Solo-Carico, html.dark .st-solo-carico { background: #43220a; color: #fdba74; }

/* Targa in monospazio */
.plate {
  display: inline-block;
  padding: 3px 8px;
  background: var(--primary-soft);
  color: var(--primary-ink);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: .04em;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--pill);
  box-shadow: var(--shadow-xs);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
}
.chip strong { color: var(--text); font-weight: 700; }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }

/* ==========================================================================
   10. STATISTICHE
   ========================================================================== */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(50% - 6px, 150px), 1fr));
  gap: 12px;
}
.stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--stat-accent, var(--primary));
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-xs);
}
.stat-value { font-size: 24px; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-soft); }

/* Su telefono i contatori diventano pastiglie in linea:
   occupano poche decine di pixel invece di tre righe di riquadri. */
@media (max-width: 640px) {
  .stats { display: flex; flex-wrap: wrap; gap: 6px; }
  .stat {
    flex-direction: row;
    align-items: baseline;
    gap: 6px;
    padding: 6px 12px;
    border-left-width: 3px;
    border-radius: var(--pill);
  }
  .stat-value { font-size: 15px; }
  .stat-label { font-size: 10px; letter-spacing: .04em; }
}

/* ==========================================================================
   10-bis. HOME IN STILE PROGRAMMA DESKTOP
   Riprende l'impostazione di home_page.py: sfondo chiaro, logo al centro,
   pulsantoni grigi con hover blu-ardesia, link piccoli in alto a destra.
   ========================================================================== */
.home-shell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(18px, 4vw, 36px);
}

/* Pagine senza barra in alto (home e accesso): lo spazio per la status bar
   dell'iPhone lo deve aggiungere la pagina, altrimenti i primi elementi
   finiscono sotto l'orologio e non si riescono a toccare. */
body.senza-topbar .page {
  padding-top: calc(14px + env(safe-area-inset-top));
}

.home-toplinks {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 4px 10px;
  width: 100%;
}
.home-toplink {
  display: inline-flex;
  align-items: center;
  /* area di tocco piena su telefono: prima erano link da 12px, impossibili
     da centrare col dito */
  min-height: var(--tap);
  padding: 6px 10px;
  border: none;
  border-radius: var(--radius-xs);
  background: none;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
}
.home-toplink:hover { color: var(--text); background: var(--surface-3); }
.home-toplink:active { background: var(--border); }

.home-logo { max-width: min(520px, 82vw); height: auto; }

.menu-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  width: 100%;
  max-width: 780px;
}
.menu-grid[hidden] { display: none; }

.menu-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 88px;
  padding: 18px 22px;
  border: 2px solid transparent;
  border-radius: 10px;
  background: #b0b0b0;
  color: #000;
  font-family: inherit;
  font-size: clamp(16px, 2.2vw, 22px);
  font-weight: 700;
  text-align: center;
  cursor: pointer;
  transition: background .18s ease, color .18s ease, border-color .18s ease;
}
.menu-btn:hover { background: #33475b; color: #fff; border-color: #2c3e50; }
.menu-btn:active { background: #2c3e50; color: #fff; border-color: #1a252f; }
.menu-btn.wide { grid-column: 1 / -1; }

.menu-back {
  grid-column: 1 / -1;
  justify-self: center;
  min-height: 46px;
  padding: 10px 22px;
  min-width: 180px;
  border: 1px solid #b8c2cc;
  border-radius: 6px;
  background: var(--surface);
  color: #33475b;
  font-family: inherit;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}
.menu-back:hover { background: #eef3f7; border-color: #7f8c99; }

html.dark .menu-btn { background: #475569; color: #f1f5f9; }
html.dark .menu-btn:hover { background: #1e293b; border-color: #0f172a; }
html.dark .menu-back { color: var(--text); border-color: var(--border-strong); }
html.dark .menu-back:hover { background: var(--surface-2); }

@media (max-width: 560px) {
  .menu-grid { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .menu-btn { min-height: 68px; }
}

/* Pulsante "Installa app" (PWA): visibile solo quando il browser lo permette */
.install-box { display: none; width: 100%; max-width: 780px; }
.install-box.is-visible { display: block; }
.install-hint {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--text-soft);
  text-align: center;
}

/* ==========================================================================
   10-ter. PAGINA DI ACCESSO
   ========================================================================== */
.login-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100dvh - 80px);
  padding: 12px 0;
}

.login-card {
  width: min(430px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.login-head {
  padding: 26px 24px 22px;
  text-align: center;
  background: var(--header-bg);
}
.login-head img { max-width: min(230px, 70%); height: auto; }
.login-head p {
  margin: 10px 0 0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, .55);
}

.login-body {
  display: flex;
  flex-direction: column;
  gap: 15px;
  padding: 24px;
}
.login-title { margin: 0; font-size: 20px; }
.login-sub { margin: -10px 0 0; font-size: 13px; color: var(--text-muted); }
.login-nota { margin: 0; font-size: 12px; color: var(--text-soft); text-align: center; }

.password-wrap { position: relative; display: flex; }
.password-wrap input { padding-right: 86px; }
.password-toggle {
  position: absolute;
  top: 4px; right: 4px; bottom: 4px;
  padding: 0 12px;
  border: none;
  border-radius: 6px;
  background: var(--surface-3);
  color: var(--text-muted);
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.password-toggle:hover { background: var(--border); color: var(--text); }

/* Riquadro riepilogo in basso a sinistra, come la card del desktop */
.home-summary {
  width: 100%;
  max-width: 320px;
  margin-right: auto;
}
.home-summary-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.home-summary-row:last-child { border-bottom: none; }
.home-summary-row .val { font-weight: 700; font-variant-numeric: tabular-nums; }

/* ==========================================================================
   11. FLASH MESSAGES
   ========================================================================== */
.flash-area { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.flash {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-xs);
  animation: fadeInUp .25s ease-out;
}
.flash-success { background: var(--success-soft); color: var(--success-ink); }
.flash-danger  { background: var(--danger-soft);  color: var(--danger-ink); }
.flash-warning { background: var(--warn-soft);    color: var(--warn-ink); }
.flash-info,
.flash-message { background: var(--info-soft);    color: var(--info-ink); }
.flash-close {
  margin-left: auto;
  border: none;
  background: transparent;
  color: inherit;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  opacity: .6;
}
.flash-close:hover { opacity: 1; }

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.animate-in { animation: fadeInUp .3s ease-out both; }

/* ==========================================================================
   12. MODALE
   ========================================================================== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(15, 23, 42, .55);
  backdrop-filter: blur(3px);
}
.modal.show { display: flex; }
.modal-content {
  position: relative;
  width: min(520px, 100%);
  max-height: 85vh;
  overflow-y: auto;
  padding: 24px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  animation: fadeInUp .2s ease-out;
}
.modal-close {
  position: absolute;
  top: 12px; right: 14px;
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  border-radius: 50%;
}
.modal-close:hover { background: var(--surface-3); color: var(--text); }

/* ==========================================================================
   13. UTILITY
   ========================================================================== */
.muted      { color: var(--text-muted); }
.soft       { color: var(--text-soft); }
.text-center{ text-align: center; }
.text-right { text-align: right; }
.nowrap     { white-space: nowrap; }
.truncate   { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.fw-700     { font-weight: 700; }
.fs-13      { font-size: 13px; }
.mt-0 { margin-top: 0; }  .mt-8  { margin-top: 8px; }  .mt-16 { margin-top: 16px; }
.mb-0 { margin-bottom: 0; } .mb-8 { margin-bottom: 8px; } .mb-16 { margin-bottom: 16px; }
.ml-auto { margin-left: auto; }
.hide { display: none !important; }
.only-mobile  { display: none; }
.only-desktop { display: initial; }
@media (max-width: 820px) {
  .only-mobile  { display: initial; }
  .only-desktop { display: none !important; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
}

/* ==========================================================================
   14. STAMPA
   ========================================================================== */
@media print {
  .topbar, .page-actions, .no-print, .form-footer, .flash-area { display: none !important; }
  body { background: #fff !important; background-image: none !important; color: #000; }
  .card, .table-wrap { box-shadow: none !important; border-color: #999 !important; }
  table.data-table thead th { background: #eee !important; color: #000; }
  a { color: #000; text-decoration: none; }
}
