@font-face { font-family: 'Barlow'; font-weight: 400; font-display: swap; src: url(fonts/barlow-latin-400-normal.woff2) format('woff2'); }
@font-face { font-family: 'Barlow'; font-weight: 500; font-display: swap; src: url(fonts/barlow-latin-500-normal.woff2) format('woff2'); }
@font-face { font-family: 'Barlow'; font-weight: 600; font-display: swap; src: url(fonts/barlow-latin-600-normal.woff2) format('woff2'); }
@font-face { font-family: 'Barlow Condensed'; font-weight: 600; font-display: swap; src: url(fonts/barlow-condensed-latin-600-normal.woff2) format('woff2'); }
@font-face { font-family: 'Barlow Condensed'; font-weight: 700; font-display: swap; src: url(fonts/barlow-condensed-latin-700-normal.woff2) format('woff2'); }

:root {
  --ink: #16233f;
  --ink-2: #2b3a5c;
  --paper: #f4f5f3;
  --surface: #ffffff;
  --rule: #d6dad8;
  --muted: #5e6775;
  --go: #0f8a4b;
  --go-soft: #e3f3ea;
  --stop: #c71f37;
  --stop-soft: #fbe6e9;
  --caution: #e3a008;
  --caution-soft: #fdf3d8;
  --focus: #2f6fed;
  --cond: 'Barlow Condensed', 'Arial Narrow', sans-serif;
  --body: 'Barlow', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--paper);
  font-variant-numeric: tabular-nums;
}
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }
h1, h2, h3 { font-family: var(--cond); font-weight: 700; line-height: 1.1; margin: 0; letter-spacing: .01em; }

/* ---------- Pulsanti e campi ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4em;
  min-height: 44px; padding: 0 18px;
  border: 1.5px solid var(--ink); border-radius: 6px;
  background: var(--surface); color: var(--ink);
  font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: #eef0f3; }
.btn.primary { background: var(--ink); color: #fff; }
.btn.primary:hover { background: var(--ink-2); }
.btn.quiet { border-color: var(--rule); }
.btn.danger { border-color: var(--stop); color: var(--stop); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 14px; }

.field { display: grid; gap: 4px; }
.field span { font-size: 14px; font-weight: 500; color: var(--muted); }
input[type=text], input[type=password], input[type=search], select {
  min-height: 44px; padding: 0 12px;
  border: 1.5px solid var(--rule); border-radius: 6px; background: var(--surface);
}
input:focus { border-color: var(--ink); outline: none; box-shadow: 0 0 0 3px rgba(47,111,237,.25); }

.msg { padding: 10px 14px; border-radius: 6px; font-weight: 500; }
.msg.err { background: var(--stop-soft); color: #8d1325; }
.msg.ok { background: var(--go-soft); color: #0a5c32; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login {
  width: min(380px, 100%);
  display: grid; gap: 16px;
}
.login .brand { font-family: var(--cond); font-size: 44px; font-weight: 700; line-height: 1; }
.login .brand small { display: block; font-family: var(--body); font-size: 16px; font-weight: 500; color: var(--muted); margin-top: 6px; }

/* ---------- Barra superiore ---------- */
.topbar {
  display: flex; align-items: center; gap: 8px;
  height: 56px; padding: 0 16px;
  background: var(--ink); color: #fff;
}
.topbar .brand { font-family: var(--cond); font-weight: 700; font-size: 24px; margin-right: 18px; }
.topbar nav { display: flex; gap: 2px; flex: 1; overflow-x: auto; }
.topbar nav a {
  font-family: var(--cond); font-weight: 600; font-size: 19px;
  color: rgba(255,255,255,.7); text-decoration: none;
  padding: 14px 12px 12px; border-bottom: 3px solid transparent;
}
.topbar nav a:hover { color: #fff; }
.topbar nav a[aria-current=page] { color: #fff; border-bottom-color: #fff; }
.topbar .who { font-size: 14px; color: rgba(255,255,255,.8); white-space: nowrap; }
.topbar .link { background: none; border: 0; color: #fff; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; font-size: 14px; padding: 6px; }

main { padding: 20px; }
.page { max-width: 1280px; margin: 0 auto; }

/* ---------- Scansione ---------- */
.scan-layout {
  display: grid; gap: 20px;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
  height: calc(100vh - 56px - 40px);
}
@media (max-width: 980px) {
  .scan-layout { grid-template-columns: 1fr; height: auto; }
}

.verdict-col { display: flex; flex-direction: column; gap: 14px; min-height: 0; }

.verdict {
  flex: 1; min-height: 300px;
  display: grid; grid-template-rows: auto 1fr auto; gap: 12px;
  padding: 28px 30px;
  border-radius: 10px;
  background: #e4e7ea; color: var(--ink);
  transition: background-color .12s;
}
.verdict .v-head { display: flex; align-items: center; gap: 18px; }
.verdict .v-icon {
  flex: none; width: 96px; height: 96px; border-radius: 50%;
  display: grid; place-items: center;
  font-family: var(--cond); font-size: 76px; font-weight: 700; line-height: 1;
  background: rgba(255,255,255,.22);
}
.verdict .v-title { font-family: var(--cond); font-weight: 700; font-size: clamp(40px, 5.2vw, 76px); line-height: .95; }
.verdict .v-body { display: flex; gap: 20px; align-items: flex-start; min-height: 0; }
.verdict .v-photo { width: 120px; height: 160px; object-fit: contain; background: #fff; border-radius: 6px; flex: none; }
.verdict .v-text { font-size: 22px; line-height: 1.3; font-weight: 500; }
.verdict .v-text strong { font-family: var(--cond); font-size: 34px; font-weight: 700; display: block; line-height: 1.05; }
.verdict .v-code { font-size: 15px; opacity: .85; }
.verdict.idle .v-icon { background: rgba(22,35,63,.08); color: var(--muted); }
.verdict.idle .v-title { font-size: clamp(34px, 4vw, 56px); color: var(--ink); }
.verdict.ok { background: var(--go); color: #fff; }
.verdict.bad { background: var(--stop); color: #fff; }
.verdict.warn { background: var(--caution); color: #1e1600; }
.verdict.done { background: var(--go); color: #fff; box-shadow: inset 0 0 0 10px rgba(255,255,255,.35); }
.verdict.flash { animation: flash .35s ease-out; }
@keyframes flash { from { transform: scale(.985); filter: brightness(1.25); } to { transform: none; filter: none; } }
@media (prefers-reduced-motion: reduce) { .verdict.flash { animation: none; } .verdict { transition: none; } }

.scanbox {
  display: flex; gap: 10px; align-items: center;
  padding: 10px; border-radius: 10px; background: var(--surface); border: 1.5px solid var(--rule);
}
.scanbox.armed { border-color: var(--ink); }
.scanbox label { font-weight: 600; white-space: nowrap; padding-left: 6px; }
.scanbox input { flex: 1; min-width: 0; font-size: 22px; font-family: var(--cond); font-weight: 600; letter-spacing: .04em; border: 0; box-shadow: none; }
.scanbox input:focus { box-shadow: none; }
.scanbox .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--rule); flex: none; }
.scanbox.armed .dot { background: var(--go); }

.actions { display: flex; flex-wrap: wrap; gap: 10px; }
.head-actions { margin-top: 12px; }

/* Pannello ordine */
.order-col { display: flex; flex-direction: column; min-height: 0; background: var(--surface); border: 1.5px solid var(--rule); border-radius: 10px; }
.order-tools { display: flex; gap: 8px; padding: 14px; border-bottom: 1.5px solid var(--rule); flex-wrap: wrap; }
.order-tools input { flex: 1; min-width: 150px; }
.order-head { padding: 18px 18px 14px; border-bottom: 1.5px solid var(--rule); }
.order-head.complete { background: var(--go-soft); }
.order-no { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.order-no h2 { font-size: 40px; }
.order-no .count { font-family: var(--cond); font-size: 30px; font-weight: 700; white-space: nowrap; }
.order-no .count small { font-size: 18px; font-weight: 600; color: var(--muted); }
.order-meta { color: var(--muted); margin-top: 2px; }
.bar { height: 10px; background: #e7eaec; border-radius: 5px; overflow: hidden; margin-top: 12px; }
.bar i { display: block; height: 100%; background: var(--go); transition: width .2s; }
.alert { margin-top: 12px; padding: 8px 12px; border-left: 5px solid var(--caution); background: var(--caution-soft); font-weight: 600; }
.complete-note { margin-top: 12px; display: flex; align-items: center; justify-content: space-between; gap: 12px; font-weight: 600; color: #0a5c32; }
.gest-note { display: block; margin-top: 2px; font-size: 14px; font-weight: 500; color: var(--ink-2); }
.gest-note.err { color: var(--stop); }

.lines { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.lines li {
  display: grid; grid-template-columns: 56px 1fr auto; gap: 14px; align-items: center;
  padding: 10px 18px; border-bottom: 1px solid var(--rule);
}
.lines li.done { background: var(--go-soft); }
.lines li.hit { animation: hit 1s ease-out; }
@keyframes hit { from { background: #bfe7cf; } }
.lines img, .lines .noimg { width: 56px; height: 74px; object-fit: contain; background: #f0f1f2; border-radius: 4px; }
.lines .p-name { font-weight: 600; line-height: 1.25; }
.lines .p-meta { font-size: 14px; color: var(--muted); word-break: break-all; }
.lines .p-warn { font-size: 13px; color: #8d6400; font-weight: 600; }
.lines .qty { font-family: var(--cond); font-size: 28px; font-weight: 700; text-align: right; white-space: nowrap; }
.lines .qty .tick { color: var(--go); }
.lines .size { display: inline-block; font-family: var(--cond); font-weight: 700; font-size: 18px; border: 1.5px solid var(--ink); border-radius: 4px; padding: 0 6px; margin-right: 6px; }

.empty { padding: 40px 24px; color: var(--muted); display: grid; gap: 14px; justify-items: start; }
.empty h3 { font-size: 28px; color: var(--ink); }

/* ---------- Ordini ---------- */
.toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar h1 { font-size: 36px; margin-right: auto; }
.seg { display: inline-flex; border: 1.5px solid var(--ink); border-radius: 6px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 0 14px; min-height: 40px; cursor: pointer; font-weight: 600; }
.seg button + button { border-left: 1.5px solid var(--ink); }
.seg button[aria-pressed=true] { background: var(--ink); color: #fff; }

table.data { width: 100%; border-collapse: collapse; background: var(--surface); border: 1.5px solid var(--rule); }
table.data th { text-align: left; font-size: 14px; font-weight: 600; color: var(--muted); padding: 10px 12px; border-bottom: 1.5px solid var(--rule); background: #fafbfa; position: sticky; top: 0; }
table.data td { padding: 10px 12px; border-bottom: 1px solid var(--rule); vertical-align: middle; }
table.data th[aria-sort] { padding: 0; }
.th-sort {
  display: flex; align-items: center; gap: 6px; width: 100%;
  padding: 10px 12px; border: 0; background: none;
  font-weight: 600; text-align: left; white-space: nowrap; cursor: pointer;
}
.th-sort:hover, th[aria-sort=ascending] .th-sort, th[aria-sort=descending] .th-sort { color: var(--ink); }
.th-sort .arrow { font-size: 11px; opacity: .35; }
th[aria-sort=ascending] .arrow, th[aria-sort=descending] .arrow { opacity: 1; }
table.data tr.clickable { cursor: pointer; }
table.data tr.clickable:hover td { background: #f3f6fb; }
.ord-no { font-family: var(--cond); font-weight: 700; font-size: 20px; }
.mini-bar { width: 90px; height: 6px; background: #e7eaec; border-radius: 3px; overflow: hidden; display: inline-block; vertical-align: middle; margin-left: 8px; }
.mini-bar i { display: block; height: 100%; background: var(--go); }
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 14px; font-weight: 600; white-space: nowrap; }
.pill.da_iniziare { background: #eceef0; color: var(--muted); }
.pill.in_corso { background: var(--caution-soft); color: #7a5600; }
.pill.completo { background: var(--go-soft); color: #0a5c32; }
.pill.warn { background: var(--caution-soft); color: #7a5600; }
.pill.err { background: var(--stop-soft); color: #8d1325; }
.r-ok { color: var(--go); font-weight: 600; }
.r-bad { color: var(--stop); font-weight: 600; }
.r-warn { color: #8d6400; font-weight: 600; }
.muted { color: var(--muted); }
.table-wrap { max-height: calc(100vh - 200px); overflow: auto; }

/* ---------- Amministrazione ---------- */
.admin { display: grid; gap: 36px; }
.admin section { display: grid; gap: 14px; }
.admin h2 { font-size: 30px; }
.admin .lead { color: var(--muted); max-width: 70ch; margin: 0; }
.drop {
  display: grid; place-items: center; gap: 10px; text-align: center;
  padding: 34px 20px; border: 2px dashed #9aa3ad; border-radius: 10px; background: var(--surface); cursor: pointer;
}
.drop.over { border-color: var(--ink); background: #eef2f8; }
.drop strong { font-family: var(--cond); font-size: 26px; }
.stats { display: flex; flex-wrap: wrap; gap: 28px; }
.stats div { display: grid; }
.stats b { font-family: var(--cond); font-size: 34px; line-height: 1; }
.stats span { color: var(--muted); font-size: 14px; }
.form-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.form-row .field { flex: 1; min-width: 150px; }

dialog { border: 0; border-radius: 10px; padding: 24px; width: min(420px, 92vw); box-shadow: 0 20px 60px rgba(22,35,63,.35); }
dialog::backdrop { background: rgba(22,35,63,.45); }
dialog form { display: grid; gap: 14px; }
dialog h2 { font-size: 28px; }

@media (max-width: 640px) {
  main { padding: 12px; }
  .topbar .who { display: none; }
  .topbar .brand { display: none; }
  .topbar nav a { font-size: 17px; padding: 14px 8px 12px; }
  .verdict { padding: 20px; min-height: 240px; }
  .verdict .v-icon { width: 64px; height: 64px; font-size: 50px; }
  .verdict .v-photo { width: 80px; height: 106px; }
  .order-no h2 { font-size: 32px; }
  table.data .hide-sm { display: none; }
}
