/* =========================================================================
   Katalog — iOS-native visual system
   Dual-mode colour tokens (light default; dark via media query AND via a
   manual [data-theme] override so a toggle can win either way).
   ========================================================================= */

:root {
  /* LIGHT (default) */
  --bg: #F2F2F7;
  --surface: #FFFFFF;
  --surface-2: #FFFFFF;
  --separator: rgba(60, 60, 67, 0.29);
  --text: #000000;
  --text-secondary: rgba(60, 60, 67, 0.6);
  --accent: #007AFF;
  --accent-press: #0060DF;
  --accent-tint: rgba(0, 122, 255, 0.12);
  --success: #34C759;
  --danger: #FF3B30;
  --warning: #FF9500;
  --warning-tint: rgba(255, 149, 0, 0.14);
  --on-accent: #FFFFFF;

  --radius-card: 16px;
  --radius-btn: 14px;
  --radius-lg: 20px;
  --radius-pill: 999px;
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.06);

  --slide-ease: cubic-bezier(0.32, 0.72, 0, 1);
  --slide-ms: 300ms;
  --fade-ms: 220ms;

  --safe-top: max(env(safe-area-inset-top), 12px);
  --safe-bottom: max(env(safe-area-inset-bottom), 12px);
  --safe-left: max(env(safe-area-inset-left), 16px);
  --safe-right: max(env(safe-area-inset-right), 16px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1C1C1E;
    --surface-2: #2C2C2E;
    --separator: rgba(84, 84, 88, 0.6);
    --text: #FFFFFF;
    --text-secondary: rgba(235, 235, 245, 0.6);
    --accent: #0A84FF;
    --accent-press: #3D9BFF;
    --accent-tint: rgba(10, 132, 255, 0.18);
    --success: #30D158;
    --danger: #FF453A;
    --warning: #FF9F0A;
    --warning-tint: rgba(255, 159, 10, 0.18);
    --shadow-card: none;
  }
}

/* Manual overrides win in both directions. */
:root[data-theme="light"] {
  --bg: #F2F2F7; --surface: #FFFFFF; --surface-2: #FFFFFF;
  --separator: rgba(60, 60, 67, 0.29); --text: #000000;
  --text-secondary: rgba(60, 60, 67, 0.6); --accent: #007AFF;
  --accent-press: #0060DF; --accent-tint: rgba(0, 122, 255, 0.12);
  --success: #34C759; --danger: #FF3B30; --warning: #FF9500;
  --warning-tint: rgba(255, 149, 0, 0.14); --shadow-card: 0 1px 2px rgba(0,0,0,0.06);
}
:root[data-theme="dark"] {
  --bg: #000000; --surface: #1C1C1E; --surface-2: #2C2C2E;
  --separator: rgba(84, 84, 88, 0.6); --text: #FFFFFF;
  --text-secondary: rgba(235, 235, 245, 0.6); --accent: #0A84FF;
  --accent-press: #3D9BFF; --accent-tint: rgba(10, 132, 255, 0.18);
  --success: #30D158; --danger: #FF453A; --warning: #FF9F0A;
  --warning-tint: rgba(255, 159, 10, 0.18); --shadow-card: none;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

/* ---- view stack + router --------------------------------------------------- */

#view-stack {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: var(--bg);
}

.view {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}
.view[hidden] { display: none; }

/* Transition mechanics driven by router.js. Offsets are instant unless .is-anim
   enables the transition. */
.view.is-anim {
  transition:
    transform var(--slide-ms) var(--slide-ease),
    opacity var(--fade-ms) ease;
  will-change: transform, opacity;
}
.view.off-right { transform: translateX(100%); }
.view.off-left  { transform: translateX(-24%); opacity: 0.5; }
.view.off-fade  { opacity: 0; transform: scale(0.98); }

/* ---- shared layout helpers ------------------------------------------------- */

.view-pad {
  padding:
    var(--safe-top)
    var(--safe-right)
    var(--safe-bottom)
    var(--safe-left);
}

.stack-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  min-height: 0;
}

/* ---- typography ------------------------------------------------------------ */

.large-title { font-size: 34px; font-weight: 700; letter-spacing: 0.01em; margin: 0; }
.title { font-size: 22px; font-weight: 700; margin: 0; }
.headline { font-size: 17px; font-weight: 600; margin: 0; }
.subhead { font-size: 15px; font-weight: 400; line-height: 1.4; margin: 0; }
.footnote { font-size: 13px; font-weight: 400; margin: 0; }
.muted { color: var(--text-secondary); }
.center { text-align: center; }

/* ---- buttons --------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: var(--radius-btn);
  font-size: 17px;
  font-weight: 600;
  padding: 14px 18px;
  width: 100%;
  min-height: 50px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  text-decoration: none;
  transition: background-color 0.15s ease, transform 0.05s ease;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; cursor: default; }

.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:active { background: var(--accent-press); }

.btn-secondary { background: var(--accent-tint); color: var(--accent); }
.btn-secondary:active { background: var(--accent-tint); filter: brightness(0.94); }

.btn-plain {
  background: transparent;
  color: var(--accent);
  min-height: 44px;
  font-weight: 400;
}

.btn-destructive { background: var(--danger); color: #fff; }

.btn-lg {
  font-size: 24px;
  padding: 36px 24px;
  border-radius: var(--radius-lg);
  min-height: 56px;
  max-width: 320px;
}

.btn-small {
  width: auto;
  min-height: 44px;
  padding: 10px 16px;
  font-size: 15px;
  flex: 0 0 auto;
}
.btn-outline {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}

.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }

/* ---- action bar (fixed bottom, translucent) -------------------------------- */

.action-bar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px var(--safe-right) var(--safe-bottom) var(--safe-left);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--separator);
}
.status-view .action-bar,
.view-pad > .action-bar {
  border-top: none;
  background: transparent;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}

/* ---- fields ---------------------------------------------------------------- */

.field {
  width: 100%;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--separator);
  border-radius: 10px;
  padding: 12px;
  font-size: 16px; /* >=16px avoids iOS zoom-on-focus */
  margin-bottom: 6px;
  font-family: inherit;
}
.field:focus { outline: none; border-color: var(--accent); }
textarea.field { resize: vertical; }
.field-qty { width: 120px; }

.field-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin: 14px 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.card > .field-label:first-child { margin-top: 0; }

.inline-msg {
  color: var(--danger);
  font-size: 13px;
  min-height: 16px;
  margin: 0;
}

/* ---- SETUP / HOME ---------------------------------------------------------- */

.brandblock { text-align: center; display: flex; flex-direction: column; gap: 8px; }
.setup-field { width: 100%; max-width: 360px; }
.home-title { margin-bottom: 8px; }
.home-foot { display: flex; justify-content: center; padding-bottom: 4px; }

/* ---- CAPTURE (full-bleed) -------------------------------------------------- */

.capture { background: #000; }
.capture-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  z-index: 0;
}

.pill {
  position: absolute;
  top: calc(var(--safe-top) + 4px);
  left: calc(var(--safe-left));
  z-index: 3;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: rgba(0, 0, 0, 0.55);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  color: #fff;
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  font-size: 14px;
  font-weight: 600;
}
.pill-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--danger);
  animation: pulse 1.2s infinite;
}
.pill-time { font-variant-numeric: tabular-nums; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }

.capture-bottom {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
}

.action-bar--capture {
  background: linear-gradient(to top, rgba(0,0,0,0.55), rgba(0,0,0,0));
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
  border-top: none;
}
.action-bar--capture .btn-secondary { background: rgba(255,255,255,0.16); color: #fff; }
.action-bar--capture .btn-plain { color: #fff; }

.count-badge {
  background: rgba(255, 255, 255, 0.25);
  border-radius: var(--radius-pill);
  padding: 2px 8px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.thumbs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 0 var(--safe-right) 10px var(--safe-left);
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.thumbs::-webkit-scrollbar { display: none; }
.thumb {
  flex: 0 0 auto;
  width: 56px;
  height: 56px;
  border-radius: 10px;
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, 0.8);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }

/* ---- toast ----------------------------------------------------------------- */

.toast {
  position: absolute;
  top: calc(var(--safe-top) + 46px);
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  z-index: 4;
  max-width: 88%;
  background: rgba(0, 0, 0, 0.82);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  color: #fff;
  padding: 10px 16px;
  border-radius: 14px;
  font-size: 14px;
  text-align: center;
  opacity: 0;
  transition: opacity 0.3s ease, transform 0.3s ease;
  pointer-events: none;
}
.toast--show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---- PROCESSING (one indicator) ------------------------------------------- */

.status-view .stack-center { gap: 16px; }

.proc-indicator {
  position: relative;
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ring { width: 56px; height: 56px; transform: rotate(-90deg); }
.ring-track { fill: none; stroke: var(--separator); stroke-width: 4; }
.ring-fill {
  fill: none;
  stroke: var(--accent);
  stroke-width: 4;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.2s ease;
}
.ring[data-mode="indeterminate"] { animation: ring-spin 0.9s linear infinite; }
.ring[data-mode="indeterminate"] .ring-fill {
  stroke-dasharray: 90 220;
  transition: none;
}
@keyframes ring-spin { to { transform: rotate(360deg); } }

.ring-pct {
  position: absolute;
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
}

#proc-title { transition: opacity 0.12s ease, transform 0.12s ease; }
#proc-title.morph-out { opacity: 0; transform: translateY(6px); }

/* Legacy indeterminate spinner (kept as a shared utility). */
.spinner {
  width: 44px;
  height: 44px;
  border: 4px solid var(--separator);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: ring-spin 0.9s linear infinite;
}

/* ---- REVIEW (the only scrolling view) ------------------------------------- */

.view-header {
  flex: 0 0 auto;
  padding: var(--safe-top) var(--safe-right) 10px var(--safe-left);
  background: var(--bg);
  border-bottom: 0.5px solid var(--separator);
}

.scroll-area {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px var(--safe-right) 16px var(--safe-left);
}

.review-root { display: flex; flex-direction: column; gap: 16px; }

.card {
  background: var(--surface);
  border-radius: var(--radius-card);
  padding: 14px;
  border: 0.5px solid var(--separator);
  box-shadow: var(--shadow-card);
}

.action-bar--review { gap: 8px; }

/* ---- tags ------------------------------------------------------------------ */

.tags { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--separator);
  border-radius: var(--radius-pill);
  padding: 8px 12px;
  font-size: 14px;
  min-height: 44px;
}
.add-row { display: flex; gap: 8px; margin-top: 10px; align-items: center; }
.add-row .field { margin-bottom: 0; }

/* ---- location (segmented control) ----------------------------------------- */

.loc-box { display: flex; flex-direction: column; gap: 10px; }
.loc-note { font-size: 13px; margin: 0; }

.segmented {
  display: flex;
  background: var(--surface-2);
  border: 1px solid var(--separator);
  border-radius: 10px;
  padding: 2px;
  gap: 2px;
}
.segment {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 40px;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  transition: background-color 0.15s ease;
}
.segment input { position: absolute; opacity: 0; pointer-events: none; }
.segment:has(input:checked) {
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
}

/* ---- image review ---------------------------------------------------------- */

.img-review { display: flex; flex-direction: column; gap: 12px; }
.img-card {
  background: var(--surface-2);
  border: 0.5px solid var(--separator);
  border-radius: 12px;
  padding: 10px;
}
.img-thumb {
  width: 100%;
  max-height: 220px;
  object-fit: contain;
  border-radius: 8px;
  background: #000;
  margin-bottom: 8px;
}
.radio-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  font-size: 15px;
  min-height: 44px;
}

/* ---- banner (collected warnings) ------------------------------------------ */

.banner {
  background: var(--warning-tint);
  color: var(--text);
  border-radius: var(--radius-card);
  padding: 12px 14px;
  font-size: 14px;
}
.banner-title { display: block; margin-bottom: 4px; color: var(--warning); }
.banner ul { margin: 6px 0 0; padding-left: 18px; }

.transcript summary { cursor: pointer; color: var(--text-secondary); font-size: 14px; }
.transcript p { margin: 8px 0 0; font-size: 14px; }

/* ---- DONE / ERROR badges --------------------------------------------------- */

.badge {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 34px;
  font-weight: 700;
  color: #fff;
}
[data-view="done"][data-state="success"] .badge { background: var(--success); }
[data-view="done"][data-state="error"] .badge { background: var(--danger); }

[data-view="done"][data-state="success"] .done-error { display: none; }
[data-view="done"][data-state="error"] .done-success { display: none; }

/* ---- reduced motion -------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .view.is-anim { transition: opacity 120ms linear; }
  .view.off-right,
  .view.off-left { transform: none; opacity: 0; }
  .view.off-fade { transform: none; opacity: 0; }
  .pill-dot { animation: none; }
  #proc-title { transition: opacity 0.12s ease; }
  #proc-title.morph-out { transform: none; }
}
