/* =============================================================================
   MisterPerizie — Back-office (periti.rinoleggio.it)
   Stile PREMIUM business: ispirato a Linear / Stripe Dashboard / Notion.
   Niente "videogioco". Palette neutra, tipografia pulita, spaziature ampie.
   ============================================================================= */

:root {
  /* PALETTE: scala di grigi + UN primario sobrio (slate-900) + accent verde sobrio */
  --bg:           #fafafa;          /* sfondo principale */
  --bg-sidebar:   #ffffff;          /* sidebar bianca */
  --bg-card:      #ffffff;
  --bg-hover:     #f4f5f7;
  --border:       #e5e7eb;          /* bordi sottili */
  --border-strong:#d1d5db;
  --txt:          #0f172a;          /* slate-900 testo principale */
  --txt-muted:    #64748b;          /* slate-500 testo secondario */
  --txt-soft:     #94a3b8;          /* slate-400 testo ancora più tenue */
  --primary:      #0f172a;          /* slate-900 (bottoni primari) */
  --primary-hov:  #1e293b;          /* slate-800 hover */
  --accent:       #059669;          /* emerald-600 conferme/successo */
  --danger:       #b91c1c;          /* red-700 errori */
  --warning:      #b45309;          /* amber-700 warning */

  /* TIPOGRAFIA */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, system-ui, sans-serif;
  --font-mono: ui-monospace, 'SF Mono', 'Cascadia Code', Menlo, monospace;
  --fs-xs:  12px;
  --fs-sm:  13px;
  --fs-base:14px;
  --fs-md:  15px;
  --fs-lg:  17px;
  --fs-xl:  22px;
  --fs-2xl: 28px;

  /* SPACING - multipli di 4 */
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px;
  --sp-5: 20px; --sp-6: 24px; --sp-8: 32px; --sp-10: 40px; --sp-12: 48px;

  /* SHADOW - leggere, premium */
  --shadow-sm:  0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow:     0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md:  0 4px 12px rgba(15, 23, 42, 0.08), 0 2px 4px rgba(15, 23, 42, 0.04);

  /* RADIUS - piccoli, professionali */
  --r-sm: 4px; --r:    6px; --r-md: 8px; --r-lg: 12px;
}

/* FIX UNIVERSALE 01/06/2026 ore 21:30: l'attributo HTML [hidden] DEVE prevalere su qualsiasi
   regola CSS che forza display (flex/grid/block). Senza questo, .login-shell{display:flex} +
   #appView{display:grid} sovrascrivevano hidden=true, e le 2 view restavano sovrapposte
   visibili anche quando il JS le marcava hidden. */
[hidden] { display: none !important; }

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--txt);
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

/* ============================================================================
   LOGIN VIEW
   ============================================================================ */

.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-6);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-md);
  padding: var(--sp-8) var(--sp-6);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-bottom: var(--sp-6);
}

.brand-mark {
  width: 40px; height: 40px;
  border-radius: var(--r-md);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: var(--fs-md);
  letter-spacing: -0.5px;
  background: var(--primary);
  color: #fff;
  object-fit: contain;
  flex-shrink: 0;
}
/* Quando brand-mark e' un <img>, niente sfondo, solo l'immagine con leggera ombra */
img.brand-mark {
  background: transparent;
  box-shadow: var(--shadow-sm);
  object-fit: cover;
}

.brand-name {
  margin: 0;
  font-size: var(--fs-lg);
  font-weight: 600;
  letter-spacing: -0.2px;
}

.brand-sub {
  margin: 2px 0 0;
  color: var(--txt-muted);
  font-size: var(--fs-sm);
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

.login-foot {
  margin: var(--sp-6) 0 0;
  text-align: center;
  color: var(--txt-soft);
  font-size: var(--fs-xs);
}

/* ============================================================================
   FORM ELEMENTS - clean, premium
   ============================================================================ */

.field {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.field-label {
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--txt);
}

/* Wrap input password con bottone toggle "occhio" (mostra/nascondi) */
.pwd-wrap { position: relative; display: block; }
.pwd-wrap input { padding-right: 42px; }
.pwd-toggle {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  color: var(--txt-muted);
  font-size: 17px;
  line-height: 1;
  padding: 6px;
  border-radius: var(--r-sm);
  transition: background 100ms, color 100ms;
}
.pwd-toggle:hover { background: var(--bg-hover); color: var(--txt); }
.pwd-toggle.on { color: var(--primary); }

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  color: var(--txt);
  background: #fff;
  border: 1px solid var(--border-strong);
  border-radius: var(--r);
  outline: none;
  transition: border-color 150ms, box-shadow 150ms;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 23, 42, 0.08);
}

/* ============================================================================
   BOTTONI - sobri, niente colori sgargianti
   ============================================================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: 9px 14px;
  font-size: var(--fs-sm);
  font-weight: 500;
  border-radius: var(--r);
  border: 1px solid transparent;
  transition: background 150ms, border-color 150ms, opacity 150ms;
  white-space: nowrap;
}

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

.btn-ghost {
  background: transparent;
  color: var(--txt);
  border-color: var(--border-strong);
}
.btn-ghost:hover { background: var(--bg-hover); }

.btn-small { padding: 6px 10px; font-size: var(--fs-xs); }

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

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ============================================================================
   APP VIEW: sidebar + main
   ============================================================================ */

#appView {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: var(--sp-5) var(--sp-4) var(--sp-4);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 0 var(--sp-2) var(--sp-6);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--sp-4);
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.nav-item {
  padding: 8px 12px;
  border-radius: var(--r);
  color: var(--txt-muted);
  font-size: var(--fs-sm);
  font-weight: 500;
  transition: background 100ms, color 100ms;
}
.nav-item:hover { background: var(--bg-hover); color: var(--txt); }
.nav-item.active { background: var(--bg-hover); color: var(--txt); font-weight: 600; }

.nav-section {
  margin-top: var(--sp-6);
  padding-top: var(--sp-4);
  border-top: 1px solid var(--border);
}

.nav-section-label {
  padding: 0 12px var(--sp-2);
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--txt-soft);
  font-weight: 600;
}

.sidebar-foot {
  margin-top: var(--sp-4);
  padding-top: var(--sp-4);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
}

.user-mini { min-width: 0; }
.user-mini-name { font-size: var(--fs-sm); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-mini-email { font-size: var(--fs-xs); color: var(--txt-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ============================================================================
   MAIN AREA
   ============================================================================ */

.main {
  background: var(--bg);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  padding: var(--sp-5) var(--sp-8);
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
}

.view-title {
  margin: 0;
  font-size: var(--fs-xl);
  font-weight: 600;
  letter-spacing: -0.3px;
}

.topbar-actions { display: flex; gap: var(--sp-2); }

.content {
  padding: var(--sp-8);
  flex: 1;
  overflow-y: auto;
}

/* ============================================================================
   KPI / cards dashboard
   ============================================================================ */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--sp-4);
  margin-bottom: var(--sp-8);
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--sp-5);
}

.kpi-label {
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--txt-muted);
  font-weight: 600;
  margin-bottom: var(--sp-2);
}

.kpi-value {
  font-size: var(--fs-2xl);
  font-weight: 600;
  letter-spacing: -0.5px;
  color: var(--txt);
}

.kpi-sub {
  margin-top: var(--sp-2);
  font-size: var(--fs-xs);
  color: var(--txt-soft);
}

/* ============================================================================
   TABELLE - clean, alternate rows leggere
   ============================================================================ */

.panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  margin-bottom: var(--sp-6);
  overflow: hidden;
}

.panel-head {
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.panel-title {
  margin: 0;
  font-size: var(--fs-md);
  font-weight: 600;
}

.panel-body { padding: var(--sp-5); }

.panel-empty {
  padding: var(--sp-12) var(--sp-5);
  text-align: center;
  color: var(--txt-soft);
  font-size: var(--fs-sm);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-sm);
}

th {
  text-align: left;
  padding: var(--sp-3) var(--sp-5);
  background: var(--bg);
  color: var(--txt-muted);
  font-size: var(--fs-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  border-bottom: 1px solid var(--border);
}

td {
  padding: var(--sp-3) var(--sp-5);
  border-bottom: 1px solid var(--border);
  color: var(--txt);
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg-hover); }

/* ============================================================================
   MESSAGGI / badge
   ============================================================================ */

.error-msg {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: var(--danger);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r);
  font-size: var(--fs-sm);
  margin: 0;
}

.success-msg {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  color: var(--accent);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r);
  font-size: var(--fs-sm);
  margin: 0;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  font-size: var(--fs-xs);
  font-weight: 500;
  border-radius: 999px;
  background: var(--bg-hover);
  color: var(--txt-muted);
}
.badge-success { background: #f0fdf4; color: var(--accent); }
.badge-warning { background: #fffbeb; color: var(--warning); }
.badge-danger  { background: #fef2f2; color: var(--danger); }

/* ============================================================================
   MODAL
   ============================================================================ */

.modal-bg {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: var(--sp-4);
}
/* FIX CRITICO 01/06/2026: l'attributo HTML [hidden] viene sovrascritto da display:flex
   sulla classe (stessa specificita', ma .modal-bg viene letta dopo). Forziamo display:none. */
.modal-bg[hidden] { display: none !important; }

.modal-card {
  background: var(--bg-card);
  border-radius: var(--r-lg);
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.modal-head {
  padding: var(--sp-5) var(--sp-6);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-head h3 { margin: 0; font-size: var(--fs-md); font-weight: 600; }

.modal-close {
  background: none;
  border: none;
  font-size: var(--fs-xl);
  line-height: 1;
  color: var(--txt-muted);
  padding: var(--sp-1);
}
.modal-close:hover { color: var(--txt); }

.modal-body {
  padding: var(--sp-6);
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-2);
  margin-top: var(--sp-2);
}

/* ============================================================================
   CODICI ZONE - matrice allowlist (Admin)
   Vista "fitta" tipo Excel: righe = codice Dekra, colonne = macro (PORTE/RUOTE/...).
   Click su cella = toggle attivo/spento. Spunta verde grossa per outdoor.
   ============================================================================ */

.al-matrice-wrap {
  overflow-x: auto;
  max-height: 60vh;
  border-top: 1px solid var(--border);
}

.al-matrice {
  border-collapse: collapse;
  font-size: var(--fs-sm);
  width: 100%;
  min-width: 720px;
}

.al-matrice thead th {
  position: sticky;
  top: 0;
  background: #f8fafc;
  border-bottom: 2px solid var(--border-strong);
  z-index: 2;
}

.al-th-macro {
  cursor: pointer;
  user-select: none;
  text-align: center;
  font-weight: 700;
  color: var(--txt);
  white-space: nowrap;
  padding: var(--sp-3) var(--sp-3);
}
.al-th-macro:hover { background: #eef3f9; color: var(--primary); }

.al-codice {
  position: sticky;
  left: 0;
  background: #fff;
  font-family: var(--font-mono);
  white-space: nowrap;
  border-right: 2px solid var(--border-strong);
  min-width: 160px;
  z-index: 1;
}
.al-codice small { color: var(--txt-muted); font-weight: 400; font-family: var(--font-sans); }

.al-cell {
  text-align: center;
  width: 56px;
  min-width: 56px;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  transition: background 120ms, transform 80ms;
}
.al-cell:hover { transform: scale(1.15); }
.al-on  { background: #dcfce7; color: #166534; }
.al-on:hover  { background: #bbf7d0; }
.al-off { background: #f3f4f6; color: #9ca3af; }
.al-off:hover { background: #fee2e2; color: var(--danger); }
.al-cell-nd { color: var(--txt-soft); background: #fafafa; cursor: default; }

/* Gerarchia: card per macro con sottocategorie e chip codici cliccabili */
.al-gerarchia {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: var(--sp-4);
}

.al-macro-card {
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--bg-card);
  overflow: hidden;
}

.al-macro-head {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
}

.al-sottocats {
  padding: var(--sp-3) var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.al-sottocat-head {
  font-size: var(--fs-xs);
  color: var(--txt-muted);
  font-weight: 600;
  margin-bottom: 4px;
}

.al-codici-mini {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.al-codice-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  padding: 4px 8px;
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  font-weight: 700;
  border-radius: var(--r-sm);
  cursor: pointer;
  user-select: none;
  border: 1px solid transparent;
  transition: transform 80ms;
}
.al-codice-chip:hover { transform: scale(1.1); }
.al-codice-chip.on  { background: #dcfce7; color: #166534; border-color: #86efac; }
.al-codice-chip.off { background: #f3f4f6; color: #9ca3af; border-color: #e5e7eb; text-decoration: line-through; }

/* "+ Aggiungi codice non presente" - dropdown sotto i chip della macro */
.al-aggiungi-codice {
  margin-top: var(--sp-2);
  padding-top: var(--sp-2);
  border-top: 1px dashed var(--border);
}
.al-aggiungi-codice .al-aggiungi-sel {
  width: 100%;
  font-size: var(--fs-xs);
  padding: 6px 8px;
  border: 1px dashed #94a3b8;
  border-radius: var(--r-sm);
  background: #f8fafc;
  color: var(--txt);
  cursor: pointer;
}
.al-aggiungi-codice .al-aggiungi-sel:hover { background: #eef2ff; border-color: var(--accent); }
.al-aggiungi-codice .al-aggiungi-sel:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.al-aggiungi-codice.al-aggiungi-piena {
  font-size: var(--fs-xs);
  color: var(--txt-muted);
  font-style: italic;
  text-align: center;
}

/* Badge "muted" per il conteggio "in lista" (totale righe DB) */
.badge.badge-muted {
  background: #f1f5f9;
  color: #475569;
  border: 1px solid #e2e8f0;
}

/* Riga draggable: cursor "move" sulla colonna codice */
.al-matrice tbody tr[draggable="true"] .al-codice { cursor: move; }
.al-matrice tbody tr[draggable="true"]:hover .al-codice { background: #f4f5f7; }

/* ============================================================================
   GRANDINE vs NORMALE — tag, badge, kpi, sidebar, tema pannello (03/06/2026)
   Palette sobria business: Normale = blu acciaio, Grandine = viola scuro.
   Niente gradient/animazioni, coerente con look Linear/Stripe.
   ============================================================================ */

/* TAG perito (sotto il nome): pill piccola con bordo, leggibile a 13px */
.tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.1px;
  line-height: 1.4;
  border: 1px solid transparent;
  white-space: nowrap;
}
.tag-normale {
  background: #eff6ff;            /* blue-50 */
  color:      #1d4ed8;            /* blue-700 */
  border-color:#bfdbfe;            /* blue-200 */
}
.tag-grandine {
  background: #f5f3ff;            /* violet-50 */
  color:      #6d28d9;            /* violet-700 */
  border-color:#ddd6fe;            /* violet-200 */
}

/* BADGE TIPO PERIZIA (colonna tabella veicoli + titolo sala controllo) */
.badge-tipo-normale {
  background: #eff6ff;
  color:      #1d4ed8;
  border:     1px solid #bfdbfe;
}
.badge-tipo-grandine {
  background: #f5f3ff;
  color:      #6d28d9;
  border:     1px solid #ddd6fe;
}
/* alias generico per uso libero */
.badge-tipo-perizia { font-weight: 600; }

/* SIDEBAR — sotto-sezioni Perizie Normali/Grandine */
.nav-group-label {
  padding: var(--sp-3) 12px 4px;
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--txt-soft);
  font-weight: 600;
}
.nav-sub {
  padding-left: 18px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.nav-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.nav-dot-normale  { background: #1d4ed8; }
.nav-dot-grandine { background: #6d28d9; }

/* KPI card con accento colorato (Normali blu / Grandine viola) */
.kpi-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}
.kpi-dot-normale  { background: #1d4ed8; }
.kpi-dot-grandine { background: #6d28d9; }
.kpi-card-normale  { border-left: 3px solid #1d4ed8; }
.kpi-card-grandine { border-left: 3px solid #6d28d9; }

/* (28/06) Cubi KPI cliccabili = filtro/scorciatoia rapida. "Basta cliccare nel cubo". */
.kpi-card.kpi-click { cursor: pointer; transition: border-color .15s, box-shadow .15s, transform .05s; }
.kpi-card.kpi-click:hover { border-color: var(--primary); box-shadow: 0 2px 10px rgba(0,0,0,.08); }
.kpi-card.kpi-click:active { transform: translateY(1px); }
.kpi-card.kpi-attivo { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary) inset; }

/* TEMA PANNELLO Sala Controllo Grandine — sottile, business, non invadente */
.tema-grandine .panel-head {
  background: #faf5ff;            /* violet-50 più chiaro */
  border-bottom-color: #ddd6fe;
}
.tema-grandine .panel-title { color: #5b21b6; }
.tema-normale  .panel-head { background: #f8fafc; }  /* slate-50, neutro */

/* TOAST (conferma rapida import / salvataggio specializzazione) */
.toast {
  position: fixed;
  right: var(--sp-5);
  bottom: var(--sp-5);
  background: var(--primary);
  color: #fff;
  padding: 10px 16px;
  border-radius: var(--r-md);
  box-shadow: var(--shadow-md);
  font-size: var(--fs-sm);
  z-index: 200;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 150ms, transform 150ms;
  pointer-events: none;
  max-width: 360px;
}
.toast.toast-show { opacity: 1; transform: translateY(0); }

/* ============================================================================
   SIDEBAR TOGGLE + RESPONSIVE (28/06)
   - Bottone ☰ (topbar) apri/chiudi la barra laterale.
   - Desktop: sidebar a colonna; con body.nav-hidden si nasconde e i campi
     prendono tutta la larghezza.
   - Tablet/stretto (<=1024px): sidebar OFF-CANVAS (overlay che NON spinge i
     campi) + backdrop; di default chiusa (vedi _initSidebarToggle in bo.js).
   ============================================================================ */

#btnToggleSidebar { display: inline-flex; align-items: center; }
#sidebarBackdrop { display: none; }

/* (28/06) Tabella Perizie scrollabile in orizzontale: su tablet si raggiungono
   le colonne azione (Pronta/Invia/Rifai/Elimina) senza perderle. */
#wrapTabellaPerizie { overflow-x: auto; }

/* (28/06) "Vedono quello che toccano": celle cliccabili per filtrare (Perizie e Veicoli). */
.filtra-cella { cursor: pointer; }
.filtra-cella:hover { background: var(--bg-hover); }

/* (28/06) Dettaglio foto perizia = MODALE centrato SOPRA (non piu' in fondo al pannello,
   che costringeva a scrollare giu' per trovarlo). Sfondo scurito, header "Chiudi" sempre in alto. */
#panelDettaglio:not([hidden]) {
  position: fixed; top: 4vh; left: 0; right: 0; margin: 0 auto;
  width: min(96vw, 1100px); max-height: 92vh; overflow-y: auto;
  z-index: 1000; box-shadow: 0 16px 50px rgba(0,0,0,.4); border-radius: 10px;
}
#panelDettaglio:not([hidden])::before {
  content: ""; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: -1;
}
#panelDettaglio:not([hidden]) .panel-head {
  position: sticky; top: 0; background: #fff; z-index: 2;
}

/* Desktop: stato "nascosta" -> colonna unica, sidebar via */
body.nav-hidden #appView { grid-template-columns: 1fr; }
body.nav-hidden .sidebar { display: none; }

@media (max-width: 1024px) {
  /* Main sempre a tutta larghezza; la sidebar diventa overlay sopra i campi */
  #appView { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: 264px; z-index: 1200;
    overflow-y: auto;
    box-shadow: 2px 0 14px rgba(0,0,0,.18);
    transform: translateX(0); transition: transform .2s ease;
  }
  /* chiusa = slittata fuori (animata) invece di display:none */
  body.nav-hidden .sidebar { display: flex; transform: translateX(-100%); }
  /* aperta (NON nav-hidden) = backdrop scuro per chiudere col tap */
  body:not(.nav-hidden) #sidebarBackdrop {
    display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 1100;
  }
  .topbar, .content { padding-left: var(--sp-5); padding-right: var(--sp-5); }
}

/* ============================================================================
   CODICI ZONA - PAGINA FULL PAGE (03/06/2026)
   Quando body.fullpage e' attivo: la sidebar e la topbar scompaiono,
   il content prende tutta la larghezza per dare massimo respiro alla
   matrice allowlist e alla tabella azioni rapide.
   Si attiva da bo.js apriVista() quando viewId === "codici-zona".
   ============================================================================ */

body.fullpage #appView {
  grid-template-columns: 1fr;        /* nasconde la sidebar (colonna unica) */
}
body.fullpage .sidebar { display: none; }
body.fullpage .topbar  { display: none; }
body.fullpage .content {
  padding: 0;                        /* il wrapper cz-fullpage gestisce i propri padding */
  background: var(--bg);
}

/* Header della pagina (titolo grosso + sottotitolo + bottone Chiudi) */
.cz-fullpage {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.cz-fp-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  padding: var(--sp-6) var(--sp-8);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.cz-fp-title {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.4px;
}
.cz-fp-sub {
  margin: 4px 0 0;
  color: var(--txt-muted);
  font-size: var(--fs-sm);
  max-width: 780px;
}
.cz-fp-actions { display: flex; gap: var(--sp-2); }

/* Tabs in alto */
.cz-tabs {
  display: flex;
  gap: 0;
  padding: 0 var(--sp-8);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}
.cz-tab {
  background: none;
  border: none;
  padding: 14px 24px;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--txt-muted);
  cursor: pointer;
  position: relative;
  transition: color 100ms;
  border-bottom: 3px solid transparent;
  margin-bottom: -1px;
}
.cz-tab:hover { color: var(--txt); }
.cz-tab.is-active {
  color: var(--accent, #2563eb);
  border-bottom-color: var(--accent, #2563eb);
}

.cz-tab-body {
  padding: var(--sp-6) var(--sp-8);
  flex: 1;
}

/* ============================================================================
   AZIONI RAPIDE - tabella + modale
   ============================================================================ */

.ar-tab-wrap {
  border-top: 1px solid var(--border);
  overflow-x: auto;
}
.ar-tabella {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-sm);
}
.ar-tabella th, .ar-tabella td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.ar-tabella th {
  background: #f8fafc;
  font-weight: 600;
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--txt-muted);
}
.ar-tabella td.num, .ar-tabella th.num { text-align: right; font-variant-numeric: tabular-nums; }
.ar-tabella td.actions { white-space: nowrap; }
.ar-tabella tbody tr:hover { background: #fafbfc; }
.ar-nome { font-weight: 600; color: var(--txt); }
.ar-icona { font-size: 11px; color: var(--txt-soft); margin-top: 2px; }
.ar-codici {
  background: #f1f5f9;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  color: #1e293b;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.ar-foot {
  padding: 12px 16px;
  color: var(--txt-muted);
  font-size: var(--fs-xs);
  background: #fafbfc;
  border-top: 1px solid var(--border);
}

/* Toggle compatto on/off (switch mini per la colonna Attiva) */
.switch-mini {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
  vertical-align: middle;
}
.switch-mini input { opacity: 0; width: 0; height: 0; }
.switch-mini-slider {
  position: absolute; inset: 0;
  background: #cbd5e1;
  border-radius: 999px;
  transition: background 120ms;
  cursor: pointer;
}
.switch-mini-slider::before {
  content: "";
  position: absolute;
  width: 14px; height: 14px;
  left: 3px; top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 120ms;
}
.switch-mini input:checked + .switch-mini-slider { background: #16a34a; }
.switch-mini input:checked + .switch-mini-slider::before { transform: translateX(16px); }
.switch-mini input:disabled + .switch-mini-slider { opacity: 0.5; cursor: not-allowed; }

.btn-danger-mini { color: #b91c1c; }
.btn-danger-mini:hover:not(:disabled) { background: #fef2f2; }

/* Modale azione rapida: piu' largo del default (480px) per la griglia checkbox codici */
.modal-card.modal-card-wide {
  max-width: 720px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}
.modal-card.modal-card-wide .modal-body {
  overflow-y: auto;
}

.ar-form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--sp-3);
}

.ar-codici-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: #fafbfc;
}
.cb-codice {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--r);
  cursor: pointer;
  transition: background 100ms;
}
.cb-codice:hover { background: #fff; }
.cb-codice input[type="checkbox"] { width: 16px; height: 16px; flex-shrink: 0; }
.cb-cod-label { font-size: 13px; color: var(--txt); line-height: 1.3; }
.cb-cod-label b { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; color: #1e293b; }

/* Mobile: full page resta usabile, tabs scrollable orizzontale */
@media (max-width: 768px) {
  .cz-fp-head, .cz-tabs, .cz-tab-body { padding-left: var(--sp-4); padding-right: var(--sp-4); }
  .cz-tabs { overflow-x: auto; }
  .modal-card.modal-card-wide { max-width: calc(100vw - 24px); }
  .ar-form-grid { grid-template-columns: 1fr; }
}

/* ============================================================================
   STRUMENTI CAMPO - card PWA installabili (PERIZIE blu navy + PRESTO viola)
   ============================================================================ */
.sc-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--sp-6);
  margin-bottom: var(--sp-6);
}
@media (max-width: 768px) {
  .sc-grid { grid-template-columns: 1fr; gap: var(--sp-4); }
}

.sc-card {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  padding: var(--sp-6);
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  overflow: hidden;
}
/* striscia colorata in alto = identita' del marchio */
.sc-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 6px;
}
.sc-card-perizie::before { background: #1e3a8a; /* blu navy */ }
.sc-card-presto::before  { background: #7c3aed; /* viola */ }

.sc-card-head {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
}
.sc-icon {
  font-size: 40px;
  line-height: 1;
  flex-shrink: 0;
}
.sc-name {
  font-size: var(--fs-2xl);
  font-weight: 800;
  letter-spacing: 0.5px;
  line-height: 1.1;
}
.sc-card-perizie .sc-name { color: #1e3a8a; }
.sc-card-presto  .sc-name { color: #7c3aed; }

.sc-tag {
  display: inline-block;
  margin-top: 4px;
  font-size: var(--fs-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--txt-muted);
  background: #f1f5f9;
  padding: 3px 8px;
  border-radius: 999px;
}

.sc-desc {
  font-size: var(--fs-sm);
  color: var(--txt-muted);
  line-height: 1.5;
  min-height: 60px;
}

.sc-qr {
  align-self: center;
  padding: var(--sp-3);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  line-height: 0;       /* evita gap sotto SVG inline */
}
.sc-qr svg { display: block; }

.sc-url {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  background: #f8fafc;
  border: 1px solid var(--border);
  padding: 8px 10px;
  border-radius: var(--r);
  text-align: center;
  color: var(--txt);
  word-break: break-all;
}

.sc-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-2);
}
.sc-actions .btn {
  width: 100%;
  text-align: center;
  font-weight: 600;
  padding: 10px 12px;
}
.sc-btn-copy {
  background: #f1f5f9;
  color: var(--txt);
  border: 1px solid var(--border-strong);
}
.sc-btn-copy:hover { background: #e2e8f0; }
.sc-btn-copy.sc-copied {
  background: #d1fae5;
  color: #065f46;
  border-color: #6ee7b7;
}
.sc-btn-wa {
  background: #25d366;   /* verde WhatsApp ufficiale */
  color: #fff;
  border: 1px solid #1ebe5d;
}
.sc-btn-wa:hover { background: #1ebe5d; color: #fff; }

/* Guida installazione iPhone/Android (2 colonne) */
.sc-help-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--sp-4);
}
@media (max-width: 768px) {
  .sc-help-grid { grid-template-columns: 1fr; }
}
.sc-help-card {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--sp-4) var(--sp-5);
}
.sc-help-head {
  font-size: var(--fs-md);
  font-weight: 600;
  margin-bottom: var(--sp-3);
  color: var(--txt);
}
.sc-help-list {
  margin: 0;
  padding-left: 20px;
  font-size: var(--fs-sm);
  color: var(--txt);
  line-height: 1.7;
}
.sc-help-list li { margin-bottom: 4px; }
