/* ============ Crifarma Warehouse — design system ============ */
:root {
  --accent: #0e8a63;
  --accent-strong: #0a6d4e;
  --accent-soft: #e6f4ef;
  --bg: #f5f7f6;
  --surface: #ffffff;
  --surface-2: #eef1f0;
  --ink: #17221e;
  --muted: #66756f;
  --line: #e3e8e6;
  --red: #d64533;
  --red-soft: #fdecea;
  --amber: #cf7d00;
  --amber-soft: #fdf2e0;
  --ok-soft: #e6f4ef;
  --radius: 16px;
  --radius-s: 11px;
  --shadow: 0 1px 3px rgba(15, 30, 25, .06), 0 4px 16px rgba(15, 30, 25, .05);
  --shadow-lg: 0 8px 32px rgba(15, 30, 25, .16);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --sidebar-w: 264px;
}
[data-theme="dark"] {
  --accent: #2fbf8f;
  --accent-strong: #27a97e;
  --accent-soft: #12332a;
  --bg: #0e1513;
  --surface: #16201c;
  --surface-2: #1d2925;
  --ink: #e8f0ec;
  --muted: #8da39a;
  --line: #24312c;
  --red: #ff7a68;
  --red-soft: #3a1f1b;
  --amber: #ffb35c;
  --amber-soft: #3a2c15;
  --ok-soft: #12332a;
  --shadow: 0 1px 3px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.5);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Inter, sans-serif;
  background: var(--bg); color: var(--ink);
  padding-bottom: calc(70px + var(--safe-b));
  overscroll-behavior-y: contain;
  transition: background .25s ease, color .25s ease;
}
h2 { font-size: 1.35rem; margin: 6px 0 14px; letter-spacing: -.02em; }
h3 { font-size: 1rem; margin: 0 0 8px; letter-spacing: -.01em; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.hidden { display: none !important; }
svg { display: block; }

/* ============ Topbar ============ */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 10px;
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
  padding: calc(8px + env(safe-area-inset-top, 0px)) 12px 8px;
}
.brand { font-weight: 800; font-size: 1.02rem; letter-spacing: -.02em; flex: 1; }
.brand span { font-weight: 500; color: var(--accent); }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:active { background: var(--surface-2); }
.op-badge {
  background: var(--accent-soft); color: var(--accent-strong); border: 0;
  padding: 9px 14px; border-radius: 999px; font-size: .84rem; font-weight: 700; cursor: pointer;
}
[data-theme="dark"] .op-badge { color: var(--accent); }

main { padding: 16px; max-width: 760px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }

/* ============ Sidebar ============ */
.drawer-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 40; }
.drawer {
  position: fixed; top: 0; left: 0; bottom: 0; width: 84%; max-width: var(--sidebar-w); z-index: 45;
  background: var(--surface); box-shadow: var(--shadow-lg);
  transform: translateX(-100%); transition: transform .22s ease;
  display: flex; flex-direction: column; padding-bottom: 20px; overflow-y: auto;
}
.drawer.open { transform: translateX(0); }
.drawer-head {
  font-weight: 800; font-size: 1.05rem; letter-spacing: -.02em;
  padding: calc(18px + env(safe-area-inset-top,0px)) 20px 16px;
  border-bottom: 1px solid var(--line);
}
.drawer-head span { color: var(--accent); font-weight: 500; }
.drawer-item {
  display: flex; align-items: center; justify-content: space-between; width: 100%; text-align: left;
  background: transparent; border: 0; cursor: pointer;
  padding: 14px 20px; font-size: .96rem; font-weight: 600; color: var(--ink);
  font-family: inherit;
}
.drawer-item:hover { background: var(--surface-2); }
.drawer-item.active-nav { background: var(--accent-soft); color: var(--accent-strong); box-shadow: inset 3px 0 0 var(--accent); }
[data-theme="dark"] .drawer-item.active-nav { color: var(--accent); }
.drawer-item.soon { color: var(--muted); font-weight: 500; cursor: default; }
.drawer-item.soon:hover { background: transparent; }
.drawer-sep { font-size: .7rem; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); padding: 16px 20px 6px; font-weight: 700; }
.mini-tag { font-size: .68rem; font-weight: 700; color: var(--accent); }

/* Desktop: sidebar fissa, contenuto adattato */
@media (min-width: 1024px) {
  .drawer { transform: none; box-shadow: none; border-right: 1px solid var(--line); width: var(--sidebar-w); }
  .drawer-overlay { display: none !important; }
  .topbar { margin-left: var(--sidebar-w); }
  main { margin-left: calc(var(--sidebar-w) + max(0px, (100% - var(--sidebar-w) - 760px) / 2)); max-width: 760px; }
  .tabbar { display: none; }
  #menuBtn { display: none; }
  body { padding-bottom: 30px; }
}

/* ============ Bottoni ============ */
button { font-family: inherit; cursor: pointer; }
.btn-primary {
  background: var(--accent); color: #fff; border: 0; border-radius: var(--radius-s);
  padding: 13px 18px; font-weight: 700; font-size: .95rem; box-shadow: var(--shadow);
  transition: background .15s ease, transform .05s ease;
}
.btn-primary:active { background: var(--accent-strong); transform: scale(.98); }
.btn-primary.big, .btn-ghost.big { width: 100%; padding: 16px; font-size: 1.05rem; }
.btn-ghost {
  background: var(--surface); color: var(--ink); border: 1px solid var(--line);
  border-radius: var(--radius-s); padding: 12px 15px; font-weight: 600;
  transition: background .15s ease;
}
.btn-ghost:active { background: var(--surface-2); }
.btn-danger { background: var(--red); color: #fff; border: 0; border-radius: var(--radius-s); padding: 13px 18px; font-weight: 700; }
.small-btn { padding: 7px 12px; font-size: .8rem; border-radius: 9px; }

/* ============ Mode switch ============ */
.mode-switch {
  display: grid; grid-template-columns: 1fr 1fr; gap: 5px;
  background: var(--surface-2); padding: 5px; border-radius: 13px; margin-bottom: 12px;
}
.mode-btn {
  border: 0; background: transparent; padding: 12px; border-radius: 9px;
  font-weight: 700; font-size: .98rem; color: var(--muted);
}
.mode-btn.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.mode-btn.active[data-mode="uscita"] { color: var(--red); }

/* ============ Barra preparazione attiva ============ */
.bancale-bar {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--amber-soft); border: 1px solid color-mix(in srgb, var(--amber) 35%, transparent);
  border-radius: var(--radius-s); padding: 10px 14px; margin-bottom: 12px;
}
.bancale-bar small { color: var(--amber); font-weight: 700; }
.bancale-bar div > div { font-weight: 700; }

/* ============ Scanner ============ */
.scanner-wrap {
  position: relative; width: 100%; aspect-ratio: 3/4; max-height: 62vh;
  background: #0a100e; border-radius: var(--radius); overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
#video { width: 100%; height: 100%; object-fit: cover; }
.scan-frame {
  position: absolute; inset: 30% 6%;
  border: 2.5px solid rgba(255,255,255,.92); border-radius: 14px;
  box-shadow: 0 0 0 100vmax rgba(0,0,0,.25);
  pointer-events: none;
}
.scan-hint {
  position: absolute; bottom: 12px; left: 12px; right: 12px;
  color: #fff; text-align: center; font-size: .85rem; text-shadow: 0 1px 3px #000;
}
.scanner-wrap.flash-ok::after, .scanner-wrap.flash-err::after {
  content: ''; position: absolute; inset: 0; pointer-events: none; animation: flashfade .55s ease forwards;
}
.scanner-wrap.flash-ok::after { box-shadow: inset 0 0 0 7px #2fbf8f; background: rgba(47,191,143,.12); }
.scanner-wrap.flash-err::after { box-shadow: inset 0 0 0 7px var(--red); background: rgba(214,69,51,.12); }
@keyframes flashfade { from { opacity: 1; } to { opacity: 0; } }
.scan-actions { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }

.rapido-toggle {
  display: flex; align-items: center; gap: 11px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius-s); padding: 12px 14px;
  margin: 12px 0; font-weight: 600; box-shadow: var(--shadow); cursor: pointer;
}
.rapido-toggle input { width: 22px; height: 22px; margin: 0; flex: none; accent-color: var(--accent); }
.rapido-toggle small { font-weight: 400; color: var(--muted); display: block; margin-top: 2px; }

/* ============ Liste ============ */
.recent-list { list-style: none; padding: 0; margin: 0; }
.recent-list li {
  display: flex; justify-content: space-between; gap: 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-s);
  padding: 10px 13px; margin-bottom: 6px; font-size: .88rem; box-shadow: var(--shadow);
}
.tag { font-weight: 800; }
.tag.in { color: var(--accent); }
.tag.out { color: var(--red); }
.pend-badge { font-size: .7rem; font-weight: 700; padding: 3px 9px; border-radius: 999px; vertical-align: middle; }
.pend-badge.has { background: var(--amber-soft); color: var(--amber); }
.pend-badge.off { background: var(--red-soft); color: var(--red); }

.search, input[type=text], input[type=number], input[type=search], textarea, select {
  width: 100%; padding: 12px 14px; border: 1px solid var(--line);
  border-radius: var(--radius-s); font-size: 1rem; background: var(--surface); margin-bottom: 10px;
  color: var(--ink); font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); border-color: var(--accent); }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.filebtn {
  display: block; text-align: center; background: var(--accent); color: #fff;
  padding: 14px; border-radius: var(--radius-s); font-weight: 700; margin: 8px 0; cursor: pointer;
}
.upload-result { font-size: .88rem; margin-top: 8px; }
.upload-result.ok { color: var(--accent); }
.upload-result.err { color: var(--red); }

.stock-list, .bancali-list { display: flex; flex-direction: column; gap: 8px; }
.stock-row, .bancale-row {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-s);
  padding: 13px 15px; box-shadow: var(--shadow);
}
.stock-row .desc, .bancale-row .nome { font-weight: 700; }
.stock-row .meta, .bancale-row .meta { color: var(--muted); font-size: .82rem; margin-top: 3px; }
.stock-row .qty { float: right; font-weight: 800; font-size: 1.15rem; color: var(--accent); }
.lotto-chip {
  display: inline-block; background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 999px; padding: 2.5px 10px; font-size: .78rem; margin: 4px 4px 0 0;
}
.lotto-chip.scaduto { background: var(--red-soft); border-color: color-mix(in srgb, var(--red) 40%, transparent); color: var(--red); }
.lotto-chip.corta { background: var(--amber-soft); border-color: color-mix(in srgb, var(--amber) 40%, transparent); color: var(--amber); }

.row-between { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; gap: 8px; }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; }

/* ============ Preparazioni ============ */
.bancale-row { cursor: pointer; transition: border-color .15s ease; }
.bancale-row:hover { border-color: var(--accent); }
.stato { float: right; font-size: .72rem; font-weight: 800; text-transform: uppercase; letter-spacing: .4px; }
.stato.aperto { color: var(--accent); }
.stato.chiuso { color: var(--muted); }
.progress-track { height: 6px; background: var(--surface-2); border-radius: 99px; margin-top: 9px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 99px; transition: width .3s ease; }
.bancale-detail { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.riga-item { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.riga-item:last-child { border-bottom: 0; }
.riga-item .rq { font-weight: 800; color: var(--accent); white-space: nowrap; }
.riga-item.done { opacity: .55; }
.riga-item.done .rq { color: var(--muted); }
.check-pill {
  font-size: .72rem; font-weight: 800; padding: 3px 9px; border-radius: 99px;
  background: var(--ok-soft); color: var(--accent);
}
.check-pill.partial { background: var(--amber-soft); color: var(--amber); }
.collo-card {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  background: var(--surface-2); border-radius: var(--radius-s); padding: 11px 13px; margin-bottom: 7px;
}
.collo-card .cm { color: var(--muted); font-size: .8rem; }
.section-title { font-size: .78rem; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); font-weight: 800; margin: 18px 0 8px; }

/* ============ Tabbar (mobile) ============ */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(4,1fr);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  padding: 6px 0 calc(6px + var(--safe-b));
}
.tab {
  border: 0; background: transparent; padding: 6px 0 4px;
  color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 3px;
}
.tab svg { width: 23px; height: 23px; }
.tab span { font-size: .66rem; font-weight: 700; }
.tab.active { color: var(--accent); }

/* ============ Bottom sheet ============ */
.sheet { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; }
.sheet-card {
  background: var(--surface); width: 100%; border-radius: 20px 20px 0 0;
  padding: 20px 18px calc(18px + var(--safe-b));
  animation: up .2s ease; max-height: 88vh; overflow-y: auto;
}
@media (min-width: 1024px) {
  .sheet { align-items: center; justify-content: center; }
  .sheet-card { max-width: 520px; border-radius: 20px; box-shadow: var(--shadow-lg); }
}
@keyframes up { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet h3 { font-size: 1.15rem; }
.sheet .prod-desc { font-weight: 800; font-size: 1.1rem; margin: 2px 0 4px; letter-spacing: -.01em; }
.sheet .prod-codes { color: var(--muted); font-size: .85rem; margin-bottom: 12px; }
.qty-label { display: block; font-size: .78rem; color: var(--muted); font-weight: 700; margin-top: 6px; }
.qty-label small { font-weight: 400; }
.qty-stepper { display: flex; align-items: center; gap: 10px; margin: 8px 0; }
.qty-stepper button { width: 54px; height: 54px; border-radius: var(--radius-s); border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-size: 1.6rem; font-weight: 700; }
.qty-stepper input { text-align: center; font-size: 1.6rem; font-weight: 800; margin: 0; height: 54px; }
.imballo-box { display: flex; align-items: center; gap: 8px; margin: 8px 0 4px; }
.imballo-box .imb-label { font-size: .82rem; color: var(--muted); font-weight: 700; white-space: nowrap; }
.imballo-box input { width: 78px; margin: 0; text-align: center; }
.imballo-box .imb-x { color: var(--muted); font-weight: 700; }
.sheet-field label { display: block; font-size: .78rem; color: var(--muted); font-weight: 700; margin-bottom: 4px; }
.sheet-actions { display: flex; gap: 8px; margin-top: 14px; }
.sheet-actions > * { flex: 1; }
.notfound { text-align: center; padding: 6px 0 4px; }
.notfound .big-x { font-size: 2.2rem; }
.warn { background: var(--red-soft); color: var(--red); border-radius: var(--radius-s); padding: 11px 13px; font-size: .9rem; margin: 8px 0; }
.info-avail { background: var(--surface-2); border-radius: var(--radius-s); padding: 11px 13px; font-size: .9rem; margin: 8px 0; }

/* ============ Toast ============ */
.toast {
  position: fixed; left: 50%; bottom: calc(84px + var(--safe-b)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 13px 20px; border-radius: 999px;
  font-weight: 700; font-size: .9rem; z-index: 60; box-shadow: var(--shadow-lg);
  max-width: 90%; text-align: center;
}
.toast.ok { background: var(--accent); color: #fff; }
.toast.err { background: var(--red); color: #fff; }
@media (min-width: 1024px) { .toast { bottom: 34px; } }
