:root {
  --navy: #14213d;
  --navy-2: #22335c;
  --amber: #fca311;
  --amber-soft: #fff4dd;
  --bg: #f2f3f6;
  --card: #ffffff;
  --ink: #111827;
  --ink-2: #4b5563;
  --ink-3: #8a93a3;
  --line: #e3e6ec;
  --blue: #2563eb;
  --blue-soft: #e6eefe;
  --green: #15803d;
  --green-soft: #e3f6e9;
  --red: #c62828;
  --red-soft: #fde8e8;
  --slate-soft: #eceef3;
  --radius: 14px;
  --mono: ui-monospace, 'SF Mono', 'Cascadia Mono', Consolas, 'Roboto Mono', monospace;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 14px rgba(16, 24, 40, .05);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
.mono { font-family: var(--mono); letter-spacing: .01em; }
.muted { color: var(--ink-3); }
.small { font-size: 13px; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px max(16px, env(safe-area-inset-left));
  background: var(--navy); color: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; min-width: 0; }
.brand img { width: 34px; height: 34px; }
.brand span { display: flex; flex-direction: column; line-height: 1.1; }
.brand small { color: var(--amber); font-weight: 700; letter-spacing: .12em; font-size: 11px; }
.top-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.role-badge { background: var(--navy-2); padding: 5px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; }
.sync-pill {
  border: 0; border-radius: 999px; padding: 5px 11px; font-size: 13px; cursor: pointer;
  background: rgba(255,255,255,.1); color: #fff; display: inline-flex; align-items: center; gap: 6px;
}
.sync-pill::before { content: ''; width: 9px; height: 9px; border-radius: 50%; background: #4ade80; box-shadow: 0 0 0 3px rgba(74,222,128,.25); }
.sync-pill.off::before { background: #f87171; box-shadow: 0 0 0 3px rgba(248,113,113,.25); }
.sync-pill.pending::before { background: var(--amber); }
.lang { display: inline-flex; background: rgba(255,255,255,.1); border-radius: 999px; padding: 3px; }
.lang button { border: 0; background: none; color: #cbd5e1; padding: 4px 10px; border-radius: 999px; cursor: pointer; font-weight: 700; font-size: 13px; }
.lang button.on { background: #fff; color: var(--navy); }

main { padding: 16px max(16px, env(safe-area-inset-left)) 48px; max-width: 1400px; margin: 0 auto; }

/* ---------- generic ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card > h2 { font-size: 16px; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.grid2 { display: grid; grid-template-columns: minmax(280px, 380px) 1fr; gap: 16px; align-items: start; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row > * { flex: 1 1 140px; }
.spacer { flex: 1; }
.fld { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: 13px; color: var(--ink-2); margin-bottom: 12px; }
select, input[type=text], input[type=number], input[type=date], input[type=search] {
  width: 100%; min-height: 48px; padding: 10px 12px; border: 1.5px solid var(--line); border-radius: 10px;
  background: #fff; font-size: 16px; color: var(--ink);
}
select:focus, input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(37,99,235,.18); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 10px 16px; border-radius: 10px; border: 1.5px solid var(--line);
  background: #fff; cursor: pointer; font-weight: 650; font-size: 15px; white-space: nowrap;
}
.btn:hover { border-color: #c9ced8; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--navy); color: #fff; border-color: var(--navy); }
.btn.primary:hover { background: var(--navy-2); }
.btn.go { background: var(--green); border-color: var(--green); color: #fff; }
.btn.warn { background: var(--amber); border-color: var(--amber); color: var(--navy); }
.btn.danger { color: var(--red); border-color: #f3c5c5; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.xl { min-height: 64px; font-size: 18px; padding: 14px 22px; border-radius: 12px; }
.btn.block { width: 100%; }
.icon-btn { border: 0; background: none; cursor: pointer; font-size: 18px; padding: 6px 10px; border-radius: 8px; color: var(--ink-2); }
.icon-btn:hover { background: var(--slate-soft); }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--slate-soft); color: var(--ink-2); }
.chip.blue { background: var(--blue-soft); color: var(--blue); }
.chip.green { background: var(--green-soft); color: var(--green); }
.chip.red { background: var(--red-soft); color: var(--red); }
.chip.amber { background: var(--amber-soft); color: #9a5b00; }
.chip.navy { background: var(--navy); color: #fff; }
.empty { text-align: center; color: var(--ink-3); padding: 28px 12px; }
.kbd { font-family: var(--mono); font-size: 12px; background: var(--slate-soft); padding: 2px 6px; border-radius: 5px; color: var(--ink-2); }

/* ---------- home ---------- */
.home { max-width: 820px; margin: 5vh auto 0; text-align: center; }
.home h1 { font-size: 26px; margin-bottom: 22px; }
.role-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.role-card {
  display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 32px 20px;
  border-radius: 18px; border: 2px solid var(--line); background: #fff; cursor: pointer; text-decoration: none; color: var(--ink);
  box-shadow: var(--shadow); transition: transform .08s, border-color .1s;
}
.role-card:hover, .role-card:focus { border-color: var(--navy); transform: translateY(-2px); outline: none; }
.role-card .ico { font-size: 44px; }
.role-card b { font-size: 22px; }
.role-card span { color: var(--ink-2); }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 6px; margin-bottom: 16px; overflow-x: auto; padding-bottom: 2px; }
.tabs a {
  padding: 10px 16px; border-radius: 10px; text-decoration: none; color: var(--ink-2); font-weight: 650; white-space: nowrap;
  background: #fff; border: 1.5px solid var(--line);
}
.tabs a.on { background: var(--navy); color: #fff; border-color: var(--navy); }
.tabs .badge { background: var(--amber); color: var(--navy); border-radius: 999px; padding: 0 7px; font-size: 12px; margin-left: 6px; }

/* ---------- scan inputs ---------- */
.scan-row { display: flex; gap: 8px; }
.scan-row input { flex: 1; }
input.scan { font-family: var(--mono); font-size: 19px; min-height: 56px; border-width: 2px; text-transform: uppercase; }
input.scan.huge { font-size: 24px; min-height: 68px; }
input.scan::placeholder { text-transform: none; font-family: system-ui, sans-serif; font-size: 16px; }
.cam-btn { min-width: 56px; font-size: 22px; }
.flash-ok { animation: flashok .5s; }
.flash-err { animation: flasherr .5s; }
@keyframes flashok { 0% { box-shadow: 0 0 0 6px rgba(21,128,61,.45); } 100% { box-shadow: none; } }
@keyframes flasherr { 0%, 60% { box-shadow: 0 0 0 6px rgba(198,40,40,.5); background: var(--red-soft); } 100% { box-shadow: none; } }

/* ---------- dispatch ---------- */
.seg { display: inline-flex; border: 1.5px solid var(--line); border-radius: 10px; overflow: hidden; width: 100%; }
.seg button { flex: 1; min-height: 46px; border: 0; background: #fff; cursor: pointer; font-weight: 700; }
.seg button.on { background: var(--navy); color: #fff; }
.binlist { list-style: none; margin: 12px 0 0; padding: 0; max-height: 52vh; overflow: auto; border: 1px solid var(--line); border-radius: 10px; counter-reset: n; }
.binlist li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-bottom: 1px solid var(--line); counter-increment: n; }
.binlist li:last-child { border-bottom: 0; }
.binlist li::before { content: counter(n); width: 26px; color: var(--ink-3); font-size: 12px; text-align: right; }
.binlist li .code { font-family: var(--mono); font-weight: 650; font-size: 16px; }
.binlist li.new { animation: flashok .6s; }
.binlist li .warn { color: #9a5b00; font-size: 12px; }
.dispatch-foot { display: flex; gap: 10px; margin-top: 14px; align-items: center; flex-wrap: wrap; }
.dispatch-foot .btn.primary { flex: 1; }
.count-big { font-size: 13px; background: var(--navy); color: #fff; padding: 2px 10px; border-radius: 999px; }

/* ---------- live board ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; box-shadow: var(--shadow); }
.kpi b { display: block; font-size: 26px; font-variant-numeric: tabular-nums; }
.kpi span { color: var(--ink-2); font-size: 13px; font-weight: 600; }
.board-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.filters { display: inline-flex; gap: 6px; }
.filters button { border: 1.5px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 14px; cursor: pointer; font-weight: 650; }
.filters button.on { background: var(--navy); color: #fff; border-color: var(--navy); }
.cart-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 12px; }
.cart-card {
  background: #fff; border: 1.5px solid var(--line); border-left: 6px solid var(--ink-3); border-radius: 12px; padding: 12px 14px;
  cursor: pointer; box-shadow: var(--shadow); text-align: left; width: 100%;
}
.cart-card:hover { border-color: #c5cbd6; }
.cart-card.s-in_progress { border-left-color: var(--blue); }
.cart-card.s-done { border-left-color: var(--green); }
.cart-card.s-cancelled { border-left-color: #bbb; opacity: .7; }
.cart-card.stale { border-left-color: var(--amber); background: linear-gradient(0deg, #fff, var(--amber-soft)); }
.cc-top { display: flex; align-items: center; gap: 8px; }
.cc-top .who { font-size: 18px; font-weight: 750; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cc-sub { color: var(--ink-2); font-size: 13px; margin: 2px 0 10px; }
.bar { height: 10px; background: var(--slate-soft); border-radius: 999px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--blue); border-radius: 999px; transition: width .4s; }
.s-done .bar i { background: var(--green); }
.cc-prog { display: flex; justify-content: space-between; font-size: 13px; margin: 6px 0 8px; font-variant-numeric: tabular-nums; }
.cc-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; font-size: 13px; }
.cc-meta div span { color: var(--ink-3); display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; font-weight: 700; }
.cc-meta div b { font-variant-numeric: tabular-nums; }
.cc-aisles { margin-top: 8px; display: flex; gap: 4px; flex-wrap: wrap; }
.stale-note { margin-top: 8px; font-size: 12px; font-weight: 700; color: #9a5b00; }

table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-3); padding: 8px 10px; border-bottom: 1.5px solid var(--line); white-space: nowrap; background: #fafbfc; position: sticky; top: 0; }
.tbl td { padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; font-variant-numeric: tabular-nums; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: #f7f9fc; }
.tbl-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 10px; max-height: 60vh; }
.section-gap { margin-top: 18px; }

/* ---------- modal ---------- */
.modal-wrap { position: fixed; inset: 0; background: rgba(15, 23, 42, .5); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: #fff; border-radius: 16px; width: min(480px, 100%); max-height: 92vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal.wide { width: min(980px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.modal-head h3 { font-size: 17px; }
.modal-body { padding: 16px; overflow: auto; }
.modal-foot { padding: 12px 16px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.modal-foot .btn { flex: 1 1 140px; }
video.cam { width: 100%; border-radius: 12px; background: #000; max-height: 60vh; }
.detail-head { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 14px; }
.detail-head div { background: #f7f8fa; border-radius: 10px; padding: 8px 10px; }
.detail-head > div > span { display: block; font-size: 11px; text-transform: uppercase; color: var(--ink-3); font-weight: 700; letter-spacing: .04em; }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.detail-actions select { width: auto; min-width: 180px; }

/* ---------- toasts ---------- */
#toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 60; width: min(92vw, 460px); pointer-events: none; }
.toast { background: var(--navy); color: #fff; padding: 12px 16px; border-radius: 12px; font-weight: 650; box-shadow: 0 10px 30px rgba(0,0,0,.25); transition: opacity .3s, transform .3s; }
.toast.ok { background: var(--green); }
.toast.err { background: var(--red); }
.toast.warn { background: var(--amber); color: var(--navy); }
.toast.out { opacity: 0; transform: translateY(8px); }

/* ---------- settings ---------- */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.plist { list-style: none; padding: 0; margin: 10px 0 0; }
.plist li { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.plist li b { flex: 1; }
.plist li.off b { color: var(--ink-3); text-decoration: line-through; }
.loc-example { font-family: var(--mono); background: var(--slate-soft); padding: 8px 10px; border-radius: 8px; margin-top: 4px; }

/* ---------- operator ---------- */
.name-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.name-grid button { min-height: 72px; font-size: 19px; font-weight: 750; border-radius: 14px; border: 2px solid var(--line); background: #fff; cursor: pointer; }
.name-grid button:hover, .name-grid button:focus { border-color: var(--navy); outline: none; }
.op-hello { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.op-hello h1 { font-size: 22px; }
.op-cart {
  display: flex; align-items: center; gap: 14px; padding: 14px 16px; border-radius: 14px; background: #fff; border: 2px solid var(--line);
  width: 100%; text-align: left; cursor: pointer; margin-bottom: 10px; box-shadow: var(--shadow);
}
.op-cart:hover { border-color: var(--navy); }
.op-cart .big { font-size: 20px; font-weight: 800; }
.op-cart .grow { flex: 1; min-width: 0; }
.op-cart .pct { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }

.work-head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap; background: var(--navy); color: #fff; border-radius: 14px; padding: 12px 14px; margin-bottom: 14px;
}
.work-head .btn { min-height: 40px; }
.work-head .t1 { font-size: 20px; font-weight: 800; }
.work-head .t2 { color: #cbd5e1; font-size: 13px; }
.work-head .prog { margin-left: auto; text-align: right; }
.work-head .prog b { font-size: 26px; font-variant-numeric: tabular-nums; }
.work-head .bar { background: rgba(255,255,255,.18); width: 180px; margin-top: 4px; }
.work-head .bar i { background: #4ade80; }
.start-banner { text-align: center; padding: 22px; margin-bottom: 14px; border: 2px dashed var(--amber); background: var(--amber-soft); border-radius: 14px; }
.prompt { font-size: 18px; font-weight: 750; margin-bottom: 10px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.prompt .step { background: var(--navy); color: #fff; border-radius: 999px; width: 28px; height: 28px; display: inline-grid; place-items: center; font-size: 14px; }
.prompt.loc .step { background: var(--amber); color: var(--navy); }
.prompt .code { font-family: var(--mono); background: var(--amber-soft); padding: 2px 8px; border-radius: 6px; }
.quick-row { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.quick-row .btn { flex: 1 1 200px; justify-content: flex-start; font-weight: 600; }
.quick-row .btn .mono { font-weight: 750; }
.picker { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 12px; }
.picker h4 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-2); }
.pk-label { font-size: 12px; font-weight: 700; color: var(--ink-3); margin: 10px 0 5px; text-transform: uppercase; letter-spacing: .04em; }
.pk-btns { display: flex; flex-wrap: wrap; gap: 6px; }
.pk-btns button { min-width: 52px; min-height: 44px; border-radius: 9px; border: 1.5px solid var(--line); background: #fff; font-family: var(--mono); font-weight: 750; cursor: pointer; font-size: 15px; }
.pk-btns button.on { background: var(--navy); color: #fff; border-color: var(--navy); }
.pk-btns.upper button.on { background: #6b21a8; border-color: #6b21a8; }
.stepper { display: flex; gap: 6px; align-items: stretch; max-width: 320px; }
.stepper button { min-width: 52px; font-size: 20px; font-weight: 800; border-radius: 9px; border: 1.5px solid var(--line); background: #fff; cursor: pointer; }
.stepper input { text-align: center; font-family: var(--mono); font-size: 22px; font-weight: 800; }
.pk-preview { margin-top: 12px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.pk-preview .mono { font-size: 22px; font-weight: 800; background: var(--slate-soft); padding: 8px 12px; border-radius: 10px; flex: 1 1 260px; text-align: center; }
.op-bins { position: relative; list-style: none; padding: 0; margin: 0; max-height: 70vh; overflow: auto; }
.op-bins li {
  flex-wrap: wrap; row-gap: 2px;
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1.5px solid var(--line); border-radius: 10px; margin-bottom: 6px; cursor: pointer; background: #fff;
}
.op-bins li .code { font-family: var(--mono); font-weight: 750; font-size: 16px; white-space: nowrap; }
.op-bins li .loc { margin-left: auto; white-space: nowrap; font-family: var(--mono); font-size: 13px; color: var(--green); font-weight: 700; text-align: right; }
.op-bins li.placed { background: var(--green-soft); border-color: #bfe5cb; }
.op-bins li.issue { background: var(--red-soft); border-color: #f3c5c5; }
.op-bins li.issue .loc { color: var(--red); }
.op-bins li.sel { border-color: var(--amber); box-shadow: 0 0 0 3px rgba(252,163,17,.35); }
.op-bins li .dot { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--ink-3); flex: none; }
.op-bins li.placed .dot { background: var(--green); border-color: var(--green); }
.op-bins li.issue .dot { background: var(--red); border-color: var(--red); }
.finish-bar { margin-top: 14px; display: flex; gap: 10px; flex-wrap: wrap; }
.finish-bar .btn.xl { flex: 1 1 260px; }

.grid-oplist { grid-template-columns: 1fr minmax(260px, 360px); }
.grid-work { grid-template-columns: minmax(300px, 1.2fr) minmax(260px, 1fr); }

@media (max-width: 860px) {
  .grid2, .grid-oplist, .grid-work { grid-template-columns: 1fr; }
  .work-head .prog { margin-left: 0; text-align: left; width: 100%; }
  .work-head .bar { width: 100%; }
  .brand small { display: none; }
}
@media (max-width: 520px) {
  .role-badge { display: none; }
  .brand b { font-size: 14px; }
}
