/* ============================================================
   KΩUNT — KEVA THEME
   Keva paper + slate + brass; Keva fonts (Space Grotesk + JetBrains Mono)
   Big, confident touch targets for bar/back-of-house use
   ============================================================ */

/* ---------- CSS VARIABLES ---------- */
:root {
  /* ====== KEVA PALETTE (re-theme 2026-10-25) ======
     Keva tokens first; the older Kount token names below are kept (used in
     ~400 inline styles) and now point at the Keva values. */
  --keva-paper: #FFFEFB;
  --keva-fog: #FAF8F5;
  --keva-fog-200: #F5F1EB;
  --keva-fog-300: #E8E2DA;
  --keva-border: #DED9D3;
  --keva-slate: #1C1917;
  --keva-slate-800: #292524;
  --keva-slate-600: #6B6156;
  --keva-brass: #D4622B;
  --keva-brass-50: #FDF5EF;
  --keva-brass-100: #FCEADB;
  --keva-brass-700: #993D18;
  --keva-olive: #5C6B4F;
  --keva-olive-50: #F4F6F2;
  --keva-error: #DC2626;
  --keva-error-50: #FEF2F2;
  --keva-error-200: #FECACA;
  --keva-error-700: #B91C1C;
  --keva-radius-card: 8px;
  --keva-radius-chip: 6px;
  --keva-radius-badge: 4px;
  --keva-shadow: 0 1px 3px rgba(28, 25, 23, 0.1), 0 1px 2px -1px rgba(28, 25, 23, 0.1);
  --keva-ring: 0 0 0 2px var(--keva-paper), 0 0 0 4px var(--keva-brass);

  /* Surfaces */
  --bg: var(--keva-paper);
  --canvas: var(--keva-paper);
  --surface: var(--keva-fog);
  --surface2: var(--keva-fog-200);
  --surface3: var(--keva-fog-300);
  --off-100: var(--keva-paper);
  --off-200: var(--keva-fog-200);
  --off-300: var(--keva-fog-300);
  --border: var(--keva-border);
  --border-strong: #BDB6AE;

  /* Text. Kount's dim-bar contrast rule stays: secondary text is slate-600
     (7:1 on paper); muted keeps its measured 4.76:1 step for placeholders. */
  --text: var(--keva-slate);
  --ink: var(--keva-slate);
  --fg-primary: var(--keva-slate);
  --fg-secondary: var(--keva-slate-600);
  --fg-muted: #767271;
  --text-muted: var(--keva-slate-600);
  --text-dim: #767271;

  /* Brand: slate is the primary CTA, brass the counting highlight */
  --accent: var(--keva-slate);
  --accent-hover: var(--keva-slate-800);
  --accent-dim: rgba(28, 25, 23, 0.08);
  --accent-soft: var(--keva-brass-50);
  --primary: var(--keva-slate);
  --primary-dim: rgba(28, 25, 23, 0.06);

  /* Dark scale */
  --dark-700: #44403C;
  --dark-800: var(--keva-slate-800);
  --dark-900: var(--keva-slate);

  /* Gold -> brass */
  --gold-100: var(--keva-brass-100);
  --gold-300: var(--keva-brass);
  --gold-400: var(--keva-brass-700);

  /* Raspberry -> error */
  --raspberry-100: var(--keva-error-50);
  --raspberry-200: var(--keva-error-200);
  --raspberry-300: var(--keva-error);
  --raspberry-400: var(--keva-error-700);

  /* Teal -> olive */
  --teal-100: var(--keva-olive-50);
  --teal-300: var(--keva-olive);

  /* Copper -> brass (700 for text) */
  --copper-100: var(--keva-brass-50);
  --copper-300: var(--keva-brass);
  --copper-400: var(--keva-brass-700);

  /* Amethyst -> slate-600 */
  --amethyst-100: var(--keva-fog-200);
  --amethyst-200: var(--keva-fog-300);
  --amethyst-300: var(--keva-slate-600);
  --amethyst-400: var(--keva-slate);

  /* Semantic names */
  --brand: var(--keva-brass);      --brand-ink: var(--keva-paper);
  --critical: var(--keva-error);   --critical-bg: var(--keva-error-50);
  --caution: var(--keva-brass-700); --caution-bg: var(--keva-brass-50);
  --positive: var(--keva-olive);   --positive-bg: var(--keva-olive-50);
  --inform: var(--keva-slate-600); --inform-bg: var(--keva-fog-200);
  --shadow-focus: 0 0 0 2px var(--keva-paper), 0 0 0 4px var(--keva-brass);

  /* Semantic aliases */
  --danger: var(--keva-error);
  --danger-dim: rgba(220, 38, 38, 0.10);
  --success: var(--keva-olive);
  --success-dim: rgba(92, 107, 79, 0.12);
  --warning: var(--keva-brass-700);
  --warning-dim: rgba(212, 98, 43, 0.10);
  --blue: var(--keva-slate-600);
  --blue-dim: rgba(87, 81, 74, 0.10);

  /* Shape */
  --radius: 8px;
  --radius-sm: 6px;
  --radius-xs: 6px;
  --shadow-sm: 0 1px 2px rgba(28, 25, 23, 0.05);
  --shadow: var(--keva-shadow);
  --shadow-lg: 0 10px 15px -3px rgba(28, 25, 23, 0.1), 0 4px 6px -4px rgba(28, 25, 23, 0.1);

  /* Typography: Keva */
  --font: 'Space Grotesk', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

/* ---------- RESET ---------- */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ---------- UTILITIES ---------- */
.hide { display: none !important; }
.fade-in { animation: fadeIn 0.25s ease; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

@keyframes scanLine {
  0% { top: 20%; }
  100% { top: 80%; }
}

@keyframes tapPulse {
  0% { transform: scale(1); }
  40% { transform: scale(0.94); }
  100% { transform: scale(1); }
}

@keyframes bumpUp {
  0% { transform: translateY(0) scale(1); }
  40% { transform: translateY(-4px) scale(1.08); }
  100% { transform: translateY(0) scale(1); }
}

.bump { animation: bumpUp 0.28s cubic-bezier(.3,1.4,.5,1); }

/* ---------- APP SHELL ---------- */
#app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
  background: var(--bg);
}

/* ---------- HEADER ---------- */
.header {
  padding: 14px 18px 10px;
  padding-top: calc(14px + var(--safe-top));
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--canvas);
  border-bottom: 1px solid var(--keva-border);
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 12px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1;
}

/* Prototype phone header is title-only — no logo, just the venue name
   reading as a bold headline. We hide the logo slot without touching
   markup and repaint the venue badge as a headline. */
.logo {
  display: none;
}

.venue-badge {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--fg-primary);
  background: transparent;
  padding: 0;
  border: none;
  border-radius: 0;
  box-shadow: none;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.15;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.count-badge {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--fg-secondary);
  background: var(--off-200);
  padding: 5px 10px;
  border-radius: 9999px;
  border: none;
  letter-spacing: 0.04em;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--keva-paper);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s;
}

.icon-btn:active {
  background: var(--surface2);
  transform: scale(0.93);
}

.icon-btn svg {
  width: 20px;
  height: 20px;
}

/* ---------- PAGES ---------- */
.page {
  flex: 1;
  padding: 18px 16px;
  padding-bottom: calc(100px + var(--safe-bottom));
  overflow-y: auto;
}

/* ---------- PROGRESS BAR ---------- */
.progress-wrap {
  margin-bottom: 16px;
}

.progress-info {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 8px;
  font-weight: 500;
}

.progress-info strong {
  color: var(--primary);
  font-family: var(--mono);
  font-weight: 600;
}

.progress-bar {
  height: 8px;
  background: var(--keva-fog-300);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--keva-brass);
  border-radius: 999px;
  transition: width 0.4s cubic-bezier(.4,0,.2,1);
  min-width: 0;
}

/* ---------- ZONE TABS ---------- */
.zone-tabs {
  display: flex;
  gap: 8px;
  padding: 0 0 14px;
  overflow-x: auto;
  scrollbar-width: none;
  margin: 0 -16px;
  padding-left: 16px;
  padding-right: 16px;
}

.zone-tabs::-webkit-scrollbar {
  display: none;
}

.zone-tab {
  flex-shrink: 0;
  padding: 10px 18px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--keva-paper);
  color: var(--primary);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  font-family: var(--font);
  min-height: 42px;
}

.zone-tab.active {
  background: var(--primary);
  color: var(--bg);
  border-color: var(--primary);
}

.zone-tab .zcnt {
  font-family: var(--mono);
  font-size: 12px;
  margin-left: 6px;
  opacity: 0.7;
  font-weight: 500;
}
.zone-tab .zone-tab-x {
  display: inline-flex;
  align-items: center; justify-content: center;
  margin-left: 6px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: rgba(28,25,23,0.08);
  color: var(--fg-muted);
  font-size: 13px; line-height: 1;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.zone-tab .zone-tab-x:hover,
.zone-tab .zone-tab-x:active {
  background: var(--danger);
  color: #fff;
}

/* ---------- SCAN ACTION BUTTONS ---------- */
.scan-actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.scan-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 18px 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--primary);
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  min-height: 96px;
  position: relative;
  overflow: hidden;
}

.scan-btn:active {
  background: var(--surface2);
  transform: scale(0.96);
  box-shadow: var(--shadow-sm);
}

.scan-btn.locked {
  opacity: 0.4;
  pointer-events: none;
}

.scan-icon {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
}

.scan-icon svg {
  width: 24px !important;
  height: 24px !important;
}

.scan-btn.barcode {
  background: var(--primary);
  color: var(--bg);
  border-color: var(--primary);
}
.scan-btn.barcode .scan-icon {
  background: rgba(255, 255, 255, 0.15);
  color: var(--bg);
}
.scan-btn.barcode:active {
  background: var(--ink);
}

.scan-btn.photo .scan-icon {
  background: var(--keva-brass-50);
  color: var(--keva-brass-700);
}

.scan-btn.manual .scan-icon {
  background: var(--surface3);
  color: var(--primary);
}

/* ---------- MODE TOGGLE ---------- */
.mode-toggle {
  display: flex;
  gap: 4px;
  background: var(--keva-fog-200);
  border: 1px solid var(--keva-fog-300);
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 14px;
}

.mode-btn {
  flex: 1;
  padding: 11px 8px;
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  border-radius: 9px;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.15s;
  background: none;
  border: none;
  font-family: var(--font);
  min-height: 40px;
}

.mode-btn.active {
  background: var(--keva-paper);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

/* ---------- STICKY CURRENT ITEM CARD ---------- */
.current-item-card {
  position: sticky;
  top: 68px;
  z-index: 50;
  background: var(--primary);
  color: var(--bg);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 14px;
}

.current-item-card .ci-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--keva-brass-100);
  margin-bottom: 4px;
}

.current-item-card .ci-name {
  font-size: 17px;
  font-weight: 700;
  line-height: 1.2;
  margin-bottom: 4px;
}

.current-item-card .ci-meta {
  font-size: 13px;
  opacity: 0.7;
}

.current-item-card .ci-info {
  flex: 1;
  min-width: 0;
}

.current-item-card .ci-info .ci-name,
.current-item-card .ci-info .ci-meta {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- SEARCH BAR ---------- */
.search-bar {
  position: relative;
  margin-bottom: 14px;
}

.search-bar input {
  width: 100%;
  padding: 12px 44px 12px 46px;
  background: var(--keva-paper);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-size: 16px;
  font-family: var(--font);
  font-weight: 500;
  outline: none;
  min-height: 48px;
}

.search-bar input:focus {
  border-color: var(--keva-brass);
  box-shadow: var(--keva-ring);
}

.search-bar input::placeholder {
  color: var(--text-dim);
}

.search-bar .si {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  display: flex;
}

.search-bar .si svg {
  width: 18px;
  height: 18px;
}

/* Clear (X) button — shows only while the field has text (placeholder hidden). */
.search-bar .clear-x {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  display: none;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: var(--border);
  color: var(--text-muted);
  cursor: pointer;
}
.search-bar input:not(:placeholder-shown) ~ .clear-x {
  display: flex;
}
.search-bar .clear-x svg {
  width: 12px;
  height: 12px;
}

/* Confirm button draws the eye once a qty is entered, so the iOS keyboard's
   "Done ✓" (which only dismisses the keypad) isn't mistaken for saving. */
@keyframes confirmPulse {
  0%, 100% { box-shadow: 0 0 0 0 var(--accent-dim); }
  50%      { box-shadow: 0 0 0 6px var(--accent-dim); }
}
.submit-btn.needs-confirm {
  animation: confirmPulse 1.4s ease-in-out infinite;
}

/* ---------- LIST HEADER ---------- */
.list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  padding: 0 4px;
}

.list-header h3 {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.list-header .total {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--primary);
  font-weight: 600;
}

/* ---------- COUNT ITEM ROW ---------- */
/* Count-list row — prototype's lighter card: 1px border, no drop shadow,
   14px radius, softer status indication (no gradient wash). */
.c-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 14px;
  transition: transform 0.12s ease, background 0.12s ease;
}

.c-item:active {
  transform: scale(0.99);
  background: var(--surface2);
}

.c-item.counted {
  background: var(--keva-olive-50);
  border-color: rgba(92, 107, 79, 0.35);
}

.c-item.flagged {
  background: var(--keva-error-50);
  border-color: var(--keva-error-200);
}

.c-thumb {
  width: 52px;
  height: 52px;
  border-radius: 10px;
  background: var(--keva-fog-200);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  flex-shrink: 0;
  overflow: hidden;
  text-transform: uppercase;
}

.c-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.c-info {
  flex: 1;
  min-width: 0;
}

.c-name {
  font-weight: 700;
  font-size: 16px;
  color: var(--primary);
  white-space: normal;
  overflow-wrap: anywhere;
  line-height: 1.25;
}

.c-meta {
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 3px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-weight: 500;
}

.method-badge {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.method-badge.barcode { background: var(--accent-dim); color: var(--keva-slate); }
.method-badge.photo { background: var(--keva-brass-50); color: var(--keva-brass-700); }
.method-badge.manual { background: var(--keva-fog-200); color: var(--keva-slate-600); }
.method-badge.guided { background: var(--keva-olive-50); color: var(--keva-olive); }
.method-badge.scale { background: var(--keva-brass-100); color: var(--keva-brass-700); }
.method-badge.vision { background: var(--keva-slate); color: var(--keva-paper); }

/* ---------- QTY CONTROLS (BIG!) ---------- */
.c-qty {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  gap: 6px;
}

.qty-btn {
  width: 48px;
  height: 48px;
  border: 1px solid var(--border);
  background: var(--keva-paper);
  color: var(--primary);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 22px;
  font-weight: 700;
  transition: all 0.12s;
  font-family: var(--font);
  line-height: 1;
}

.qty-btn:active {
  background: var(--primary);
  color: var(--bg);
  transform: scale(0.9);
  box-shadow: none;
}

.qty-btn.plus {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.qty-btn.plus:active {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.qty-val {
  font-family: var(--mono);
  font-size: 24px;
  font-weight: 700;
  min-width: 44px;
  text-align: center;
  color: var(--primary);
  letter-spacing: -0.5px;
}

/* ---------- VENUE CARDS ---------- */
.venue-select-page h1 {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 4px;
  color: var(--primary);
  letter-spacing: -0.5px;
}

.venue-select-page .subtitle {
  color: var(--text-muted);
  font-size: 15px;
  margin-bottom: 24px;
  font-weight: 500;
}

/* Venue picker card — rounder, no drop shadow, gentler padding. */
.venue-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.12s ease;
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 72px;
}

.venue-card:active {
  background: var(--surface2);
  transform: scale(0.99);
}

.venue-card .v-body {
  flex: 1;
  min-width: 0;
}

.venue-card .v-chev {
  color: var(--text-dim);
  font-size: 20px;
  flex-shrink: 0;
  font-weight: 400;
  line-height: 1;
}

.venue-avatar {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--keva-brass-100);
  color: var(--keva-brass-700);
  font-family: var(--font);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.02em;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.venue-name {
  font-weight: 700;
  font-size: 16px;
  color: var(--fg-primary);
  letter-spacing: -0.005em;
}

.venue-addr {
  color: var(--fg-muted);
  font-size: 12px;
  margin-top: 3px;
  font-weight: 500;
  line-height: 1.35;
}

/* ---------- BOTTOM NAV ---------- */
/* Bottom nav — ported from phone_screens.jsx prototype:
   frosted paper bar; active tab = brass-700 text + semibold. Class names + markup
   are unchanged so showPage()'s existing toggling continues to work. */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 520px;
  background: rgba(255, 254, 251, 0.94);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  display: flex;
  padding: 8px 12px;
  padding-bottom: calc(8px + var(--safe-bottom));
  z-index: 100;
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 4px 0;
  cursor: pointer;
  color: var(--fg-muted);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.02em;
  background: none;
  border: none;
  font-family: var(--font);
}

/* The SVG gets wrapped in its own pill via an inline span — since we can't
   touch the markup, render the pill via the .nav-item's SVG itself by
   setting an inset box around it through a flex shell. */
.nav-item svg {
  width: 18px;
  height: 18px;
  display: block;
  padding: 3px 8px;
  box-sizing: content-box;
  border-radius: 12px;
  transition: background 0.15s ease, color 0.15s ease;
}

.nav-item.active {
  color: var(--keva-brass-700);
  font-weight: 600;
}

.nav-item:active svg {
  transform: scale(0.96);
}
.nav-item.k-rail-only { display: none; }
/* Counters/viewers during Count 1: Variance shows a lock (class toggled by JS) */
.nav-item.is-locked { position: relative; opacity: 0.7; }
.nav-item.is-locked::after {
  content: '\1F512';
  position: absolute;
  top: 0;
  left: calc(50% + 8px);
  font-size: 10px;
  line-height: 1;
}

/* ---------- CAMERA MODAL ---------- */
.camera-modal {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 200;
  display: flex;
  flex-direction: column;
}

.camera-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  padding-top: calc(14px + var(--safe-top));
  color: #fff;
  background: rgba(0, 0, 0, 0.85);
  z-index: 1;
}

.camera-header h3 {
  font-size: 16px;
  font-weight: 700;
}

.camera-close {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: #fff;
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.camera-close:active {
  background: rgba(255, 255, 255, 0.25);
  transform: scale(0.93);
}

.camera-flash {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: #fff;
  cursor: pointer;
  display: none; /* shown only when the active video track supports torch */
  align-items: center;
  justify-content: center;
  margin-right: 8px;
}
.camera-flash.on {
  background: var(--keva-brass);
  color: #fff;
}
.camera-flash:active { transform: scale(0.93); }
.camera-flash svg { width: 22px; height: 22px; }

.camera-viewfinder {
  flex: 1;
  position: relative;
  overflow: hidden;
}

.camera-viewfinder video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scan-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.scan-frame {
  /* Larger centered scan region (v1.83): a wider/taller window lets a barcode
     held farther back still land inside the frame, extending the effective
     range. Capped with vw/vh so it stays centered and never overflows a small
     phone screen. */
  width: min(340px, 86vw);
  height: min(210px, 40vh);
  border: none;
  border-radius: 14px;
  position: relative;
  box-shadow: 0 0 0 2000px rgba(0, 0, 0, 0.45);
}

/* Gold corner brackets (Woody scanner style) */
.scan-frame::before,
.scan-frame::after {
  content: '';
  position: absolute;
  pointer-events: none;
}
.scan-frame::before {
  inset: -3px;
  border-radius: 14px;
  background:
    linear-gradient(to right, var(--gold-300) 0, var(--gold-300) 32px, transparent 32px, transparent calc(100% - 32px), var(--gold-300) calc(100% - 32px), var(--gold-300) 100%) top / 100% 3px no-repeat,
    linear-gradient(to right, var(--gold-300) 0, var(--gold-300) 32px, transparent 32px, transparent calc(100% - 32px), var(--gold-300) calc(100% - 32px), var(--gold-300) 100%) bottom / 100% 3px no-repeat,
    linear-gradient(to bottom, var(--gold-300) 0, var(--gold-300) 32px, transparent 32px, transparent calc(100% - 32px), var(--gold-300) calc(100% - 32px), var(--gold-300) 100%) left / 3px 100% no-repeat,
    linear-gradient(to bottom, var(--gold-300) 0, var(--gold-300) 32px, transparent 32px, transparent calc(100% - 32px), var(--gold-300) calc(100% - 32px), var(--gold-300) 100%) right / 3px 100% no-repeat;
  transition: background 0.15s ease;
}

/* Laser line */
.scan-frame::after {
  left: 10%;
  right: 10%;
  top: 50%;
  height: 2px;
  background: var(--gold-300);
  box-shadow: 0 0 12px var(--gold-300);
  animation: scanLine 1.5s ease-in-out infinite alternate;
}

/* ---------- PHASE A: SCAN TARGETING STATES ---------- */
/* Targeting — barcode detected, accumulating frames (copper) */
.scan-frame.targeting {
  box-shadow: 0 0 0 2000px rgba(0, 0, 0, 0.45),
              inset 0 0 28px rgba(178, 112, 63, 0.18);
  transition: all 0.12s ease;
}
.scan-frame.targeting::before {
  background:
    linear-gradient(to right, var(--copper-300) 0, var(--copper-300) 32px, transparent 32px, transparent calc(100% - 32px), var(--copper-300) calc(100% - 32px), var(--copper-300) 100%) top / 100% 3px no-repeat,
    linear-gradient(to right, var(--copper-300) 0, var(--copper-300) 32px, transparent 32px, transparent calc(100% - 32px), var(--copper-300) calc(100% - 32px), var(--copper-300) 100%) bottom / 100% 3px no-repeat,
    linear-gradient(to bottom, var(--copper-300) 0, var(--copper-300) 32px, transparent 32px, transparent calc(100% - 32px), var(--copper-300) calc(100% - 32px), var(--copper-300) 100%) left / 3px 100% no-repeat,
    linear-gradient(to bottom, var(--copper-300) 0, var(--copper-300) 32px, transparent 32px, transparent calc(100% - 32px), var(--copper-300) calc(100% - 32px), var(--copper-300) 100%) right / 3px 100% no-repeat;
}
.scan-frame.targeting::after {
  background: var(--copper-300);
  box-shadow: 0 0 12px var(--copper-300);
  animation: none;
  opacity: 0.95;
}

/* Locked — 4 frames confirmed (teal) */
.scan-frame.locked {
  box-shadow: 0 0 0 2000px rgba(0, 0, 0, 0.45),
              inset 0 0 36px rgba(63, 125, 115, 0.22);
}
.scan-frame.locked::before {
  background:
    linear-gradient(to right, var(--teal-300) 0, var(--teal-300) 32px, transparent 32px, transparent calc(100% - 32px), var(--teal-300) calc(100% - 32px), var(--teal-300) 100%) top / 100% 3px no-repeat,
    linear-gradient(to right, var(--teal-300) 0, var(--teal-300) 32px, transparent 32px, transparent calc(100% - 32px), var(--teal-300) calc(100% - 32px), var(--teal-300) 100%) bottom / 100% 3px no-repeat,
    linear-gradient(to bottom, var(--teal-300) 0, var(--teal-300) 32px, transparent 32px, transparent calc(100% - 32px), var(--teal-300) calc(100% - 32px), var(--teal-300) 100%) left / 3px 100% no-repeat,
    linear-gradient(to bottom, var(--teal-300) 0, var(--teal-300) 32px, transparent 32px, transparent calc(100% - 32px), var(--teal-300) calc(100% - 32px), var(--teal-300) 100%) right / 3px 100% no-repeat;
}
.scan-frame.locked::after {
  background: var(--teal-300);
  box-shadow: 0 0 16px var(--teal-300);
  animation: none;
}
.scan-progress {
  position: absolute;
  bottom: -26px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 7px;
  pointer-events: none;
}
.scan-progress .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.35);
  transition: all 0.15s ease;
}
.scan-progress .dot.filled {
  background: var(--warning);
  border-color: var(--warning);
  box-shadow: 0 0 7px var(--warning);
}
.scan-progress .dot.done {
  background: var(--success);
  border-color: var(--success);
  box-shadow: 0 0 9px var(--success);
}

.camera-controls {
  padding: 20px;
  padding-bottom: calc(20px + var(--safe-bottom));
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 24px;
}

.capture-btn {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  background: var(--accent);
  border: 5px solid #fff;
  cursor: pointer;
  box-shadow: 0 0 0 3px var(--accent);
}

.capture-btn:active {
  transform: scale(0.92);
}

.scan-status {
  position: absolute;
  bottom: 120px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  padding: 10px 18px;
  border-radius: 24px;
  font-size: 14px;
  font-weight: 500;
  backdrop-filter: blur(8px);
}

/* INSTANT SCAN confirmation — compact overlay that appears after a known
   barcode is counted, without closing the camera. Sits above the scan-status
   pill so both can show; auto-hides after a short window. */
.instant-scan-feedback {
  position: absolute;
  bottom: 178px;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 90%;
  background: rgba(92, 107, 79, 0.95);
  color: #fff;
  padding: 10px 12px 10px 16px;
  border-radius: 24px;
  font-size: 14px;
  backdrop-filter: blur(8px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 20;
}
.instant-scan-feedback.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}
.instant-scan-feedback .isf-body {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.instant-scan-feedback .isf-check {
  font-size: 16px;
  font-weight: 700;
  flex-shrink: 0;
}
.instant-scan-feedback .isf-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.instant-scan-feedback .isf-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.instant-scan-feedback .isf-qty {
  font-size: 12px;
  opacity: 0.85;
}
.instant-scan-feedback .isf-edit {
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  border: none;
  border-radius: 16px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

/* ---------- MODAL ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(28, 25, 23, 0.45);
  z-index: 300;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  backdrop-filter: blur(4px);
}

.modal-sheet {
  background: var(--bg);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  border-radius: 20px 20px 0 0;
  padding: 20px 18px;
  padding-bottom: calc(20px + var(--safe-bottom));
  overflow-y: auto;
  animation: slideUp 0.25s cubic-bezier(.3,1.1,.5,1);
  box-shadow: 0 -10px 40px rgba(124, 45, 18, 0.12);
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-sheet h3 {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.close-x {
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--keva-paper);
  color: var(--text-muted);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.close-x:active {
  background: var(--surface2);
  transform: scale(0.93);
}

/* ---------- FORM ---------- */
.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  color: var(--keva-slate);
  margin-bottom: 6px;
}

.form-input {
  width: 100%;
  padding: 12px 14px;
  background: var(--keva-paper);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-size: 16px;
  font-family: var(--font);
  font-weight: 500;
  outline: none;
  min-height: 48px;
}

.form-input:focus {
  border-color: var(--keva-brass);
  box-shadow: var(--keva-ring);
}

.form-input::placeholder {
  color: var(--text-dim);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.submit-btn {
  width: 100%;
  padding: 16px;
  background: var(--keva-slate);
  border: 1px solid var(--keva-slate);
  border-radius: 12px;
  color: #fff;
  font-family: var(--font);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  min-height: 56px;
  letter-spacing: 0.01em;
}

.submit-btn:active {
  background: var(--accent-hover);
  transform: scale(0.98);
}

.submit-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.submit-btn.secondary {
  background: var(--keva-paper);
  color: var(--keva-slate);
  border: 1px solid var(--border-strong);
}

.submit-btn.secondary:active {
  background: var(--surface2);
}

/* ---------- ISSUE CHIPS ---------- */
.issue-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.issue-chip {
  padding: 9px 14px;
  border: 1px solid var(--border);
  background: var(--keva-paper);
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
}

.issue-chip.selected {
  background: var(--primary);
  color: var(--bg);
  border-color: var(--primary);
}

/* ---------- SUMMARY CARD ---------- */
/* Summary / stats card — Keva fog card, 1px border, 12px radius. */
.summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  margin-bottom: 14px;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 0;
  min-height: 40px;
}

.stat-row + .stat-row {
  border-top: 1px solid color-mix(in oklab, var(--border) 60%, transparent);
}

.stat-label {
  font-size: 14px;
  color: var(--text-muted);
  font-weight: 500;
}

.stat-value {
  font-family: var(--mono);
  font-size: 17px;
  font-weight: 700;
  color: var(--primary);
}

.stat-value.accent { color: var(--accent); }
.stat-value.danger { color: var(--danger); }
.stat-value.success { color: var(--success); }
.stat-value.warning { color: var(--warning); }

/* Section label ('eyebrow' in the prototype) — smaller, wider tracking,
   muted tone so the card contents below carry the visual weight. */
.section-title {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin: 22px 0 8px;
}

/* ---------- VARIANCE ROW ---------- */
.var-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Keva: red = short, brass = over, olive = match */
.var-row.over { border-left: 4px solid var(--keva-brass); }
.var-row.under { border-left: 4px solid var(--keva-error); }
.var-row.ok { border-left: 4px solid var(--keva-olive); }

.var-info { flex: 1; min-width: 0; }
.var-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.var-detail { font-size: 13px; color: var(--text-muted); font-weight: 500; margin-top: 2px; }
.var-diff {
  font-family: var(--mono);
  font-size: 18px;
  font-weight: 700;
  min-width: 60px;
  text-align: right;
  color: var(--primary);
}

/* ---------- AUDIT BADGE ---------- */
.audit-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  display: inline-block;
}

.audit-badge.active { background: var(--success-dim); color: var(--success); }
.audit-badge.submitted { background: var(--blue-dim); color: var(--blue); }

/* ---------- TIMER ---------- */
.timer-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 14px;
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 700;
  color: var(--primary);
}

.timer-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--success);
  animation: pulse 1.5s infinite;
  flex-shrink: 0;
}

.timer-phase {
  font-family: var(--font);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--keva-brass-700);
  text-transform: uppercase;
}

/* ---------- RECOUNT BANNER ---------- */
.recount-banner {
  background: var(--keva-brass-50);
  border: 1px solid var(--keva-brass-100);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 14px;
  color: var(--keva-brass-700);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
}

.recount-banner:active {
  transform: scale(0.99);
}

/* ---------- TOAST ---------- */
.toast {
  position: fixed;
  top: calc(64px + var(--safe-top));
  bottom: auto;
  left: 50%;
  transform: translateX(-50%);
  background: var(--keva-slate);
  color: var(--keva-paper);
  border: 1px solid var(--keva-slate);
  padding: 12px 20px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  z-index: 1000;
  box-shadow: var(--shadow-lg);
  animation: fadeIn 0.2s ease;
  max-width: 90%;
  text-align: center;
  pointer-events: none;
}

.toast.success {
  background: var(--success);
  color: #fff;
  border-color: var(--success);
}
.toast.error {
  background: var(--keva-error-700);
  color: #fff;
  border-color: var(--keva-error-700);
}
.toast.warn {
  background: var(--warning);
  color: #fff;
  border-color: var(--warning);
}

/* ---------- PHASE A: DUPLICATE WARNING BANNER ---------- */
.dupe-warning {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  background: var(--keva-brass-50);
  border: 1px solid var(--keva-brass-100);
  border-radius: 12px;
  margin-bottom: 14px;
  font-size: 13px;
  line-height: 1.45;
  color: var(--warning);
}
.dupe-warning svg {
  flex-shrink: 0;
  margin-top: 1px;
  color: var(--warning);
}
.dupe-warning strong {
  color: var(--warning);
  font-weight: 600;
}
.dupe-warning .dupe-detail {
  color: var(--text);
  display: block;
  margin-top: 4px;
  font-weight: 400;
}

/* ---------- CONFIRM ---------- */
.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(28, 25, 23, 0.45);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 400;
  padding: 20px;
}

.confirm-box {
  background: var(--bg);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 360px;
  width: 100%;
  box-shadow: var(--shadow-lg);
}

.confirm-box p {
  font-size: 16px;
  color: var(--text);
  font-weight: 500;
  margin-bottom: 20px;
  line-height: 1.5;
}

.confirm-btns {
  display: flex;
  gap: 10px;
}

.confirm-btns button {
  flex: 1;
  padding: 14px;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  border: none;
  min-height: 50px;
}

.confirm-btns .c-cancel {
  background: var(--keva-paper);
  color: var(--primary);
  border: 1px solid var(--border-strong);
}

.confirm-btns .c-confirm {
  background: var(--danger);
  color: #fff;
}

/* ---------- EMPTY STATE ---------- */
.empty-state {
  text-align: center;
  padding: 50px 20px;
  color: var(--text-muted);
}

.empty-state svg {
  width: 56px;
  height: 56px;
  margin-bottom: 14px;
  opacity: 0.4;
}

.empty-state p {
  font-size: 15px;
  font-weight: 500;
}

/* ---------- LOG ENTRY ---------- */
.log-entry {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 8px;
}

.log-entry .log-time {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 4px;
  font-weight: 500;
}

.log-entry .log-user {
  font-size: 12px;
  color: var(--keva-brass-700);
  font-weight: 700;
  margin-left: 6px;
}

.log-entry .log-text {
  font-size: 14px;
  color: var(--text);
  font-weight: 500;
}

/* ---------- PAR ALERT ---------- */
.par-alert {
  background: var(--keva-brass-50);
  border: 1px solid var(--keva-brass-100);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 10px;
  color: var(--warning);
  font-size: 14px;
  font-weight: 600;
}

/* ---------- PARTIAL BUTTON ---------- */
.partial-btn {
  padding: 10px 14px;
  background: var(--keva-paper);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  font-family: var(--font);
  min-height: 40px;
}

.partial-btn.active {
  background: var(--dark-900);
  color: var(--off-100);
  border-color: var(--dark-900);
  font-family: var(--mono);
  letter-spacing: 0.04em;
}

/* ---------- WOODY GUIDED HERO CARD ---------- */
.hidden-title {
  position: absolute;
  left: -10000px;
  top: auto;
  width: 1px;
  height: 1px;
  overflow: hidden;
}
.modal-sheet .close-x {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 10;
}
.guided-hero {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 18px 18px 16px;
  margin-bottom: 14px;
}
.gh-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.gh-eyebrow {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--fg-muted);
}
.gh-mode-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 22px;
  padding: 0 10px;
  border-radius: 9999px;
  background: var(--gold-100);
  color: var(--gold-400);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.gh-title {
  font-family: var(--font);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.005em;
  color: var(--fg-primary);
  line-height: 1.2;
  margin-bottom: 4px;
  word-break: break-word;
}
.gh-meta {
  font-size: 12px;
  color: var(--fg-muted);
  margin-bottom: 14px;
  line-height: 1.4;
}
.gh-stepper {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.gh-step {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--fg-primary);
  font-size: 22px;
  font-weight: 600;
  cursor: pointer;
  display: grid;
  place-items: center;
  font-family: var(--mono);
  transition: all 0.12s;
}
.gh-step:active { transform: scale(0.94); }
.gh-step.gh-plus {
  background: var(--dark-900);
  color: var(--off-100);
  border-color: var(--dark-900);
}
.gh-qty {
  flex: 1;
  height: 48px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--off-200);
  font-family: var(--mono);
  font-size: 24px;
  font-weight: 700;
  color: var(--fg-primary);
  text-align: center;
  outline: none;
  padding: 0 10px;
  -moz-appearance: textfield;
}
.gh-qty::-webkit-inner-spin-button,
.gh-qty::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.gh-qty:focus {
  border-color: var(--dark-900);
  background: var(--surface);
}
/* -/+ stepper wrapper for the barcode + photo review modals' quantity
   fields. Reuses the .gh-step button styling from the guided modal,
   shrunk to 44px so the pair still fits the half-width form-row column
   next to the category select. */
.modal-qty-stepper {
  display: flex;
  align-items: center;
  gap: 6px;
}
.modal-qty-stepper .gh-step {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
}
.modal-qty-stepper .form-input {
  flex: 1;
  min-width: 0;
  text-align: center;
}
.gh-partials {
  display: flex;
  gap: 6px;
}
.gh-partials .partial-btn {
  flex: 1;
  height: 36px;
  min-height: 36px;
  padding: 0;
  font-size: 12px;
  font-family: var(--mono);
  letter-spacing: 0.02em;
}

/* ---------- COUNT PHASE ---------- */
.count-phase {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  background: var(--surface);
  padding: 6px;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.count-phase .phase {
  flex: 1;
  padding: 10px 6px;
  text-align: center;
  border-radius: 9px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: transparent;
  transition: all 0.15s;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.count-phase .phase.active {
  background: var(--primary);
  color: var(--bg);
}

.count-phase .phase.done {
  background: var(--success-dim);
  color: var(--success);
}

/* ---------- SEV BADGE ---------- */
.sev-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  display: inline-block;
}

.sev-badge.critical { background: var(--keva-error-50); color: var(--keva-error-700); }
.sev-badge.high { background: var(--keva-brass-100); color: var(--keva-brass-700); }
.sev-badge.medium { background: var(--keva-brass-50); color: var(--keva-brass-700); }
.sev-badge.watch { background: var(--keva-fog-200); color: var(--keva-slate-600); }
.sev-badge.low { background: var(--keva-olive-50); color: var(--keva-olive); }

/* ---------- RECOUNT FOCUS ITEM ---------- */
.focus-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 10px;
  border-left: 4px solid var(--danger);
}

.focus-item.medium {
  border-left-color: var(--keva-brass);
}

.focus-item.resolved {
  border-left-color: var(--success);
  opacity: 0.6;
}

/* Per-zone recount row (inside a focus-item card) — the full row is one tap
   target (onclick lives on this div, not a child span), but needs visible
   press feedback or it doesn't read as tappable. */
.recount-zone-row:active {
  background: var(--keva-brass-50);
}

/* ---------- ADMIN SECTION ---------- */
.admin-section {
  border: 1px solid var(--keva-brass-100);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
  background: var(--accent-soft);
}

.admin-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--keva-brass-700);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 10px;
}

/* ---------- HEADER MENU (Keva dropdown) ---------- */
.k-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 12px;
  background: var(--keva-paper);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px;
  min-width: 220px;
  z-index: 150;
  box-shadow: var(--shadow-lg);
}
.k-menu-item {
  width: 100%;
  text-align: left;
  padding: 0 14px;
  background: none;
  border: none;
  color: var(--keva-slate);
  font-family: var(--font);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  border-radius: 10px;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
}
.k-menu-item:active, .k-menu-item:hover { background: var(--keva-fog-200); }
.k-menu-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.k-menu-item--danger { color: var(--keva-error-700); }
.k-menu-sep { border-top: 1px solid var(--border); margin: 4px 0; }
.k-menu-count {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  background: var(--keva-brass-100);
  color: var(--keva-brass-700);
  padding: 1px 7px;
  border-radius: 999px;
}

/* ---------- SCROLLBAR ---------- */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--border-strong);
}

/* ---------- ZONE TABS COUNT STYLING ---------- */
.zone-tab.active .zcnt {
  opacity: 0.9;
}

/* ---------- BOTTOM NAV SPACING FIX ---------- */
.nav-item > span:last-child {
  font-size: 11px;
  font-weight: 600;
}

/* ---------- LARGE SCREEN FALLBACK ---------- */
@media (min-width: 640px) {
  #app {
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
}
/* Tablet: the shell widens; nav and sheets follow. Phone geometry is untouched. */
@media (min-width: 768px) {
  #app { max-width: 1200px; }
  .bottom-nav { max-width: 1200px; }
  .modal-sheet { max-width: 640px; }
  .page { padding-left: 24px; padding-right: 24px; }
  .zone-tabs { margin: 0 -24px; padding-left: 24px; padding-right: 24px; }
}

/* ---------- FLOATING CALCULATOR (edge-docked FAB + panel) ----------
   Z-INDEX AUDIT (grep "z-index", 2026-06): stylesheet layers —
   current-item-card 50 · header / bottom-nav 100 · header dropdowns 150 ·
   camera modals 200 · modal-overlay 300 · confirm-overlay 400 ·
   modal close-x 10 (local) · toast 1000. Inline/JS layers —
   offline banner 999 · master-data error banner 9999 (max found).
   FAB = 10000, panel = 10001 so the calculator floats above every
   modal/overlay/toast. The camera modals hide it via JS hooks (camera
   feed must never be obscured), not by out-stacking it. */
.calc-fab {
  position: fixed;
  width: 44px;
  height: 44px;
  z-index: 10000;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--accent);
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  font-family: var(--font);
  box-shadow: var(--shadow-lg);
  touch-action: none;        /* pointermove drag must not become a scroll */
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: left 0.18s ease, top 0.18s ease;
}
/* Monochrome glyph (same calculator outline as the bottom-nav tab),
   currentColor so it inherits the accent above. */
.calc-fab svg { width: 22px; height: 22px; }
.calc-fab.dragging { transition: none; opacity: 0.92; }

/* ---------- BACK-TO-TOP FAB (counted-item list) ----------
   Bottom-LEFT dock so it never collides with the right-edge calculator FAB,
   and raised above the bottom nav (~64px tall + safe area) so the nav tabs
   stay tappable. Fades in only after the list is scrolled past a threshold. */
.back-to-top {
  position: fixed;
  left: 16px;
  bottom: calc(78px + var(--safe-bottom));
  width: 44px;
  height: 44px;
  z-index: 99;               /* below the calc FAB (10000), above page content */
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  -webkit-tap-highlight-color: transparent;
  opacity: 1;
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.back-to-top.hide { display: none; }
.back-to-top svg { width: 20px; height: 20px; }

.calc-fab-panel {
  position: fixed;
  z-index: 10001;
  width: min(272px, calc(100vw - 24px));
  background: var(--keva-paper);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  padding: 10px;
}
.calc-fab-handle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 2px 8px;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.calc-fab-grip {
  width: 26px;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
}
.calc-fab-title { font-size: 12px; font-weight: 600; color: var(--text-muted); }
.calc-fab-min {
  margin-left: auto;
  width: 28px;
  height: 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm, 8px);
  color: var(--text-muted);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  font-family: var(--font);
}
.calc-fab-display {
  background: var(--keva-fog);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  margin-bottom: 8px;
  text-align: right;
  font-family: var(--mono, 'JetBrains Mono', monospace);
}
#calcFabExpr { font-size: 12px; color: var(--text-muted); min-height: 15px; word-break: break-all; }
#calcFabResult { font-size: 24px; font-weight: 700; color: var(--text); word-break: break-all; }
.calc-fab-keys { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
/* Reuse the calculator page's .calc-key skin, just denser */
#calcFabPanel .calc-key { padding: 11px 0; font-size: 17px; min-height: 0; border-radius: 10px; }
#calcFabPanel .calc-fn  { font-size: 14px; }

.calc-key {
  background: var(--keva-paper);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
  padding: 18px 0;
  min-height: 64px;
  cursor: pointer;
  font-family: var(--mono);
  transition: background 0.1s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.calc-key:active { background: var(--keva-fog-300); }
.calc-fn { background: var(--keva-fog-200); color: var(--keva-slate-600); font-size: 18px; }
.calc-op { background: var(--keva-brass-50); color: var(--keva-brass-700); border-color: var(--keva-brass-100); font-weight: 700; }
.calc-eq { background: var(--keva-slate); color: #fff; border-color: var(--keva-slate); font-weight: 700; }

/* ============================================================
   KEVA COMPONENTS (k-*) — shared by static markup and JS renderers
   ============================================================ */
.k-card {
  background: var(--keva-fog);
  border: 1px solid var(--keva-border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 12px;
}
.k-card--rule { border-left-width: 4px; }
.k-card--brass { border-left-color: var(--keva-brass); }
.k-card--olive { border-left-color: var(--keva-olive); }
.k-card--error { border-left-color: var(--keva-error); }
.k-eyebrow {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--keva-brass-700);
  margin-bottom: 6px;
}
.k-hero { padding: 18px; }
.k-hero-title { font-size: 20px; font-weight: 700; color: var(--keva-slate); line-height: 1.25; }
.k-hero-sub { font-size: 14px; color: var(--keva-slate-600); margin-top: 4px; }
.k-page-title { font-size: 22px; font-weight: 700; color: var(--keva-slate); letter-spacing: -0.01em; }
.k-page-sub { font-size: 14px; color: var(--keva-slate-600); margin-top: 2px; }
.k-hint { font-size: 13px; color: var(--keva-slate-600); margin: 8px 0; }

.k-stat-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 12px; }
.k-stat-grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.k-stat {
  background: var(--keva-fog);
  border: 1px solid var(--keva-border);
  border-radius: 12px;
  padding: 12px;
  min-width: 0;
}
.k-stat-value { font-family: var(--mono); font-size: 22px; font-weight: 700; color: var(--keva-slate); line-height: 1.2; }
.k-stat-value.is-brass { color: var(--keva-brass-700); }
.k-stat-value.is-olive { color: var(--keva-olive); }
.k-stat-value.is-error { color: var(--keva-error-700); }
.k-stat-label { font-size: 12px; color: var(--keva-slate-600); margin-top: 2px; }

.k-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 2px 6px;
  border-radius: 4px;
  line-height: 1.4;
  background: var(--keva-fog-200);
  color: var(--keva-slate-600);
  white-space: nowrap;
}
.k-badge--brass { background: var(--keva-brass-50); color: var(--keva-brass-700); }
.k-badge--olive { background: var(--keva-olive-50); color: var(--keva-olive); }
.k-badge--error { background: var(--keva-error-50); color: var(--keva-error-700); }
.k-badge--neutral { background: var(--keva-fog-200); color: var(--keva-slate-600); }
.k-badge--scale { background: var(--keva-brass-100); color: var(--keva-brass-700); }
.k-badge--vision { background: var(--keva-slate); color: var(--keva-paper); }

.k-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--keva-border);
  background: var(--keva-paper);
  color: var(--keva-slate);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}
.k-chip.is-active { background: var(--keva-slate); border-color: var(--keva-slate); color: var(--keva-paper); }
.k-chips { display: flex; flex-wrap: wrap; gap: 8px; }

.k-phase-strip {
  display: flex;
  gap: 4px;
  margin-bottom: 14px;
  background: var(--keva-fog);
  padding: 4px;
  border-radius: 12px;
  border: 1px solid var(--keva-border);
}
.k-phase {
  flex: 1;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  border-radius: 9px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--keva-slate-600);
}
.k-phase.is-active, .k-phase.active { background: var(--keva-slate); color: var(--keva-paper); }
.k-phase.is-done, .k-phase.done { background: var(--keva-olive-50); color: var(--keva-olive); }

.k-rows {
  background: var(--keva-fog);
  border: 1px solid var(--keva-border);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 12px;
}
.k-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding: 10px 14px;
  color: var(--keva-slate);
}
.k-row + .k-row { border-top: 1px solid var(--keva-border); }
.k-row[onclick], .k-row[role="button"] { cursor: pointer; }
.k-row[onclick]:active, .k-row[role="button"]:active { background: var(--keva-fog-200); }
.k-row-body { flex: 1; min-width: 0; }
.k-row-title { font-size: 15px; font-weight: 600; overflow-wrap: anywhere; }
.k-row-meta { font-size: 13px; color: var(--keva-slate-600); margin-top: 2px; }
.k-row-chev { color: var(--keva-slate-600); font-size: 20px; line-height: 1; flex-shrink: 0; }

.k-progress { height: 8px; background: var(--keva-fog-300); border-radius: 999px; overflow: hidden; }
.k-progress-fill { height: 100%; background: var(--keva-brass); border-radius: 999px; transition: width 0.4s ease; }
.k-fillbar { display: inline-block; width: 48px; height: 6px; background: var(--keva-fog-300); border-radius: 999px; overflow: hidden; vertical-align: middle; }
.k-fillbar > span { display: block; height: 100%; background: var(--keva-brass); }

/* Static on phones (keeps the docked calculator clear of tap targets); sticks on tablets */
.k-sticky-actions { margin-top: 16px; }
@media (min-width: 768px) {
  .k-sticky-actions {
    position: sticky;
    bottom: calc(72px + var(--safe-bottom));
    z-index: 40;
    background: rgba(255, 254, 251, 0.96);
    border-top: 1px solid var(--keva-border);
    padding: 12px 0;
  }
}

.k-empty { text-align: center; padding: 40px 16px; color: var(--keva-slate-600); }
.k-empty-icon {
  width: 56px; height: 56px; margin: 0 auto 12px;
  display: grid; place-items: center;
  border-radius: 12px;
  background: var(--keva-brass-50);
  color: var(--keva-brass-700);
  font-size: 24px;
}
.k-empty-title { font-size: 16px; font-weight: 600; color: var(--keva-slate); margin-bottom: 4px; }

.submit-btn.k-btn-brass, .k-btn-brass { background: var(--keva-brass); border-color: var(--keva-brass); color: #fff; }
.submit-btn.k-btn-brass:active, .k-btn-brass:active { background: var(--keva-brass-700); border-color: var(--keva-brass-700); }
.submit-btn.k-btn-outline, .k-btn-outline { background: var(--keva-paper); border: 1px solid var(--border-strong); color: var(--keva-slate); }
.submit-btn.k-btn-outline--brass, .k-btn-outline--brass { background: var(--keva-paper); border: 1px solid var(--keva-brass); color: var(--keva-brass-700); }

.k-search { position: relative; margin-bottom: 12px; }
.k-search input {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px 12px 42px;
  background: var(--keva-paper);
  border: 1px solid var(--keva-border);
  border-radius: 12px;
  font-family: var(--font);
  font-size: 16px;
  color: var(--keva-slate);
  outline: none;
}
.k-search input:focus { border-color: var(--keva-brass); box-shadow: var(--keva-ring); }
.k-search input::placeholder { color: var(--text-dim); }
.k-search .si { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--keva-slate-600); display: flex; }
.k-search .si svg { width: 18px; height: 18px; }

.k-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.k-table th, .k-table td { padding: 10px 12px; border-bottom: 1px solid var(--keva-border); text-align: left; }
.k-table th { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--keva-slate-600); }
.k-table th button { background: none; border: none; font: inherit; color: inherit; text-transform: inherit; letter-spacing: inherit; cursor: pointer; padding: 0; }
.k-table td.num, .k-table th.num { text-align: right; font-family: var(--mono); }
.k-table th.num button { margin-left: auto; }

.k-sync-line { font-size: 13px; color: var(--keva-slate-600); display: flex; align-items: center; gap: 6px; margin: 8px 0; }

.k-split { display: block; }
.k-grid { display: block; }
@media (min-width: 768px) {
  .k-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .k-stat-grid:not(.k-stat-grid--3) { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (min-width: 1024px) {
  .k-split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; align-items: start; }
}
@media (min-width: 1200px) {
  .k-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

.k-avatar {
  width: 44px; height: 44px;
  border-radius: 12px;
  background: var(--keva-brass-100);
  color: var(--keva-brass-700);
  font-weight: 700;
  font-size: 14px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

/* Header brand tile + sync status */
.k-brand-tile {
  width: 28px; height: 28px;
  border-radius: 8px;
  background: var(--keva-brass-100);
  color: var(--keva-brass-700);
  font-family: var(--mono);
  font-weight: 700;
  font-size: 14px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.k-sync {
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  color: var(--keva-olive);
}
.k-sync.is-waiting { color: var(--keva-brass-700); }
.k-sync.is-offline { color: var(--keva-error-700); }

/* Login (page 1) */
#page-login:not(.hide) { display: flex; align-items: center; justify-content: center; min-height: calc(100vh - 72px); }
.k-login { width: 100%; max-width: 384px; margin: 0 auto; }
.k-login-brand { text-align: center; padding: 8px 0 24px; }
.k-login-brand .k-brand-tile { width: 56px; height: 56px; border-radius: 14px; font-size: 24px; margin: 0 auto 12px; }
.k-login-word { font-family: var(--mono); font-size: 28px; font-weight: 700; letter-spacing: 4px; color: var(--keva-slate); }
.k-login-sub { font-size: 14px; color: var(--keva-slate-600); margin-top: 2px; }
#loginError {
  background: var(--keva-error-50);
  border: 1px solid var(--keva-error-200);
  color: var(--keva-error-700);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 13px;
  text-align: left;
  margin: 0 0 14px;
}
/* Info messages (reset / magic link) set an inline muted colour: show them neutral */
#loginError[style*="text-muted"] { background: var(--keva-fog-200); border-color: var(--keva-border); }
.k-login-link { color: var(--keva-brass-700); text-decoration: none; font-weight: 500; }
.k-pw-wrap { position: relative; }
.k-pw-wrap .form-input { padding-right: 52px; }
.k-pw-toggle {
  position: absolute;
  right: 4px; top: 50%;
  transform: translateY(-50%);
  width: 44px; height: 44px;
  border: none; background: none;
  color: var(--keva-slate-600);
  border-radius: 10px;
  cursor: pointer;
  display: grid; place-items: center;
}
.k-pw-toggle svg { width: 20px; height: 20px; }
.k-spinner {
  display: inline-block;
  width: 16px; height: 16px;
  margin-right: 8px;
  vertical-align: -3px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: kSpin 0.8s linear infinite;
}
@keyframes kSpin { to { transform: rotate(360deg); } }

/* Calculator page (page 6) */
.k-calc-display {
  background: var(--keva-fog);
  border: 1px solid var(--keva-border);
  border-radius: 12px;
  padding: 18px 16px;
  margin-bottom: 14px;
  text-align: right;
  font-family: var(--mono);
  min-height: 92px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 4px;
}
#calcExpr { font-size: 14px; color: var(--keva-slate-600); min-height: 18px; word-break: break-all; }
#calcResult { font-size: 40px; font-weight: 700; color: var(--keva-slate); word-break: break-all; line-height: 1.1; }
.k-calc-keys { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.k-calc-recent .k-row { min-height: 48px; font-family: var(--mono); }
.k-calc-recent .k-row-meta { font-family: var(--mono); }
@media (min-width: 768px) {
  .k-calc-layout { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 20px; align-items: start; }
}
.calc-fab-use {
  width: 100%;
  margin-top: 8px;
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid var(--keva-brass);
  background: var(--keva-brass);
  color: #fff;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

/* Summary activity: no inner scroll box (page 8) */
#activityLog { max-height: none; overflow: visible; }

/* iPad landscape: bottom nav becomes a left side rail (same .nav-item buttons) */
@media (min-width: 1024px) and (orientation: landscape) {
  #app { padding-left: 96px; }
  .bottom-nav {
    top: 0;
    bottom: 0;
    left: max(0px, calc(50% - 600px));
    transform: none;
    width: 96px;
    max-width: 96px;
    flex-direction: column;
    justify-content: flex-start;
    gap: 4px;
    padding: calc(16px + var(--safe-top)) 8px calc(16px + var(--safe-bottom));
    border-top: none;
    border-right: 1px solid var(--keva-border);
  }
  .nav-item { flex: 0 0 auto; min-height: 64px; justify-content: center; border-radius: 12px; }
  .nav-item.active { background: var(--keva-brass-50); }
  .nav-item.k-rail-only { display: flex; }
  .page { padding-bottom: calc(32px + var(--safe-bottom)); }
  .toast { top: calc(24px + var(--safe-top)); bottom: auto; }
  .k-sticky-actions { bottom: 0; }
}

/* Keyboard focus: brass ring */
button:focus-visible, a:focus-visible, [role="button"]:focus-visible, .nav-item:focus-visible, .calc-key:focus-visible {
  outline: 2px solid var(--keva-brass);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- Count bar ⋯ menu (wraps #cancelAuditBtn) ---------- */
.count-more-btn {
  min-width: 44px;
  min-height: 44px;
  border-radius: 12px;
  color: var(--keva-slate);
  font-family: var(--font);
}
.count-more-btn:active { background: var(--keva-fog-200); }
.count-more-menu {
  min-width: 180px;
  margin: 4px 0 0;
  background: var(--keva-paper);
  border: 1px solid var(--keva-border);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
}
/* Before the menu is built it sits inline in the timer bar; inside the menu it is a 44 px row */
.count-cancel-btn {
  background: none;
  border: 1px solid var(--keva-error);
  color: var(--keva-error-700);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  margin-left: 6px;
  border-radius: 6px;
  cursor: pointer;
}
.count-more-menu .count-cancel-btn {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 44px;
  margin: 0;
  padding: 0 14px;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 500;
  text-align: left;
}
.count-more-menu .count-cancel-btn:active { background: var(--keva-error-50); }

/* ---------- Stat tints + counted card ---------- */
.k-stat--brass { background: var(--keva-brass-50); border-color: var(--keva-brass-100); }
.k-stat--brass .k-stat-value { color: var(--keva-brass-700); }
.k-stat--olive { background: var(--keva-olive-50); border-color: rgba(92, 107, 79, 0.25); }
.k-stat--olive .k-stat-value { color: var(--keva-olive); }
.k-stat--error { background: var(--keva-error-50); border-color: var(--keva-error-200); }
.k-stat--error .k-stat-value { color: var(--keva-error-700); }
.is-counted { background: var(--keva-olive-50); border-color: rgba(92, 107, 79, 0.35); }

/* ---------- Venue list: one card with hairline rows on phones, card grid on tablets ---------- */
.venue-rows { padding: 0; overflow: hidden; }
.venue-rows .venue-card {
  margin: 0;
  border: none;
  border-radius: 0;
  background: transparent;
  min-height: 56px;
  padding: 12px 14px;
}
.venue-rows .venue-card + .venue-card { border-top: 1px solid var(--keva-border); }
@media (min-width: 768px) {
  .venue-rows { background: none; border: none; overflow: visible; }
  .venue-rows .venue-card,
  .venue-rows .venue-card + .venue-card {
    background: var(--keva-fog);
    border: 1px solid var(--keva-border);
    border-radius: 12px;
  }
}

/* ---------- Step 12a: Item editor popup (#guidedEntryModal) ---------- */
.modal-handle {
  width: 36px;
  height: 4px;
  border-radius: 999px;
  background: var(--keva-border);
  margin: 0 auto 10px;
}
#guidedEntryModal .modal-sheet {
  background: var(--keva-paper);
  border: 1px solid var(--keva-border);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -4px 24px rgba(28, 25, 23, 0.08);
  padding: 12px 18px 20px;
}
#guidedEntryModal .guided-hero {
  background: var(--keva-fog);
  border: 1px solid var(--keva-border);
  border-left: 4px solid var(--keva-brass);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 14px;
}
#guidedEntryModal .gh-stepper .gh-step {
  width: 56px;
  height: 56px;
  min-width: 56px;
  border-radius: 12px;
  font-size: 24px;
  border: 1px solid var(--keva-border);
  background: var(--keva-paper);
  color: var(--keva-slate);
}
#guidedEntryModal .gh-stepper .gh-qty {
  height: 56px;
  font-size: 32px;
  font-weight: 700;
  font-family: var(--mono);
  background: var(--keva-paper);
  border: 1px solid var(--keva-border);
  border-radius: 12px;
  color: var(--keva-slate);
  text-align: center;
}
#guidedEntryModal .gh-stepper .gh-qty:focus {
  border-color: var(--keva-brass);
  box-shadow: var(--keva-ring);
}
#guidedEntryModal .gh-partials .partial-btn {
  height: 40px;
  min-height: 40px;
  border-radius: 10px;
  border: 1px solid var(--keva-border);
  background: var(--keva-paper);
  color: var(--keva-slate);
  font-weight: 600;
}
#guidedEntryModal .gh-partials .partial-btn.active {
  background: var(--keva-brass);
  color: #fff;
  border-color: var(--keva-brass);
}
#guidedEntryModal .issue-chip {
  background: var(--keva-fog);
  border: 1px solid var(--keva-border);
  color: var(--keva-slate-600);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  user-select: none;
}
#guidedEntryModal .issue-chip.selected {
  background: var(--keva-brass-50);
  border-color: var(--keva-brass-700);
  color: var(--keva-brass-700);
  font-weight: 600;
}

/* Keva styling for count modals: barcode, manual, photo, ai-chat */
#barcodeEntryModal .modal-sheet,
#manualModal .modal-sheet,
#photoReviewModal .modal-sheet,
#aiChatModal .modal-sheet {
  background: var(--keva-paper);
  border: 1px solid var(--keva-border);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -4px 24px rgba(28, 25, 23, 0.08);
  padding: 12px 18px 20px;
}
#aiChatModal .modal-sheet {
  padding: 0;
}

#barcodeEntryModal .issue-chips,
#manualModal .issue-chips,
#photoReviewModal .issue-chips {
  padding-right: 48px;
}

#barcodeEntryModal .issue-chip,
#manualModal .issue-chip,
#photoReviewModal .issue-chip {
  background: var(--keva-fog);
  border: 1px solid var(--keva-border);
  color: var(--keva-slate-600);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  user-select: none;
}

#barcodeEntryModal .issue-chip.selected,
#manualModal .issue-chip.selected,
#photoReviewModal .issue-chip.selected {
  background: var(--keva-brass-50);
  border-color: var(--keva-brass-700);
  color: var(--keva-brass-700);
  font-weight: 600;
}

.modal-qty-stepper .gh-step {
  width: 44px;
  height: 44px;
  min-width: 44px;
  border-radius: 10px;
  font-size: 20px;
  border: 1px solid var(--keva-border);
  background: var(--keva-paper);
  color: var(--keva-slate);
}
.modal-qty-stepper .form-input {
  height: 44px;
  font-family: var(--mono);
  font-size: 18px;
  font-weight: 600;
  color: var(--keva-slate);
  text-align: center;
  background: var(--keva-paper);
  border: 1px solid var(--keva-border);
  border-radius: 10px;
}
.modal-qty-stepper .form-input:focus {
  border-color: var(--keva-brass);
  box-shadow: var(--keva-ring);
}

@media (min-width: 768px) {
  #guidedEntryModal,
  #barcodeEntryModal,
  #manualModal,
  #photoReviewModal,
  #aiChatModal {
    align-items: center;
    justify-content: center;
  }
  #barcodeEntryModal .modal-sheet,
  #manualModal .modal-sheet,
  #photoReviewModal .modal-sheet,
  #aiChatModal .modal-sheet {
    max-width: 560px;
    border-radius: 16px;
    margin: auto;
    max-height: 90vh;
    overflow-y: auto;
  }
  #guidedEntryModal .modal-sheet {
    max-width: 760px;
    width: 760px;
    border-radius: 16px;
    margin: auto;
    max-height: 90vh;
    overflow-y: auto;
  }
  #guidedEntryModal .guided-editor-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    align-items: start;
    margin-bottom: 12px;
  }
  #guidedEntryModal .guided-hero {
    margin-bottom: 0;
  }
}

/* ============================================================
   FIX PASS 2026-10-25 (phone header, iPad columns, login shell)
   ============================================================ */
/* Signed-out: the sign-in page shows no app shell (header, nav, rail gutter). */
body.is-login .header,
body.is-login .bottom-nav { display: none; }
body.is-login #app { padding-left: 0; }
body.is-login #page-login:not(.hide) { min-height: 100vh; }

/* Header: the venue name takes whatever width is left; ellipsis only when long. */
.venue-badge { max-width: none; flex: 1 1 auto; min-width: 0; }
@media (max-width: 767px) {
  .k-sync-txt { display: none; }               /* icon only; full text in title/aria-label */
  .k-sync-ico { font-size: 14px; }
  #headerAuditBadge { display: none !important; } /* JS sets inline display; the count bar shows status */
}

/* Item editor stepper: −, qty, + always fit the card (input min-width was pushing + out). */
#guidedEntryModal .gh-stepper { display: grid; grid-template-columns: 56px minmax(0, 1fr) 56px; gap: 10px; }
#guidedEntryModal .gh-stepper .gh-qty { width: 100%; min-width: 0; }

/* "Not yet counted": one card, hairline rows (rows drop their own card chrome). */
#guidedContent .k-card.k-rows { padding: 0; }
.k-rows > .c-item.k-row { background: transparent; border: 0; border-radius: 0; margin: 0; }
.k-rows > .c-item.k-row + .c-item.k-row { border-top: 1px solid var(--keva-border); }

/* Pre-audit: name and date read as body text (mono stays for numbers). */
#preAuditUser, #preAuditDate { font-family: var(--font); font-size: 15px; font-weight: 500; letter-spacing: 0; }

/* Phase strip + stat values never wrap. */
.count-phase .phase, .k-phase { white-space: nowrap; }
#summaryStats .k-stat-value { white-space: nowrap; }  /* "12 min" on one line; 2x2 on phones leaves room */
@media (max-width: 767px) {
  .count-phase.k-phase-strip { gap: 2px; padding: 3px; }
  .count-phase .phase.k-phase { font-size: 10px; letter-spacing: 0.02em; padding: 8px 2px; min-width: 0; }
}

/* Active counting: Close Count 1 sits below the tool tiles. #guidedContent's
   two wrappers become direct layout items so the bar can slot between them. */
#activeAuditContent:not(.hide) { display: flex; flex-direction: column; }
#guidedContent { display: contents; }
#closeCount1Bar { order: 1; margin-top: 2px; }
#guidedContent > .k-count-list { order: 2; }

/* Tablet: keep content out of the docked calculator's right-edge lane;
   cap wide single buttons. Symmetrical left and right padding. */
@media (min-width: 768px) {
  .page { padding-left: 48px; padding-right: 48px; }
  body.is-login #page-login { padding-left: 24px; padding-right: 24px; }
  .venue-signout { max-width: 320px; }
  #varianceActions .submit-btn, #varianceActions > div, #recountCloseBtn { max-width: 560px; }
}

/* iPad landscape: two-column layouts. */
@media (min-width: 1024px) {
  /* Count: controls left (~400 px), counted + not-yet-counted right. The
     list spans every row; the last 1fr row absorbs its height so the left
     column stays tight. */
  #activeAuditContent:not(.hide) {
    display: grid;
    grid-template-columns: 400px minmax(0, 1fr);
    grid-template-rows: repeat(7, auto) 1fr;
    column-gap: 24px;
    align-items: start;
  }
  #activeAuditContent > *, #guidedContent > .k-count-controls { grid-column: 1; min-width: 0; }
  #guidedContent > .k-count-list { grid-column: 2; grid-row: 1 / -1; min-width: 0; }
  #activeAuditContent .zone-tabs { margin: 0; padding: 0 0 14px; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  #activeAuditContent .zone-tabs::-webkit-scrollbar { display: none; }
  #guidedContent .k-count-list > .list-header:first-child { margin-top: 0 !important; }
  /* Issues: no list/detail split yet; keep the list a readable width. */
  #page-issues > * { max-width: 880px; }
}

/* ===== UI PASS 2 — PAGES (agent 2) ===== */
/* Header menu open: the floating calculator must not sit on top of it. */
body:has(#headerMenu:not(.hide)) #calcFab { visibility: hidden; }

/* Variance: stat cards sit directly on the page (no card inside a card);
   an odd last card spans the leftover cells so the grid has no hole. */
#varianceStats.summary-card { background: none; border: 0; padding: 0; box-shadow: none; }
#varianceStats .k-stat-grid { margin-bottom: 0; }
@media (max-width: 767px) {
  #varianceStats .k-stat-grid--3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #varianceStats .k-stat:last-child:nth-child(odd) { grid-column: span 2; }
}
@media (min-width: 768px) {
  #varianceStats .k-stat:last-child:nth-child(3n+2) { grid-column: span 2; }
}

/* Summary: tighter empty state under "Past audits". */
#historyList .k-empty { padding: 16px; }

@media (min-width: 1024px) {
  /* Pre-audit: "Back to venues" duplicates the side rail, so it becomes a
     quiet text link (same button, text and handler). */
  #preAuditScreen .k-back-link {
    display: block;
    width: auto;
    min-height: 44px;
    margin: 4px auto 0 !important;
    padding: 0 12px;
    background: none;
    border: 0;
    box-shadow: none;
    color: var(--keva-slate-600);
    font-size: 14px;
    font-weight: 500;
    text-decoration: underline;
    text-underline-offset: 3px;
  }
  #preAuditScreen .k-back-link:hover { color: var(--keva-slate); background: none; }
  #preAuditScreen .k-split > div > .section-title:first-child { margin-top: 0; }

  /* Summary: the split column is narrow, so stats go 2x2 (equal heights,
     one-line labels) and the right column starts level with the left. */
  #summaryStats .k-stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  #page-summary .k-split > div:last-child > .section-title:first-child { margin-top: 0 !important; }
}

/* ===== UI PASS 2 — COUNT (agent 1) ===== */
/* Header count pill: hidden until this venue has an audit (updateHeaderCount sets .is-live). */
#headerCount:not(.is-live) { display: none; }

/* Counted card ("This Zone"). Phone: tight two rows — name row, then qty controls. */
/* 40 px right lane: the docked calc FAB spans 8–52 px from the screen edge, so ⇄ never scrolls under it. */
.c-item.k-counted { flex-direction: column; align-items: stretch; gap: 10px; padding: 12px 40px 12px 12px; margin-bottom: 8px; }
.k-counted-top { display: flex; align-items: center; gap: 12px; }
.k-counted .c-thumb { width: 44px; height: 44px; font-size: 10px; }
.k-counted .k-counted-qty { justify-content: center; gap: 12px; }
.k-counted .qty-editable {
  font-size: 24px; min-width: 52px; padding: 4px 8px; cursor: pointer;
  border-radius: 8px; background: var(--keva-fog-200); border: 1px solid var(--keva-border);
}
.k-counted .k-plusn { width: auto; min-width: 48px; padding: 0 10px; font-size: 13px; font-weight: 600; }
.k-counted .k-move-btn { background: transparent; font-size: 16px; flex-shrink: 0; }
.k-weigh-row { background: transparent; font-size: 18px; flex-shrink: 0; }

/* Tablet (>=768): one line per item — thumb · name + badges · [-][qty][+][+N] · move. */
@media (min-width: 768px) {
  .c-item.k-counted { flex-direction: row; align-items: center; gap: 8px; padding: 8px 10px 8px 12px; min-height: 60px; }
  .k-counted .k-counted-top, .k-counted .k-counted-qty { display: contents; }
  .k-counted .c-thumb { width: 40px; height: 40px; margin-right: 4px; }
  .k-counted .c-info { margin-right: 4px; }
  .k-counted .c-name { font-size: 15px; }
  .k-counted .c-meta { margin-top: 2px; }
  .k-counted .qty-btn { width: 44px; height: 44px; font-size: 20px; }
  .k-counted .qty-val { font-size: 20px; }
  .k-counted .k-plusn { width: auto; }
  .k-counted .k-move-btn { order: 1; margin-left: 4px; }
}

/* iPad portrait (768–1023): compact controls so the counted list starts above
   the fold — search + This Zone/All Count/List share one row, tool tiles are
   56 px horizontal tiles in one row. List stays full width (one-line rows need it). */
@media (min-width: 768px) and (max-width: 1023px) {
  #guidedContent > .k-count-controls { display: flex; flex-wrap: wrap; align-items: center; column-gap: 12px; }
  .k-count-controls > .search-bar { order: 1; flex: 1 1 300px; min-width: 0; }
  .k-count-controls > .mode-toggle { order: 2; flex: 0 0 300px; }
  .k-count-controls > #guidedSearchResults { order: 3; flex: 0 0 100%; }
  .k-count-controls > .scan-actions { order: 4; flex: 0 0 100%; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
  .k-count-controls .scan-btn { flex-direction: row; min-height: 56px; padding: 6px 12px; gap: 10px; }
  .k-count-controls .scan-icon { width: 36px; height: 36px; border-radius: 10px; }
  .k-count-controls .scan-icon svg { width: 20px !important; height: 20px !important; }
}

/* Item editor: "Set total | Add to count" is a Keva segmented control in body
   font (mono is for numbers), not a second brass button row. */
#guidedEntryModal #guidedQtyModeRow {
  gap: 4px; padding: 4px; background: var(--keva-fog-200);
  border: 1px solid var(--keva-fog-300); border-radius: 12px;
}
#guidedEntryModal #guidedQtyModeRow .partial-btn {
  height: 40px; font-family: var(--font); font-size: 14px; letter-spacing: 0;
  background: none; border-color: transparent; border-radius: 9px; color: var(--keva-slate-600);
}
#guidedEntryModal #guidedQtyModeRow .partial-btn.active {
  background: var(--keva-paper); color: var(--keva-slate); box-shadow: var(--shadow-sm);
}
