:root {
  --bg: #f3f5f2; --card: #ffffff; --ink: #1c2420; --muted: #65706a; --line: #dfe5e0;
  --green: #1f6f43; --green-2: #e3f1e8; --amber: #a86400; --amber-2: #fff3dc;
  --red: #b3261e; --red-2: #fde8e6; --blue: #1d5fa8; --blue-2: #e5effa; --grey-2: #eceeec;
  --radius: 14px; --tap: 56px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #131715; --card: #1c211e; --ink: #e8ece9; --muted: #9aa59f; --line: #2d3530;
    --green: #5cc38a; --green-2: #1d3326; --amber: #f0b14a; --amber-2: #3a2e17; --red: #ff8a80; --red-2: #3b1f1d;
    --blue: #8ab8f0; --blue-2: #1c2a3b; --grey-2: #262c28; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); font-size: 17px; -webkit-tap-highlight-color: transparent; }
button, input, textarea { font: inherit; color: inherit; }
button { min-height: var(--tap); padding: 0 20px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); cursor: pointer; font-weight: 600; touch-action: manipulation; }
button:active { transform: scale(0.98); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--green); border-color: var(--green); color: #fff; }
button.danger { background: var(--red); border-color: var(--red); color: #fff; }
button.link { min-height: 0; padding: 0; border: 0; background: none; color: var(--blue); font-weight: 600; text-decoration: underline; margin-right: 8px; }
button.icon { min-width: var(--tap); padding: 0; font-size: 22px; }
input, textarea { width: 100%; min-height: var(--tap); padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); }
input:focus, textarea:focus, button:focus-visible { outline: 3px solid color-mix(in srgb, var(--green) 45%, transparent); outline-offset: 1px; }
.sr-only { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.muted { color: var(--muted); } .small { font-size: 14px; } .pad { padding: 24px; }
.row { display: flex; gap: 12px; align-items: center; } .between { justify-content: space-between; }
.error { background: var(--red-2); color: var(--red); padding: 12px 14px; border-radius: 12px; margin: 12px 0; font-weight: 600; }
.notice { background: var(--amber-2); color: var(--amber); padding: 10px 12px; border-radius: 10px; margin: 8px 0; }

/* sign in */
.signin { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.signin-card { width: min(420px, 100%); background: var(--card); border-radius: 20px; padding: 28px; box-shadow: 0 8px 30px rgb(0 0 0 / .08); }
.brand { font-size: 22px; font-weight: 800; display: flex; align-items: center; gap: 8px; }
.brand small { font-weight: 500; color: var(--muted); font-size: 15px; }
.signin .brand { margin-bottom: 20px; }
.pin-input { font-size: 26px; letter-spacing: 8px; text-align: center; }
.pin-dots { display: flex; justify-content: center; gap: 12px; margin: 18px 0; }
.pin-dots span { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--muted); }
.pin-dots span.on { background: var(--ink); border-color: var(--ink); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.keypad button { min-height: 68px; font-size: 26px; }
.device-line { margin-top: 18px; font-size: 14px; color: var(--muted); display: flex; gap: 8px; align-items: center; justify-content: center; }
.device-line input { min-height: 44px; } .device-line button { min-height: 44px; }

/* shell */
header { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 16px; padding: 10px 16px;
  background: var(--card); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
header nav { display: flex; gap: 6px; flex: 1; }
header nav button { border: 0; background: none; } header nav button.active { background: var(--green-2); color: var(--green); }
.who { display: flex; align-items: center; gap: 12px; }
.who .user { display: flex; flex-direction: column; line-height: 1.2; text-align: right; }
.who small { color: var(--muted); }
main { max-width: 1100px; margin: 0 auto; padding: 16px; }
.page h3 { margin: 24px 4px 10px; }
.tabs { display: flex; gap: 8px; margin-bottom: 14px; overflow-x: auto; }
.tabs button { white-space: nowrap; flex: none; }
.tabs button.active { background: var(--ink); color: var(--card); border-color: var(--ink); }
.tabs .refresh { margin-left: auto; }
.backbar { margin: 4px 0 10px; } .backbar .link { font-size: 18px; text-decoration: none; }

/* cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; text-align: left; font-weight: 400; }
button.card { min-height: 0; display: flex; flex-direction: column; gap: 8px; }
.batch-no { font-weight: 800; letter-spacing: .3px; } .batch-no.big { font-size: 24px; }
.product { font-size: 17px; }
.empty { text-align: center; padding: 48px 16px; } .empty .big { font-size: 22px; font-weight: 700; margin-bottom: 6px; }
.progress { display: flex; gap: 4px; } .progress span { flex: 1; height: 6px; border-radius: 3px; background: var(--grey-2); }
.progress span.on { background: var(--green); }
.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 13px; font-weight: 700; background: var(--grey-2); white-space: nowrap; }
.pill.big { font-size: 16px; padding: 6px 14px; }
.st-released, .st-ready, .st-available, .st-open { background: var(--blue-2); color: var(--blue); }
.st-inprogress { background: var(--amber-2); color: var(--amber); }
.st-completed, .st-closed, .st-approved, .st-passed { background: var(--green-2); color: var(--green); }
.st-onhold, .st-quarantine, .st-blocked { background: var(--amber-2); color: var(--amber); }
.st-failed, .st-cancelled, .st-damaged, .st-waste, .st-expired, .st-rejected { background: var(--red-2); color: var(--red); }
.head-card .facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin: 16px 0; }
.facts span { display: block; font-size: 13px; color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; } .actions.end { justify-content: flex-end; }
.states { display: flex; gap: 8px; flex-wrap: wrap; }

/* stages */
.stages { display: flex; flex-direction: column; gap: 10px; }
.stage { display: flex; gap: 14px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.stage.next { border: 2px solid var(--green); }
.stage.s-completed, .stage.s-skipped { opacity: .75; }
.stage-dot { flex: none; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: var(--grey-2); font-weight: 800; }
.s-completed .stage-dot { background: var(--green); color: #fff; } .s-inprogress .stage-dot { background: var(--amber); color: #fff; }
.stage-body { flex: 1; display: flex; flex-direction: column; gap: 4px; }

/* tables */
.table-card { padding: 0; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 15px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 13px; color: var(--muted); font-weight: 600; text-transform: capitalize; }
tr:last-child td { border-bottom: 0; }
.search { display: flex; gap: 10px; padding: 12px; margin-bottom: 14px; }

/* modal */
.modal-back { position: fixed; inset: 0; background: rgb(0 0 0 / .4); display: grid; place-items: center; padding: 16px; z-index: 20; }
.modal { width: min(560px, 100%); max-height: 92vh; overflow: auto; background: var(--card); border-radius: 20px; padding: 20px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; } .modal-head h2 { margin: 0; font-size: 22px; }
.field { display: flex; flex-direction: column; gap: 6px; margin: 14px 0; } .field > span { font-weight: 600; font-size: 15px; }
.stepper { display: flex; gap: 8px; } .stepper button { min-width: var(--tap); font-size: 24px; padding: 0; } .stepper input { text-align: center; font-size: 20px; font-weight: 700; }
.seg { display: flex; gap: 8px; flex-wrap: wrap; } .seg button.active { background: var(--green-2); border-color: var(--green); color: var(--green); }
.lot-pick { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.lot-option { display: flex; gap: 10px; align-items: center; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; min-height: var(--tap); }
.lot-option.on { border-color: var(--green); background: var(--green-2); }
.lot-option input { width: 22px; min-height: 0; } .lot-option span:last-child { margin-left: auto; }
.toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 30; width: min(520px, calc(100% - 32px)); }
.toast { padding: 14px 18px; border-radius: 12px; background: var(--ink); color: var(--card); font-weight: 600; box-shadow: 0 6px 20px rgb(0 0 0 / .2); }
.toast.err { background: var(--red); color: #fff; }
@media (max-width: 640px) { header nav { order: 3; width: 100%; } .who small { display: none; } }

/* ---------- office screens (W3) ---------- */
main.wide { max-width: none; }
.page.narrow { max-width: 680px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 4px 0 14px; flex-wrap: wrap; }
.page-head h2, .page-head h3 { margin: 0; }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar .tabs { margin-bottom: 0; }
.search-inline { display: flex; gap: 8px; min-width: 0; }
.search-inline input { min-width: 0; }
.row.wrap { flex-wrap: wrap; }
.form-card { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.inline-field { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; font-size: 15px; }
.inline-field input, .inline-field select, .row select, .row input[type=date] { width: auto; }
select { min-height: var(--tap); padding: 0 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); font: inherit; color: inherit; }
.pick-list { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.pick-list button { text-align: left; font-weight: 400; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
td.r, th.r { text-align: right; } td.c, th.c { text-align: center; }
.num { font-variant-numeric: tabular-nums; }
tr.click { cursor: pointer; } tr.click:hover td { background: var(--green-2); }
tr.late td { background: var(--red-2); }
.grid-edit input.qty { width: 64px; min-height: 44px; padding: 6px; text-align: center; font-weight: 700; }
.grid-edit input.qty.price { width: 84px; text-align: right; }
.grid-edit tfoot td { border-top: 2px solid var(--line); }
.small-btn { min-height: 40px; min-width: 40px; font-size: 16px; }
button.danger-link { border: 0; background: none; color: var(--red); text-decoration: underline; padding: 0 8px; }
.notice.ok { background: var(--green-2); color: var(--green); }
.steps { list-style: none; counter-reset: step; padding: 0; margin: 0 0 14px; display: flex; flex-direction: column; gap: 8px; }
.step { counter-increment: step; display: flex; align-items: center; justify-content: space-between; gap: 14px; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px 12px 56px; position: relative; flex-wrap: wrap; }
.step::before { content: counter(step); position: absolute; left: 14px; top: 50%; transform: translateY(-50%); width: 30px; height: 30px;
  border-radius: 50%; background: var(--green-2); color: var(--green); font-weight: 800; display: grid; place-items: center; }
.step > div { flex: 1; min-width: 220px; }
.legend-line { margin: -4px 0 10px; }
.matrix-wrap { overflow: auto; max-height: calc(100vh - 230px); }
.matrix { font-size: 14px; border-collapse: separate; border-spacing: 0; }
.matrix th, .matrix td { padding: 6px 8px; white-space: nowrap; }
.matrix thead th { position: sticky; top: 0; background: var(--card); z-index: 2; }
.matrix .sticky { position: sticky; left: 0; background: var(--card); z-index: 1; min-width: 190px; }
.matrix thead .sticky { z-index: 3; }
.matrix .dname { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; } .matrix .dnum { font-size: 15px; color: var(--ink); }
.matrix .we { background: var(--grey-2); }
.matrix .wk { border-left: 2px solid var(--line); }
.matrix .today { box-shadow: inset 0 0 0 2px var(--green); }
.matrix td.has { font-weight: 700; background: var(--green-2); color: var(--green); }
.matrix td.plan { background: var(--amber-2); color: var(--amber); }
.matrix tfoot td { border-top: 2px solid var(--line); position: sticky; bottom: 0; background: var(--card); }
header nav { min-width: 0; overflow-x: auto; scrollbar-width: none; }
header nav button { flex: none; white-space: nowrap; }
@media (max-width: 640px) { header nav { order: 3; width: 100%; flex: 1 1 100%; } }

/* ---------- customer portal (W4) ---------- */
.cards.single { grid-template-columns: 1fr; }
.wide-btn { width: 100%; margin-top: 8px; }
.portal-signin .signin-card p { margin: 6px 0; }
.portal-page { max-width: 860px; margin: 0 auto; }
.delivery-list { display: flex; flex-direction: column; gap: 10px; }
.delivery { display: grid; grid-template-columns: 64px 1fr auto; gap: 16px; align-items: center; }
.delivery-date { text-align: center; background: var(--green-2); color: var(--green); border-radius: 12px; padding: 6px 0; }
.delivery-date .dow { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; font-weight: 700; }
.delivery-date .dom { font-size: 26px; font-weight: 800; line-height: 1.1; }
.delivery-date .mon { font-size: 12px; }
.delivery-body { min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.delivery .items { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 16px; }
.delivery .items li { display: inline-flex; align-items: center; gap: 6px; }
.qty-badge { display: inline-grid; place-items: center; min-width: 30px; height: 26px; padding: 0 6px; border-radius: 8px; background: var(--ink); color: var(--card); font-weight: 800; font-size: 14px; font-variant-numeric: tabular-nums; }
.change-rows { display: flex; flex-direction: column; gap: 10px; margin: 8px 0 14px; }
.change-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.change-row .stepper { flex: none; } .change-row .stepper input { width: 70px; }
.detail-card { margin-bottom: 12px; } .detail-card h3 { margin: 0 0 8px; }
.dl-row { display: grid; grid-template-columns: 180px 1fr auto; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.dl-row:last-child { border-bottom: 0; } .dl-row dt { color: var(--muted); } .dl-row dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
nav .count { display: inline-grid; place-items: center; min-width: 20px; height: 20px; margin-left: 6px; border-radius: 10px; background: var(--amber); color: #fff; font-size: 12px; }
@media (max-width: 560px) {
  .delivery { grid-template-columns: 56px 1fr; } .delivery-act { grid-column: 1 / -1; } .delivery-act button { width: 100%; }
  .dl-row { grid-template-columns: 1fr; gap: 2px; }
}
.notice .link { margin-left: 10px; }

/* ---------- driver app (W5) ---------- */
.driver main { max-width: 640px; padding: 12px; }
.driver-head { gap: 10px; flex-wrap: nowrap; top: env(safe-area-inset-top, 0px); }
.driver-head .brand { flex: 1; font-size: 20px; }
.sync { padding: 6px 12px; border-radius: 999px; font-weight: 700; font-size: 14px; white-space: nowrap; cursor: pointer; }
.sync.ok { background: var(--green-2); color: var(--green); } .sync.wait { background: var(--amber-2); color: var(--amber); } .sync.off { background: var(--red-2); color: var(--red); }
.route-head { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.stop-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.stop-card { display: grid !important; grid-template-columns: 44px 1fr auto; gap: 12px; align-items: center; text-align: left; }
.stop-card.next { border: 2px solid var(--green); }
.stop-card.s-completed, .stop-card.s-skipped { opacity: .6; }
.stop-no { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: var(--grey-2); font-weight: 800; }
.s-completed .stop-no { background: var(--green); color: #fff; } .s-arrived .stop-no { background: var(--amber); color: #fff; }
.stop-main { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.stop-info { display: flex; flex-direction: column; gap: 6px; margin: 6px 0 12px; }
.nav-btn { display: inline-flex; align-items: center; justify-content: center; min-height: var(--tap); border-radius: 12px; background: var(--blue-2); color: var(--blue); font-weight: 700; text-decoration: none; }
.driver-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.driver-actions .row button { flex: 1; }
.big-btn { min-height: 64px; font-size: 20px; }
.problems { border-color: var(--red); margin-bottom: 10px; display: flex; flex-direction: column; gap: 4px; }

/* ---------- dispatcher & team (W5) ---------- */
.flow { list-style: none; display: flex; gap: 4px; padding: 0; margin: 12px 0 4px; flex-wrap: wrap; }
.flow li { flex: 1; min-width: 90px; text-align: center; padding: 6px 4px; border-radius: 8px; background: var(--grey-2); font-size: 13px; font-weight: 700; color: var(--muted); }
.flow li.on { background: var(--green-2); color: var(--green); } .flow li.now { background: var(--amber-2); color: var(--amber); outline: 2px solid var(--amber); }
.line-chip { display: inline-block; margin: 2px 10px 2px 0; }
.warn { color: var(--amber); font-weight: 700; }
.role-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 6px; }
.role-grid .lot-option input { width: 22px; min-height: 0; }

/* print: only the page content (e.g. an invoice basis for typing into e-conomic) */
@media print {
  header, .tabs, .actions, .backbar, .toasts, .seg { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; border: 1px solid #ccc; }
}

.demo-tag { position: fixed; left: 12px; bottom: 12px; z-index: 40; background: #c0392b; color: #fff; font-weight: 700;
  padding: 6px 12px; border-radius: 999px; font-size: 13px; pointer-events: none; box-shadow: 0 2px 8px rgb(0 0 0 / .25); }
@media print { .demo-tag { display: none; } }

/* sign-in: PIN or password, device setup */
.signin-mode { display: flex; margin: 4px 0 14px; }
.signin-mode button { flex: 1; }
.setup-code { font: 700 34px/1.2 ui-monospace, Menlo, Consolas, monospace; letter-spacing: .18em; text-align: center;
  padding: 16px; margin: 6px 0 12px; border-radius: 12px; background: var(--green-2); color: var(--green); }
