:root {
  --bg: #eef1f4; --card: #ffffff; --ink: #14202b; --muted: #5d6b78; --line: #d8dee4;
  --accent: #e8a317; --accent-ink: #1b1300; --head: #14202b; --head-ink: #f5f7f9;
  --ok: #1f8a4c; --ok-bg: #e3f4ea; --warn: #b26a00; --warn-bg: #fff2d9; --bad: #c0352b; --bad-bg: #fde5e3;
  --r: 14px; --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0d151c; --card: #17222c; --ink: #e8edf1; --muted: #93a2af; --line: #2a3845;
    --head: #0a1117; --ok-bg: #12301f; --warn-bg: #3a2a0c; --bad-bg: #3b1714; --ok: #4cc27f; --warn: #f0b440; --bad: #ff7a6e; color-scheme: dark; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; color: inherit; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 12px; background: var(--head); color: var(--head-ink); }
.brand { font-size: 12px; letter-spacing: .14em; text-transform: uppercase; color: var(--accent); font-weight: 700; }
.brand.big { font-size: 20px; }
.top h1 { margin: 0; font-size: 22px; }
.icon-btn { background: none; border: 0; padding: 8px; border-radius: 10px; color: inherit; cursor: pointer; min-width: 40px; min-height: 40px; }
.top .icon-btn { background: rgba(255,255,255,.08); }

main { padding: 12px 16px calc(90px + var(--safe-b)); max-width: 720px; margin: 0 auto; }
.view { display: none; } .view.active { display: block; }

.tabs { position: fixed; bottom: 0; left: 0; right: 0; z-index: 6; display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--card); border-top: 1px solid var(--line); padding-bottom: var(--safe-b); }
.tabs button { background: none; border: 0; padding: 8px 2px 6px; display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--muted); font-size: 11px; cursor: pointer; }
.tabs button.on { color: var(--ink); font-weight: 700; }
.tabs button.on svg { stroke: var(--accent); }

.searchbar input, .field input, .field select, .field textarea, .inline input, textarea {
  width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); }
textarea { min-height: 180px; resize: vertical; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 10px 0 4px; scrollbar-width: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--card); padding: 6px 12px; border-radius: 99px; font-size: 14px; cursor: pointer; }
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.summary { color: var(--muted); font-size: 13px; margin: 6px 2px 8px; }
.banner { background: var(--warn-bg); color: var(--warn); border-radius: 12px; padding: 10px 12px; font-size: 14px; margin: 6px 0 10px; }
.banner.ok { background: var(--ok-bg); color: var(--ok); } .banner.bad { background: var(--bad-bg); color: var(--bad); }

.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.item { display: flex; align-items: center; gap: 12px; background: var(--card); border-radius: var(--r); padding: 10px 12px; cursor: pointer; border-left: 4px solid transparent; }
.item.s-zero { border-left-color: var(--bad); } .item.s-low { border-left-color: var(--warn); }
.item .mid { flex: 1; min-width: 0; }
.item .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .sub { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .qty { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.item .qty small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.s-zero .qty { color: var(--bad); } .s-low .qty { color: var(--warn); }

.thumb { width: 46px; height: 46px; border-radius: 10px; object-fit: cover; flex: none; background: var(--line); }
.thumb.ph, .big.ph { display: grid; place-items: center; font-weight: 800; color: #fff; background: hsl(var(--h) 45% 42%); font-size: 15px; }
.big { width: 120px; height: 120px; border-radius: 14px; object-fit: cover; display: block; }
.big.ph { font-size: 28px; }

.fab { position: fixed; right: 16px; bottom: calc(76px + var(--safe-b)); z-index: 4; background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 99px; padding: 14px 20px; font-weight: 700; box-shadow: 0 6px 18px rgba(0,0,0,.2); cursor: pointer; }

.btn { border: 1px solid var(--line); background: var(--card); padding: 10px 14px; border-radius: 12px; cursor: pointer; font-weight: 600; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--bad); }
.btn.big { display: block; width: 100%; padding: 16px; font-size: 17px; margin-top: 10px; text-align: left; }
.btn.tiny { padding: 6px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; }
.link { background: none; border: 0; color: var(--accent); text-decoration: underline; padding: 0; cursor: pointer; font-weight: 600; }
.inline { display: flex; gap: 8px; align-items: center; }
.inline input { flex: 1; }
.muted { color: var(--muted); } .small { font-size: 13px; }
.err { color: var(--bad); min-height: 1.2em; }

.hero { background: var(--card); border-radius: var(--r); padding: 18px 16px; }
.hero h2 { margin: 0 0 4px; }
.hero p { margin: 0 0 6px; color: var(--muted); }
h3.sec { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 22px 2px 8px; }
.card { background: var(--card); border-radius: var(--r); padding: 12px 14px; margin: 10px 0; }
.card h3 { margin: 0 0 8px; font-size: 15px; }

.draft-head { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.draft-head label { font-size: 12px; color: var(--muted); }
.draft-head input { width: 100%; margin-top: 2px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); }
.draft-head .full { grid-column: 1 / -1; }
.rows { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.row { background: var(--card); border-radius: var(--r); padding: 10px 12px; border-left: 4px solid var(--line); }
.row.r-ok { border-left-color: var(--ok); } .row.r-warn { border-left-color: var(--warn); } .row.r-bad { border-left-color: var(--bad); }
.row-prod { display: flex; align-items: center; gap: 10px; width: 100%; background: none; border: 0; padding: 0; text-align: left; cursor: pointer; }
.row-prod .thumb { width: 40px; height: 40px; }
.rp-name { flex: 1; font-weight: 600; }
.tag-q { background: var(--warn-bg); color: var(--warn); border-radius: 99px; padding: 2px 8px; font-size: 12px; font-weight: 700; }
.raw { font-size: 12px; color: var(--muted); margin: 6px 0 0; font-family: ui-monospace, monospace; word-break: break-word; }
.row-bot { display: flex; align-items: center; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.row-bot input { width: 84px; padding: 8px; border: 1px solid var(--line); border-radius: 10px; text-align: center; background: var(--bg); font-weight: 700; }
.qbtn { width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); font-size: 20px; cursor: pointer; }
.row-bot .unit { font-weight: 600; margin-right: auto; }
.st { font-size: 13px; margin-top: 6px; font-weight: 600; }
.r-ok .st { color: var(--ok); } .r-warn .st { color: var(--warn); } .r-bad .st { color: var(--bad); }
.alts { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; font-size: 13px; align-items: center; }
.newcode { font-size: 13px; margin-top: 6px; color: var(--warn); }
.draft-add { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.draft-add .btn { flex: 1; min-width: 30%; }
.draft-foot { position: sticky; bottom: calc(64px + var(--safe-b)); display: flex; gap: 8px; padding: 10px 0; background: linear-gradient(transparent, var(--bg) 30%); }
.draft-foot .primary { flex: 1; }
details { background: var(--card); border-radius: var(--r); padding: 10px 14px; margin: 10px 0; }
details pre { white-space: pre-wrap; font-size: 12px; max-height: 260px; overflow: auto; }

.log-day { font-size: 13px; color: var(--muted); margin: 16px 2px 6px; font-weight: 700; }
.mv { display: flex; gap: 10px; align-items: center; background: var(--card); border-radius: 12px; padding: 10px 12px; margin-bottom: 6px; }
.mv .ic { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; flex: none; }
.mv.in .ic { background: var(--ok-bg); color: var(--ok); } .mv.out .ic { background: var(--warn-bg); color: var(--warn); } .mv.adj .ic { background: var(--line); }
.mv .mid { flex: 1; min-width: 0; } .mv .mid div:first-child { font-weight: 600; }
.mv.undone { opacity: .45; text-decoration: line-through; }
.mv .q { font-weight: 700; font-variant-numeric: tabular-nums; }

.sheet { position: fixed; inset: 0; z-index: 20; }
.sheet-bg { position: absolute; inset: 0; background: rgba(0,0,0,.45); }
.sheet-card { position: absolute; left: 0; right: 0; bottom: 0; max-height: 92vh; background: var(--bg); border-radius: 20px 20px 0 0; display: flex; flex-direction: column; max-width: 720px; margin: 0 auto; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 4px 16px; }
.sheet-head h2 { margin: 0; font-size: 18px; }
.sheet-body { overflow-y: auto; padding: 4px 16px calc(20px + var(--safe-b)); }
.field { display: block; margin: 10px 0; } .field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.pv-head { display: flex; gap: 14px; align-items: center; }
.pv-photo { position: relative; cursor: pointer; background: none; border: 0; padding: 0; border-radius: 14px; }
.pv-photo span { position: absolute; bottom: 4px; left: 4px; right: 4px; background: rgba(0,0,0,.55); color: #fff; font-size: 11px; border-radius: 8px; text-align: center; padding: 2px; }
.pv-stock { font-size: 28px; font-weight: 800; } .pv-stock.s-zero { color: var(--bad); } .pv-stock.s-low { color: var(--warn); }
.codes { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.code { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 3px 8px; font-size: 13px; font-family: ui-monospace, monospace; }
.code b { font-family: system-ui; font-weight: 600; color: var(--muted); margin-right: 4px; }
.syns { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.syn { background: var(--bg); border-radius: 99px; padding: 4px 6px 4px 10px; font-size: 14px; display: inline-flex; align-items: center; gap: 2px; }
.syn.learn { font-style: italic; }
.syn button { background: none; border: 0; padding: 0 4px; cursor: pointer; color: var(--muted); }
.actions { display: flex; gap: 8px; margin-top: 14px; } .actions .btn { flex: 1; }
.pick-list .item { margin-bottom: 6px; }

.scanner { position: fixed; inset: 0; z-index: 30; background: #000; }
.scanner video { width: 100%; height: 100%; object-fit: cover; }
.scan-frame { position: absolute; left: 10%; right: 10%; top: 32%; height: 22%; border: 3px solid var(--accent); border-radius: 16px; box-shadow: 0 0 0 9999px rgba(0,0,0,.35); }
.scan-ui { position: absolute; left: 16px; right: 16px; bottom: calc(24px + var(--safe-b)); display: grid; gap: 10px; color: #fff; text-align: center; }
.scan-ui input { background: rgba(255,255,255,.95); color: #111; }

.busy { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.5); display: grid; place-items: center; }
.busy-card { background: var(--card); border-radius: 18px; padding: 22px; width: min(320px, 86vw); text-align: center; }
.spinner { width: 36px; height: 36px; border: 4px solid var(--line); border-top-color: var(--accent); border-radius: 50%; margin: 0 auto 10px; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.bar { height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; } .bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }

.lock { position: fixed; inset: 0; z-index: 50; background: var(--head); display: grid; place-items: center; color: var(--head-ink); }
.lock-card { display: grid; gap: 12px; width: min(300px, 86vw); text-align: center; }
.lock-card input { padding: 14px; font-size: 24px; text-align: center; letter-spacing: .4em; border-radius: 12px; border: 0; color: #111; }

.toast { position: fixed; left: 50%; bottom: calc(84px + var(--safe-b)); transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none; z-index: 60;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600; transition: .25s; max-width: 90vw; text-align: center; }
.toast.show { opacity: 1; transform: translateX(-50%); } .toast.ok { background: var(--ok); color: #fff; } .toast.err { background: var(--bad); color: #fff; }
.hidden { display: none !important; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }

/* Anteprima foto a schermo intero */
.viewer { position: fixed; inset: 0; z-index: 35; background: rgba(6,10,14,.97); display: flex; flex-direction: column; color: #f2f5f7;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px); }
.v-top { display: flex; justify-content: flex-end; padding: 8px 10px 0; }
.v-top .icon-btn { color: #f2f5f7; background: rgba(255,255,255,.12); font-size: 18px; }
.v-img { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 8px 12px; }
.v-img img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 12px; }
.v-info { background: var(--card); color: var(--ink); border-radius: 18px 18px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom, 0px)); display: grid; gap: 4px; }
.v-name { font-weight: 700; font-size: 18px; }
.v-desc, .v-meta { color: var(--muted); font-size: 14px; }
.v-meta { font-family: ui-monospace, monospace; font-size: 12px; }
.v-stock { font-size: 22px; font-weight: 800; margin-top: 4px; } .v-stock small { font-size: 13px; font-weight: 400; color: var(--muted); }
.v-stock.s-zero { color: var(--bad); } .v-stock.s-low { color: var(--warn); }
.v-actions { display: flex; gap: 8px; margin-top: 10px; } .v-actions .btn { flex: 1; }

/* Fix larghezza: le righe non devono mai allargare la pagina (su Android la pagina si rimpiccioliva tutta) */
.list, .rows { grid-template-columns: minmax(0, 1fr); }
.item, .row, .mv { min-width: 0; }
html, body { overflow-x: hidden; max-width: 100%; }
/* Miniature più grandi in elenco */
.thumb { width: 60px; height: 60px; border-radius: 12px; }
.item { padding: 10px 12px; gap: 14px; }
.item .name { font-size: 16px; }
.item .name { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; line-height: 1.25; }

.raw { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 0; cursor: pointer; color: var(--muted); }
.raw-edit { font-family: system-ui; font-size: 12px; color: var(--accent); white-space: nowrap; }
.sugg { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 8px; font-size: 13px; color: var(--muted); }
.sugg .chip { font-size: 13px; padding: 5px 10px; }

/* Spazio per il badge "Powered by Netlify" sotto la barra delle schede */
body.nf-badge { --badge: 58px; }
body.nf-badge .tabs { padding-bottom: calc(var(--badge) + var(--safe-b)); }
body.nf-badge main { padding-bottom: calc(150px + var(--safe-b)); }
body.nf-badge .fab { bottom: calc(76px + var(--badge) + var(--safe-b)); }
body.nf-badge .toast { bottom: calc(84px + var(--badge) + var(--safe-b)); }
body.nf-badge .draft-foot { bottom: calc(64px + var(--badge) + var(--safe-b)); }
