/* Gestione magazzino - foglio di stile unico (nessuna dipendenza esterna obbligatoria) */
:root {
  --carta: #F2F5F8;
  --superficie: #FFFFFF;
  --inchiostro: #15243B;
  --tenue: #5B6B80;
  --linea: #D5DDE6;
  --linea-forte: #AEBBCB;
  --blu: #1565C0;
  --blu-scuro: #0E4C94;
  --blu-chiaro: #E3EEFA;
  --rosso: #C0362C;
  --rosso-chiaro: #FBE7E5;
  --giallo: #B7791F;
  --giallo-chiaro: #FDF3D8;
  --verde: #2E7D4A;
  --verde-chiaro: #E2F2E7;
  --raggio: 6px;
  --ombra: 0 1px 2px rgba(21, 36, 59, .08);
  --font: 'Atkinson Hyperlegible', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
* { box-sizing: border-box; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--carta); color: var(--inchiostro); font-family: var(--font); line-height: 1.45; }
a { color: var(--blu); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .6rem; }
h1 { font-size: 1.6rem; font-weight: 700; }
h2 { font-size: 1.2rem; font-weight: 700; }
h3 { font-size: 1.02rem; font-weight: 700; }
p { margin: 0 0 .8rem; }
:focus-visible { outline: 3px solid var(--blu); outline-offset: 2px; }
.num, td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tenue { color: var(--tenue); }
.piccolo { font-size: .86rem; }
.nascosto { display: none !important; }

/* ---------------- struttura */
.layout { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.barra { background: var(--inchiostro); color: #DCE5EF; padding: 1.1rem .8rem; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.marchio { display: flex; gap: .6rem; align-items: center; padding: 0 .5rem 1rem; color: #fff; font-weight: 700; font-size: 1.05rem; line-height: 1.2; }
.marchio svg { flex: none; }
.nav-gruppo { margin: .9rem 0 .2rem .5rem; font-size: .8rem; color: #8FA2B8; }
.nav a { display: block; color: #DCE5EF; padding: .42rem .6rem; border-radius: var(--raggio); }
.nav a:hover { background: rgba(255,255,255,.08); text-decoration: none; }
.nav a.attivo { background: var(--blu); color: #fff; }
.utente-box { margin-top: 1.4rem; padding: .8rem .6rem 0; border-top: 1px solid rgba(255,255,255,.15); font-size: .88rem; }
.utente-box form { display: inline; }
.utente-box button { background: none; border: 0; color: #9FC3EE; padding: 0; font: inherit; cursor: pointer; }
.contenuto { padding: 1.4rem 1.8rem 5rem; max-width: 1280px; width: 100%; min-width: 0; }
.testata { display: flex; flex-wrap: wrap; gap: .8rem; align-items: flex-end; justify-content: space-between; margin-bottom: 1.1rem; }
.testata h1 { margin: 0; }
.testata .sotto { color: var(--tenue); margin-top: .2rem; }
.azioni { display: flex; flex-wrap: wrap; gap: .5rem; }
.topbar { display: none; }

/* ---------------- pannelli */
.pannello { background: var(--superficie); border: 1px solid var(--linea); border-radius: var(--raggio); padding: 1rem 1.1rem; margin-bottom: 1rem; box-shadow: var(--ombra); }
.pannello > h2:first-child { margin-top: 0; }
.griglia { display: grid; gap: 1rem; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

/* indicatori dashboard: una riga sobria, il dato è il protagonista */
.indicatori { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border: 1px solid var(--linea); border-radius: var(--raggio); background: var(--superficie); margin-bottom: 1rem; }
.indicatore { padding: .9rem 1.1rem; border-left: 1px solid var(--linea); }
.indicatore:first-child { border-left: 0; }
.indicatore .valore { font-size: 1.7rem; font-weight: 700; font-variant-numeric: tabular-nums; display: block; }
.indicatore .etichetta { color: var(--tenue); font-size: .9rem; }
.indicatore.allarme .valore { color: var(--rosso); }

/* azioni rapide: i movimenti sono il lavoro quotidiano */
.rapide { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .6rem; margin-bottom: 1rem; }
.rapida { display: flex; flex-direction: column; gap: .15rem; padding: .85rem 1rem; border-radius: var(--raggio); background: var(--superficie); border: 1px solid var(--linea); border-left: 5px solid var(--blu); color: var(--inchiostro); }
.rapida:hover { text-decoration: none; border-color: var(--linea-forte); }
.rapida strong { font-size: 1.02rem; }
.rapida span { color: var(--tenue); font-size: .86rem; }
.rapida.entrata { border-left-color: var(--verde); }
.rapida.uscita { border-left-color: var(--rosso); }

/* ---------------- tabelle */
.tabella-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; background: var(--superficie); }
th, td { padding: .5rem .6rem; border-bottom: 1px solid var(--linea); text-align: left; vertical-align: top; }
th { font-size: .86rem; color: var(--tenue); font-weight: 700; background: #F7F9FB; position: sticky; top: 0; }
tbody tr:hover { background: #F7FAFD; }
tfoot td { font-weight: 700; border-top: 2px solid var(--linea-forte); }
tr.annullato td { color: var(--tenue); text-decoration: line-through; }
td.azioni-riga { white-space: nowrap; text-align: right; }

/* quantità firmata: il segno del movimento si legge a colpo d'occhio */
.qta { font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
.qta.piu { color: var(--verde); }
.qta.meno { color: var(--rosso); }
.qta.grande { font-size: 1.15rem; }

.etichetta-stato { display: inline-block; padding: .08rem .5rem; border-radius: 999px; font-size: .82rem; font-weight: 700; background: var(--blu-chiaro); color: var(--blu-scuro); white-space: nowrap; }
.etichetta-stato.rosso { background: var(--rosso-chiaro); color: var(--rosso); }
.etichetta-stato.giallo { background: var(--giallo-chiaro); color: var(--giallo); }
.etichetta-stato.verde { background: var(--verde-chiaro); color: var(--verde); }
.etichetta-stato.grigio { background: #E9EDF2; color: var(--tenue); }

/* ---------------- moduli */
form.modulo .campi { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .8rem 1rem; }
.campo { display: flex; flex-direction: column; gap: .25rem; }
.campo.largo { grid-column: 1 / -1; }
label { font-size: .9rem; font-weight: 700; }
label .facoltativo { font-weight: 400; color: var(--tenue); }
input, select, textarea { font: inherit; color: inherit; padding: .5rem .6rem; border: 1px solid var(--linea-forte); border-radius: var(--raggio); background: #fff; min-height: 2.5rem; width: 100%; }
textarea { min-height: 4.5rem; }
input[type=checkbox] { width: auto; min-height: 0; }
input:focus, select:focus, textarea:focus { border-color: var(--blu); outline: 2px solid var(--blu-chiaro); }
.check { display: flex; gap: .5rem; align-items: center; font-weight: 400; }
.aiuto { font-size: .84rem; color: var(--tenue); }
.filtri { display: flex; flex-wrap: wrap; gap: .6rem; align-items: flex-end; margin-bottom: 1rem; background: var(--superficie); border: 1px solid var(--linea); border-radius: var(--raggio); padding: .8rem; }
.filtri .campo { min-width: 150px; flex: 1 1 150px; }
.filtri .campo.stretto { flex: 0 1 140px; min-width: 120px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; font: inherit; font-weight: 700; padding: .5rem 1rem; min-height: 2.5rem; border-radius: var(--raggio); border: 1px solid var(--blu); background: var(--blu); color: #fff; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--blu-scuro); text-decoration: none; }
.btn.secondario { background: #fff; color: var(--blu); }
.btn.secondario:hover { background: var(--blu-chiaro); }
.btn.pericolo { background: #fff; color: var(--rosso); border-color: var(--rosso); }
.btn.pericolo:hover { background: var(--rosso-chiaro); }
.btn.piccolo { padding: .25rem .6rem; min-height: 2rem; font-size: .88rem; }
.btn.verde { background: var(--verde); border-color: var(--verde); }
.link-btn { background: none; border: 0; padding: 0; font: inherit; color: var(--blu); cursor: pointer; }

/* righe documento */
.righe-doc td { vertical-align: middle; }
.righe-doc input, .righe-doc select { min-width: 80px; }
.righe-doc .col-art { min-width: 260px; }
.righe-doc .info-art { font-size: .82rem; color: var(--tenue); margin-top: .2rem; }
.righe-doc .info-art.allarme { color: var(--rosso); }

/* messaggi */
.messaggi { margin-bottom: 1rem; }
.msg { padding: .7rem 1rem; border-radius: var(--raggio); margin-bottom: .5rem; border-left: 5px solid var(--blu); background: var(--blu-chiaro); }
.msg.errore { border-left-color: var(--rosso); background: var(--rosso-chiaro); }
.msg.ok { border-left-color: var(--verde); background: var(--verde-chiaro); }
.msg.avviso { border-left-color: var(--giallo); background: var(--giallo-chiaro); }
.vuoto { padding: 1.4rem; text-align: center; color: var(--tenue); }
.vuoto .btn { margin-top: .6rem; }

dl.dati { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1rem; margin: 0; }
dl.dati dt { color: var(--tenue); }
dl.dati dd { margin: 0; }

.paginazione { display: flex; gap: .4rem; align-items: center; margin-top: .8rem; flex-wrap: wrap; }

/* pagine di accesso */
.accesso { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.accesso .pannello { width: 100%; max-width: 400px; padding: 1.6rem; }
.accesso h1 { font-size: 1.35rem; }

/* pulsante fisso su telefono */
.fab { display: none; }

/* ---------------- telefono e tablet */
@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .barra { position: fixed; inset: 0 auto 0 0; width: 270px; z-index: 30; transform: translateX(-100%); transition: transform .2s ease; }
  body.menu-aperto .barra { transform: none; }
  body.menu-aperto::after { content: ''; position: fixed; inset: 0; background: rgba(21,36,59,.45); z-index: 20; }
  .topbar { display: flex; align-items: center; gap: .7rem; padding: .6rem 1rem; background: var(--inchiostro); color: #fff; position: sticky; top: 0; z-index: 10; }
  .topbar button { background: none; border: 1px solid rgba(255,255,255,.35); color: #fff; border-radius: var(--raggio); min-height: 2.4rem; padding: 0 .7rem; font: inherit; }
  .contenuto { padding: 1rem 1rem 6rem; }
  .indicatori { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .indicatore:nth-child(3) { border-left: 0; }
  .indicatore:nth-child(n+3) { border-top: 1px solid var(--linea); }
  .rapide { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g2, .g3, .g4 { grid-template-columns: minmax(0, 1fr); }
  .fab { display: flex; position: fixed; right: 1rem; bottom: 1rem; z-index: 15; box-shadow: 0 4px 14px rgba(21,36,59,.3); padding: .8rem 1.2rem; }
  /* righe documento come schede impilate */
  .righe-doc thead { display: none; }
  .righe-doc, .righe-doc tbody, .righe-doc tr, .righe-doc td { display: block; width: 100%; }
  .righe-doc tr { border: 1px solid var(--linea); border-radius: var(--raggio); padding: .4rem; margin-bottom: .6rem; }
  .righe-doc td { border: 0; padding: .3rem; }
  .righe-doc td[data-label]::before { content: attr(data-label); display: block; font-size: .8rem; font-weight: 700; color: var(--tenue); }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---------------- stampa (ordini, documenti) */
@media print {
  .barra, .topbar, .azioni, .fab, .filtri, .no-stampa, .messaggi { display: none !important; }
  .layout { display: block; }
  body { background: #fff; }
  .contenuto { padding: 0; max-width: none; }
  .pannello { border: 0; box-shadow: none; padding: 0; }
  th { position: static; }
}

/* ---------------------------------------------------------------- impostazioni (v2.0) */
.schede { display: flex; gap: .25rem; flex-wrap: wrap; border-bottom: 1px solid var(--linea); margin-bottom: 1rem; }
.schede a { padding: .55rem .9rem; color: var(--tenue); text-decoration: none; border-bottom: 3px solid transparent; margin-bottom: -1px; font-weight: 700; }
.schede a:hover { color: var(--inchiostro); }
.schede a.attivo { color: var(--blu-scuro); border-bottom-color: var(--blu); }
.catena { display: flex; align-items: stretch; gap: .4rem; flex-wrap: wrap; margin: .4rem 0 .2rem; }
.catena .livello { border: 1px solid var(--linea); border-radius: var(--raggio); padding: .45rem .7rem; background: var(--superficie); min-width: 140px; }
.catena .livello strong { display: block; }
.catena .livello span { color: var(--tenue); font-size: .82rem; }
.catena .livello.corrente { border-color: var(--blu); background: var(--blu-chiaro); }
.catena .freccia { align-self: center; color: var(--linea-forte); font-size: 1.2rem; }
.origine { display: inline-block; font-size: .78rem; padding: .05rem .45rem; border-radius: 999px; background: #E9EDF2; color: var(--tenue); white-space: nowrap; }
.origine.personalizzata { background: var(--giallo-chiaro); color: var(--giallo); font-weight: 700; }
.tabella-impostazioni td { vertical-align: top; }
.tabella-impostazioni input[type=text], .tabella-impostazioni input:not([type]) { min-width: 0; width: 100%; }
.termine-campi { display: grid; grid-template-columns: 1fr 1fr 7.5rem; gap: .4rem; }
.esempio { color: var(--tenue); font-size: .82rem; margin-top: .25rem; }
.modulo-riga { display: flex; gap: .8rem; align-items: flex-start; padding: .7rem 0; border-top: 1px solid var(--linea); }
.modulo-riga:first-child { border-top: 0; }
.modulo-riga .descr { flex: 1; }
.scelte-siti { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: .3rem .8rem; }
@media (max-width: 640px) {
  .termine-campi { grid-template-columns: 1fr 1fr; }
  .termine-campi select { grid-column: 1 / -1; }
}
.impostazioni-testa { grid-template-columns: minmax(0, 1fr) minmax(0, 1.7fr); }
@media (max-width: 900px) { .impostazioni-testa { grid-template-columns: 1fr; } }
[hidden] { display: none !important; }
@media (max-width: 700px) {
  .tabella-impostazioni, .tabella-impostazioni tbody, .tabella-impostazioni tr, .tabella-impostazioni td { display: block; width: 100% !important; }
  .tabella-impostazioni thead { display: none; }
  .tabella-impostazioni tr { padding: .7rem 0; border-bottom: 1px solid var(--linea); }
  .tabella-impostazioni td { border: 0; padding: .25rem 0; }
  .origine { white-space: normal; }
}

/* ---------------------------------------------------------------- personale, pianificazione, contratti, controllo (v2.1) */
.negativo { color: var(--rosso); }
.rosso-testo { color: var(--rosso); font-weight: 700; }
.elenco-semplice { margin: 0; padding-left: 1.1rem; }
.elenco-semplice li { margin: .3rem 0; }
.etichetta-campo { font-size: .9rem; font-weight: 700; }
.giorni-scelta { display: flex; flex-wrap: wrap; gap: .3rem 1rem; padding-top: .3rem; }
.riga-fattura { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: .8rem 1rem; margin-top: 1rem; }

/* ore: inserimento da telefono */
.riga-piano { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: center; justify-content: space-between; padding: .55rem 0; border-top: 1px solid var(--linea); }
.riga-piano:first-of-type { border-top: 0; }
#modulo-ore .campi-ore select, #modulo-ore .campi-ore input { font-size: 1.05rem; }
tr.nota-riga td { border-top: 0; padding-top: 0; }
.righe-foglio td { padding: .35rem .25rem; }
.righe-foglio td:nth-child(1) input { min-width: 8.8rem; }
.righe-foglio td:nth-child(2) select { min-width: 8.5rem; }
.righe-foglio td:nth-child(3) select { min-width: 10.5rem; max-width: 15rem; }
.righe-foglio td:nth-child(4) input, .righe-foglio td:nth-child(5) input { min-width: 6.2rem; }
.righe-foglio td:nth-child(6) input, .righe-foglio td:nth-child(7) input { min-width: 3.8rem; }
.righe-foglio td:nth-child(8) input { min-width: 5.5rem; }

/* griglia settimanale e calendario */
.griglia-settimana th.oggi, .calendario th.oggi { color: var(--blu-scuro); }
.griglia-settimana td.cella-ore { min-width: 4.5rem; }
.griglia-settimana td.scarto { background: var(--giallo-chiaro); }
.griglia-settimana td.mancante { background: var(--rosso-chiaro); }
.punto { color: var(--blu); font-weight: 700; }
.calendario { table-layout: fixed; min-width: 860px; }
.calendario th[scope=row] { width: 170px; font-size: .92rem; color: var(--inchiostro); background: #F7F9FB; position: static; }
.calendario td { padding: .35rem; }
.calendario td.oggi { background: #F5F9FE; }
.calendario tr.da-assegnare th { color: var(--giallo); }
.voce-cal { display: flex; flex-direction: column; font-size: .8rem; line-height: 1.25; padding: .3rem .4rem; margin-bottom: .3rem; border-radius: 4px; background: var(--blu-chiaro); border-left: 3px solid var(--blu); }
.voce-cal.intervento { background: #FDEBD8; border-left-color: #C0611B; }
.voce-cal strong { font-size: .82rem; }
.effettive { font-size: .78rem; color: var(--verde); font-weight: 700; }
.agenda-giorno { padding: .6rem 0; border-top: 1px solid var(--linea); }
.agenda-giorno:first-child { border-top: 0; padding-top: 0; }
.agenda-giorno h3 { font-size: .95rem; margin-bottom: .4rem; }
.agenda-giorno.oggi h3 { color: var(--blu-scuro); }
.agenda-giorno p { margin: 0; }
.agenda .voce-cal { font-size: .9rem; }
.agenda .voce-cal strong { font-size: .92rem; }

/* controllo */
table.conto td { padding: .4rem .2rem; }
table.conto tr.totale td { font-weight: 700; border-top: 2px solid var(--linea-forte); }
.andamento td.barre { width: 34%; min-width: 140px; }
.barre span { display: block; height: .45rem; border-radius: 2px; margin: .15rem 0; min-width: 1px; }
.barra-ricavi, .legenda.ricavi { background: var(--blu); }
.barra-costi, .legenda.costi { background: #E39A57; }
.legenda { display: inline-block; width: .8rem; height: .8rem; border-radius: 2px; vertical-align: middle; margin-left: .6rem; }
.tabella-redditivita td .etichetta-stato { white-space: normal; margin-bottom: .2rem; }

@media (max-width: 700px) {
  /* elenchi come schede impilate su telefono */
  .tabella-schede thead { display: none; }
  .tabella-schede, .tabella-schede tbody, .tabella-schede tr, .tabella-schede td { display: block; width: 100%; }
  .tabella-schede tr { border-bottom: 1px solid var(--linea); padding: .4rem 0; }
  .tabella-schede td { border: 0; padding: .15rem 0; text-align: left; }
  .tabella-schede td.num { text-align: left; }
  .tabella-schede td:empty { display: none; }
  .tabella-schede td.azioni-riga { text-align: left; }
  .tabella-schede td[data-label]:not([data-label=Giorno])::before { content: attr(data-label) ': '; color: var(--tenue); font-size: .82rem; }
  .riga-piano .btn { width: 100%; }
}

/* ---------------------------------------------------------------- v2.2: scelta vista, menu richiudibile, scheda commessa */
.vista-scelta { display: flex; gap: .4rem; margin: -.4rem 0 .8rem; flex-wrap: wrap; }
.nav-blocco > summary { list-style: none; cursor: pointer; display: flex; justify-content: space-between; align-items: center; padding-right: .5rem; border-radius: var(--raggio); }
.nav-blocco > summary::-webkit-details-marker { display: none; }
.nav-blocco > summary::after { content: ''; width: .45rem; height: .45rem; border-right: 2px solid #8FA2B8; border-bottom: 2px solid #8FA2B8; transform: rotate(45deg); margin-top: -.2rem; transition: transform .15s ease; }
.nav-blocco:not([open]) > summary::after { transform: rotate(-45deg); margin-top: 0; }
.nav-blocco > summary:hover { color: #DCE5EF; }
.nav-blocco > summary:focus-visible { outline: 2px solid #9FC3EE; outline-offset: 2px; }
.panoramica dl.dati { grid-template-columns: minmax(0, max-content) minmax(0, 1fr); }
.panoramica dl.dati dd { overflow-wrap: break-word; min-width: 0; }
.panoramica .etichetta-stato { white-space: normal; }
.panoramica .pannello { margin-bottom: 0; }
