/**
 * Batch scan — full-viewport workflow page. Sticky scanner top, scrolling
 * qty list middle, sticky save bar bottom. Dark theme + LEGO yellow.
 */
:root {
  --bg: #0c0c12;
  --card: #15151c;
  --card-2: #1a1a23;
  --border: #2a2a36;
  --text: #e9e9f0;
  --muted: #8a8aa0;
  --accent: #ffcc02;
  --accent-2: #d92027;
  --green: #4ade80;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  width: 100%; max-width: 100vw;
  overflow-x: hidden;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
body.tbc-batch {
  display: flex; flex-direction: column;
  /* dvh tracks the dynamic viewport (Safari bottom bar collapse) — and we
     pin the height so internal panels handle their own scrolling rather
     than the whole page rubber-banding. */
  height: 100vh; height: 100dvh;
  overflow: hidden;
  width: 100%;
}
body.tbc-batch > * { max-width: 100%; flex-shrink: 0; }
body.tbc-batch > .bx-items { flex: 1 1 0; min-height: 0; }
a { color: inherit; }

/* ---- Sticky topbar ---- */
.bx-topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--card); border-bottom: 1px solid var(--border);
}
.bx-back {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 50%;
  background: transparent; color: var(--muted); text-decoration: none;
  font-size: 22px; line-height: 1;
}
.bx-back:hover { background: var(--card-2); color: var(--accent); }
.bx-title { flex: 1; min-width: 0; overflow: hidden; }
.bx-title strong {
  display: block; font-size: 16px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.bx-counts {
  display: block; font-size: 12px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.bx-toggle {
  background: var(--accent); color: #1a1306; border: 0;
  padding: 8px 14px; border-radius: 999px;
  font-weight: 700; font-size: 14px; cursor: pointer;
}
.bx-toggle.is-on { background: var(--accent-2); color: #fff; }
.bx-toggle:hover { filter: brightness(1.05); }
.bx-reset {
  background: transparent; color: var(--muted);
  border: 1px solid var(--border); border-radius: 999px;
  width: 34px; height: 34px;
  font-size: 16px; cursor: pointer; line-height: 1;
}
.bx-reset:hover { border-color: var(--accent-2); color: var(--accent-2); }
.bx-reset[hidden] { display: none; }

/* Diagnostic statusline — version + camera/wedge/network state. Thin
   monospace strip below the topbar; muted by default, color-coded when
   a subsystem is active. */
.bx-statusline {
  display: flex; flex-wrap: wrap; gap: 14px;
  padding: 4px 14px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 11px;
  color: var(--muted);
  flex-shrink: 0;
}
.bx-statusline .bx-stat-version { color: rgba(255,255,255,0.4); }
.bx-statusline .is-on  { color: var(--green); }
.bx-statusline .is-warn { color: var(--accent); }
.bx-statusline .is-err  { color: var(--accent-2); }

/* ---- Camera ---- */
/* No fixed aspect-ratio — phones return a portrait-orientation stream
   (720×1280), so a 4:3 wrap was over-cropping. Cap height as a slice of
   the viewport and let object-fit:cover handle the rest. */
.bx-camera-wrap {
  position: relative; background: #000;
  height: clamp(180px, 32vh, 320px);
  overflow: hidden;
  flex-shrink: 0;
}
.bx-camera-wrap video { width: 100%; height: 100%; object-fit: cover; display: block; }
.bx-overlay {
  position: absolute; inset: 0; width: 100%; height: 100%;
  pointer-events: none;
}
.bx-scan-status {
  position: absolute; left: 12px; bottom: 12px;
  background: rgba(0,0,0,0.7); color: var(--accent);
  padding: 4px 10px; border-radius: 4px; font-size: 12px;
}

/* ---- Manual add ---- */
.bx-add-row {
  padding: 8px 14px;
  background: var(--card-2); border-bottom: 1px solid var(--border);
}
.bx-manual-form { display: flex; gap: 6px; }
.bx-manual-form input {
  flex: 1; padding: 8px 10px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 4px;
  /* 16px is the magic number — anything smaller makes iOS Safari
     auto-zoom on focus and the zoom-out afterward is flaky. */
  font-size: 16px;
}
.bx-manual-form input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.bx-manual-form button {
  background: transparent; color: var(--text);
  border: 1px solid var(--border); border-radius: 4px;
  padding: 8px 14px; cursor: pointer; font-size: 14px;
}
.bx-manual-form button:hover { border-color: var(--accent); color: var(--accent); }

/* ---- Toast ---- */
.bx-toast {
  padding: 6px 14px; min-height: 24px;
  font-size: 13px; color: var(--muted);
}
.bx-toast.is-ok  { color: var(--green); }
.bx-toast.is-err { color: var(--accent-2); }

/* ---- Items ---- */
.bx-items {
  padding: 8px 12px 12px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.bx-empty {
  padding: 32px 16px; text-align: center; color: var(--muted);
}
.bx-empty .muted { font-size: 12px; }

.bx-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px;
  background: var(--card); border: 1px solid var(--border); border-radius: 8px;
  margin-bottom: 8px;
  animation: bxIn 180ms ease-out;
}
@keyframes bxIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.bx-item.is-fresh { border-color: var(--accent); }

.bx-item-thumb {
  width: 56px; height: 56px; flex-shrink: 0;
  background: var(--bg); border-radius: 6px; padding: 4px;
  display: flex; align-items: center; justify-content: center;
}
.bx-item-thumb img { width: 100%; height: 100%; object-fit: contain; }
.bx-item-thumb .empty { font-size: 22px; opacity: 0.4; }

.bx-item-body { flex: 1; min-width: 0; }
.bx-item-name {
  font-weight: 600; font-size: 14px; line-height: 1.3;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.bx-item-sub {
  color: var(--muted); font-size: 12px; margin-top: 2px;
}
.bx-item-prices {
  font-size: 12px; margin-top: 4px; color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.bx-item-prices .pn { color: var(--green); }
.bx-item-prices .pu { color: var(--accent); }

.bx-qty {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg); border-radius: 999px;
  padding: 2px 4px;
  border: 1px solid var(--border);
}
.bx-qty button {
  width: 28px; height: 28px; border-radius: 50%;
  background: transparent; border: 0; color: var(--text);
  font-size: 18px; line-height: 1; cursor: pointer;
}
.bx-qty button:hover { background: var(--card-2); color: var(--accent); }
.bx-qty .v {
  min-width: 26px; text-align: center;
  font-weight: 700; font-size: 14px;
  font-variant-numeric: tabular-nums;
}
.bx-item-remove {
  background: transparent; color: var(--muted); border: 0;
  width: 30px; height: 30px; border-radius: 50%;
  font-size: 18px; line-height: 1; cursor: pointer;
}
.bx-item-remove:hover { background: rgba(217, 32, 39, 0.15); color: var(--accent-2); }

.bx-item-error { color: var(--accent-2); font-size: 12px; margin-top: 2px; }

/* ---- Activity log ---- */
.bx-log {
  border-top: 1px solid var(--border);
  background: #0a0a0e;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 11px;
  line-height: 1.4;
  flex-shrink: 0;
}
.bx-log-head {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 12px;
}
.bx-log-head .muted { color: var(--muted); font-size: 11px; }
.bx-log-spacer { flex: 1; }
.bx-log-toggle, .bx-log-clear {
  background: transparent; color: var(--muted); border: 0;
  font-family: inherit; cursor: pointer; padding: 2px 6px;
  font-size: 11px;
}
.bx-log-toggle:hover, .bx-log-clear:hover { color: var(--accent); }
.bx-log-list {
  list-style: none; margin: 0; padding: 0;
  max-height: 22vh; overflow-y: auto;
  background: #0a0a0e;
  -webkit-overflow-scrolling: touch;
}
.bx-log.is-collapsed .bx-log-list { display: none; }
.bx-log-list li {
  padding: 3px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  color: var(--muted);
  white-space: pre-wrap; word-break: break-all;
}
.bx-log-list li .ts {
  color: rgba(255,255,255,0.3);
  margin-right: 6px;
}
.bx-log-list li.k-info { color: #8fc0ff; }
.bx-log-list li.k-ok   { color: #4ade80; }
.bx-log-list li.k-warn { color: #fbbf24; }
.bx-log-list li.k-err  { color: #ff6b78; }
.bx-log-list li.k-zx   { color: #c4b5fd; }

/* ---- Sticky savebar ---- */
.bx-savebar {
  position: sticky; bottom: 0; z-index: 30;
  display: flex; gap: 8px; align-items: center;
  flex-wrap: wrap;
  padding: 10px 12px;
  background: var(--card); border-top: 1px solid var(--border);
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
}
.bx-savebar select {
  flex: 1 1 140px; min-width: 0;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 4px;
  padding: 8px 10px; font-size: 16px;
  max-width: 100%;
}
.bx-pricing-toggle {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
}
.bx-pricing-toggle input { accent-color: var(--accent); }
.bx-save {
  background: var(--accent); color: #1a1306; border: 0;
  padding: 9px 14px; border-radius: 4px;
  font-weight: 700; font-size: 14px; cursor: pointer;
  flex-shrink: 0;
}
/* Drop the "Snapshot prices" wording on narrow viewports — checkbox alone
   stays clickable, label text becomes a tooltip via title attr. */
@media (max-width: 380px) {
  .bx-pricing-toggle span { display: none; }
}
.bx-save:hover:not(:disabled) { filter: brightness(1.05); }
.bx-save:disabled { opacity: 0.5; cursor: not-allowed; }
.bx-signin {
  width: 100%; text-align: center;
  background: var(--accent); color: #1a1306;
  padding: 10px; border-radius: 4px;
  text-decoration: none; font-weight: 700; font-size: 14px;
}

/* Hide topbar/savebar on print just in case */
@media print {
  .bx-topbar, .bx-camera-wrap, .bx-add-row, .bx-savebar { display: none; }
}
