:root {
  --bg: #f4f5f7;
  --card: #fff;
  --fg: #16181d;
  --muted: #646b78;
  --line: #dde0e6;
  --primary: #1d4ed8;
  --primary-fg: #fff;
  --danger: #b42318;
  --warn-bg: #fff6e0;
  --warn-line: #f0c36b;
  --ok-bg: #e8f6ec;
  --radius: 12px;
  --tap: 48px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317; --card: #1b1e24; --fg: #e8eaee; --muted: #9aa1ad; --line: #2c3038;
    --primary: #4f7cff; --danger: #ff6b5e; --warn-bg: #2e2612; --warn-line: #7a5a17; --ok-bg: #14281b;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
main { max-width: 760px; margin: 0 auto; padding: 12px 16px 48px; }
body.narrow main { max-width: 420px; padding-top: 10vh; }
h1 { font-size: 1.4rem; margin: .2em 0 .3em; }
h2 { font-size: 1.1rem; margin: 1.2em 0 .5em; }
h3 { margin: 0 0 .5em; }
a { color: var(--primary); }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .02em; }
.clip { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* header */
.top {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 12px;
  padding: 8px 16px; padding-top: max(8px, env(safe-area-inset-top));
  background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 1.25rem; color: var(--fg); text-decoration: none; }
.brand b { color: var(--primary); }
.brand.big { font-size: 2rem; text-align: center; }
.top nav { display: flex; gap: 4px; margin-left: auto; align-items: center; overflow-x: auto; }
.top nav a, .top nav button {
  padding: 8px 10px; border-radius: 8px; text-decoration: none; color: var(--fg);
  white-space: nowrap; font: inherit; background: none; border: 0; cursor: pointer;
}
.top nav .nav-scan { background: var(--primary); color: var(--primary-fg); font-weight: 600; }
.show-sm { display: none; }
@media (max-width: 480px) {
  .hide-sm { display: none; }
  .show-sm { display: inline; }
  .top { gap: 6px; padding-left: 12px; padding-right: 12px; }
  .top nav { gap: 2px; }
  .top nav a, .top nav button { padding: 8px 6px; }
}

/* controls */
input, textarea, select {
  width: 100%; font: inherit; color: inherit; background: var(--card);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; min-height: var(--tap);
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
textarea { resize: vertical; }
label { display: block; font-size: .9rem; color: var(--muted); }
label > input, label > textarea, label > select, label > .row { margin-top: 4px; color: var(--fg); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: var(--tap); padding: 0 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--fg); font: inherit; font-weight: 500; text-decoration: none;
  cursor: pointer; white-space: nowrap; -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-fg); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.big { min-height: 56px; font-size: 1.05rem; }
.btn.huge { min-height: 88px; font-size: 1.35rem; width: 100%; font-weight: 600; }
.btn.huge .ico { font-size: 1.8rem; }
.btn.block { width: 100%; }
.btn.small { min-height: 36px; padding: 0 10px; font-size: .9rem; }
.btn:disabled { opacity: .6; cursor: default; }
.btn-ghost { background: none; border: 0; color: var(--primary); font: inherit; cursor: pointer; padding: 6px; }
.btn-ghost.danger { color: var(--danger); }
.row { display: flex; gap: 8px; align-items: stretch; }
.row > input { flex: 1; min-width: 0; }
.grow { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stack > * + * { margin-top: 12px; }
.w-qty { max-width: 80px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 12px 0; }
.card.warn, .notice { background: var(--warn-bg); border-color: var(--warn-line); }
.card.warn ul { padding-left: 1.2em; }
.notice { border: 1px solid var(--ok-bg); background: var(--ok-bg); border-radius: var(--radius); padding: 12px 14px; }
.alert { background: var(--warn-bg); border: 1px solid var(--warn-line); border-radius: 10px; padding: 10px 12px; }
.auth form > * + * { margin-top: 12px; }
.empty { color: var(--muted); text-align: center; padding: 24px 0; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); padding: 12px 14px 14px; margin: 0; }
fieldset > * + * { margin-top: 10px; }
legend { font-weight: 600; padding: 0 6px; }

/* home */
.hero { margin: 8px 0 4px; }
.hero-row { display: grid; gap: 8px; margin-top: 10px; }
@media (min-width: 560px) { .hero-row { grid-template-columns: auto 1fr; } }
.code-form { display: flex; gap: 8px; }
.search { display: flex; gap: 8px; }
.tabs { display: flex; gap: 6px; }
.tabs a { padding: 6px 12px; border-radius: 999px; text-decoration: none; color: var(--muted); border: 1px solid var(--line); }
.tabs a.on { background: var(--fg); color: var(--bg); border-color: var(--fg); }

/* lists */
.list { list-style: none; margin: 0; padding: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list li + li { border-top: 1px solid var(--line); }
.list a { display: flex; gap: 12px; padding: 12px 14px; color: inherit; text-decoration: none; }
.list a:active { background: var(--bg); }
.list-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.list-side { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; text-align: right; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--bg); border: 1px solid var(--line); white-space: nowrap; }
.badge.big { font-size: .9rem; padding: 4px 12px; }
.s-received { background: #e0e7ff; color: #1e3a8a; border-color: #c7d2fe; }
.s-in_progress { background: #fef3c7; color: #78350f; border-color: #fde68a; }
.s-waiting_parts { background: #fde2e2; color: #7f1d1d; border-color: #fecaca; }
.s-ready { background: #dcfce7; color: #14532d; border-color: #bbf7d0; }
.s-released { background: #e5e7eb; color: #374151; border-color: #d1d5db; }

/* order */
.order-head { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; }
.order-head p { margin: 0; }
.tag-code { font-family: ui-monospace, Menlo, monospace; font-weight: 600; }
.customer .contact { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.customer p { margin: 8px 0 0; }
/* Thumb-reach action bar on phones; the card keeps kind/caption/gallery. */
.bottom-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: grid; grid-template-columns: 2fr 1fr; gap: 8px;
  padding: 10px 16px; padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: var(--card); border-top: 1px solid var(--line); box-shadow: 0 -4px 16px rgba(0,0,0,.08);
}
body.has-bar main { padding-bottom: 110px; }
@media (min-width: 761px) { .bottom-bar { display: none; } body.has-bar main { padding-bottom: 48px; } }
.capture-buttons { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 8px; margin-top: 10px; }
.capture-buttons .btn { padding: 0 8px; }
.caption { margin-top: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; }
.chips label, .chips button {
  display: inline-flex; color: var(--fg); font: inherit; background: none; border: 0; padding: 0; cursor: pointer;
}
.chips button, .chips label span {
  padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); font-size: .95rem;
}
.chips label { position: relative; }
.chips input { position: absolute; inset: 0; width: 1px; height: 1px; min-height: 0; padding: 0; opacity: 0; pointer-events: none; }
.chips input:checked + span { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.chips input:focus-visible + span { outline: 2px solid var(--primary); }
.note-form { margin-top: 10px; }
.note-form > * + * { margin-top: 8px; }
.queue { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 6px; }
.queue li { display: flex; align-items: center; gap: 10px; font-size: .9rem; }
.queue img { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; background: var(--bg); }
.queue progress { flex: 1; height: 8px; }
.queue .err { color: var(--danger); flex: 1; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 12px; margin: 0 0 8px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; white-space: pre-wrap; }
.items { list-style: none; padding: 0; margin: 0; }
.items li + li { border-top: 1px solid var(--line); }
.items summary { display: flex; gap: 8px; padding: 10px 0; cursor: pointer; list-style: none; align-items: baseline; }
.items summary::-webkit-details-marker { display: none; }
.items details form { margin: 0 0 10px; }
.item-name { flex: 1; min-width: 0; }
.item-name a { text-decoration: none; }
.item-qty { color: var(--muted); white-space: nowrap; }
.item-price { white-space: nowrap; font-weight: 600; }
.item-price.missing { color: var(--danger); font-weight: 500; }
.total { text-align: right; font-size: 1.1rem; margin: 8px 0; }
.add-item { margin-top: 10px; }
.add-item > summary { list-style: none; }
.add-item > summary::-webkit-details-marker { display: none; }
.add-item[open] > summary { display: none; }
.checks { list-style: none; padding: 10px 12px; margin: 12px 0 0; background: var(--warn-bg); border: 1px solid var(--warn-line); border-radius: 10px; font-size: .92rem; }
.checks li + li { margin-top: 4px; }
.status-buttons { display: flex; flex-wrap: wrap; gap: 6px; }
.status-buttons .btn { flex: 1 1 140px; }
.status-buttons .btn.current { outline: 3px solid var(--fg); outline-offset: 1px; opacity: 1; }
.warn-btn { border-color: var(--warn-line); background: var(--warn-bg); }

.timeline { list-style: none; padding: 0; margin: 0; }
.ev { position: relative; padding: 0 0 14px 18px; border-left: 2px solid var(--line); margin-left: 6px; }
.ev::before { content: ""; position: absolute; left: -7px; top: 4px; width: 12px; height: 12px; border-radius: 50%; background: var(--line); }
.ev-status::before { background: var(--primary); }
.ev-photo::before, .ev-item::before { background: #d97706; }
.ev-meta { font-size: .8rem; color: var(--muted); }
.ev-body { margin: 2px 0 0; white-space: pre-wrap; }
.ev-photo { display: flex; gap: 12px; margin-top: 4px; align-items: flex-start; }
.ev-photo img { width: 120px; height: 120px; object-fit: cover; border-radius: 10px; display: block; background: var(--line); }
.ev-photo p { margin: 4px 0; }
.ev-photo .btn { margin-top: 6px; }
:target { scroll-margin-top: 70px; }
.ev:target { background: var(--warn-bg); border-radius: 8px; }

/* intake */
.chosen { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; background: var(--ok-bg); border-radius: 10px; }
.suggest { list-style: none; padding: 0; margin: 4px 0 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.suggest li + li { border-top: 1px solid var(--line); }
.suggest button { width: 100%; text-align: left; background: var(--card); border: 0; padding: 10px 12px; font: inherit; color: inherit; cursor: pointer; }
.suggest small { color: var(--muted); display: block; }

/* scanner overlay */
.scanner { position: fixed; inset: 0; z-index: 100; background: #000; color: #fff; display: flex; flex-direction: column; }
.scanner video { flex: 1; width: 100%; min-height: 0; object-fit: cover; }
.scanner-bar { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); font-weight: 600; }
.scanner-bar .btn-ghost { color: #fff; font-size: 1.4rem; min-width: var(--tap); min-height: var(--tap); }
.scanner-frame { position: absolute; left: 50%; top: 45%; width: min(70vw, 300px); aspect-ratio: 1; transform: translate(-50%, -50%); border: 3px solid rgba(255,255,255,.85); border-radius: 18px; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); pointer-events: none; }
.scanner.barcode .scanner-frame { aspect-ratio: 2.2; width: min(86vw, 420px); }
.scanner.nocam .scanner-frame { display: none; }
.scanner-foot { padding: 12px 16px; padding-bottom: max(16px, env(safe-area-inset-bottom)); display: grid; gap: 10px; background: #000; }
.scanner-foot p { margin: 0; text-align: center; }
.scanner-foot .btn { background: #222; color: #fff; border-color: #444; flex: 1; }
.scanner-foot input { background: #111; color: #fff; border-color: #444; }

/* label sheet (A4) */
.sheet { display: grid; background: #fff; color: #000; margin: 0 auto; }
.sheet.l-3x8 { grid-template-columns: repeat(3, 70mm); grid-auto-rows: 37.125mm; width: 210mm; }
.sheet.l-5x13 { grid-template-columns: repeat(5, 38mm); grid-auto-rows: 21.2mm; width: 190mm; padding-top: 10.7mm; }
.label { display: flex; align-items: center; gap: 2mm; padding: 2mm 3mm; overflow: hidden; break-inside: avoid; }
.label .qr { height: 100%; aspect-ratio: 1; flex: none; }
.label .qr svg { width: 100%; height: 100%; display: block; }
.label-text { display: flex; flex-direction: column; font-family: ui-monospace, Menlo, monospace; line-height: 1.1; }
.label-brand { font: 700 9pt system-ui, sans-serif; }
.label-brand b { color: #1d4ed8; }
.label-code { font-size: 14pt; font-weight: 700; letter-spacing: .05em; }
.l-5x13 .label { padding: 1mm 1.5mm; gap: 1.5mm; }
.l-5x13 .label-brand { font-size: 6pt; }
.l-5x13 .label-code { font-size: 8pt; }
.label.used { opacity: .35; text-decoration: line-through; }
.print-page main { max-width: none; }
@media screen { .sheet { box-shadow: 0 2px 12px rgba(0,0,0,.15); } }
@media print {
  @page { size: A4; margin: 0; }
  body { background: #fff; }
  .top, .no-print { display: none !important; }
  main { padding: 0; }
  .label.used { visibility: hidden; }
}
@media screen { .print-page main { overflow-x: auto; } }

/* untagged queue / hand-off */
.top nav .nav-badge { background: var(--warn-bg); border: 1px solid var(--warn-line); font-weight: 600; }
#untagged h2 { margin-top: 0; }
#untagged .list { margin-top: 8px; }
.untagged .stack { margin-top: 10px; }
.handoff { display: flex; gap: 16px; align-items: center; }
.handoff h3 { margin: 0 0 4px; }
.handoff p { margin: 4px 0; }
.handoff-qr { width: 150px; flex: none; }
.handoff-qr svg { width: 100%; display: block; }
/* Pointless on the phone itself. */
@media (max-width: 760px), (pointer: coarse) { .handoff { display: none; } }
.list.pick form { margin: 0; }
.list.pick button {
  display: flex; gap: 12px; width: 100%; padding: 14px; border: 0; background: none;
  font: inherit; color: inherit; text-align: left; cursor: pointer;
}
.list.pick button:active { background: var(--bg); }
