/* Magazzino Laboratorio - stile */
:root {
  --bg: #F2F3F5; --card: #FFFFFF; --line: #E3E5E8; --tx: #1B1F24; --mut: #5F6672;
  --acc: #1F6FEB; --acctx: #FFFFFF; --accbg: #E8F0FD; --inb: #D1D5DB; --soft: #F7F8FA; --hov: #F5F8FD;
  --ok-bg: #DCFCE7; --ok: #15803D; --low-bg: #FFEDD5; --low: #C2410C; --out-bg: #FEE2E2; --out: #B91C1C;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04);
  --c-indigo-bg: #EEF2FF; --c-indigo: #4338CA; --c-purple-bg: #F3E8FF; --c-purple: #7E22CE;
  --c-pink-bg: #FCE7F3; --c-pink: #BE185D; --c-red-bg: #FEE2E2; --c-red: #B91C1C;
  --c-amber-bg: #FEF3C7; --c-amber: #A3480A; --c-teal-bg: #CCFBF1; --c-teal: #0F766E;
  --c-green-bg: #E3F6EE; --c-green: #047857; --c-sky-bg: #E0F2FE; --c-sky: #0369A1;
  --c-orange-bg: #FFEDD5; --c-orange: #C2410C; --c-slate-bg: #EEF0F3; --c-slate: #475467;
  --font: Inter, "Segoe UI", Roboto, system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono", "Cascadia Mono", "SF Mono", Consolas, ui-monospace, monospace;
  color-scheme: light;
}
[data-tema="scuro"] {
  --bg: #0F1115; --card: #171A21; --line: #2A2F3A; --tx: #E6E8EB; --mut: #9BA3AF;
  --acc: #6EA8FF; --acctx: #0B1220; --accbg: #1B2B4A; --inb: #3A404C; --soft: #1C2028; --hov: #1C2430;
  --ok-bg: #12351F; --ok: #4ADE80; --low-bg: #3B2410; --low: #FDBA74; --out-bg: #3D1515; --out: #FCA5A5;
  --shadow: none;
  --c-indigo-bg: #25264D; --c-indigo: #A5B4FC; --c-purple-bg: #33204A; --c-purple: #D8B4FE;
  --c-pink-bg: #3D1A2E; --c-pink: #F9A8D4; --c-red-bg: #3D1515; --c-red: #FCA5A5;
  --c-amber-bg: #3A2C0E; --c-amber: #FCD34D; --c-teal-bg: #0E3330; --c-teal: #5EEAD4;
  --c-green-bg: #0F3328; --c-green: #6EE7B7; --c-sky-bg: #0C2E44; --c-sky: #7DD3FC;
  --c-orange-bg: #3B2410; --c-orange: #FDBA74; --c-slate-bg: #262B35; --c-slate: #CBD2DC;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.45 var(--font); background: var(--bg); color: var(--tx); -webkit-text-size-adjust: 100%; }
a { color: var(--acc); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--acc); outline-offset: 2px; }
.mono { font-family: var(--mono); }
.mut { color: var(--mut); }
.small { font-size: 12px; color: var(--mut); }
.sr { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.ico { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.boot { padding: 40px; text-align: center; color: var(--mut); }
[hidden] { display: none !important; }

/* ---------- struttura */
.app { display: flex; min-height: 100vh; }
.side { width: 224px; flex: 0 0 224px; background: var(--card); border-right: 1px solid var(--line); padding: 18px 12px;
  display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.logo { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 15px; padding: 4px 10px 18px; white-space: nowrap; }
.mark { width: 28px; height: 28px; border-radius: 8px; background: var(--acc); color: var(--acctx); display: flex; align-items: center; justify-content: center; }
.nav { display: flex; align-items: center; gap: 10px; padding: 9px 10px; color: var(--mut); border-radius: 8px; text-decoration: none; white-space: nowrap; }
.nav:hover { background: var(--soft); color: var(--tx); }
.nav.on { background: var(--accbg); color: var(--acc); font-weight: 600; }
.side .foot { margin-top: auto; display: flex; flex-direction: column; gap: 6px; }
.main { flex: 1; min-width: 0; padding: 24px 28px 40px; display: flex; flex-direction: column; gap: 16px; max-width: 1480px; }
.tabbar { display: none; }

.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.h1 { margin: 0; font-size: 24px; font-weight: 700; letter-spacing: -.01em; }
.sub { color: var(--mut); font-size: 13px; margin-top: 4px; }
.acts { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.crumb { font-size: 13px; color: var(--mut); }
.crumb a { text-decoration: none; }

/* ---------- controlli */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; background: var(--acc); color: var(--acctx);
  border: 1px solid var(--acc); border-radius: 8px; padding: 0 16px; height: 40px; font-weight: 600; text-decoration: none; white-space: nowrap; cursor: pointer; }
.btn:hover { filter: brightness(1.06); }
.btn.sec { background: var(--card); color: var(--tx); border-color: var(--inb); }
.btn.sec:hover { background: var(--soft); filter: none; }
.btn.danger { background: var(--card); color: var(--out); border-color: var(--out); }
.btn.big { height: 48px; font-size: 15px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.link { background: none; border: 0; padding: 0; color: var(--acc); font-weight: 600; cursor: pointer; }
.in { width: 100%; height: 40px; border: 1px solid var(--inb); border-radius: 8px; padding: 0 12px; background: var(--card); color: var(--tx); min-width: 0; }
textarea.in { height: auto; min-height: 80px; padding: 10px 12px; resize: vertical; }
select.in { padding-right: 28px; }
.in:focus { border-color: var(--acc); outline: none; box-shadow: 0 0 0 3px var(--accbg); }
.in.err { border-color: var(--out); }
.field label, .lbl { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.field .hint { font-size: 12px; color: var(--mut); margin-top: 5px; }
.field .warn { font-size: 12px; color: var(--low); margin-top: 6px; display: flex; gap: 5px; align-items: center; font-weight: 600; }
.seg { display: inline-flex; border: 1px solid var(--inb); border-radius: 8px; overflow: hidden; height: 40px; background: var(--card); }
.seg button { border: 0; border-right: 1px solid var(--line); background: none; color: var(--mut); padding: 0 12px; font-weight: 600; font-size: 13px;
  cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--accbg); color: var(--acc); }
.cnt { font-size: 11px; font-weight: 700; background: var(--soft); color: var(--mut); border-radius: 999px; padding: 1px 7px; }
.seg button.on .cnt { background: var(--card); color: var(--acc); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
.pad { padding: 20px; }
.sec-t { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--mut); margin: 0 0 10px; }
.h2 { margin: 0 0 12px; font-size: 16px; font-weight: 600; }

.pill { display: inline-block; border-radius: 999px; padding: 3px 10px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.t-indigo { background: var(--c-indigo-bg); color: var(--c-indigo); } .t-purple { background: var(--c-purple-bg); color: var(--c-purple); }
.t-pink { background: var(--c-pink-bg); color: var(--c-pink); } .t-red { background: var(--c-red-bg); color: var(--c-red); }
.t-amber { background: var(--c-amber-bg); color: var(--c-amber); } .t-teal { background: var(--c-teal-bg); color: var(--c-teal); }
.t-green { background: var(--c-green-bg); color: var(--c-green); } .t-sky { background: var(--c-sky-bg); color: var(--c-sky); }
.t-orange { background: var(--c-orange-bg); color: var(--c-orange); } .t-slate { background: var(--c-slate-bg); color: var(--c-slate); }

.qty { display: inline-block; min-width: 44px; text-align: center; border-radius: 6px; padding: 3px 8px; font-weight: 700; font-variant-numeric: tabular-nums; }
.s-ok { background: var(--ok-bg); color: var(--ok); } .s-low { background: var(--low-bg); color: var(--low); } .s-out { background: var(--out-bg); color: var(--out); }
.c-ok { color: var(--ok); } .c-low { color: var(--low); } .c-out { color: var(--out); }
.meter { position: relative; width: 64px; height: 4px; border-radius: 2px; background: var(--line); display: block; }
.meter i { display: block; height: 100%; border-radius: 2px; }
.meter.has-min::after { content: ""; position: absolute; left: 50%; top: -2px; width: 1px; height: 8px; background: var(--mut); }
.f-ok { background: var(--ok); } .f-low { background: var(--low); } .f-out { background: var(--out); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; vertical-align: middle; }
.loc { display: inline-flex; align-items: center; gap: 5px; font-family: var(--mono); font-size: 12.5px; white-space: nowrap; }
.loc .ico { width: 14px; height: 14px; color: var(--mut); }
.step { display: inline-flex; gap: 6px; }
.step button { width: 36px; height: 36px; border: 1px solid var(--inb); border-radius: 8px; background: var(--card); color: var(--tx); font-size: 17px; line-height: 1; cursor: pointer; }
.step button:hover { border-color: var(--acc); color: var(--acc); }
.step button:disabled { opacity: .35; cursor: not-allowed; }

/* ---------- inventario */
.bar { padding: 12px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.bar select.in { width: auto; flex: 0 1 auto; }
.search { position: relative; flex: 1 1 280px; min-width: 0; }
.search .ico { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--mut); }
.search .in { padding-left: 36px; }
.meta { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 12px; color: var(--mut); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; }

.tbl { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; min-width: 980px; }
table.grid th { padding: 11px 12px; font-size: 11px; font-weight: 600; color: var(--mut); text-transform: uppercase; letter-spacing: .05em;
  background: var(--soft); border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
table.grid td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.grid tr:last-child td { border-bottom: 0; }
table.grid tbody tr:hover td { background: var(--hov); }
.thumb { width: 40px; height: 40px; border-radius: 8px; object-fit: cover; background: var(--soft); border: 1px solid var(--line); display: block; }
.thumb.none { display: flex; align-items: center; justify-content: center; color: var(--mut); }
.namecell { display: flex; gap: 12px; align-items: center; min-width: 0; }
.name { color: var(--tx); font-weight: 600; text-decoration: none; }
.name:hover { color: var(--acc); text-decoration: underline; }
.stock { display: flex; flex-direction: column; gap: 5px; align-items: flex-start; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.icard { padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.crow { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.icard .thumb { width: 56px; height: 56px; }
.empty { border: 1px dashed var(--inb); border-radius: 12px; padding: 44px 20px; text-align: center; color: var(--mut); background: var(--card); }
.empty b { display: block; color: var(--tx); font-size: 15px; margin-bottom: 6px; }

/* ---------- dettaglio */
.two { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.col { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.photo { border-radius: 10px; background: var(--soft); border: 1px dashed var(--inb); aspect-ratio: 4 / 3; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 8px; color: var(--mut); overflow: hidden; }
.photo img { width: 100%; height: 100%; object-fit: contain; background: var(--soft); }
.photo-acts { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 10px 12px; margin: 0; }
.kv dt { color: var(--mut); } .kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.path { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.lv { background: var(--soft); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.lv span { display: block; font-size: 11px; color: var(--mut); }
.lv b { display: block; font-family: var(--mono); font-size: 18px; margin-top: 2px; min-height: 1.3em; }
.qbox { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.qbig { font-size: 40px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.qbox .step button { width: 44px; height: 44px; font-size: 20px; }
.moveform { display: grid; grid-template-columns: 110px minmax(0, 1fr) auto auto; gap: 8px; margin-top: 14px; }
.hist { width: 100%; border-collapse: collapse; }
.hist th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--mut); font-weight: 600; padding: 8px 12px 8px 0; white-space: nowrap; }
.hist td { padding: 9px 12px 9px 0; border-top: 1px solid var(--line); white-space: nowrap; }
.hist td.wrap { white-space: normal; }
.mv-in { color: var(--ok); font-weight: 600; } .mv-out { color: var(--out); font-weight: 600; } .mv-adj { color: var(--mut); font-weight: 600; }

/* ---------- form */
.formgrid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.5fr); gap: 20px; align-items: start; }
.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 18px; }
.span2 { grid-column: 1 / -1; }
.loc3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.loc3 label { font-weight: 500; color: var(--mut); font-size: 12px; }
.drop { border: 2px dashed var(--inb); background: var(--soft); border-radius: 12px; min-height: 260px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 10px; text-align: center; padding: 20px; position: relative; overflow: hidden; }
.drop.over { border-color: var(--acc); background: var(--accbg); }
.drop img { max-width: 100%; max-height: 320px; border-radius: 8px; object-fit: contain; }
.drop .t { font-weight: 600; color: var(--acc); font-size: 15px; }
.formacts { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }

/* ---------- dashboard */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.kpi { padding: 16px 18px; text-decoration: none; color: var(--tx); display: block; }
.kpi:hover { border-color: var(--acc); }
.kpi .n { font-size: 32px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.lists { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.ritem { display: flex; justify-content: space-between; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; text-decoration: none; color: var(--tx); }
.ritem:hover { border-color: var(--acc); }
.group + .group { margin-top: 16px; }

/* ---------- impostazioni */
.rows { display: flex; flex-direction: column; }
.srow { display: grid; grid-template-columns: minmax(0, 1fr) 130px auto auto; gap: 8px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }
.srow:first-child { border-top: 0; }
.srow.forn { grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr) auto auto; }
.add-row { display: flex; gap: 8px; margin-top: 12px; }

/* ---------- login */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login .card { width: 100%; max-width: 380px; padding: 28px; display: flex; flex-direction: column; gap: 16px; }
.login .err { color: var(--out); font-size: 13px; font-weight: 600; }

/* ---------- avvisi */
#toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 50; width: max-content; max-width: calc(100vw - 32px); }
.toast { background: #1B1F24; color: #fff; border-radius: 10px; padding: 11px 16px; font-weight: 500; box-shadow: 0 8px 24px rgba(0,0,0,.25); }
.toast.err { background: #B91C1C; }
[data-tema="scuro"] .toast { background: #E6E8EB; color: #0F1115; }
[data-tema="scuro"] .toast.err { background: #FCA5A5; color: #3D1515; }
.overlay { position: fixed; inset: 0; background: rgba(10,12,16,.82); display: flex; align-items: center; justify-content: center; z-index: 40; padding: 20px; border: 0; cursor: zoom-out; }
.overlay img { max-width: 100%; max-height: 100%; border-radius: 8px; }

/* ---------- responsive */
@media (max-width: 1100px) {
  .two, .formgrid, .lists { grid-template-columns: minmax(0, 1fr); }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 820px) {
  .side { display: none; }
  .main { padding: 16px 14px 96px; gap: 14px; }
  .tabbar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--card); border-top: 1px solid var(--line);
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); justify-content: space-around; }
  .tabbar a, .tabbar button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 2px; font-size: 11px;
    color: var(--mut); text-decoration: none; background: none; border: 0; cursor: pointer; min-height: 48px; }
  .tabbar .on { color: var(--acc); font-weight: 600; }
  .tabbar .ico { width: 22px; height: 22px; }
  .tabbar .cam span.c { width: 46px; height: 46px; margin-top: -18px; border-radius: 50%; background: var(--acc); color: var(--acctx);
    display: flex; align-items: center; justify-content: center; box-shadow: 0 4px 14px rgba(31,111,235,.35); }
  .viewseg { display: none; }
  #toasts { bottom: 88px; }
}
@media (max-width: 640px) {
  .h1 { font-size: 21px; }
  .bar { padding: 10px; }
  .bar select.in { flex: 1 1 calc(50% - 5px); }
  .head { flex-wrap: nowrap; align-items: center; }
  .head .acts .btn { width: 44px; height: 44px; padding: 0; }
  .photo { aspect-ratio: 16 / 10; }
  .stseg { flex: 1 1 100%; }
  .stseg button { flex: 1; justify-content: center; }
  .step button { width: 44px; height: 44px; }
  .fields, .loc3 { grid-template-columns: minmax(0, 1fr); }
  .kv { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .kv dt { margin-top: 10px; font-size: 12px; }
  .moveform { grid-template-columns: 90px minmax(0, 1fr); }
  .moveform .btn { grid-column: span 1; }
  .head .acts .btn .lbl { display: none; }
  .formacts .btn { flex: 1; }
  .srow, .srow.forn { grid-template-columns: minmax(0, 1fr) auto auto; }
  .srow .in:nth-child(2) { grid-column: 1 / -1; order: 3; }
  .drop { min-height: 200px; }
}
@media (min-width: 641px) { .only-phone { display: none !important; } }
@media (max-width: 640px) { .only-wide { display: none !important; } }
.ico.big { width: 32px; height: 32px; }
