/* scan.ai-kgf.org — lot-audit PWA. Two views (Scan / Inventory) + bottom nav. */
:root {
  --bg: #0b0d10; --panel: #ffffff; --ink: #11151a; --muted: #6b7280; --line: #e6e8eb;
  --brand: #1d4ed8; --green: #16a34a; --green-bg: #0f2a17; --amber: #d97706; --red: #dc2626; --gray: #cbd1d8;
  --safe-top: env(safe-area-inset-top, 0px); --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; background: var(--bg); color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, system-ui, sans-serif;
  overscroll-behavior: none;
}
body { display: flex; flex-direction: column; height: 100dvh; }

.view { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.view[hidden] { display: none; }

/* ---------- camera ---------- */
#cam { position: relative; flex: 1 1 auto; min-height: 0; background: #000; overflow: hidden; padding-top: var(--safe-top); }
#video { width: 100%; height: 100%; object-fit: cover; display: block; }
#camHint {
  position: absolute; top: 22%; left: 0; right: 0; text-align: center;
  color: #c4ccd4; font-size: 13px; letter-spacing: .02em; pointer-events: none; text-shadow: 0 1px 3px rgba(0,0,0,.6);
}
#reticle {
  position: absolute; left: 8%; right: 8%; top: 34%; height: 24%;
  border: 3px solid var(--green); border-radius: 14px; box-shadow: 0 0 0 100vmax rgba(0,0,0,.28);
  pointer-events: none; transition: border-color .15s;
}
#reticle.flash { border-color: #22c55e; background: rgba(34,197,94,.18); }
#reticle.err { border-color: var(--red); background: rgba(220,38,38,.16); }

#modeToggle {
  position: absolute; top: calc(10px + var(--safe-top)); right: 12px; z-index: 2;
  background: rgba(17,21,26,.55); color: #f3f5f7; border: 1px solid rgba(255,255,255,.22);
  border-radius: 999px; font-size: 13px; font-weight: 500; padding: 8px 14px;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); line-height: 1;
}
#modeToggle[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: #fff; }

#popover {
  position: absolute; left: 8%; right: 8%; bottom: 14px;
  background: var(--green-bg); border: 2px solid var(--green); border-radius: 14px; padding: 12px 14px;
  color: #d8f5e1; transform: translateY(8px); opacity: 0; transition: opacity .15s, transform .15s; pointer-events: none;
}
#popover.show { opacity: 1; transform: none; }
#popover.amber { background: #2a1e0a; border-color: var(--amber); color: #f7e3c2; }
#popover.red { background: #2a1010; border-color: var(--red); color: #f6cccc; }
#popover .pv-title { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 8px; }
#popover .pv-sub { font-size: 14px; margin-top: 2px; }
#popover .pv-meta { font-size: 12px; opacity: .8; margin-top: 4px; }

#shutter {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%);
  width: 60px; height: 60px; border-radius: 50%; border: 4px solid #fff; background: rgba(255,255,255,.18); display: none;
}
body[data-mode="tap"] #shutter { display: block; }
body[data-mode="tap"] #popover { bottom: 86px; }

/* ---------- scan bottom (counter + manual entry) ---------- */
#scanBottom { flex: 0 0 auto; background: #fff; border-top: 1px solid var(--line); padding: 10px 12px 10px; display: flex; flex-direction: column; gap: 10px; }
#scanStatus { display: flex; flex-direction: column; align-items: center; gap: 1px; width: 100%; background: #f3f5f7; border: 1px solid var(--line); border-radius: 14px; padding: 11px; }
#scanStatus:active { transform: scale(.99); }
#scanStatus .cnt { font-size: 27px; font-weight: 800; letter-spacing: -.02em; }
#scanStatus .cnt .sep { color: var(--muted); font-weight: 600; margin: 0 3px; }
#scanStatus .cnt-sub { font-size: 13px; color: var(--muted); }
#scanStatus .chev { color: var(--brand); font-weight: 700; }

#composer { display: flex; gap: 10px; }
#vinInput {
  flex: 1; font-size: 16px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 999px;
  background: #f3f5f7; color: var(--ink); text-transform: uppercase; letter-spacing: .08em;
}
#vinSend { width: 48px; height: 48px; border-radius: 50%; border: 0; background: var(--brand); color: #fff; font-size: 20px; display: grid; place-items: center; }
#vinSend:disabled { opacity: .5; }

/* ---------- inventory view ---------- */
#invView { background: var(--panel); }
#tabs { display: flex; gap: 8px; padding: 10px 12px 6px; }
.tab { flex: 1; border: 0; border-radius: 10px; background: #eef1f4; color: var(--ink); font-weight: 600; font-size: 15px; padding: 11px 0; }
.tab[aria-selected="true"] { background: var(--brand); color: #fff; }

#storeFilter { display: flex; gap: 7px; padding: 4px 12px 2px; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
#storeFilter::-webkit-scrollbar { display: none; }
.schip { flex: 0 0 auto; border: 1px solid var(--line); background: #fff; color: #374151; border-radius: 999px; font-size: 13px; font-weight: 500; padding: 6px 13px; white-space: nowrap; }
.schip[aria-pressed="true"] { background: #11151a; color: #fff; border-color: #11151a; }
.schip:active { transform: scale(.96); }

#searchRow { padding: 6px 12px 2px; }
#invSearch { width: 100%; font-size: 16px; padding: 11px 14px; border: 1px solid var(--line); border-radius: 10px; background: #f3f5f7; color: var(--ink); }

#listMeta { display: flex; justify-content: space-between; align-items: baseline; padding: 6px 14px 6px; }
#listMeta .note { color: var(--muted); font-size: 12px; }
#listMeta .count { color: var(--green); font-weight: 700; font-size: 14px; }

#list { flex: 1 1 auto; overflow-y: auto; padding: 2px 12px 10px; -webkit-overflow-scrolling: touch; }
.card { display: flex; gap: 10px; align-items: stretch; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 11px 12px 11px 0; margin-bottom: 8px; }
.card .rail { width: 5px; border-radius: 5px; background: var(--gray); }
.card.scanned .rail { background: var(--green); }
.card.amber .rail { background: var(--amber); }
.card.red .rail { background: var(--red); }
.card .body { padding-left: 12px; }
.card .stock { font-weight: 700; font-size: 15px; }
.card .ymm { font-size: 14px; color: #222; margin-top: 1px; }
.card .stat { font-size: 12px; color: var(--muted); margin-top: 3px; }
.card.scanned .stat { color: var(--green); }
#listEmpty { color: var(--muted); text-align: center; padding: 24px 12px; font-size: 14px; }

/* ---------- bottom nav ---------- */
#nav { flex: 0 0 auto; display: flex; background: #fff; border-top: 1px solid var(--line); padding-bottom: var(--safe-bottom); }
.navbtn { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 7px; background: none; border: 0; color: var(--muted); font-size: 11px; font-weight: 600; text-decoration: none; }
.navbtn .ni { font-size: 17px; line-height: 1; }
.navbtn[aria-current="true"] { color: var(--brand); }
.navbtn:active { opacity: .6; }

/* ---------- auth / manager (shared) ---------- */
.center { min-height: 100dvh; display: grid; place-items: center; background: #f3f5f7; color: var(--ink); padding: 24px; }
.card-lg { width: 100%; max-width: 380px; background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 22px; }
.mgr { max-width: 760px; margin: 0 auto; padding: 16px 14px calc(24px + var(--safe-bottom)); background: #f3f5f7; min-height: 100dvh; }
.mgr h1 { font-size: 20px; margin: 4px 2px 12px; }
.mgr .controls { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.mgr select, .mgr button { font-size: 14px; padding: 9px 12px; border-radius: 9px; border: 1px solid var(--line); background: #fff; }
.mgr button.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.mgr section { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin-bottom: 12px; }
.mgr section h2 { font-size: 15px; margin: 0 0 8px; display: flex; gap: 8px; align-items: center; }
.mgr .pill { font-size: 12px; font-weight: 700; color: #fff; background: var(--red); border-radius: 999px; padding: 2px 9px; }
.mgr .pill.warn { background: var(--amber); }
.mgr table { width: 100%; border-collapse: collapse; font-size: 13px; }
.mgr th, .mgr td { text-align: left; padding: 7px 6px; border-bottom: 1px solid var(--line); }
.mgr th { color: var(--muted); font-weight: 600; }
.mgr .empty { color: var(--muted); font-size: 13px; padding: 6px 2px; }
