:root {
  --bg: #eef1f7;
  --card: #ffffff;
  --ink: #111a33;
  --muted: #5d6886;
  --line: #d9deea;
  --navy: #0f1b3d;
  --accent: #f5c542;
  --accent-ink: #1d1600;
  --primary: #1f4fd8;
  --primary-ink: #ffffff;
  --danger: #c62828;
  --warn-bg: #fff4d6;
  --warn-ink: #6b4b00;
  --ok: #1b7f3b;
  --radius: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a1022;
    --card: #141c34;
    --ink: #eef1fa;
    --muted: #9aa5c4;
    --line: #26304d;
    --primary: #4d7cff;
    --warn-bg: #3a2f0c;
    --warn-ink: #ffd877;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font: 17px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  padding: env(safe-area-inset-top) 0 0;
}
[hidden] { display: none !important; }
h1, h2 { margin: 0 0 10px; letter-spacing: -0.01em; }
h2 { font-size: 19px; display: flex; align-items: center; gap: 8px; }
.muted { color: var(--muted); }
.small { font-size: 14px; font-weight: 400; }
.error { color: var(--danger); font-weight: 600; }
.warn { background: var(--warn-bg); color: var(--warn-ink); padding: 10px 12px; border-radius: 10px; font-size: 15px; }

.screen { max-width: 640px; margin: 0 auto; padding: 0 12px; }

/* login */
#login { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card { width: 100%; max-width: 360px; text-align: center; }
.logo { font-size: 56px; color: var(--accent); background: var(--navy); width: 88px; height: 88px; border-radius: 24px; display: grid; place-items: center; margin: 0 auto 16px; }
#login form { display: grid; gap: 12px; margin-top: 18px; }

/* top bar */
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 14px 4px 10px; }
.brand { font-weight: 800; font-size: 20px; }
.brand::first-letter { color: var(--accent); }

.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; border: 1px solid var(--line); }
.num { background: var(--navy); color: var(--accent); width: 26px; height: 26px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 15px; flex: none; }
@media (prefers-color-scheme: dark) { .num { background: var(--accent); color: var(--accent-ink); } }

input, textarea, select {
  width: 100%; font: inherit; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 12px; padding: 12px; min-height: 48px;
}
textarea { resize: vertical; }
input:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 0; }
.field-label { display: block; font-size: 14px; font-weight: 600; color: var(--muted); margin: 14px 0 6px; }
.row { display: flex; gap: 8px; }
.row input { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }

.btn {
  font: inherit; font-weight: 650; border: 0; border-radius: 12px; padding: 12px 16px; min-height: 48px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; cursor: pointer;
  background: var(--bg); color: var(--ink); text-decoration: none; text-align: center;
}
.btn.primary { background: var(--primary); color: var(--primary-ink); }
.btn.ghost { background: transparent; border: 1.5px solid var(--line); }
.btn.big { min-height: 56px; font-size: 18px; }
.btn.full { width: 100%; margin-top: 10px; }
.btn:disabled { opacity: 0.45; }
.btn:active:not(:disabled) { transform: scale(0.98); }
.chip { font: inherit; font-size: 14px; background: var(--card); color: var(--ink); border: 1px solid var(--line); border-radius: 999px; padding: 8px 14px; }

/* shot guide */
.shots { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.shot {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 74px; border: 1.5px dashed var(--line); border-radius: 12px; font-size: 14px; font-weight: 600;
  text-align: center; padding: 6px; cursor: pointer; background: var(--bg);
}
.shot .ico { font-size: 22px; }
.shot.done { border-style: solid; border-color: var(--ok); color: var(--ok); }
.shot.done::after { content: "✓"; position: absolute; top: 4px; right: 8px; }
.shot.required:not(.done)::before { content: "needed"; position: absolute; top: 3px; left: 6px; font-size: 10px; color: var(--muted); font-weight: 500; }

.thumbs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.thumb { position: relative; aspect-ratio: 1; border-radius: 12px; overflow: hidden; background: var(--bg); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .tag { position: absolute; left: 6px; bottom: 6px; background: rgba(0,0,0,.65); color: #fff; font-size: 12px; padding: 2px 7px; border-radius: 6px; }
.thumb .bad { position: absolute; left: 6px; top: 6px; background: var(--danger); color: #fff; font-size: 11px; padding: 2px 6px; border-radius: 6px; font-weight: 700; }
.thumb .del, .thumb .cover {
  position: absolute; top: 4px; right: 4px; width: 32px; height: 32px; border-radius: 50%; border: 0;
  background: rgba(0,0,0,.6); color: #fff; font-size: 16px;
}
.thumb .cover { top: auto; bottom: 4px; font-size: 14px; }
.thumb.processing::after { content: "…"; position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,.35); color: #fff; font-size: 28px; }

#video-preview video { width: 100%; border-radius: 12px; margin-top: 8px; background: #000; max-height: 280px; }

.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.segmented button {
  font: inherit; font-size: 15px; font-weight: 600; min-height: 46px; border-radius: 10px;
  border: 1.5px solid var(--line); background: var(--bg); color: var(--ink);
}
.segmented button.on { background: var(--navy); color: #fff; border-color: var(--navy); }
@media (prefers-color-scheme: dark) { .segmented button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); } }

#ai-status { margin-top: 12px; display: flex; gap: 10px; align-items: center; }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--primary); animation: spin 0.9s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
#ai-flags > * { margin-top: 10px; }
.badge { display: inline-block; font-size: 13px; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); margin-right: 6px; }
.badge.high { color: var(--ok); border-color: var(--ok); }
.badge.low { color: var(--danger); border-color: var(--danger); }
details { margin-top: 14px; }
summary { font-weight: 650; cursor: pointer; padding: 6px 0; }
.comp { padding: 8px 0; border-top: 1px solid var(--line); font-size: 15px; }
.comp a { color: var(--primary); word-break: break-all; }

.spacer { height: 96px; }
.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; gap: 10px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.actionbar .primary { flex: 1; }
@media (min-width: 664px) { .actionbar { left: 50%; transform: translateX(-50%); max-width: 640px; border-radius: 16px 16px 0 0; } }

/* overlays */
.overlay { position: fixed; inset: 0; z-index: 50; background: #000; display: flex; flex-direction: column; }
.overlay.light { background: rgba(10,16,34,.7); align-items: center; justify-content: center; padding: 16px; }
#scanner-video { flex: 1; width: 100%; object-fit: cover; }
.scan-frame { position: absolute; left: 10%; right: 10%; top: 35%; height: 22%; border: 3px solid var(--accent); border-radius: 14px; box-shadow: 0 0 0 9999px rgba(0,0,0,.35); pointer-events: none; }
.scanner-bar { position: absolute; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-between; align-items: center; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); color: #fff; background: linear-gradient(transparent, rgba(0,0,0,.8)); }
.scanner-bar .btn { color: #fff; border-color: rgba(255,255,255,.5); }

.progress-card { background: var(--card); border-radius: 20px; padding: 22px; width: 100%; max-width: 420px; text-align: center; }
.bar { height: 12px; background: var(--bg); border-radius: 999px; overflow: hidden; margin: 14px 0; }
#bar-fill { height: 100%; width: 0; background: var(--primary); transition: width .2s; }
.sku { font-size: 26px; font-weight: 800; letter-spacing: .02em; margin: 6px 0; }

#toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--navy); color: #fff; padding: 10px 16px; border-radius: 12px; z-index: 60; font-size: 15px; max-width: 90vw;
}

/* simplified layout */
.grid2.tight { gap: 10px; margin-top: 12px; }
.thumbs:empty { display: none; }
.row.between { justify-content: space-between; align-items: center; margin-top: 6px; }
.ok { color: var(--ok); font-weight: 600; }
#match { margin: 10px 0 0; }
.stepper { display: grid; grid-template-columns: 56px 1fr 56px; gap: 8px; }
.stepper input { text-align: center; font-size: 22px; font-weight: 700; }
.stepper .btn { font-size: 26px; padding: 0; }

/* combined media */
.thumb.video { cursor: pointer; background: #000; }
.thumb.video video { width: 100%; height: 100%; object-fit: cover; display: block; }
#video-info { margin: 10px 0 0; }

/* in-app camera */
#camera { background: #000; }
#camera-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
#camera-flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
#camera-flash.on { animation: flash 0.25s ease-out; }
@keyframes flash { from { opacity: 0.8; } to { opacity: 0; } }
.camera-top {
  position: absolute; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: center;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px; color: #fff; background: linear-gradient(rgba(0,0,0,.6), transparent);
}
.camera-top .btn { color: #fff; border-color: rgba(255,255,255,.5); min-height: 40px; padding: 8px 16px; }
#camera-status { font-weight: 700; color: #ff4d4d; font-variant-numeric: tabular-nums; }
#camera-res { opacity: .7; }
.camera-bottom {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 12px 20px calc(18px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgba(0,0,0,.75)); display: grid; gap: 14px;
}
.camera-modes { display: flex; justify-content: center; gap: 8px; }
.camera-modes button {
  font: inherit; font-size: 15px; font-weight: 700; color: #fff; background: rgba(255,255,255,.15);
  border: 0; border-radius: 999px; padding: 8px 18px;
}
.camera-modes button.on { background: var(--accent); color: var(--accent-ink); }
.camera-modes.locked { opacity: .4; pointer-events: none; }
.camera-row { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; }
.camera-last { width: 56px; height: 56px; border-radius: 10px; overflow: hidden; border: 2px solid rgba(255,255,255,.6); background: rgba(255,255,255,.1); }
.camera-last img { width: 100%; height: 100%; object-fit: cover; display: block; }
.camera-count { justify-self: end; color: #fff; font-weight: 700; font-size: 18px; font-variant-numeric: tabular-nums; }
.shutter {
  width: 78px; height: 78px; border-radius: 50%; border: 5px solid #fff; background: #fff;
  box-shadow: inset 0 0 0 4px #000; cursor: pointer;
}
.shutter:active { transform: scale(0.94); }
.shutter.video { background: #e53935; }
.shutter.recording { background: #e53935; border-radius: 18px; transform: scale(0.8); }
