/* Pack Evidence — hand-written, no framework.
   Phone-first: the packer screen is used one-handed at a bench, so tap targets
   are large and the primary action is always the widest thing on screen. */

:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #0f172a;
  --accent: #2563eb;
  --ok: #059669;
  --warn: #b45309;
  --danger: #dc2626;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 12px rgba(15, 23, 42, .05);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3 { line-height: 1.25; margin: 0 0 8px; }
h2 { font-size: 19px; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); font-size: 13.5px; }
.offscreen { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 10px 16px; background: var(--brand); color: #fff;
  padding-top: calc(10px + env(safe-area-inset-top));
  position: sticky; top: 0; z-index: 20;
}
.topbar .brand { font-size: 15px; }
.topbar nav { display: flex; align-items: center; gap: 4px; }
.topbar nav a {
  color: #cbd5e1; text-decoration: none; font-size: 13.5px; font-weight: 600;
  padding: 6px 10px; border-radius: 8px;
}
.topbar nav a.on { background: rgba(255, 255, 255, .14); color: #fff; }
.inline { display: inline; margin: 0; }
.linkish {
  background: none; border: 0; color: #94a3b8; font-size: 13.5px;
  cursor: pointer; padding: 6px 10px; font-family: inherit;
}

main { max-width: 620px; margin: 0 auto; padding: 16px 16px 48px; }

/* ---------- background upload queue bar ---------- */
.qbar {
  position: sticky; top: 0; z-index: 19;
  display: flex; align-items: center; gap: 9px;
  padding: 9px 16px; font-size: 13px; font-weight: 600;
  background: #eef2ff; color: #3730a3; border-bottom: 1px solid #c7d2fe;
}
.qbar.bad { background: #fef3c7; color: var(--warn); border-bottom-color: #fcd34d; }
.qbar #qtext { flex: 1; }
.qdot {
  width: 9px; height: 9px; border-radius: 50%; background: currentColor;
  animation: qpulse 1.4s ease-in-out infinite; flex: 0 0 9px;
}
@keyframes qpulse { 0%,100% { opacity: .3; } 50% { opacity: 1; } }
.qbtn {
  background: rgba(255,255,255,.75); border: 1px solid currentColor; color: inherit;
  padding: 4px 10px; font-size: 12px; border-radius: 999px; font-weight: 600;
}

/* ---------- forms & buttons ---------- */
label { display: block; font-size: 13px; font-weight: 600; margin: 14px 0 5px; }
input[type=text], input[type=password], input:not([type]), select, textarea {
  width: 100%; padding: 12px 13px; border: 1px solid #cbd5e1; border-radius: 10px;
  font-size: 16px; /* 16px stops iOS zooming the page on focus */
  font-family: inherit; background: #fff; color: var(--ink);
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }

button {
  font-family: inherit; font-size: 15px; font-weight: 600; cursor: pointer;
  border-radius: 10px; padding: 12px 16px; border: 1px solid transparent;
}
button:disabled { opacity: .45; cursor: not-allowed; }
.primary { background: var(--accent); color: #fff; }
.primary.big { display: block; width: 100%; padding: 15px; font-size: 16px; margin-top: 16px; }
.ghost { background: #fff; border-color: #cbd5e1; color: var(--ink); }
.ghost.block { display: block; text-align: center; text-decoration: none; margin-top: 10px; padding: 12px; border: 1px solid #cbd5e1; border-radius: 10px; background: #fff; color: var(--ink); font-weight: 600; }
.ghost.danger { color: var(--danger); border-color: #fecaca; }
.row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.row > .primary.big { flex: 1 1 100%; margin-top: 0; }
.row > .ghost { flex: 1; }

/* ---------- panels ---------- */
.panel {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow);
}
.panel.done { text-align: center; }

/* ---------- step rail ---------- */
.steps {
  display: flex; gap: 4px; list-style: none; margin: 0 0 14px; padding: 0;
  font-size: 11px; color: var(--muted); overflow-x: auto;
}
.steps li { display: flex; align-items: center; gap: 5px; flex: 1; white-space: nowrap; }
.steps span {
  display: grid; place-items: center; width: 20px; height: 20px; flex: 0 0 20px;
  border-radius: 50%; background: #e2e8f0; color: var(--muted);
  font-size: 11px; font-weight: 700;
}
.steps li.on span { background: var(--accent); color: #fff; }
.steps li.done span { background: var(--ok); color: #fff; }
.steps li.on { color: var(--ink); font-weight: 700; }

/* ---------- scanner ---------- */
.scanner { position: relative; border-radius: var(--radius); overflow: hidden; background: #000; display: none; }
.scanner.live { display: block; }
#cam { width: 100%; display: block; max-height: 62vh; object-fit: cover; background: #000; }
.reticle { position: absolute; inset: 0; pointer-events: none; display: grid; place-items: center; }
.reticle .band {
  width: 80%; height: 30%; border: 2px solid rgba(255, 255, 255, .9); border-radius: 8px;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .45);
}
.scanbar {
  position: absolute; left: 0; right: 0; bottom: 0; display: flex; gap: 8px;
  padding: 10px; background: linear-gradient(transparent, rgba(0, 0, 0, .6));
}
.scanbar button { padding: 10px 14px; font-size: 14px; }
#torchBtn.on { background: #fff; color: #0f172a; border-color: #fff; font-weight: 700; }
.scanbar input[type=range] { flex: 1; accent-color: #fff; }
.scanstatus {
  position: absolute; top: 10px; left: 10px; right: 10px; text-align: center;
  color: #fff; font-size: 13px; text-shadow: 0 1px 3px rgba(0, 0, 0, .8);
}
.manual { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 10px; }
.manual summary { cursor: pointer; font-weight: 600; font-size: 14px; }
.manual[open] summary { margin-bottom: 4px; }

/* ---------- AWB confirm ---------- */
.awb-confirm { text-align: center; padding: 12px 0; }
.awb-big {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: clamp(22px, 7vw, 32px); font-weight: 700; letter-spacing: 1px;
  word-break: break-all;
}
.chips { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin-top: 10px; }
.chip {
  background: #eef2ff; color: #3730a3; border-radius: 999px;
  padding: 4px 11px; font-size: 12px; font-weight: 600;
}
.chip.warn { background: #fef3c7; color: var(--warn); }
.chip.ok { background: #d1fae5; color: var(--ok); }

/* ---------- label shot (confirm step) ---------- */
.labelshot {
  border: 1px solid var(--line); border-radius: 10px; padding: 12px;
  margin: 14px 0; background: #f8fafc;
}
.labelshot-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.labelshot img {
  width: 100%; max-height: 260px; object-fit: contain; border-radius: 8px;
  background: #fff; border: 1px solid var(--line); display: block; margin-bottom: 8px;
}
.labelshot p { margin: 0 0 10px; }

/* ---------- duplicate / resume cards ---------- */
.notice {
  border: 1px solid #fcd34d; background: #fffbeb; border-radius: 10px;
  padding: 13px; margin: 12px 0; font-size: 14px;
}
.notice h3 { font-size: 14.5px; margin-bottom: 4px; }
.notice.info { border-color: #bfdbfe; background: #eff6ff; }
.resume-card { margin-top: 14px; }

/* ---------- photo grid ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; margin: 12px 0; }
.tile {
  position: relative; aspect-ratio: 3/4; border-radius: 10px; overflow: hidden;
  background: #e2e8f0; border: 1px solid var(--line);
}
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .badge {
  position: absolute; left: 5px; top: 5px; background: rgba(15, 23, 42, .8); color: #fff;
  font-size: 10.5px; padding: 2px 6px; border-radius: 999px; font-weight: 600;
}
.tile .rm {
  position: absolute; right: 4px; top: 4px; width: 24px; height: 24px; padding: 0;
  border-radius: 50%; background: rgba(15, 23, 42, .8); color: #fff; border: 0;
  font-size: 14px; line-height: 1;
}
.tile .state {
  position: absolute; left: 0; right: 0; bottom: 0; font-size: 10.5px; text-align: center;
  padding: 3px; color: #fff; background: rgba(15, 23, 42, .75);
}
.tile.uploading .state { background: var(--accent); }
.tile.stored .state { background: var(--ok); }
.tile.failed .state { background: var(--danger); }

/* ---------- upload progress ---------- */
.uploadbar { margin-top: 14px; }
.bar { height: 8px; border-radius: 999px; background: #e2e8f0; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .25s; }
.upmeta { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--muted); margin-top: 6px; }
.netwarn { margin-top: 8px; font-size: 13px; color: var(--warn); font-weight: 600; }
.videofile {
  display: flex; align-items: center; gap: 10px; padding: 11px; margin-top: 12px;
  border: 1px solid var(--line); border-radius: 10px; background: #f8fafc; font-size: 13.5px;
}
.videofile .grow { flex: 1; min-width: 0; }
.videofile b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.tick {
  width: 56px; height: 56px; margin: 4px auto 12px; border-radius: 50%;
  background: var(--ok); color: #fff; font-size: 30px; display: grid; place-items: center;
}

/* ---------- searcher ---------- */
.searchbox { display: flex; gap: 8px; margin-bottom: 10px; }
.searchbox input { flex: 1; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .5px; }
.rec {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin-bottom: 10px; box-shadow: var(--shadow);
}
.rec-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.rec-awb { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 17px; font-weight: 700; }
.rec-meta { font-size: 13px; color: var(--muted); margin-top: 3px; }
.rec.clickable { cursor: pointer; }
.rec.clickable:hover { border-color: var(--accent); }
/* ---------- channel picker (packer) ---------- */
.chanpick { display: flex; gap: 8px; flex-wrap: wrap; }
.chan {
  flex: 1 1 auto; min-width: 90px; padding: 13px 10px; font-size: 15px;
  background: #fff; border: 1.5px solid #cbd5e1; color: var(--ink);
}
.chan.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.scanhead { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.scanhead h2 { margin: 0; }
.chip-btn {
  background: #eef2ff; color: #3730a3; border: 0; border-radius: 999px;
  padding: 6px 12px; font-size: 12.5px; font-weight: 700; white-space: nowrap;
}

/* ---------- filters (reviewer) ---------- */
.filters {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.filters summary { cursor: pointer; font-weight: 700; font-size: 14px; }
.fcount {
  background: var(--accent); color: #fff; border-radius: 999px;
  padding: 1px 8px; font-size: 11px; margin-left: 6px;
}
.fgrid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px; margin: 12px 0;
}
.fgrid .fwide { grid-column: 1 / -1; }
.fgrid label { margin: 0 0 4px; font-size: 12px; }
.fgrid input, .fgrid select { padding: 9px 10px; font-size: 14px; }
.pills { display: flex; gap: 6px; flex-wrap: wrap; }
.pill {
  background: #fff; border: 1px solid #cbd5e1; color: var(--ink);
  padding: 7px 12px; font-size: 13px; border-radius: 999px; font-weight: 600;
}
.pill.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.fquick { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px;
          border-top: 1px solid var(--line); padding-top: 10px; }
.filters .row a.ghost { text-align: center; padding: 12px; text-decoration: none;
  border: 1px solid #cbd5e1; border-radius: 10px; font-weight: 600; font-size: 15px; }

/* ---------- summary tiles ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(84px, 1fr)); gap: 8px; margin-bottom: 12px; }
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 8px; text-align: center;
}
.stat b { display: block; font-size: 20px; line-height: 1.1; }
.stat span { font-size: 11px; color: var(--muted); }
.stat.warn { border-color: #fcd34d; background: #fffbeb; }
.stat.warn b { color: var(--warn); }
.chan-chip { background: #ecfdf5; color: #047857; }

.labelcheck { display: flex; gap: 12px; align-items: flex-start; flex-wrap: wrap; margin: 10px 0; }
.labelcheck img {
  width: 190px; max-width: 100%; border-radius: 8px; cursor: zoom-in;
  border: 1px solid var(--line); background: #fff; object-fit: contain;
}
.labelcheck-side { flex: 1; min-width: 190px; display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.labelcheck-side .rec-awb { font-size: 19px; word-break: break-all; }
.labelcheck-side .ghost.block { margin-top: 2px; width: auto; padding: 8px 14px; font-size: 13px; }

.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 7px; margin: 12px 0; }
.thumbs img { width: 100%; aspect-ratio: 3/4; object-fit: cover; border-radius: 8px; cursor: pointer; background: #e2e8f0; border: 1px solid var(--line); }
video.player { width: 100%; border-radius: 10px; background: #000; margin: 10px 0; max-height: 70vh; }
.dl-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.dl-row a, .dl-row button {
  text-decoration: none; font-size: 13.5px; font-weight: 600; padding: 10px 14px;
  border-radius: 9px; border: 1px solid #cbd5e1; background: #fff; color: var(--ink);
}
.dl-row a.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.empty { text-align: center; padding: 30px 16px; color: var(--muted); }
.empty code { background: #e2e8f0; padding: 2px 6px; border-radius: 5px; font-size: 13px; }
.section-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 0 8px; }

/* ---------- lightbox ---------- */
.lightbox { position: fixed; inset: 0; background: rgba(2, 6, 23, .95); z-index: 60; display: grid; place-items: center; }
.lightbox img { max-width: 96vw; max-height: 84vh; object-fit: contain; }
.lb-close, .lb-nav {
  position: absolute; background: rgba(255, 255, 255, .12); color: #fff; border: 0;
  width: 44px; height: 44px; border-radius: 50%; font-size: 20px; line-height: 1;
}
.lb-close { top: calc(14px + env(safe-area-inset-top)); right: 14px; }
.lb-nav.prev { left: 10px; top: 50%; transform: translateY(-50%); }
.lb-nav.next { right: 10px; top: 50%; transform: translateY(-50%); }
.lb-dl {
  position: absolute; bottom: calc(20px + env(safe-area-inset-bottom)); left: 50%;
  transform: translateX(-50%); background: #fff; color: var(--ink);
  padding: 11px 20px; border-radius: 999px; text-decoration: none; font-weight: 600; font-size: 14px;
}

/* ---------- toasts ---------- */
.toasts {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 80;
  bottom: calc(16px + env(safe-area-inset-bottom)); display: flex;
  flex-direction: column; gap: 8px; width: min(92vw, 460px);
}
.toast {
  background: #0f172a; color: #fff; padding: 11px 15px; border-radius: 10px;
  font-size: 14px; box-shadow: 0 8px 24px rgba(0, 0, 0, .3);
}
.toast.err { background: var(--danger); }
.toast.ok { background: var(--ok); }

/* ---------- login ---------- */
.login-body { display: grid; place-items: center; min-height: 100dvh; margin: 0; }
.login-card {
  background: #fff; border: 1px solid var(--line); border-radius: 16px;
  padding: 32px 28px; width: min(340px, 90vw); text-align: center; box-shadow: var(--shadow);
}
.login-mark { font-size: 34px; margin-bottom: 6px; }
.login-card h1 { font-size: 19px; margin-bottom: 2px; }
.login-card input { margin: 16px 0 10px; text-align: center; }
.login-card button { width: 100%; background: var(--accent); color: #fff; }
.err { color: var(--danger); font-size: 13px; font-weight: 600; }
.hint { font-size: 12px; color: var(--muted); margin: 14px 0 0; }

@media (min-width: 700px) {
  .row > .primary.big { flex: 1; }
}
