:root {
  --bg: #101311;
  --panel: #191d1a;
  --panel-2: #222723;
  --line: #2e3530;
  --text: #eef2ee;
  --muted: #8f9a92;
  --accent: #9fe870;
  --accent-ink: #10200a;
  --out: #f5b942;
  --late: #ff6b5e;
  --booked: #7fb2ff;
  --radius: 14px;
  --tabs-h: 64px;
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font-size: 16px; line-height: 1.4; padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 16px); }
main { max-width: 720px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 16px) 16px 0; }
a { color: inherit; text-decoration: none; }
h1 { font-size: 26px; margin: 4px 0 16px; letter-spacing: -0.02em; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 28px 0 10px; font-weight: 600; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 10px; align-items: center; }
.row > .grow { flex: 1; min-width: 0; }
.spacer { height: 12px; }
.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.topbar h1 { margin: 0; flex: 1; font-size: 22px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.back { font-size: 26px; padding: 4px 10px 4px 0; color: var(--muted); }

/* tab bar */
#tabs { position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-around; align-items: flex-end;
  background: rgba(16,19,17,.94); backdrop-filter: blur(12px); border-top: 1px solid var(--line);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); z-index: 10; }
#tabs a { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 10.5px; color: var(--muted); padding: 4px 0; white-space: nowrap; letter-spacing: -0.01em; }
body.auth #tabs { display: none; }
#tabs a.on { color: var(--text); }
#tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#tabs .scan-tab svg { width: 30px; height: 30px; padding: 12px; box-sizing: content-box; background: var(--accent); color: var(--accent-ink);
  border-radius: 50%; margin-top: -26px; box-shadow: 0 6px 20px rgba(0,0,0,.4); stroke-width: 2.2; }
#tabs .scan-tab { color: var(--text); }

/* buttons & forms */
button, .btn { font: inherit; border: 0; border-radius: 12px; padding: 13px 16px; background: var(--panel-2); color: var(--text);
  font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; }
button:disabled { opacity: .4; cursor: default; }
.primary { background: var(--accent); color: var(--accent-ink); }
.warn { background: var(--out); color: #231500; }
.danger { background: transparent; color: var(--late); border: 1px solid var(--line); }
.ghost { background: transparent; border: 1px solid var(--line); }
.block { width: 100%; }
.btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0; }
.btns.one { grid-template-columns: 1fr; }
label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 6px; font-weight: 500; }
input, select, textarea { font: inherit; width: 100%; padding: 13px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); min-height: 48px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
textarea { min-height: 80px; resize: vertical; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.seg { display: flex; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; min-height: 42px; background: transparent; color: var(--muted); padding: 8px; font-size: 14px; }
.seg button.on { background: var(--panel-2); color: var(--text); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin: 10px 0; scrollbar-width: none; }
.chips button { min-height: 36px; padding: 6px 14px; border-radius: 999px; font-size: 14px; font-weight: 500; white-space: nowrap;
  background: var(--panel); border: 1px solid var(--line); color: var(--muted); }
.chips button.on { background: var(--text); color: var(--bg); border-color: var(--text); }

/* list & cards */
.list { background: var(--panel); border-radius: var(--radius); overflow: hidden; }
.li { display: flex; align-items: center; gap: 12px; padding: 13px 14px; border-bottom: 1px solid var(--line); min-height: 60px; }
.li:last-child { border-bottom: 0; }
.li .grow { flex: 1; min-width: 0; }
.li .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.li .sub { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.li .x { background: none; min-height: 36px; padding: 6px 10px; color: var(--muted); font-size: 20px; }
.code { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12px; color: var(--muted); }
.empty { padding: 22px 14px; text-align: center; color: var(--muted); font-size: 14px; }
.card { background: var(--panel); border-radius: var(--radius); padding: 16px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 15px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.badge { font-size: 12px; font-weight: 600; padding: 4px 9px; border-radius: 999px; white-space: nowrap; }
.b-in { background: rgba(159,232,112,.14); color: var(--accent); }
.b-out { background: rgba(245,185,66,.15); color: var(--out); }
.b-late { background: rgba(255,107,94,.16); color: var(--late); }
.b-booked { background: rgba(127,178,255,.15); color: var(--booked); }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--panel); border-radius: var(--radius); padding: 14px; }
.stat b { display: block; font-size: 28px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }
.stat.late b { color: var(--late); }
.stat.out b { color: var(--out); }

.big-scan { display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; min-height: 64px; margin: 0;
  font-size: 17px; border-radius: 16px; }
.big-scan svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }

.alert { padding: 12px 14px; border-radius: 12px; font-size: 14px; margin: 10px 0; }
.alert.late { background: rgba(255,107,94,.12); color: #ffb3ab; }
.alert.info { background: rgba(127,178,255,.1); color: #bcd6ff; }
.alert.ok { background: rgba(159,232,112,.1); color: #cdf5b3; }

/* scanner */
#reader { width: 100%; border-radius: var(--radius); overflow: hidden; background: #000; min-height: 220px; position: relative; }
#reader video { width: 100%; height: 38vh; min-height: 220px; display: block; object-fit: cover; }
.scan-frame { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
.scan-frame i { width: 78%; height: 36%; border: 2px solid rgba(159,232,112,.9); border-radius: 12px; box-shadow: 0 0 0 100vmax rgba(0,0,0,.28); }
.torch { position: absolute; right: 10px; bottom: 10px; min-height: 44px; width: 44px; padding: 0; border-radius: 50%; background: rgba(0,0,0,.55); font-size: 20px; }
.torch.on { background: var(--accent); }
#reader.off { display: flex; align-items: center; justify-content: center; text-align: center; padding: 20px; color: var(--muted); font-size: 14px; }
.flash { animation: flash .5s; }
@keyframes flash { from { background: rgba(159,232,112,.35); } to { background: transparent; } }
.progress { height: 6px; background: var(--panel-2); border-radius: 3px; overflow: hidden; margin: 8px 0 4px; }
.progress i { display: block; height: 100%; background: var(--accent); transition: width .2s; }
.check { width: 24px; height: 24px; border-radius: 7px; border: 2px solid var(--line); flex: none; display: grid; place-items: center; font-size: 15px; }
.check.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.sticky-actions { position: sticky; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom)); padding: 12px 0; background: linear-gradient(transparent, var(--bg) 30%); }

/* bottom sheet */
#sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 20; }
#sheet { position: fixed; left: 0; right: 0; bottom: 0; max-height: 92vh; overflow-y: auto; background: var(--panel); z-index: 21;
  border-radius: 20px 20px 0 0; padding: 10px 16px calc(20px + env(safe-area-inset-bottom)); max-width: 720px; margin: 0 auto; }
#sheet::before { content: ""; display: block; width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 14px; }
#sheet h1 { font-size: 21px; }
#sheet input, #sheet select, #sheet textarea { background: var(--bg); }
#sheet .seg { background: var(--bg); }

#toast { position: fixed; left: 50%; top: calc(env(safe-area-inset-top) + 12px); transform: translate(-50%, -140%); transition: transform .25s;
  background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 12px; font-weight: 600; z-index: 30; max-width: 90vw; font-size: 15px; }
#toast.show { transform: translate(-50%, 0); }
#toast.err { background: var(--late); color: #fff; }

.pick-list { max-height: 50vh; overflow-y: auto; }

/* etichette */
.labels-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--lw, 62mm), 1fr)); gap: 3mm; margin-top: 16px; }
.label { background: #fff; color: #000; display: flex; gap: 2.5mm; align-items: center; padding: 2mm; border-radius: 2mm; border: 1px dashed #bbb;
  width: var(--lw, 62mm); height: var(--lh, 29mm); overflow: hidden; break-inside: avoid; }
.label svg { height: 100%; width: auto; flex: none; }
.label .lt { min-width: 0; font-family: -apple-system, Helvetica, Arial, sans-serif; }
.label .lc { font-weight: 800; font-size: 4.2mm; letter-spacing: .02em; }
.label .ln { font-size: 2.8mm; line-height: 1.2; max-height: 3.4em; overflow: hidden; }
.label .lb { font-size: 2.2mm; letter-spacing: .15em; margin-top: 1mm; color: #555; }
@media print {
  body { background: #fff; padding: 0; }
  #tabs, .no-print, #toast { display: none !important; }
  main { padding: 0; max-width: none; }
  .labels-grid { gap: 2mm; margin: 0; grid-template-columns: repeat(auto-fill, var(--lw, 62mm)); }
  .label { border-color: #ddd; }
}
@media (min-width: 720px) {
  #sheet { border-radius: 20px; bottom: 5vh; }
}

/* aggiunte v2 */
.small-btn { min-height: 38px; padding: 6px 12px; font-size: 14px; }
.li.tick { cursor: pointer; user-select: none; }
.li.tick:active { background: var(--panel-2); }
.auth-box { max-width: 380px; margin: 8vh auto 0; }
.auth-logo { display: block; width: 220px; max-width: 70%; margin: 0 auto 10px; }
.home-head { display: flex; align-items: center; margin-bottom: 14px; }
.home-logo { height: 30px; width: auto; opacity: .95; }
select { appearance: none; -webkit-appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 55%, calc(100% - 14px) 55%; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 36px; }

/* etichette codice a barre */
.label .lbar { width: 100%; }
.label.lqr { flex-direction: row; }
.labels-grid.lab-bar .label { flex-direction: column; align-items: stretch; justify-content: space-between; gap: 1mm; padding: 1.8mm 2.5mm; }
.label .lbar svg { display: block; }
.label .lrow { display: flex; align-items: center; gap: 2mm; min-width: 0; }
.label .lrow .lc { font-weight: 800; font-size: 3.6mm; letter-spacing: .02em; white-space: nowrap; }
.label .lrow .ln { flex: 1; min-width: 0; font-size: 2.6mm; line-height: 1.15; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.label .llogo { height: 3.4mm; width: auto; flex: none; }
.label.lqr .llogo { margin-top: 1mm; height: 3mm; }
.labels-grid.lab-flag .label { padding: 1mm 2mm; }
.labels-grid.lab-flag .lrow .lc { font-size: 2.8mm; }
.labels-grid.lab-flag .lrow .ln { font-size: 2.2mm; }
.labels-grid.lab-mini .lrow .ln { display: none; }
