:root {
  --ink: #1B1F23; --muted: #5B636B; --line: #DADDD8; --line2: #ECEEEA;
  --bg: #F3F4F1; --card: #FFFFFF; --head: #1F2A33; --head2: #2E3D49;
  --accent: #C2410C; --accent-ink: #FFFFFF; --ok: #2F6B3A; --bad: #B42318;
  --warn-bg: #FFF1D6; --warn: #7A4B00;
  --mono: ui-monospace, "Cascadia Mono", Consolas, "SF Mono", Menlo, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; font-size: 16px; }
body { min-height: 100vh; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }

#app { max-width: 720px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; }
header.top { background: var(--head); color: #fff; padding: 14px 16px; display: flex; align-items: center; gap: 8px;
  position: sticky; top: 0; z-index: 5; }
header.top h1 { margin: 0; font-size: 19px; font-weight: 600; flex: 1; }
.iconbtn { width: 44px; height: 44px; border: 0; background: transparent; color: inherit; display: inline-flex;
  align-items: center; justify-content: center; border-radius: 10px; cursor: pointer; text-decoration: none; flex: none; }
.iconbtn:hover { background: rgba(255,255,255,.08); }
.iconbtn svg { width: 22px; height: 22px; }
main { flex: 1; padding: 16px; display: flex; flex-direction: column; gap: 14px; padding-bottom: 96px; }

nav.bottom { position: fixed; left: 0; right: 0; bottom: 0; background: #fff; border-top: 1px solid var(--line);
  display: flex; justify-content: center; z-index: 5; padding-bottom: env(safe-area-inset-bottom); }
nav.bottom .in { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; width: 100%; max-width: 720px; }
nav.bottom a { height: 62px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 12px; color: var(--muted); text-decoration: none; }
nav.bottom a svg { width: 22px; height: 22px; }
nav.bottom a.on { color: var(--accent); font-weight: 600; }

.brandbar { background: #fff; padding: 12px 16px; justify-content: flex-start; display: flex; align-items: center; border-bottom: 3px solid var(--accent); }
.hero { background: var(--head); color: #fff; padding: 18px 16px 22px; display: flex; flex-direction: column; gap: 14px; }
.hero .who { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.hero .who b { font-size: 20px; font-weight: 600; display: block; }
.chip-dark { background: var(--head2); color: #fff; border: 0; padding: 8px 12px; border-radius: 999px; font-size: 13px; cursor: pointer; }
.searchbar { display: flex; align-items: center; gap: 8px; background: #fff; border-radius: 10px; padding: 0 4px 0 12px; height: 50px; color: var(--ink); }
.searchbar input { border: 0; outline: none; flex: 1; font-size: 16px; background: transparent; min-width: 0; }
.searchbar svg { width: 20px; height: 20px; flex: none; }

.bigbtns { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.bigbtn { height: 120px; border-radius: 14px; padding: 16px; display: flex; flex-direction: column; justify-content: space-between;
  text-decoration: none; font-size: 22px; font-weight: 700; border: 2px solid var(--head); background: #fff; }
.bigbtn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.bigbtn svg { width: 32px; height: 32px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.card.pad { padding: 14px 16px; }
.card h2, h2.sec { margin: 0; font-size: 14px; font-weight: 600; color: var(--muted); }
.card > .head { padding: 12px 16px 8px; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--line2); text-decoration: none; }
.card > .row:first-child { border-top: 0; }
.row .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row .title { font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; }
.qty { font-family: var(--mono); font-weight: 600; min-width: 44px; }
.qty.out { color: var(--bad); } .qty.in { color: var(--ok); }
.strike { text-decoration: line-through; opacity: .6; }

.item { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: flex; gap: 12px;
  align-items: center; text-decoration: none; }
.thumb { width: 56px; height: 56px; border-radius: 8px; background: #E4E7E2; object-fit: cover; flex: none;
  display: flex; align-items: center; justify-content: center; color: #7A828A; }
.item .tot { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.item .tot b { font-size: 22px; }
.badge { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--warn-bg); color: var(--warn); white-space: nowrap; }
.badge.gray { background: #ECEEEA; color: var(--muted); }

.pills { display: flex; gap: 8px; flex-wrap: wrap; }
.pill { height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid #C4C8C2; background: #fff; cursor: pointer; font-size: 14px; }
.pill.on { background: var(--head); border-color: var(--head); color: #fff; font-weight: 600; }

.btn { height: 52px; border-radius: 12px; border: 1px solid var(--head); background: #fff; padding: 0 18px; font-size: 16px;
  font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
.btn.small { height: 40px; font-size: 14px; padding: 0 12px; border-radius: 10px; }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn:disabled { opacity: .5; cursor: default; }
.btn svg { width: 20px; height: 20px; }
.actions { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 8px; }
.stickybar { position: sticky; bottom: 72px; background: var(--bg); padding-top: 8px; z-index: 3; }

label.f { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; }
label.f .hint { font-weight: 400; color: var(--muted); font-size: 13px; }
input.in, select.in, textarea.in { height: 50px; border-radius: 10px; border: 1px solid #C4C8C2; background: #fff; padding: 0 12px;
  font-size: 16px; font-weight: 400; width: 100%; }
textarea.in { height: auto; min-height: 80px; padding: 10px 12px; }
input.in:focus, select.in:focus, textarea.in:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.f2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.multi { display: flex; gap: 8px; align-items: center; }
.multi select { width: 38%; flex: none; }
fieldset.f { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
fieldset.f legend { font-size: 14px; font-weight: 600; margin-bottom: 8px; padding: 0; }
.opt { display: flex; align-items: center; gap: 12px; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; cursor: pointer; }
.opt input { width: 20px; height: 20px; margin: 0; accent-color: var(--accent); }
.opt:has(input:checked) { border: 2px solid var(--accent); padding: 11px 13px; }
.stepper { display: flex; gap: 10px; align-items: center; }
.stepper button { width: 56px; height: 56px; border-radius: 12px; border: 1px solid var(--head); background: #fff; font-size: 26px; cursor: pointer; }
.stepper input { flex: 1; height: 56px; text-align: center; font-size: 24px; font-weight: 700; }

.gallery { display: flex; gap: 8px; overflow-x: auto; scroll-snap-type: x mandatory; margin: 0 -16px; padding: 0 16px; }
.gallery img { height: 200px; max-width: 85%; border-radius: 12px; object-fit: cover; scroll-snap-align: start; background: #D9DDD6; }
.gallery .ph { height: 160px; width: 100%; border-radius: 12px; background: #D9DDD6; display: flex; align-items: center; justify-content: center; color: #6B737B; }
.codes { display: flex; flex-wrap: wrap; gap: 6px; }
.code { font-size: 12px; background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; }
.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.kv > div { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; }
.kv dt { font-size: 12px; color: var(--muted); } .kv dd { margin: 2px 0 0; font-weight: 600; }
dl { margin: 0; }
.titlebar { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.titlebar h1 { margin: 0; font-size: 22px; line-height: 1.2; }
.bignum { font-size: 30px; font-weight: 700; line-height: 1; text-align: right; }

.msg { padding: 12px 14px; border-radius: 10px; background: #FDECEA; color: var(--bad); font-size: 14px; }
.msg.info { background: #E7F1FB; color: #17406B; }
#toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: var(--head); color: #fff;
  padding: 12px 18px; border-radius: 10px; font-size: 15px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 20; max-width: 90vw; }
#toast.show { opacity: 1; }

.scanbox { background: #11171C; border-radius: 14px; overflow: hidden; min-height: 300px; }
#reader video { border-radius: 14px; }
.labelprev { width: 100%; height: auto; border: 2px dashed #A9AEA7; border-radius: 12px; background: #fff; }
.tabs { display: flex; gap: 6px; overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th, table.t td { text-align: left; padding: 8px 10px; border-top: 1px solid var(--line2); vertical-align: top; }
table.t th { font-size: 12px; color: var(--muted); font-weight: 600; border-top: 0; }
.scroll { overflow-x: auto; }
.login { max-width: 380px; width: calc(100% - 32px); margin: 10vh auto 0; padding: 28px 24px; display: flex; flex-direction: column; gap: 16px; background: #fff; border: 1px solid var(--line); border-top: 4px solid var(--head); border-radius: 16px; }
.login h1 { margin: 0; font-size: 26px; }
details summary { cursor: pointer; font-weight: 600; padding: 4px 0; }

/* Foglio etichette stampabile: A4, 3 x 8 etichette 70 x 37 mm */
.sheet { display: none; }
@media print {
  @page { size: A4; margin: 0; }
  body { background: #fff; }
  #app > *:not(.sheet), nav.bottom, #toast { display: none !important; }
  #app { max-width: none; }
  .sheet { display: grid !important; grid-template-columns: repeat(3, 70mm); grid-auto-rows: 37.125mm; }
  .lab { padding: 3mm; display: flex; gap: 2.5mm; align-items: center; overflow: hidden; break-inside: avoid; font-family: Arial, sans-serif; }
  .lab img { width: 28mm; height: 28mm; flex: none; }
  .lab .c { font-family: Consolas, monospace; font-weight: 700; font-size: 10pt; }
  .lab .d { font-size: 8pt; line-height: 1.15; max-height: 3.5em; overflow: hidden; margin: 1mm 0; }
  .lab .p { font-family: Consolas, monospace; font-size: 8pt; }
}
@media (min-width: 700px) { .bigbtn { height: 140px; } }
