/* Magazzino Nebula: stessi colori del sito (verde del cerchio, lime della nuvola, nero). */
:root {
  color-scheme: light;
  --bg: #f6f7f3;
  --surface: #ffffff;
  --surface-2: #f0f3ec;
  --border: #dde3d7;
  --border-strong: #c5cebf;
  --text: #0f1611;
  --text-2: #3f4b42;
  --text-3: #57635a;
  --brand: #15803d;
  --brand-hover: #116a32;
  --brand-ink: #ffffff;
  --brand-soft: #e3f3e6;
  --brand-text: #116a32;
  --lime: #d4e020;
  --lime-ink: #151a05;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --warning: #8a5a00;
  --warning-soft: #fff4d6;
  --shadow: 0 1px 2px rgb(15 22 17 / 0.05), 0 8px 24px -6px rgb(15 22 17 / 0.1);
  --radius: 16px;
  --radius-sm: 10px;
  --font: 'Plus Jakarta Sans', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #080b09;
    --surface: #101612;
    --surface-2: #151d17;
    --border: #1f2a22;
    --border-strong: #2c3b30;
    --text: #ecf2ed;
    --text-2: #bac6bd;
    --text-3: #93a097;
    --brand: #3ecf6a;
    --brand-hover: #5bdc82;
    --brand-ink: #04130a;
    --brand-soft: #12261a;
    --brand-text: #5bdc82;
    --danger: #ff8a7a;
    --danger-soft: #2c1512;
    --warning: #f5c451;
    --warning-soft: #2a2110;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 8px 24px -6px rgb(0 0 0 / 0.5);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 var(--font);
  min-height: 100dvh;
  border-top: 4px solid var(--brand);
}
a { color: var(--brand-text); }
code { font-family: ui-monospace, Consolas, monospace; background: var(--surface-2); padding: 1px 6px; border-radius: 6px; margin-right: 4px; }
h1, h2, h3, h4 { margin: 0 0 8px; line-height: 1.2; }
:focus-visible { outline: 3px solid var(--lime); outline-offset: 2px; }

/* ---------- testata ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.top .logo { width: 36px; height: 36px; border-radius: 50%; }
.top-titolo { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.top-titolo strong { font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-titolo small { color: var(--text-3); font-size: 12px; }
.contenuto { max-width: 760px; margin: 0 auto; padding: 16px 16px 48px; display: flex; flex-direction: column; gap: 14px; }

/* ---------- pulsanti ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 18px;
  border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
  touch-action: manipulation;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { background: var(--brand-hover); }
.btn-big { min-height: 60px; font-size: 18px; width: 100%; }
.btn-small { min-height: 40px; padding: 6px 12px; font-size: 14px; }
.icon-btn { min-width: 44px; min-height: 44px; border: 0; background: transparent; color: var(--text); font-size: 22px; cursor: pointer; border-radius: 50%; }
.icon-btn:hover { background: var(--surface-2); }

/* ---------- home ---------- */
.tiles { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 560px) { .tiles { grid-template-columns: 1fr 1fr; } }
.tile {
  display: flex; align-items: center; gap: 16px;
  min-height: 92px; padding: 16px 18px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); text-decoration: none; box-shadow: var(--shadow);
}
.tile-ico {
  flex: none; display: grid; place-items: center;
  width: 54px; height: 54px; border-radius: 50%;
  background: var(--brand-soft); color: var(--brand-text); font-size: 26px; font-weight: 800;
}
.tile-txt { display: flex; flex-direction: column; }
.tile-txt strong { font-size: 20px; }
.tile-txt small { color: var(--text-3); }
.tile-primaria { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.tile-primaria .tile-ico { background: var(--lime); color: var(--lime-ink); }
.tile-primaria small { color: inherit; opacity: 0.85; }
.tile-allerta .tile-ico { background: var(--warning-soft); color: var(--warning); }
.tile-allerta small { color: var(--warning); font-weight: 600; }
.piede { color: var(--text-3); font-size: 13px; text-align: center; }

/* ---------- accesso ---------- */
.login { max-width: 420px; margin: 0 auto; padding: 40px 20px; display: flex; flex-direction: column; gap: 14px; text-align: center; }
.login-logo { width: 120px; height: 120px; margin: 0 auto; border-radius: 50%; box-shadow: var(--shadow); }
.login .form { text-align: left; }

/* ---------- moduli ---------- */
.form { display: flex; flex-direction: column; gap: 8px; }
label { font-weight: 600; font-size: 14px; color: var(--text-2); }
input, select, textarea {
  width: 100%; min-height: 48px; padding: 10px 12px;
  font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
}
input[type='checkbox'] { width: 22px; height: 22px; min-height: 0; accent-color: var(--brand); flex: none; }
.check { display: inline-flex; align-items: center; gap: 10px; min-height: 44px; font-weight: 600; color: var(--text); }
.flags { display: flex; flex-wrap: wrap; gap: 4px 16px; }
.griglia { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; }
.griglia > div { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.campi { display: flex; flex-direction: column; gap: 8px; }
.azioni { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; margin-top: 8px; }
.azioni-col { display: flex; flex-direction: column; gap: 10px; }
.errore-testo { color: var(--danger); font-weight: 600; margin: 4px 0; min-height: 1em; }
.ok-testo { color: var(--brand-text); font-weight: 600; }
.nota { color: var(--text-3); font-size: 14px; margin: 0; }
.filtri { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.filtri label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }

/* ---------- card, liste ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 6px; }
.card.errore { border-color: var(--danger); background: var(--danger-soft); color: var(--danger); font-weight: 600; }
.card.warn { border-color: var(--warning); background: var(--warning-soft); }
.sezione { margin: 10px 0 0; font-size: 15px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-3); }
.lista { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.lista > li { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.lista-compatta > li { display: flex; justify-content: space-between; gap: 12px; padding: 10px 12px; align-items: center; }
.lista-compatta > li > span:first-child { display: flex; flex-direction: column; min-width: 0; }
.lista small, .riga-btn small { color: var(--text-3); font-size: 13px; }
.lista .vuoto, .vuoto { color: var(--text-3); padding: 12px; text-align: center; border-style: dashed; }
.riga-btn {
  display: grid; grid-template-columns: 1fr auto; grid-template-areas: 'a c' 'b c';
  align-items: center; gap: 2px 12px; width: 100%;
  padding: 12px 14px; min-height: 56px;
  background: transparent; border: 0; color: var(--text); text-align: left; font: inherit; text-decoration: none; cursor: pointer;
}
.riga-btn > strong { grid-area: a; }
.riga-btn > small { grid-area: b; }
.riga-btn > .badge, .riga-btn > .qta-grande, .riga-btn > .prezzo { grid-area: c; }
.qta-grande { font-size: 24px; font-weight: 800; min-width: 48px; text-align: right; }
.qta-grande.basso, .basso { color: var(--danger); font-weight: 800; }
.mov-dx { display: flex; flex-direction: column; align-items: flex-end; flex: none; }
.piu { color: var(--brand-text); }
.meno { color: var(--danger); }
.barrato span { text-decoration: line-through; opacity: 0.6; }
.archiviato { opacity: 0.55; }
li.scaduto { border-color: var(--danger); background: var(--danger-soft); }
li.in-scadenza { border-color: var(--warning); }
.scad-vicina { color: var(--warning); font-weight: 700; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.badge-ok { background: var(--brand-soft); color: var(--brand-text); }
.badge-warn, .badge-manca, .badge-zero { background: var(--warning-soft); color: var(--warning); }
.badge-eccesso { background: var(--danger-soft); color: var(--danger); }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { min-height: 40px; padding: 6px 14px; border-radius: 999px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; }
.chip[aria-pressed='true'] { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }

.tabella-scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); }
.tabella { width: 100%; border-collapse: collapse; font-size: 15px; }
.tabella th, .tabella td { padding: 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.tabella th { font-size: 13px; color: var(--text-3); position: sticky; top: 0; background: var(--surface); }
.tabella td small { display: block; color: var(--text-3); font-size: 12px; }
.tabella .num { text-align: right; white-space: nowrap; }
.tabella .col-prodotto { min-width: 150px; }
@media (max-width: 559px) { .tabella .col-prodotto small { display: none; } .tabella th, .tabella td { padding: 8px 6px; } }
.dati { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 6px 0 0; }
.dati dt { color: var(--text-3); }
.dati dd { margin: 0; font-weight: 600; }
.prod-nome { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* ---------- scanner ---------- */
.scanner { display: flex; flex-direction: column; gap: 8px; }
.video-box { position: relative; aspect-ratio: 4 / 3; max-height: 46dvh; width: 100%; background: #000; border-radius: var(--radius); overflow: hidden; }
.video { width: 100%; height: 100%; object-fit: cover; display: block; }
.mirino { position: absolute; inset: 28% 10%; border: 3px solid var(--lime); border-radius: 12px; box-shadow: 0 0 0 200vmax rgb(0 0 0 / 0.25); pointer-events: none; }
.scan-riga { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.scan-stato { margin: 0; color: var(--text-2); font-weight: 600; }
.manuale { display: flex; gap: 8px; }
.manuale input { flex: 1; }

.esito-card { border-width: 2px; }
.esito-card.ok { border-color: var(--brand); }
.esito-nome { font-size: 22px; }
.esito-desc { color: var(--text-3); font-size: 14px; }
.esito-qta { font-size: 18px; }
.esito-qta b { font-size: 26px; }
.esito-warn { color: var(--warning); font-weight: 700; }

/* ---------- righe fattura ---------- */
.righe-fattura { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.riga-f {
  display: grid; grid-template-columns: 1fr auto; gap: 8px 12px;
  padding: 12px; border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--border); border-left-width: 6px;
}
.riga-f.st-ok { border-left-color: var(--brand); }
.riga-f.st-manca, .riga-f.st-zero { border-left-color: var(--warning); }
.riga-f.st-eccesso { border-left-color: var(--danger); }
.riga-f-testo { display: flex; flex-direction: column; min-width: 0; }
.riga-f-testo small { color: var(--text-3); }
.riga-f-testo .collegato { color: var(--brand-text); }
.riga-f-testo .scollegato { color: var(--warning); font-weight: 700; }
.riga-f-qta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.qta { font-size: 18px; }
.qta b { font-size: 24px; }
.riga-f-azioni { grid-column: 1 / -1; display: flex; gap: 8px; justify-content: flex-end; }
.riga-f-azioni .btn { min-width: 52px; }
.servizi { color: var(--text-3); }
.servizi summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; }

/* ---------- finestre e avvisi ---------- */
.modal-bg { position: fixed; inset: 0; z-index: 20; background: rgb(0 0 0 / 0.55); display: flex; align-items: flex-end; justify-content: center; }
@media (min-width: 640px) { .modal-bg { align-items: center; } }
.modal { width: 100%; max-width: 560px; max-height: 92dvh; overflow: auto; background: var(--bg); border-radius: 20px 20px 0 0; box-shadow: var(--shadow); }
@media (min-width: 640px) { .modal { border-radius: 20px; } }
.modal-head { position: sticky; top: 0; display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 12px 8px 18px; background: var(--bg); border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; font-size: 19px; }
.modal-body { padding: 14px 18px 22px; display: flex; flex-direction: column; gap: 10px; }
.modal-body p { white-space: pre-line; margin: 0; }

.toast {
  position: fixed; left: 50%; bottom: 20px; z-index: 30; transform: translateX(-50%);
  width: min(92vw, 520px); padding: 14px 18px; border-radius: 14px;
  background: var(--text); color: var(--bg); font-weight: 700; box-shadow: var(--shadow);
  transition: opacity 0.4s, transform 0.4s;
}
.toast-errore { background: var(--danger); color: #fff; }
.toast-avviso { background: var(--warning); color: #111; }
.toast.via { opacity: 0; transform: translate(-50%, 12px); }

.loading { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 80px 20px; color: var(--text-3); }
.spinner { width: 40px; height: 40px; border-radius: 50%; border: 4px solid var(--border); border-top-color: var(--brand); animation: gira 0.8s linear infinite; }
@keyframes gira { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } .toast { transition: none; } }
