/* ─── Magazzino — stile condiviso da tutte le pagine ─────────────────────────────
   Colori, testi e componenti stanno SOLO qui. Le pagine hanno in <style> soltanto
   quello che è davvero loro (es. la scheda del picking), e usano queste variabili.
   Tema scuro: stesse variabili ridefinite sotto html.dark (classe messa da theme.js).

   Colori, con un significato fisso:
     --primario  azioni principali (Salva, Cerca, Sposta…)
     --ok        conferma / esito positivo (CONFERMA nel picking, messaggi verdi)
     --pericolo  SOLO per eliminare o per errori
     --avviso    attenzione (non in catalogo, backup manuali, aggiornamenti in corso)
     --info      informazioni e numeri (quantità, link)                              */

:root {
  --sfondo:        #f2f3f7;
  --superficie:    #ffffff;
  --superficie-2:  #f5f6f9;
  --bordo:         #e2e4ea;
  --bordo-forte:   #c9cdd6;
  --testo:         #1a1a2e;
  --testo-2:       #5b6072;
  --testo-3:       #9398a8;

  --primario:      #1a1a2e;
  --primario-testo:#ffffff;
  --ok:            #0f9d74;
  --ok-sfondo:     #e2f5ee;
  --pericolo:      #d23c50;
  --pericolo-sfondo:#fdecee;
  --avviso:        #a86300;
  --avviso-sfondo: #fff3d9;
  --info:          #2563c9;
  --info-sfondo:   #e8f0fd;

  --barra:         #1a1a2e;   /* intestazione e menu laterale */
  --barra-testo:   #ffffff;

  --font:  -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --mono:  'SF Mono', ui-monospace, 'Fira Code', Menlo, Consolas, monospace;

  /* scala dei testi */
  --t-xs:  0.75rem;
  --t-sm:  0.875rem;
  --t-md:  1rem;
  --t-lg:  1.125rem;
  --t-xl:  1.5rem;

  --raggio:    12px;
  --raggio-sm: 8px;
  --ombra:     0 1px 3px rgba(16, 24, 40, 0.07), 0 1px 2px rgba(16, 24, 40, 0.04);
  --ombra-alta: 0 12px 32px rgba(16, 24, 40, 0.18);
  --h-controllo: 48px;   /* campi e pulsanti: comodi col telefono in mano */
}

html.dark {
  --sfondo:        #0f1014;
  --superficie:    #191b21;
  --superficie-2:  #21242c;
  --bordo:         #2b2f39;
  --bordo-forte:   #3a3f4b;
  --testo:         #e7e9ee;
  --testo-2:       #a6abb8;
  --testo-3:       #6c7182;

  --primario:      #e7e9ee;
  --primario-testo:#15161b;
  --ok:            #2cc594;
  --ok-sfondo:     #10291f;
  --pericolo:      #f0667a;
  --pericolo-sfondo:#2c1418;
  --avviso:        #e0a53c;
  --avviso-sfondo: #2a2010;
  --info:          #6fa3ff;
  --info-sfondo:   #13213a;

  --barra:         #15161b;
  --barra-testo:   #e7e9ee;
  --ombra:     0 1px 2px rgba(0, 0, 0, 0.4);
  --ombra-alta: 0 12px 32px rgba(0, 0, 0, 0.6);
}

/* ─── Base ──────────────────────────────────────────────────────────────────── */
* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  font-size: var(--t-md);
  line-height: 1.45;
  background: var(--sfondo);
  color: var(--testo);
  min-height: 100vh;
}
a { color: var(--info); }
strong { font-weight: 700; }
.mono { font-family: var(--mono); }
.muted { color: var(--testo-3); }
.nascosto { display: none !important; }

/* ─── Intestazione e menu laterale (generati da layout.js) ──────────────────── */
.intestazione {
  position: sticky; top: 0; z-index: 50;
  height: 56px; padding: 0 12px 0 8px;
  display: flex; align-items: center; gap: 8px;
  background: var(--barra); color: var(--barra-testo);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}
.hamburger {
  width: 44px; height: 44px; flex-shrink: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px;
  background: none; border: none; cursor: pointer; border-radius: var(--raggio-sm);
}
.hamburger:hover { background: rgba(255, 255, 255, 0.08); }
.hamburger span { display: block; width: 22px; height: 2px; background: var(--barra-testo); border-radius: 2px; }
.intestazione-titolo { font-size: var(--t-md); font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.intestazione-destra { margin-left: auto; display: flex; align-items: center; gap: 10px; min-width: 0; }
.intestazione-utente { font-size: var(--t-xs); opacity: 0.6; white-space: nowrap; }
.intestazione-badge {
  background: var(--pericolo); color: #fff; font-size: var(--t-xs); font-weight: 700;
  padding: 2px 9px; border-radius: 20px;
}
.btn-esci {
  height: 34px; padding: 0 12px; border: none; border-radius: var(--raggio-sm);
  background: rgba(255, 255, 255, 0.12); color: var(--barra-testo);
  font: 600 var(--t-xs) var(--font); cursor: pointer; white-space: nowrap;
}
.btn-esci:hover { background: rgba(255, 255, 255, 0.22); }

.nav-overlay { display: none; position: fixed; inset: 0; background: rgba(0, 0, 0, 0.4); z-index: 98; }
.nav-overlay.aperto { display: block; }
.nav-drawer {
  position: fixed; top: 0; left: 0; bottom: 0; width: 250px; z-index: 99;
  background: var(--barra); color: var(--barra-testo);
  display: flex; flex-direction: column;
  transform: translateX(-100%); transition: transform 0.22s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.4);
}
.nav-drawer.aperto { transform: translateX(0); }
.drawer-header {
  height: 56px; padding: 0 20px; display: flex; align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08); font-weight: 700;
}
.drawer-links { padding: 8px 0; flex: 1; overflow-y: auto; }
.drawer-link {
  display: flex; align-items: center; gap: 14px; min-height: 48px; padding: 0 20px;
  color: var(--barra-testo); opacity: 0.7; text-decoration: none; font-size: var(--t-sm); font-weight: 500;
}
.drawer-link:hover { background: rgba(255, 255, 255, 0.06); opacity: 1; }
.drawer-link.attivo { opacity: 1; color: #2cc594; background: rgba(44, 197, 148, 0.1); box-shadow: inset 3px 0 0 #2cc594; }
.drawer-link .icon { width: 22px; text-align: center; font-size: 1.1rem; }
.drawer-piede { border-top: 1px solid rgba(255, 255, 255, 0.08); }
.drawer-tema, .drawer-esci {
  display: flex; align-items: center; gap: 14px; width: 100%; min-height: 48px; padding: 0 20px;
  background: none; border: none; color: var(--barra-testo); opacity: 0.7;
  font: 500 var(--t-sm) var(--font); cursor: pointer; text-align: left;
}
.drawer-tema:hover, .drawer-esci:hover { background: rgba(255, 255, 255, 0.06); opacity: 1; }
.drawer-user { padding: 12px 20px 16px; font-size: var(--t-xs); opacity: 0.45; }

/* ─── Impaginazione ─────────────────────────────────────────────────────────── */
.container { max-width: 1100px; margin: 0 auto; padding: 20px 16px 40px; }
.card {
  background: var(--superficie); border: 1px solid var(--bordo); border-radius: var(--raggio);
  box-shadow: var(--ombra); padding: 20px; margin-bottom: 16px;
}
.card > h2, .titolo-sezione {
  font-size: var(--t-xs); font-weight: 700; color: var(--testo-2);
  text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 14px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.testo-info { font-size: var(--t-sm); color: var(--testo-2); line-height: 1.55; margin-bottom: 16px; }

/* ─── Campi ─────────────────────────────────────────────────────────────────── */
input[type=text], input[type=password], input[type=number], input[type=search], select, .campo {
  height: var(--h-controllo); padding: 0 14px;
  border: 1.5px solid var(--bordo-forte); border-radius: var(--raggio-sm);
  background: var(--superficie); color: var(--testo);
  font: var(--t-md) var(--font); min-width: 0;
  transition: border-color 0.15s, box-shadow 0.15s;
}
select { padding-right: 32px; cursor: pointer; }
input::placeholder { color: var(--testo-3); }
input:focus, select:focus, .campo:focus {
  outline: none; border-color: var(--info); box-shadow: 0 0 0 3px var(--info-sfondo);
}
select.vuoto { color: var(--testo-3); }
input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--primario); cursor: pointer; vertical-align: middle; }

.form-row { display: flex; gap: 10px; flex-wrap: wrap; }
.form-row > input, .form-row > select, .form-row > .campo { flex: 1 1 160px; }

.search { position: relative; flex: 2 1 260px; }
.search input { width: 100%; padding-left: 42px; }
.search svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--testo-3); pointer-events: none; }

.filtri { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.filtri > select { flex: 1 1 180px; }

.hint { font-size: var(--t-xs); color: var(--testo-2); margin-top: 8px; min-height: 1em; }
.hint.attenzione { color: var(--avviso); }

/* ─── Pulsanti ──────────────────────────────────────────────────────────────── */
.btn, .btn-primary, .btn-secondary, .btn-neutral, .btn-annulla, .btn-danger, .btn-elimina-confirm,
.btn-ok, .btn-ghost, .btn-move {
  height: var(--h-controllo); padding: 0 20px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1.5px solid transparent; border-radius: var(--raggio-sm);
  font: 600 var(--t-md) var(--font); white-space: nowrap; cursor: pointer; text-decoration: none;
  transition: filter 0.15s, background 0.15s, transform 0.08s;
}
.btn:active, .btn-primary:active, .btn-secondary:active, .btn-neutral:active, .btn-annulla:active,
.btn-danger:active, .btn-elimina-confirm:active, .btn-ok:active, .btn-move:active { transform: scale(0.98); }
.btn-primary, .btn-move { background: var(--primario); color: var(--primario-testo); }
.btn-secondary, .btn-neutral, .btn-annulla { background: var(--superficie-2); color: var(--testo); border-color: var(--bordo); }
.btn-danger, .btn-elimina-confirm { background: var(--pericolo); color: #fff; }
.btn-ok { background: var(--ok); color: #fff; }
.btn-ghost { background: none; color: var(--testo-2); padding: 0 12px; }
.btn-primary:hover, .btn-move:hover, .btn-danger:hover, .btn-elimina-confirm:hover, .btn-ok:hover { filter: brightness(1.1); }
.btn-secondary:hover, .btn-neutral:hover, .btn-annulla:hover { background: var(--bordo); }
.btn-ghost:hover { color: var(--testo); background: var(--superficie-2); }
button:disabled { opacity: 0.45; cursor: default; filter: none !important; transform: none !important; }
.btn-sm { height: 36px; padding: 0 12px; font-size: var(--t-sm); }
.btn-icona {
  width: 40px; height: 40px; display: inline-flex; align-items: center; justify-content: center;
  border: none; border-radius: var(--raggio-sm); background: none; color: var(--testo-3); font-size: 1.05rem; cursor: pointer;
}
.btn-icona:hover { background: var(--superficie-2); color: var(--testo); }
.btn-icona.pericolo:hover { background: var(--pericolo-sfondo); color: var(--pericolo); }

/* ─── Messaggi ──────────────────────────────────────────────────────────────── */
.msg { display: none; margin-top: 12px; padding: 11px 14px; border-radius: var(--raggio-sm); font-size: var(--t-sm); font-weight: 500; }
.msg.ok  { display: block; background: var(--ok-sfondo); color: var(--ok); }
.msg.err { display: block; background: var(--pericolo-sfondo); color: var(--pericolo); }

/* ─── Schede (tab) ──────────────────────────────────────────────────────────── */
.tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1.5px solid var(--bordo); overflow-x: auto; scrollbar-width: none; }
.tab-btn {
  min-height: 46px; padding: 0 16px; margin-bottom: -1.5px;
  background: none; border: none; border-bottom: 3px solid transparent;
  font: 600 var(--t-sm) var(--font); color: var(--testo-3); cursor: pointer; white-space: nowrap;
}
.tab-btn:hover { color: var(--testo); }
.tab-btn.attivo { color: var(--testo); border-bottom-color: var(--primario); }
.tab-panel { display: none; }
.tab-panel.attivo { display: block; }

/* Schede "a pillola" dentro un riquadro (es. Inserisci · Sposta · Rinomina) */
.segmenti { display: flex; gap: 4px; padding: 4px; margin-bottom: 16px; background: var(--superficie-2); border-radius: 10px; }
.segmento {
  flex: 1; min-height: 42px; padding: 0 10px; border: none; border-radius: var(--raggio-sm);
  background: none; color: var(--testo-2); font: 600 var(--t-sm) var(--font); cursor: pointer; white-space: nowrap;
}
.segmento.attivo { background: var(--superficie); color: var(--testo); box-shadow: var(--ombra); }

/* ─── Tabelle ───────────────────────────────────────────────────────────────── */
.table-scroll, .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: var(--t-sm); }
thead th {
  text-align: left; padding: 10px; white-space: nowrap;
  font-size: var(--t-xs); font-weight: 700; color: var(--testo-3); text-transform: uppercase; letter-spacing: 0.05em;
  border-bottom: 1.5px solid var(--bordo);
}
tbody td { padding: 10px; vertical-align: middle; border-bottom: 1px solid var(--bordo); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--superficie-2); }
.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.count { font-size: var(--t-xs); color: var(--testo-3); margin: 4px 0 8px; }
.empty { text-align: center; padding: 40px 20px; color: var(--testo-3); font-size: var(--t-sm); }
.chk-cell { width: 36px; padding-right: 0 !important; }
tbody tr.selezionata { background: var(--pericolo-sfondo); }

/* Etichetta di posizione a scaffale */
.pos, .pos-cell {
  display: inline-block; padding: 3px 9px; border-radius: 6px; white-space: nowrap;
  background: var(--superficie-2); border: 1px solid var(--bordo);
  font-family: var(--mono); font-weight: 700; font-size: var(--t-sm); color: var(--testo);
}

/* ─── Etichette (badge) ─────────────────────────────────────────────────────── */
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 20px; white-space: nowrap;
  font-size: var(--t-xs); font-weight: 700; background: var(--superficie-2); color: var(--testo-2);
}
.badge.ok, .badge.attiva { background: var(--ok-sfondo); color: var(--ok); }
.badge.pericolo { background: var(--pericolo-sfondo); color: var(--pericolo); }
.badge.avviso, .badge.esclusa { background: var(--avviso-sfondo); color: var(--avviso); }
.badge.info, .badge.caricata { background: var(--info-sfondo); color: var(--info); }

/* ─── Barra "N selezionati" (eliminazione multipla) ─────────────────────────── */
.sel-bar {
  display: none; align-items: center; gap: 8px; flex-wrap: wrap;
  margin: 8px 0 12px; padding: 8px 8px 8px 14px;
  background: var(--pericolo-sfondo); border-radius: var(--raggio-sm);
}
.sel-bar.visibile { display: flex; }
.sel-count { flex: 1; font-size: var(--t-sm); font-weight: 700; color: var(--pericolo); }
.btn-desel { height: 38px; padding: 0 12px; border: none; background: none; color: var(--testo-2); font: 600 var(--t-sm) var(--font); cursor: pointer; }
.btn-desel:hover { color: var(--testo); }
.btn-cestino {
  height: 38px; padding: 0 14px; border: none; border-radius: var(--raggio-sm);
  background: var(--pericolo); color: #fff; font: 600 var(--t-sm) var(--font); cursor: pointer;
}

/* ─── Numeri riassuntivi ────────────────────────────────────────────────────── */
.stats { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.stat-box {
  flex: 1 1 140px; background: var(--superficie); border: 1px solid var(--bordo);
  border-radius: var(--raggio); box-shadow: var(--ombra); padding: 12px 16px;
}
.stat-label { font-size: var(--t-xs); color: var(--testo-3); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 2px; }
.stat-value { font-size: var(--t-xl); font-weight: 700; font-variant-numeric: tabular-nums; }

/* ─── Finestre di dialogo: dal basso sul telefono, al centro sul computer ──── */
.modal-overlay, .sheet-overlay {
  display: none; position: fixed; inset: 0; z-index: 200;
  background: rgba(10, 12, 18, 0.55); align-items: flex-end; justify-content: center;
}
.modal-overlay.aperto, .sheet-overlay.aperto { display: flex; }
.modal-box, .sheet, .modal-sheet {
  width: 100%; max-width: 480px; max-height: 88vh; overflow-y: auto;
  background: var(--superficie); color: var(--testo);
  border-radius: 18px 18px 0 0; box-shadow: var(--ombra-alta);
  padding: 22px 20px calc(22px + env(safe-area-inset-bottom));
  animation: sale 0.2s ease;
}
@keyframes sale { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (min-width: 640px) {
  .modal-overlay, .sheet-overlay { align-items: center; padding: 20px; }
  .modal-box, .sheet, .modal-sheet { border-radius: 16px; padding-bottom: 22px; }
}
.modal-box > p { font-size: var(--t-md); line-height: 1.5; margin-bottom: 18px; text-align: center; }
.modal-box > input, .modal-box > select { width: 100%; margin-bottom: 10px; }
.modal-btn-row { display: flex; gap: 10px; margin-top: 4px; }
.modal-btn-row > button { flex: 1; }
.modal-msg { color: var(--pericolo); font-size: var(--t-sm); min-height: 1em; margin-bottom: 8px; text-align: center; }

/* ─── Varie ─────────────────────────────────────────────────────────────────── */
.spinner {
  display: inline-block; width: 14px; height: 14px; vertical-align: -2px; margin-right: 6px;
  border: 2px solid var(--bordo); border-top-color: var(--ok); border-radius: 50%;
  animation: gira 0.7s linear infinite;
}
@keyframes gira { to { transform: rotate(360deg); } }

.barra-progresso { height: 8px; background: var(--superficie-2); border-radius: 6px; overflow: hidden; }
.barra-progresso > div { height: 100%; width: 0; background: var(--ok); border-radius: 6px; transition: width 0.5s ease; }

@media (max-width: 640px) {
  .container { padding: 12px 10px 32px; }
  .card { padding: 16px 14px; }
  .hide-mobile { display: none; }
  .form-row { flex-direction: column; }
  .form-row > * { width: 100%; flex: none !important; }
  .intestazione-utente { display: none; }
}

/* ─── Avviso temporaneo in basso (toast) ────────────────────────────────────── */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 9999;
  padding: 12px 20px; border-radius: var(--raggio-sm); box-shadow: var(--ombra-alta);
  background: var(--primario); color: var(--primario-testo); font-size: var(--t-sm); font-weight: 500;
  max-width: calc(100% - 32px); animation: sale 0.2s ease;
}
