:root {
  --bg: #f5f6f8; --surface: #ffffff; --surface-2: #eef1f5; --border: #dde2e9;
  --text: #17202b; --text-2: #4a5666; --muted: #6f7b8b;
  --brand: #1f4e79; --brand-ink: #ffffff; --accent: #f2c14e;
  --owe: #b3261e; --owe-bg: #fde8e6; --credit: #1b6e3a; --credit-bg: #e3f4e8;
  --deliver: #1f4e79; --collect: #1b6e3a;
  --bar: #3a6ea5;
  --radius: 12px; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f141a; --surface: #182029; --surface-2: #212b36; --border: #2d3946;
    --text: #e8edf3; --text-2: #b6c0cc; --muted: #8995a3;
    --brand: #5b9bd5; --brand-ink: #0f141a;
    --owe: #ff8a80; --owe-bg: #3a1d1b; --credit: #7fd69a; --credit-bg: #16301f;
    --deliver: #7fb3e6; --collect: #7fd69a; --bar: #6fa3d8;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .6em; }
h1 { font-size: 1.4rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
a { color: var(--brand); }
.muted { color: var(--muted); } .small { font-size: .85rem; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
[hidden] { display: none !important; }

/* top bar */
header#topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 16px; padding: 8px 16px;
  background: var(--brand); color: var(--brand-ink); flex-wrap: wrap; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) header#topbar { background: var(--surface); color: var(--text); border-bottom: 1px solid var(--border); } }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; }
#nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; scrollbar-width: none; }
#nav a { color: inherit; text-decoration: none; padding: 6px 12px; border-radius: 8px; white-space: nowrap; opacity: .85; }
#nav a.on, #nav a:hover { background: rgba(255,255,255,.16); opacity: 1; }
.who { display: flex; align-items: center; gap: 10px; font-size: .9rem; }
button.link { background: none; border: 0; color: inherit; text-decoration: underline; cursor: pointer; font: inherit; padding: 4px; }
@media (max-width: 720px) {
  header#topbar { gap: 6px 12px; } #nav { order: 3; flex-basis: 100%; }
}

main { max-width: 1200px; margin: 0 auto; padding: 16px; }
main.narrow { max-width: 560px; }

/* cards & layout */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: end; }
.row > * { flex: 1 1 160px; }
.row > .grow-0 { flex: 0 0 auto; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.toolbar .spacer { flex: 1; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

/* forms */
label { display: block; font-size: .85rem; color: var(--text-2); margin-bottom: 4px; font-weight: 600; }
input, select, textarea { width: 100%; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; min-height: 44px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 1px; border-color: transparent; }
.field { margin-bottom: 12px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; font: inherit; font-weight: 600; cursor: pointer;
  border-radius: 10px; padding: 10px 16px; min-height: 44px; border: 1px solid var(--border); background: var(--surface); color: var(--text); text-decoration: none; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--owe); }
.btn.big { width: 100%; min-height: 56px; font-size: 1.1rem; }
.btn.sm { min-height: 34px; padding: 4px 10px; font-size: .85rem; }
.btn:disabled { opacity: .5; cursor: default; }
.err { color: var(--owe); font-weight: 600; margin: 8px 0; }

/* tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; white-space: nowrap; }
th.num { text-align: right; }
tbody tr.click { cursor: pointer; } tbody tr.click:hover { background: var(--surface-2); }
tr.voided td { color: var(--muted); text-decoration: line-through; }
tfoot td { font-weight: 700; border-top: 2px solid var(--border); border-bottom: 0; }

.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--surface-2); color: var(--text-2); }
.pill.delivered { color: var(--deliver); } .pill.collected { color: var(--collect); }
.bal { font-weight: 700; } .bal.pos { color: var(--owe); } .bal.neg { color: var(--credit); }

/* stat tiles */
.tiles { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 16px; }
@media (max-width: 1000px) { .tiles { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 800px) { .tiles { grid-template-columns: repeat(2, 1fr); } }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.tile .k { font-size: .8rem; color: var(--muted); font-weight: 600; }
.tile .v { font-size: 1.9rem; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }
.tile .s { font-size: .8rem; color: var(--muted); }

/* bar list (single series) */
.bars { display: grid; gap: 6px; }
.bars .b { display: grid; grid-template-columns: minmax(90px, 38%) 1fr auto; gap: 10px; align-items: center; font-size: .9rem; cursor: pointer; padding: 2px 0; }
.bars .b:hover .name { text-decoration: underline; }
.bars .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bars .track { height: 14px; }
.bars .fill { height: 14px; background: var(--bar); border-radius: 0 4px 4px 0; min-width: 2px; }

/* operator */
.scan-area { position: relative; border-radius: var(--radius); overflow: hidden; background: #000; margin-bottom: 12px; }
#reader { width: 100%; min-height: 240px; }
#reader video { width: 100% !important; height: auto !important; display: block; }
.or { text-align: center; color: var(--muted); margin: 12px 0; font-size: .9rem; }
.cust-head { display: flex; justify-content: space-between; gap: 12px; align-items: start; }
.cust-name { font-size: 1.3rem; font-weight: 700; }
.balance-box { text-align: center; border-radius: var(--radius); padding: 16px; margin: 12px 0; background: var(--surface-2); }
.balance-box.pos { background: var(--owe-bg); } .balance-box.neg { background: var(--credit-bg); }
.balance-box .n { font-size: 3rem; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.1; }
.balance-box.pos .n { color: var(--owe); } .balance-box.neg .n { color: var(--credit); }
.balance-box .l { font-weight: 600; color: var(--text-2); }
.steppers { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.stepper { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; text-align: center; background: var(--surface); }
.stepper .t { font-weight: 700; margin-bottom: 6px; }
.stepper.d .t { color: var(--deliver); } .stepper.c .t { color: var(--collect); }
.stepper .ctl { display: grid; grid-template-columns: 48px 1fr 48px; gap: 6px; align-items: center; }
.stepper .ctl button { height: 48px; font-size: 1.5rem; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); cursor: pointer; }
.stepper input { text-align: center; font-size: 1.5rem; font-weight: 700; padding: 6px; }
.after { text-align: center; color: var(--text-2); margin: 4px 0 12px; }
.results { list-style: none; margin: 8px 0 0; padding: 0; }
.results li { padding: 10px 8px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; gap: 8px; cursor: pointer; }
.results li:hover { background: var(--surface-2); }
.entry { display: flex; justify-content: space-between; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: .92rem; }
.entry:last-child { border-bottom: 0; }

/* login */
.login { max-width: 380px; margin: 8vh auto; }
.login .logo { text-align: center; margin-bottom: 16px; }

/* modal & toast */
dialog { border: 0; border-radius: var(--radius); padding: 0; width: min(640px, calc(100vw - 24px)); max-height: calc(100vh - 32px);
  background: var(--surface); color: var(--text); box-shadow: 0 10px 40px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(0,0,0,.45); }
#modal-body { padding: 20px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
/* Hidden toast slides fully below the screen and fades out: a long message wraps to several lines,
   and a fixed 120px slide left its top line ("Saved.") stuck at the bottom of small screens */
#toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%) translateY(calc(100% + 40px)); background: var(--text); color: var(--bg);
  padding: 12px 18px; border-radius: 10px; font-weight: 600; transition: transform .25s, opacity .25s, visibility .25s; z-index: 100; max-width: calc(100vw - 32px);
  opacity: 0; visibility: hidden; pointer-events: none; }
#toast.show { transform: translateX(-50%) translateY(0); opacity: 1; visibility: visible; }

/* labels sheet */
.labels { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.label { border: 1px dashed var(--border); border-radius: 8px; padding: 10px; text-align: center; background: #fff; color: #000; break-inside: avoid; }
.label svg { max-width: 100%; height: auto; }
.label .ln { font-weight: 700; font-size: .95rem; }

.print-only { display: none; }
@media print {
  header#topbar, .toolbar, .no-print, #toast { display: none !important; }
  .print-only { display: block; }
  body { background: #fff; color: #000; }
  main { max-width: none; padding: 0; }
  .card { border: 0; box-shadow: none; padding: 0; }
  .bal.pos, .bal.neg { color: #000; }
}
.entry.voided > div:first-child { opacity: .55; text-decoration: line-through; }
.grid-2 > .card { align-self: start; }

/* phone: keep the app locked to the screen width, no sideways sliding or zoom-on-tap */
html, body { overflow-x: hidden; max-width: 100%; touch-action: manipulation; }
input, select, textarea { font-size: 16px; }
.stepper .ctl { grid-template-columns: 44px minmax(0, 1fr) 44px; }
.stepper .ctl input { min-width: 0; padding: 6px 2px; }
@media (max-width: 420px) {
  main { padding: 12px; }
  .card { padding: 12px; }
  .steppers { gap: 8px; }
  .stepper { padding: 8px 6px; }
  .stepper .ctl { grid-template-columns: 40px minmax(0, 1fr) 40px; gap: 4px; }
  .stepper .ctl button { height: 44px; }
}
.bars .fill.credit { background: var(--credit); }
.bal-list { max-height: 460px; overflow-y: auto; padding-right: 4px; }
.bal-h { font-size: .85rem; color: var(--muted); margin: 4px 0 8px; }
.bal-h:not(:first-child) { margin-top: 16px; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
th.sortable[data-dir="asc"]::after { content: " ▲"; }
th.sortable[data-dir="desc"]::after { content: " ▼"; }
th.sortable[data-dir="asc"], th.sortable[data-dir="desc"] { color: var(--brand); }

/* scan screen: Delivering above Picking up, big touch targets */
.steppers { grid-template-columns: 1fr; gap: 12px; }
.stepper { padding: 12px; }
.stepper .t { font-size: 1.35rem; margin-bottom: 10px; }
.stepper .ctl { grid-template-columns: 76px minmax(0, 1fr) 76px; gap: 10px; }
.stepper .ctl button { height: 72px; font-size: 2.4rem; font-weight: 700; line-height: 1; }
.stepper .ctl input { height: 72px; font-size: 2.2rem; }
@media (max-width: 420px) {
  .steppers { gap: 10px; }
  .stepper { padding: 10px; }
  .stepper .ctl { grid-template-columns: 72px minmax(0, 1fr) 72px; gap: 8px; }
  .stepper .ctl button { height: 68px; }
}
#save-move { min-height: 64px; font-size: 1.35rem; }
.results.readonly li { cursor: default; }
.results.readonly li:hover { background: none; }
.btn.primary.danger-fill { background: var(--owe); border-color: var(--owe); color: #fff; }
td.user-cell { font-size: calc(.85rem + 2pt); font-weight: 700; }
.results.tap2 li { cursor: pointer; user-select: none; -webkit-user-select: none; touch-action: manipulation; }
.results.tap2 li:active { background: var(--surface-2); }
#complete-move { width: 100%; min-height: 64px; font-size: 1.35rem; margin: 4px 0 12px; background: var(--surface-2); border: 2px solid var(--brand); color: var(--brand); display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.2; }
#complete-move span { font-size: .85rem; font-weight: 500; color: var(--muted); }
/* phones: driver screens run edge to edge */
@media (max-width: 600px) {
  main.narrow { padding: 0; }
  main.narrow .card { border-radius: 0; border-left: 0; border-right: 0; box-shadow: none; margin-bottom: 8px; padding: 16px; }
}
/* when opened from the home screen the app runs full screen; keep clear of the notch and home bar */
header#topbar { padding-top: max(8px, env(safe-area-inset-top)); padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
main { padding-bottom: max(16px, env(safe-area-inset-bottom)); }
/* pallet reconciliation: laid out like the paper control sheet */
.rc-wrap { grid-template-columns: minmax(0, 640px) minmax(0, 1fr); }
@media (max-width: 900px) { .rc-wrap { grid-template-columns: 1fr; } }
.rc-title { text-align: center; margin: 0 0 12px; }
.rc-period { margin-bottom: 8px; }
.rc-sec { display: grid; grid-template-columns: 110px 1fr; gap: 12px; padding: 6px 0; }
.rc-head, .rc-total .rc-lbl, .rc-total .rc-val { color: #1a6fc4; font-weight: 700; font-size: 1.1rem; }
.rc-row { display: grid; grid-template-columns: 1fr 120px; align-items: center; gap: 12px; min-height: 48px; }
.rc-total { border-top: 1.5px solid var(--text); border-bottom: 1.5px solid var(--text); min-height: 36px; margin: 4px 0 8px; }
.rc-val { text-align: center; }
.rc-balance { margin-left: 18%; }
.rc-in { text-align: center; font-weight: 700; font-size: 1.1rem; border: 2px solid var(--text); border-radius: 2px; padding: 8px 4px; width: 100%; }
.rc-in.sys { background: var(--surface-2); }
.rc-tag { font-size: .7rem; font-weight: 600; color: var(--muted); background: var(--surface-2); border-radius: 6px; padding: 1px 6px; margin-left: 4px; white-space: nowrap; }
.rc-chep { border: 2px solid var(--text); padding: 4px 8px; margin: 8px 0; }
.rc-chep .rc-lbl { color: #1a6fc4; font-weight: 700; font-size: 1.1rem; }
.rc-chep .rc-in { border-width: 1px; }
.rc-note { font-weight: 700; font-size: .85rem; }
#rc-list li.on { background: var(--surface-2); }
@media (max-width: 420px) { .rc-sec { grid-template-columns: 1fr; gap: 0; } .rc-balance { margin-left: 0; } .rc-row { grid-template-columns: 1fr 96px; } }
@media print { .rc-wrap { display: block; } .rc-in { border-color: #000; } .rc-tag { display: none; } }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .rc-head, :root:not([data-theme="light"]) .rc-total .rc-lbl, :root:not([data-theme="light"]) .rc-total .rc-val, :root:not([data-theme="light"]) .rc-chep .rc-lbl { color: #6fb2f2; } }
.rc-big { font-weight: 700; font-size: 1.2rem; color: #1a6fc4; }
.rc-bf .rc-in { border-width: 1px; font-size: 1rem; }
.rc-date { text-align: center; margin: -4px 0 12px; font-size: 1.05rem; }
.rc-in.locked { background: var(--surface-2); color: var(--muted); cursor: not-allowed; }
.pill.tx { background: #e0ecfa; color: #1a4f8a; font-weight: 700; }
/* drivers: big confirmation after Save / Complete */
.saved-banner { background: #1e7a3c; color: #fff; border-radius: var(--radius); padding: 14px 16px; margin: 0 0 12px; font-size: 1.6rem; font-weight: 800; text-align: center; animation: saved-in .25s ease-out; }
.saved-banner span { display: block; font-size: 1rem; font-weight: 600; margin-top: 4px; }
@keyframes saved-in { from { transform: scale(.96); opacity: 0; } to { transform: none; opacity: 1; } }
@media (max-width: 600px) { main.narrow .saved-banner { border-radius: 0; margin: 0 0 8px; } }

/* ---------- scanner users (Users > Device = Scanner): compact screen sized for the handheld ---------- */
body.dev-scanner { overflow-x: clip; } /* hidden would make body a scroll box and break sticky Save */
.hw-help { text-align: center; color: var(--muted); margin: 4px 0 10px; font-weight: 600; }
body.dev-scanner #q { min-height: 56px; font-size: 1.2rem; border: 2px dashed var(--muted); }
body.dev-scanner #q.on { border: 2px solid var(--credit); background: var(--credit-bg); outline: none; }
/* Customer open: Find box shrunk out of sight but still focused (see findShow) */
/* (kept full size: in a 1px box the browser put scanned characters in the wrong order) */
#find.parked { position: fixed; left: 0; right: 0; top: 0; opacity: 0; pointer-events: none; z-index: -1; }
body.dev-scanner header#topbar { position: static; padding-top: 4px; padding-bottom: 4px; gap: 2px 10px; font-size: .9rem; }
body.dev-scanner #nav a { padding: 4px 10px; }
body.dev-scanner main.narrow .card { padding: 10px 12px; }
body.dev-scanner .cust-name { font-size: 1.45rem; font-weight: 800; line-height: 1.15; }
body.dev-scanner .cust-head .btn.sm { min-height: 30px; }
body.dev-scanner .balance-box { padding: 6px 10px; margin: 8px 0; }
body.dev-scanner .balance-box .n { font-size: 2.6rem; }
body.dev-scanner .balance-box .l { font-size: .9rem; }
body.dev-scanner .steppers { gap: 6px; margin-bottom: 4px; }
body.dev-scanner .stepper { display: grid; grid-template-columns: 5.5rem minmax(0, 1fr); align-items: center; gap: 6px; padding: 6px 8px; text-align: left; }
body.dev-scanner .stepper .t { font-size: 1.05rem; margin: 0; }
body.dev-scanner .stepper .ctl { grid-template-columns: 56px minmax(0, 1fr) 56px; gap: 6px; }
body.dev-scanner .stepper .ctl button { height: 50px; font-size: 2rem; }
body.dev-scanner .stepper .ctl input { height: 50px; min-height: 0; font-size: 1.7rem; }
body.dev-scanner .after { margin: 2px 0 0; font-size: .9rem; }
body.dev-scanner .move-actions { display: grid; grid-auto-rows: 1fr; gap: 6px; padding: 4px 0 max(6px, env(safe-area-inset-bottom));
  position: sticky; bottom: 0; z-index: 5; background: var(--surface); } /* Save as tall as Complete, always on screen */
body.dev-scanner #complete-move, body.dev-scanner #save-move { min-height: 54px; margin: 0; font-size: 1.2rem; }
body.dev-scanner #complete-move span { font-size: .75rem; }
body.dev-scanner .saved-banner { padding: 8px 12px; font-size: 1.3rem; }
