/* ChemLister capture — mobile-first, big targets, shed-legible.
   UK English copy lives in index.html/app.js. No fancy dependencies. */

:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-2: #334155;
  --line: #475569;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --ok: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;

  /* group colours (instruction screen) */
  --g-flammables: #d32f2f;
  --g-acids: #e64a19;
  --g-caustics: #7b1fa2;
  --g-aerosols: #0277bd;
  --g-general: #37474f;
  --g-quarantine: #f9a825;
  --g-reject: #b71c1c;

  --tap: 60px; /* minimum touch target */
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 18px;
  line-height: 1.35;
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
}

#app { min-height: 100dvh; display: flex; flex-direction: column; }

/* ---- Screens ---- */
.screen { display: none; flex: 1; flex-direction: column; min-height: 100dvh; }
.screen.active { display: flex; }

/* ---- Top bar ---- */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; background: var(--panel);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5;
}
.topbar .site { font-weight: 700; font-size: 16px; }
.topbar .spacer { flex: 1; }
.topbar .badge {
  background: var(--panel-2); border-radius: 999px; padding: 4px 12px;
  font-size: 14px; color: var(--muted);
}
.topbar .badge.busy { color: var(--bg); background: var(--warn); font-weight: 700; }
.topbar .badge.err { color: #fff; background: var(--danger); font-weight: 700; }

/* ---- Buttons ---- */
button {
  font: inherit; color: var(--text); background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 14px;
  min-height: var(--tap); padding: 14px 18px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
}
button:active { transform: translatey(1px); }
button:disabled { opacity: 0.4; }
.btn-primary { background: var(--accent); color: #04283a; border-color: transparent; font-weight: 800; }
.btn-ok { background: var(--ok); color: #052e16; border-color: transparent; font-weight: 800; }
.btn-ghost { background: transparent; }
.btn-danger { background: var(--danger); color: #fff; border-color: transparent; font-weight: 800; }
.btn-block { width: 100%; }
.btn-lg { min-height: 76px; font-size: 22px; font-weight: 800; }

/* ---- Camera screen ---- */
/* The capture screen scrolls (camera on top, queue below); cam-view is pinned
   to exactly one viewport so the shutter is always visible without scrolling. */
#screen-capture.active { display: block; }
.cam-view { height: 100dvh; display: flex; flex-direction: column; }
.cam-wrap { position: relative; flex: 1; min-height: 0; background: #000; overflow: hidden; display: flex; }
#video { width: 100%; height: 100%; object-fit: cover; }
.cam-fallback {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 16px; text-align: center;
  padding: 24px; color: var(--muted); background: #000;
}
/* A class rule beats the UA [hidden] { display:none }, so restore it here. */
.cam-fallback[hidden] { display: none; }
.cam-controls {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px calc(16px + env(safe-area-inset-right)) calc(20px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
  background: var(--panel);
}
.shutter {
  width: 82px; height: 82px; border-radius: 50%;
  background: #fff; border: 6px solid var(--panel-2);
  flex: 0 0 auto;
}
.shutter:disabled { background: var(--muted); }
.cam-side { flex: 1; display: flex; }
.cam-side.left { justify-content: flex-start; }
.cam-side.right { justify-content: flex-end; }
.pick-label {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 12px 16px; border-radius: 14px;
  background: var(--panel-2); border: 1px solid var(--line); font-size: 15px;
}
.pick-label input { display: none; }

/* ---- Queue list ---- */
.queue { padding: 10px 14px 24px; overflow-y: auto; }
.queue h2 { font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 14px 4px 8px; }
.qcard {
  display: flex; gap: 12px; align-items: center; background: var(--panel);
  border: 1px solid var(--line); border-radius: 14px; padding: 10px; margin-bottom: 10px;
}
.qcard img { width: 56px; height: 56px; border-radius: 10px; object-fit: cover; background: var(--panel-2); flex: 0 0 auto; }
.qcard .meta { flex: 1; min-width: 0; }
.qcard .meta .name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qcard .meta .sub { font-size: 14px; color: var(--muted); }
.qcard .status { font-size: 13px; font-weight: 700; padding: 4px 10px; border-radius: 999px; flex: 0 0 auto; }
.st-working { background: var(--warn); color: #3a2a00; }
.st-ready { background: var(--ok); color: #052e16; }
.st-error { background: var(--danger); color: #fff; }
.st-done { background: var(--panel-2); color: var(--muted); }
.qcard.tappable { cursor: pointer; }
.empty-hint { color: var(--muted); text-align: center; padding: 40px 20px; }

/* ---- Confirm screen ---- */
.pad { padding: 16px 16px calc(20px + env(safe-area-inset-bottom)); overflow-y: auto; flex: 1; }
.photo-strip { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; }
.photo-strip img { height: 120px; border-radius: 12px; object-fit: cover; flex: 0 0 auto; }
label.field { display: block; margin: 18px 0 6px; font-size: 14px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
input[type=text], textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--panel);
  border: 1px solid var(--line); border-radius: 12px; padding: 14px; -webkit-user-select: text; user-select: text;
}
textarea { min-height: 72px; resize: vertical; }
.ai-hint { font-size: 14px; color: var(--muted); margin-top: 6px; }
.pictos { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.picto { background: var(--panel-2); border-radius: 8px; padding: 4px 10px; font-size: 13px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.chip {
  min-height: 48px; padding: 10px 16px; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--line); font-weight: 700;
}
.chip.selected { background: var(--accent); color: #04283a; border-color: transparent; }
.size-block.missing input, .size-block.missing .chip { border-color: var(--danger); }
.req-flag { color: var(--danger); font-weight: 800; }

.stepper { display: flex; align-items: center; gap: 14px; margin-top: 8px; }
.stepper button { width: 60px; height: 60px; font-size: 28px; font-weight: 800; padding: 0; }
.stepper .count { font-size: 32px; font-weight: 800; min-width: 48px; text-align: center; }

.merge-box {
  margin-top: 18px; background: #0b3b2e; border: 1px solid #16a34a; border-radius: 14px; padding: 14px;
}
.merge-box .q { font-weight: 700; margin-bottom: 10px; }
.merge-box .row { display: flex; gap: 10px; }

.confirm-actions { position: sticky; bottom: 0; background: linear-gradient(transparent, var(--bg) 24%);
  padding: 12px 16px calc(16px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 10px; }

/* ---- Instruction screen ---- */
#screen-instruction { color: #fff; }
.instr-hero {
  flex: 0 0 auto; padding: 28px 20px calc(22px + env(safe-area-inset-top));
  padding-top: calc(22px + env(safe-area-inset-top));
  text-align: center;
}
.instr-hero .kicker { font-size: 15px; opacity: .85; text-transform: uppercase; letter-spacing: .12em; }
.instr-hero .group { font-size: 52px; font-weight: 900; line-height: 1.02; margin-top: 6px; letter-spacing: -.01em; }
.instr-hero .stop { font-size: 40px; }
.instr-hero .say { font-size: 20px; margin-top: 10px; font-weight: 600; }
.instr-body { flex: 1; background: var(--bg); border-radius: 22px 22px 0 0; padding: 18px 16px calc(20px + env(safe-area-inset-bottom)); overflow-y: auto; }
.instr-body h3 { color: var(--muted); font-size: 14px; text-transform: uppercase; letter-spacing: .05em; margin: 6px 4px 12px; }
.box-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.box-btn {
  flex-direction: column; gap: 4px; min-height: 92px; align-items: center; justify-content: center;
  background: var(--panel); border: 2px solid var(--line);
}
.box-btn .n { font-size: 30px; font-weight: 900; }
.box-btn .c { font-size: 14px; color: var(--muted); font-weight: 700; }
.box-btn.empty { border-style: dashed; }
.ack-wrap { padding: 18px 16px calc(24px + env(safe-area-inset-bottom)); }

/* group colour classes applied to the hero */
.grp-flammables { background: var(--g-flammables); }
.grp-acids { background: var(--g-acids); }
.grp-caustics { background: var(--g-caustics); }
.grp-aerosols { background: var(--g-aerosols); }
.grp-general { background: var(--g-general); }
.grp-quarantine { background: var(--g-quarantine); color: #241a00; }
.grp-quarantine .kicker { opacity: .7; }
.grp-reject { background: var(--g-reject); }

/* ---- Setup screen ---- */
.setup { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 24px; gap: 18px; }
.setup .logo { width: 84px; height: 84px; }
.setup h1 { font-size: 26px; margin: 0; }
.setup p { color: var(--muted); max-width: 30ch; }
.setup input { max-width: 360px; text-align: center; }

/* ---- Toast ---- */
#toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #000; color: #fff; padding: 12px 18px; border-radius: 12px; font-weight: 700;
  max-width: 90vw; text-align: center; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 50;
  border: 1px solid var(--line);
}
#toast.show { opacity: 1; }

/* ---- Spinner ---- */
.spin { width: 18px; height: 18px; border: 3px solid rgba(255,255,255,.35); border-top-color: #fff; border-radius: 50%; animation: sp .7s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes sp { to { transform: rotate(360deg); } }
.center-spin { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; color: var(--muted); }

/* ---- Capture banner (adding a photo / reading) ---- */
.cap-banner {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 10px 14px; font-weight: 700; font-size: 15px; text-align: center;
}
.cap-banner.adding { background: var(--accent); color: #04283a; }
.cap-banner.reading { background: var(--panel-2); color: var(--text); }
.cap-banner.batch { background: var(--accent); color: #04283a; }
.cap-banner .batch-count { font-size: 20px; font-weight: 900; }
.banner-btn { min-height: 36px; padding: 4px 12px; border-radius: 10px; background: #04283a; color: #fff; border: none; font-weight: 700; }

/* ---- Capture mode toggle (Single / BX5 / BX10) ---- */
.mode-bar { display: flex; gap: 6px; padding: 8px 12px; background: var(--panel); border-bottom: 1px solid var(--line); }
.mode-seg {
  flex: 1; min-height: 44px; padding: 8px; border-radius: 10px; font-size: 15px; font-weight: 800;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--muted);
}
.mode-seg.on { background: var(--accent); color: #04283a; border-color: transparent; }

/* ---- Recent strip (committed this session) ---- */
.recent { padding: 6px 14px 0; }
.recent h2 { font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 12px 4px 8px; }
.recent-strip { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 8px; }
.recent-card {
  flex: 0 0 auto; width: 116px; padding: 0; background: var(--panel);
  border: 1px solid var(--line); border-radius: 12px; overflow: hidden;
  display: flex; flex-direction: column; align-items: stretch; text-align: left; min-height: 0;
}
.recent-card img { width: 100%; height: 84px; object-fit: cover; background: var(--panel-2); }
.recent-card .rc-name { font-size: 13px; font-weight: 700; padding: 6px 8px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recent-card .rc-where { font-size: 12px; color: var(--muted); padding: 2px 8px 8px; }

/* ---- Confirm: photo cells with per-photo actions ---- */
.photo-cell { flex: 0 0 auto; display: flex; flex-direction: column; gap: 6px; }
.photo-actions { display: flex; gap: 6px; }
.pchip {
  min-height: 40px; padding: 6px 12px; border-radius: 10px; font-size: 14px; font-weight: 700;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
}
.pchip.danger { color: #fff; background: transparent; border-color: var(--danger); }
.add-photo-btn { margin-top: 10px; }
.ro-value { font-size: 20px; font-weight: 700; margin-top: 4px; }
