/* Built for a warehouse, not a desk.
   Big targets because gloves. High contrast because overhead fluorescents.

   Two palettes. Dark is easier on the eyes for a phone held at arm length all
   day; light is easier to read under a skylight or beside a roll-up door, and
   it is what most people expect an app to look like. Neither is correct for
   every bay in the building, so it is a setting, and it defaults to light.

   Every colour in this file is a token. Adding a third palette should mean
   adding one block, not hunting hex codes through the rules. */

:root {
  /* ---- light, the default ---- */
  --bg: #f4f6f9;
  --panel: #ffffff;
  --panel-2: #eaeef4;
  --line: #d6dde6;
  --text: #11141a;
  --dim: #5c6675;
  --accent: #1f6feb;
  --on-accent: #ffffff;
  --ok: #16794a;
  --warn: #8a5a00;
  --bad: #c0342a;

  --hdr-bg: rgba(244,246,249,.92);
  --bar-bg: rgba(255,255,255,.96);
  --scrim: rgba(20,24,31,.38);
  --shadow: 0 6px 18px rgba(31,111,235,.28);

  --tag-warn-bg: #fdf0d5;
  --tag-accent-bg: #dfeaff;
  --tag-ok-bg: #d8f0e2;
  --tag-dim-bg: #e7ebf1;
  --tag-bad-bg: #fbe0dd;
  --danger-bg: #fbe8e6;
  --danger-line: #f0bdb7;
  --pip-sent: #b3bcc8;

  --tap: 52px;
}

/* Dark, chosen explicitly. */
:root[data-theme="dark"] {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --line: #2a2f3a;
  --text: #e8eaed;
  --dim: #98a0ae;
  --accent: #4c8dff;
  --on-accent: #ffffff;
  --ok: #2fbf71;
  --warn: #f0a92e;
  --bad: #f2564a;

  --hdr-bg: rgba(15,17,21,.92);
  --bar-bg: rgba(23,26,33,.96);
  --scrim: rgba(8,9,12,.55);
  --shadow: 0 6px 18px rgba(76,141,255,.35);

  --tag-warn-bg: #3a2f16;
  --tag-accent-bg: #16304a;
  --tag-ok-bg: #1c3a2a;
  --tag-dim-bg: #23272f;
  --tag-bad-bg: #3d1f1c;
  --danger-bg: #2a1714;
  --danger-line: #52241d;
  --pip-sent: #444b57;
}

/* Following the device, and the device says dark. */
@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] {
    --bg: #0f1115;
    --panel: #171a21;
    --panel-2: #1e222b;
    --line: #2a2f3a;
    --text: #e8eaed;
    --dim: #98a0ae;
    --accent: #4c8dff;
    --on-accent: #ffffff;
    --ok: #2fbf71;
    --warn: #f0a92e;
    --bad: #f2564a;

    --hdr-bg: rgba(15,17,21,.92);
    --bar-bg: rgba(23,26,33,.96);
    --scrim: rgba(8,9,12,.55);
    --shadow: 0 6px 18px rgba(76,141,255,.35);

    --tag-warn-bg: #3a2f16;
    --tag-accent-bg: #16304a;
    --tag-ok-bg: #1c3a2a;
    --tag-dim-bg: #23272f;
    --tag-bad-bg: #3d1f1c;
    --danger-bg: #2a1714;
    --danger-line: #52241d;
    --pip-sent: #444b57;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* [hidden] is a plain attribute selector, so any element given an explicit
   display - every button here is inline-flex - silently outranks it and
   stays on screen. That has now caused two visible bugs: a capture sheet
   stuck open over the drafts list, and a flashlight button offering itself
   on a device with no camera. Settle it once, for everything. */
[hidden] { display: none !important; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  overscroll-behavior-y: none;
}

#app { padding-bottom: calc(72px + env(safe-area-inset-bottom)); min-height: 100%; }

/* ---------- headers ---------- */
.hdr {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  background: var(--hdr-bg); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.hdr h1 { font-size: 19px; margin: 0; font-weight: 650; letter-spacing: -.01em; }
.hdr .sub { color: var(--dim); font-size: 13px; }
.spacer { flex: 1; }
.iconbtn {
  min-height: 40px; padding: 0 12px; background: transparent;
  border: none; color: var(--dim); font-size: 18px;
}

/* ---------- lists / cards ---------- */
.list { padding: 12px 16px 24px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px; margin-bottom: 10px;
}
.card:active { background: var(--panel-2); }
.row { display: flex; align-items: center; gap: 10px; }
.title { font-weight: 600; letter-spacing: -.01em; }
.meta { color: var(--dim); font-size: 13px; margin-top: 3px; }
.hint { font-weight: 600; text-transform: none; letter-spacing: 0; opacity: .8; }

.tag {
  font-size: 11.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  padding: 4px 9px; border-radius: 999px; white-space: nowrap;
}
.tag.incomplete       { background: var(--tag-warn-bg); color: var(--warn); }
.tag.ready_to_review  { background: var(--tag-accent-bg); color: var(--accent); }
.tag.partly_published { background: var(--tag-ok-bg); color: var(--ok); }
.tag.sent             { background: var(--tag-dim-bg); color: var(--dim); }
.tag.attention        { background: var(--tag-bad-bg); color: var(--bad); }
.tag.wait             { background: var(--tag-dim-bg); color: var(--dim); }
.tag.ready            { background: var(--tag-accent-bg); color: var(--accent); }
.tag.approved         { background: var(--tag-ok-bg); color: var(--ok); }

/* The price is the number most often changed, so it is an input, not a
   readout dressed up as one. */
.pricerow { display: flex; align-items: center; gap: 4px; margin: 2px 0 8px; }
.pricerow .dollar { font-size: 27px; font-weight: 700; color: var(--dim); }
.pricerow input {
  font: 700 27px/1.1 inherit; letter-spacing: -.02em;
  padding: 6px 8px; min-height: 52px; background: var(--panel-2);
  font-variant-numeric: tabular-nums;
}
.srcline .dim { color: var(--dim); font-weight: 600; }

/* ---------- item status pips ---------- */
.pip { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.pip.ready { background: var(--ok); }
.pip.approved { background: var(--accent); }
.pip.needs_review { background: var(--warn); }
.pip.failed { background: var(--bad); }
.pip.identifying { background: var(--dim); animation: pulse 1.1s infinite; }
.pip.capturing { background: var(--dim); }
.pip.sent { background: var(--pip-sent); }
@keyframes pulse { 50% { opacity: .25; } }

/* ---------- buttons ---------- */
button, .btn {
  font: inherit; font-weight: 600; color: var(--text);
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 12px; min-height: var(--tap); padding: 0 18px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  cursor: pointer;
}
button:active { transform: scale(.985); }
button[disabled] { opacity: .4; }
.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.danger  { background: var(--danger-bg); border-color: var(--danger-line); color: var(--bad); }
.danger.solid { background: var(--bad); border-color: var(--bad); color: #fff; }
.ghost   { background: transparent; }

/* ---------- segmented control ---------- */
.seg {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 12px; padding: 4px;
}
.seg button {
  min-height: 40px; border: none; background: transparent;
  color: var(--dim); font-size: 14px; padding: 0 8px;
}
.seg button.on {
  background: var(--panel); color: var(--text);
  box-shadow: 0 1px 3px rgba(0,0,0,.18);
}

/* ---------- bottom tab bar (native-style, not a web hamburger) ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 8px 20px calc(8px + env(safe-area-inset-bottom));
  background: var(--bar-bg); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.tabbar button {
  background: none; border: none; min-height: 56px; color: var(--dim);
  flex-direction: column; gap: 3px; font-size: 11px; font-weight: 600;
}
.tabbar button.on { color: var(--text); }
.tabbar .plus {
  width: 58px; height: 58px; border-radius: 50%;
  background: var(--accent); color: var(--on-accent);
  font-size: 30px; font-weight: 300;
  box-shadow: var(--shadow); min-height: 0;
}
.tabbar svg { width: 23px; height: 23px; }

/* ---------- sheets (a window over the background) ---------- */
.sheet {
  position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column;
  background: var(--scrim); backdrop-filter: blur(3px);
}
/* [hidden] only sets display:none at low specificity, so a display rule on the
   element itself silently wins and the sheet is stuck open. */
.sheet[hidden] { display: none; }
/* The scanner is a step, not a layer: it always sits above the capture sheet,
   whatever the document order says. Belt to beginPart()'s braces. */
#scansheet { z-index: 60; }
.sheet-body {
  margin-top: auto; background: var(--bg);
  border-radius: 20px 20px 0 0; border-top: 1px solid var(--line);
  max-height: 94%; display: flex; flex-direction: column;
}
.sheet-head {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 16px 16px 8px; border-bottom: 1px solid var(--line);
}
.sheet-head h2 { margin: 0; font-size: 20px; font-weight: 650; letter-spacing: -.01em; }
.counter { font-size: 30px; font-weight: 700; line-height: 1; letter-spacing: -.02em; }
.counter small { display: block; font-size: 12px; color: var(--dim); font-weight: 600;
  letter-spacing: .04em; text-transform: uppercase; margin-top: 4px; }
.sheet-scroll { overflow-y: auto; padding: 14px 16px 16px; flex: 1; }
.sheet-foot {
  display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px;
  padding: 10px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line); background: var(--panel);
}
.sheet-foot.two-up { grid-template-columns: 1fr 2fr; }

/* ---------- photo slots ---------- */
.slots { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.slot {
  aspect-ratio: 1; border-radius: 12px; border: 1.5px dashed var(--line);
  background: var(--panel); display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 4px;
  color: var(--dim); font-size: 10.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .03em; overflow: hidden; position: relative;
}
.slot.filled { border-style: solid; border-color: var(--accent); }
.slot img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.slot .x {
  position: absolute; top: 3px; right: 3px; width: 22px; height: 22px;
  border-radius: 50%; background: rgba(0,0,0,.65); color: #fff;
  font-size: 14px; display: flex; align-items: center; justify-content: center;
}
.slot svg { width: 20px; height: 20px; }

/* ---------- fields ---------- */
label.f { display: block; margin: 14px 0 6px; font-size: 12px; font-weight: 700;
  color: var(--dim); text-transform: uppercase; letter-spacing: .05em; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--panel);
  border: 1px solid var(--line); border-radius: 12px;
  padding: 13px 14px; min-height: var(--tap);
}
textarea { min-height: 220px; resize: vertical; line-height: 1.5; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[hidden] { display: none; }
.check { display: flex; align-items: center; gap: 12px; padding: 14px 0; }
.check input { width: 24px; height: 24px; min-height: 0; flex: none; }
.check span { font-weight: 600; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* The SKU counts itself. Showing the number instead of an empty box is the
   difference between being told what it is and being asked what it is. */
.skurow {
  display: flex; align-items: center; gap: 12px; margin-top: 16px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 8px 8px 8px 14px; min-height: var(--tap);
}
.skurow .grow { flex: 1; min-width: 0; }
.skurow .k { font-size: 12px; font-weight: 700; color: var(--dim);
  text-transform: uppercase; letter-spacing: .05em; }
.skurow .v { font-size: 17px; font-weight: 700; letter-spacing: -.01em; margin-top: 1px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.skurow button { min-height: 40px; padding: 0 14px; font-size: 14px; }

/* ---------- confirm panel ---------- */
.confirm { background: var(--panel); border: 1px solid var(--danger-line);
  border-radius: 14px; padding: 18px; margin-top: 4px; }
.confirm h2 { margin: 0 0 8px; font-size: 19px; letter-spacing: -.01em; }
.confirm ul { margin: 12px 0; padding-left: 18px; color: var(--dim); font-size: 14.5px; }
.confirm li { margin-bottom: 6px; }
.confirm li b { color: var(--text); }
.confirm .acts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }

/* ---------- evidence / price ---------- */
.evidence { background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 14px; margin: 14px 0; }
.evidence h3 { margin: 0 0 4px; font-size: 13px; text-transform: uppercase;
  letter-spacing: .05em; color: var(--dim); }
.big { font-size: 27px; font-weight: 700; letter-spacing: -.02em; }
.band { color: var(--dim); font-size: 14px; }
/* Caveats are context, not alarms. Three lines of warning colour on every
   item trained the eye to ignore the colour, which is the opposite of what a
   warning is for. Only the one that changes a decision keeps it. */
.caveat { color: var(--dim); font-size: 13px; margin-top: 6px; }
.caveat.strong { color: var(--warn); font-weight: 600; }
.srcline { display: flex; justify-content: space-between; gap: 10px;
  padding: 7px 0; border-top: 1px solid var(--line); font-size: 14px; }
.srcline a { color: var(--accent); text-decoration: none; }

.banner { padding: 12px 14px; border-radius: 12px; margin: 0 16px 12px;
  font-size: 14px; font-weight: 600; }
.banner.warn { background: var(--tag-warn-bg); color: var(--warn); }
.empty { text-align: center; color: var(--dim); padding: 64px 24px; }
.refs { display: flex; gap: 8px; overflow-x: auto; padding-top: 8px; }
.refs img { width: 76px; height: 76px; border-radius: 10px; object-fit: cover;
  border: 1px solid var(--line); flex: none; }

/* loading skeleton */
.skel { height: 74px; background: linear-gradient(90deg, var(--panel) 25%, var(--panel-2) 50%, var(--panel) 75%); background-size: 200% 100%; animation: shimmer 1.3s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- the tag scanner ---------- */
/* The camera view is always dark, in both palettes. A light chrome around a
   live camera feed reads as a photo app; a dark one reads as an instrument,
   and the whole point of this screen is that it is measuring something. */
.scan-body { max-height: 96%; }
/* aspect-ratio plus max-height let the HEIGHT decide the width, so on a tall
   phone the camera shrank to about three quarters of the screen and left a
   band of page beside it. The view owns the full width; the height follows. */
.scanview {
  position: relative; background: #000; overflow: hidden;
  width: 100%; height: 54vh; min-height: 260px;
}
.scanview video {
  position: absolute; inset: 0;
  width: 100%; height: 100%; object-fit: cover; display: block;
}

/* The box is the instruction. Corner brackets rather than a full rectangle,
   because a closed rectangle reads as a border and brackets read as aim. */
.scanframe {
  position: absolute; left: 7%; right: 7%; top: 27%; bottom: 27%;
  pointer-events: none;
}
.scanframe span {
  position: absolute; width: 30px; height: 30px;
  border: 3px solid rgba(255,255,255,.95); border-radius: 4px;
}
.scanframe span:nth-child(1) { top: 0; left: 0; border-right: 0; border-bottom: 0; }
.scanframe span:nth-child(2) { top: 0; right: 0; border-left: 0; border-bottom: 0; }
.scanframe span:nth-child(3) { bottom: 0; left: 0; border-right: 0; border-top: 0; }
.scanframe span:nth-child(4) { bottom: 0; right: 0; border-left: 0; border-top: 0; }

.focusbar {
  position: absolute; left: 7%; right: 7%; bottom: 20%; height: 4px;
  background: rgba(255,255,255,.18); border-radius: 999px; overflow: hidden;
}
.focusbar i { display: block; height: 100%; width: 0;
  background: var(--ok); transition: width .12s linear, background .2s; }

.scanfound {
  position: absolute; inset: auto 0 0 0; padding: 16px;
  background: linear-gradient(transparent, rgba(0,0,0,.85) 40%); color: #fff;
}
.scanfound .big { color: #fff; }
.scanfound .meta { color: rgba(255,255,255,.8); }

.scannocam {
  position: absolute; inset: 0; display: flex; align-items: center;
  justify-content: center; text-align: center; padding: 32px;
  color: rgba(255,255,255,.85); font-size: 15px; background: #111;
}

.scanstatus {
  padding: 13px 16px; text-align: center; font-weight: 600; font-size: 15px;
  color: var(--dim); background: var(--bg);
}
/* Coaching ("hold steadier") is not a warning. Only a stop is. */
.scanstatus.warn { color: var(--warn); }
.scanstatus.coach { color: var(--dim); }

/* What the scanner found, carried into the capture sheet so the number is
   confirmed before four more photos are taken rather than after. */
.scanbanner {
  padding: 12px 14px; border-radius: 12px; margin-bottom: 14px;
  font-size: 14px; font-weight: 600;
  background: var(--tag-ok-bg); color: var(--ok);
}
.scanbanner.unconfirmed { background: var(--tag-warn-bg); color: var(--warn); }
.scanbanner small { display: block; font-weight: 600; opacity: .85; margin-top: 2px; }

/* ---------- parts held on this phone ---------- */
/* Above the tab bar on every screen. Amber, not red: waiting for a signal is
   normal and expected. Red only when something needs a person. */
.pendingbar {
  position: fixed; left: 0; right: 0; z-index: 41;
  bottom: calc(72px + env(safe-area-inset-bottom));
  padding: 10px 16px; font-size: 14px; font-weight: 600;
  background: var(--tag-warn-bg); color: var(--warn);
  border-top: 1px solid var(--line);
}
.pendingbar small {
  display: block; font-weight: 600; opacity: .85; font-size: 12.5px; margin-top: 1px;
}
.pendingbar.stuck { background: var(--tag-bad-bg); color: var(--bad); }
.pendingbar .barbtn {
  margin-top: 8px; width: 100%; min-height: 40px; font-size: 14px;
  background: var(--panel); border-color: currentColor; color: inherit;
}

/* ---------- bulk import review ---------- */
.impshot { position: relative; flex: none; }
.impshot img {
  width: 76px; height: 76px; border-radius: 10px; object-fit: cover;
  border: 1px solid var(--line); display: block;
}
/* The scissors sit ON the boundary they would create, between this photo and
   the one before it, rather than in a menu describing the same thing. */
.impshot .cut {
  position: absolute; left: -13px; top: 50%; transform: translateY(-50%);
  width: 26px; height: 26px; min-height: 0; padding: 0; border-radius: 50%;
  background: var(--panel); border: 1px solid var(--line); font-size: 12px;
  color: var(--dim); z-index: 2;
}
