:root {
  --bg-primary: #0a0f1d;
  --bg-secondary: #11192d;
  --bg-card: #162038;
  --bg-elevated: #1e2c4d;
  --border-color: rgba(255, 255, 255, 0.08);
  --border-focus: #3b82f6;

  --text-main: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --accent-blue: #3b82f6;
  --accent-blue-hover: #2563eb;
  --accent-green: #10b981;
  --accent-green-hover: #059669;
  --accent-amber: #f59e0b;
  --accent-red: #ef4444;
  --accent-purple: #8b5cf6;
  --accent-purple-hover: #7c3aed;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.5);

  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', SFMono-Regular, Menlo, monospace;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow-x: hidden;
  background-color: var(--bg-primary);
  color: var(--text-main);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
}

/* Master App Container: 100% full-bleed on mobile, centered card on desktop */
.app-container {
  width: 100%;
  max-width: 500px;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-primary);
  position: relative;
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.6);
}

@media (max-width: 600px) {
  .app-container {
    max-width: 100%;
    box-shadow: none;
  }
}

/* Header */
.app-header {
  height: 56px;
  padding: 0 14px;
  padding-top: env(safe-area-inset-top, 0px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: rgba(17, 25, 45, 0.9);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 100;
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.4);
}

.brand-text h1 {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.3px;
  line-height: 1.1;
}

.brand-badge {
  font-size: 9.5px;
  font-family: var(--font-mono);
  color: #60a5fa;
  background: rgba(59, 130, 246, 0.12);
  padding: 1px 5px;
  border-radius: 4px;
  display: inline-block;
  margin-top: 1px;
}

.header-actions {
  display: flex;
  gap: 6px;
}

.nav-tab {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 11px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  border-radius: var(--radius-full);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.nav-tab.active {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
  border-color: var(--border-color);
}

.count-pill {
  font-size: 10px;
  background: var(--accent-blue);
  color: white;
  padding: 1px 5px;
  border-radius: var(--radius-full);
  font-weight: 700;
}

/* Main Views */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
}

.view-section {
  display: none;
  flex: 1;
  flex-direction: column;
  min-height: 0;
}

.view-section.active {
  display: flex;
}

/* =========================================================
   CAMERA SCANNER VIEW (Full Screen Responsive Mobile Layout)
   ========================================================= */
.camera-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  background: #000;
  height: calc(100dvh - 56px);
  min-height: 0;
  overflow: hidden;
}

.camera-viewport {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

#cameraVideo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  position: absolute;
  top: 0;
  left: 0;
}

/* Tap-to-Focus Reticle */
.focus-reticle {
  position: absolute;
  width: 60px;
  height: 60px;
  border: 2px solid #fbbf24;
  border-radius: 8px;
  pointer-events: none;
  z-index: 35;
  display: none;
  transform: translate(-50%, -50%) scale(1.3);
  transition: transform 0.22s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.25s ease;
  box-shadow: 0 0 14px rgba(251, 191, 36, 0.6);
}

.focus-reticle::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 6px;
  height: 6px;
  background: #fbbf24;
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

.focus-reticle.active {
  display: block;
  transform: translate(-50%, -50%) scale(1);
  opacity: 1;
}

.focus-reticle.fade-out {
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.85);
}

/* Framing Overlay */
.camera-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  pointer-events: none;
  z-index: 10;
}

/* Real-time Receipt Detection Pill */
.detection-status-pill {
  position: absolute;
  top: 56px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 11px;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  pointer-events: none;
  z-index: 20;
  transition: all 0.25s ease;
}

.detection-status-pill .status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #94a3b8;
  transition: background-color 0.25s ease;
}

.detection-status-pill.detected {
  background: rgba(16, 185, 129, 0.2);
  border-color: rgba(16, 185, 129, 0.5);
  color: #34d399;
}

.detection-status-pill.detected .status-dot {
  background: #10b981;
  box-shadow: 0 0 8px #10b981;
  animation: pulseDot 1.2s infinite;
}

/* Framing corners change to emerald green when receipt is detected */
.receipt-frame.detected {
  border-color: rgba(16, 185, 129, 0.4);
}

.receipt-frame.detected .frame-corner {
  border-color: #10b981;
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.5);
}

.receipt-frame.detected .scanning-laser {
  background: linear-gradient(90deg, transparent, #10b981, #34d399, #10b981, transparent);
  box-shadow: 0 0 12px #10b981;
}

/* Auto-cropped badge in review view */
.crop-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.3);
  border-radius: 4px;
  white-space: nowrap;
}

/* =========================================================
   LIVE AUTO-CROP RECEIPT BOUNDING QUAD & ANIMATIONS
   ========================================================= */
.capture-flash {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #ffffff;
  opacity: 0;
  pointer-events: none;
  z-index: 60;
  transition: opacity 0.25s ease-out;
}

.capture-flash.flash {
  opacity: 0.88;
  transition: none;
}

.live-crop-quad {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.93);
  width: min(84vw, 335px);
  height: min(57vh, 435px);
  border: 2px solid transparent;
  border-radius: 10px;
  pointer-events: none;
  z-index: 25;
  opacity: 0;
  box-sizing: border-box;
  transition: left 0.2s cubic-bezier(0.16, 1, 0.3, 1),
              top 0.2s cubic-bezier(0.16, 1, 0.3, 1),
              width 0.2s cubic-bezier(0.16, 1, 0.3, 1),
              height 0.2s cubic-bezier(0.16, 1, 0.3, 1),
              opacity 0.25s ease, 
              transform 0.25s cubic-bezier(0.16, 1, 0.3, 1),
              border-color 0.25s ease,
              box-shadow 0.25s ease;
}

.live-crop-quad.active {
  opacity: 1;
  border-color: rgba(16, 185, 129, 0.9);
  background: rgba(16, 185, 129, 0.06);
  box-shadow: 0 0 24px rgba(16, 185, 129, 0.4), inset 0 0 16px rgba(16, 185, 129, 0.12);
  animation: cropQuadBreath 2.2s infinite ease-in-out;
}

.live-crop-quad.snapped {
  transform: scale(0.96) !important;
  border-color: #38bdf8 !important;
  background: rgba(56, 189, 248, 0.22) !important;
  box-shadow: 0 0 35px rgba(56, 189, 248, 0.75) !important;
  transition: all 0.14s ease-out;
}

/* Dim the static dashed frame while the live crop quad is actively tracking the receipt */
.receipt-frame.tracking {
  border-color: transparent !important;
  box-shadow: none !important;
}

.receipt-frame.tracking .frame-corner {
  opacity: 0.35;
}

.receipt-frame.tracking .frame-hint {
  opacity: 0;
}

@keyframes cropQuadBreath {
  0%, 100% {
    box-shadow: 0 0 20px rgba(16, 185, 129, 0.3), inset 0 0 14px rgba(16, 185, 129, 0.08);
    border-color: rgba(16, 185, 129, 0.85);
  }
  50% {
    box-shadow: 0 0 32px rgba(16, 185, 129, 0.55), inset 0 0 22px rgba(16, 185, 129, 0.16);
    border-color: #34d399;
  }
}

.crop-corner {
  position: absolute;
  width: 24px;
  height: 24px;
  border-color: #10b981;
  border-style: solid;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.crop-corner.c-tl {
  top: -3px;
  left: -3px;
  border-width: 4px 0 0 4px;
  border-top-left-radius: 8px;
}

.crop-corner.c-tr {
  top: -3px;
  right: -3px;
  border-width: 4px 4px 0 0;
  border-top-right-radius: 8px;
}

.crop-corner.c-bl {
  bottom: -3px;
  left: -3px;
  border-width: 0 0 4px 4px;
  border-bottom-left-radius: 8px;
}

.crop-corner.c-br {
  bottom: -3px;
  right: -3px;
  border-width: 0 4px 4px 0;
  border-bottom-right-radius: 8px;
}

.live-crop-quad.active .crop-corner {
  animation: cornerPulse 1.8s infinite alternate ease-in-out;
}

@keyframes cornerPulse {
  0% {
    box-shadow: 0 0 6px #10b981;
  }
  100% {
    box-shadow: 0 0 14px #34d399, 0 0 24px rgba(16, 185, 129, 0.5);
  }
}

.crop-scan-glow {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, rgba(16, 185, 129, 0.12) 0%, transparent 75%);
  pointer-events: none;
}

.crop-locked-badge {
  position: absolute;
  top: -30px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 5px;
  background: #10b981;
  color: #022c22;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 11px;
  border-radius: 20px;
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.45);
  white-space: nowrap;
  opacity: 0;
  transform: translateX(-50%) translateY(4px);
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.live-crop-quad.active .crop-locked-badge {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.crop-icon {
  font-size: 12px;
}

.receipt-frame {
  width: min(85vw, 340px);
  height: min(58vh, 440px);
  border: 2px dashed rgba(255, 255, 255, 0.25);
  border-radius: var(--radius-md);
  position: relative;
  overflow: hidden;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.45);
  pointer-events: auto;
  cursor: pointer;
}

.frame-corner {
  position: absolute;
  width: 20px;
  height: 20px;
  border-color: #3b82f6;
  border-style: solid;
}

.frame-corner.top-left {
  top: -2px;
  left: -2px;
  border-width: 4px 0 0 4px;
  border-top-left-radius: 12px;
}

.frame-corner.top-right {
  top: -2px;
  right: -2px;
  border-width: 4px 4px 0 0;
  border-top-right-radius: 12px;
}

.frame-corner.bottom-left {
  bottom: -2px;
  left: -2px;
  border-width: 0 0 4px 4px;
  border-bottom-left-radius: 12px;
}

.frame-corner.bottom-right {
  bottom: -2px;
  right: -2px;
  border-width: 0 4px 4px 0;
  border-bottom-right-radius: 12px;
}

.scanning-laser {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, transparent, #3b82f6, #60a5fa, #3b82f6, transparent);
  box-shadow: 0 0 10px #3b82f6;
  animation: laserScan 2.5s ease-in-out infinite alternate;
}

@keyframes laserScan {
  0% { top: 5%; opacity: 0.2; }
  50% { opacity: 1; }
  100% { top: 95%; opacity: 0.2; }
}

.frame-hint {
  position: absolute;
  bottom: 12px;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: rgba(255, 255, 255, 0.9);
  font-size: 11.5px;
  font-weight: 500;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
  pointer-events: none;
}

.frame-center-action {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: white;
  text-align: center;
  pointer-events: auto;
  cursor: pointer;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(6px);
  padding: 16px 20px;
  border-radius: var(--radius-md);
  border: 1px dashed rgba(255, 255, 255, 0.35);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
  width: 80%;
  max-width: 240px;
}

.center-camera-icon {
  font-size: 32px;
}

.frame-center-action span {
  font-size: 12px;
  font-weight: 600;
  color: #93c5fd;
  line-height: 1.3;
}

/* Camera Overlay Controls */
.camera-overlay-controls {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 20;
}

.icon-btn.glass {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.15s ease;
}

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

.attempt-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-full);
  font-size: 11.5px;
  font-weight: 600;
  color: #fbbf24;
}

.attempt-indicator .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #fbbf24;
  animation: pulseDot 1.5s infinite;
}

@keyframes pulseDot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* Camera Mode Switcher (Standard vs Panorama) */
.camera-mode-switcher {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  z-index: 21;
}

.mode-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #94a3b8;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.mode-pill.active {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.25), rgba(6, 182, 212, 0.25));
  border-color: #10b981;
  color: #34d399;
  box-shadow: 0 0 12px rgba(16, 185, 129, 0.35);
}

.mode-pill:active {
  transform: scale(0.95);
}

/* Vertical Panorama Overlay (iOS Pano Style for Receipts) */
.panorama-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 15;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.pano-guide-rail {
  position: absolute;
  top: 12%;
  bottom: 12%;
  left: 50%;
  transform: translateX(-50%);
  width: min(85vw, 320px);
  display: flex;
  justify-content: center;
  align-items: center;
}

.pano-rail-line {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 2px;
  transform: translateX(-50%);
  background: linear-gradient(180deg, rgba(6, 182, 212, 0.2) 0%, #06b6d4 50%, rgba(6, 182, 212, 0.2) 100%);
  box-shadow: 0 0 8px #06b6d4;
}

.pano-target-box {
  width: 100%;
  height: min(65vh, 420px);
  border: 2px solid #06b6d4;
  border-radius: var(--radius-md);
  position: relative;
  background: rgba(6, 182, 212, 0.06);
  box-shadow: 0 0 18px rgba(6, 182, 212, 0.35), inset 0 0 12px rgba(6, 182, 212, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease;
}

.pano-box-corners {
  position: absolute;
  inset: -2px;
  pointer-events: none;
}

.pano-arrow-indicator {
  color: #06b6d4;
  filter: drop-shadow(0 0 8px #06b6d4);
  animation: panoBounce 1.2s infinite ease-in-out;
}

@keyframes panoBounce {
  0%, 100% {
    transform: translateY(-8px);
    opacity: 0.6;
  }
  50% {
    transform: translateY(8px);
    opacity: 1;
  }
}

.pano-hud {
  position: absolute;
  top: 24px;
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 18;
}

.pano-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(6, 182, 212, 0.4);
  border-radius: var(--radius-full);
  color: #e2e8f0;
  font-size: 12px;
  font-weight: 600;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
}

.pano-pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #06b6d4;
  box-shadow: 0 0 8px #06b6d4;
  animation: pulseDot 1.2s infinite;
}

.pano-speed-warning {
  padding: 4px 12px;
  background: rgba(239, 68, 68, 0.9);
  color: white;
  font-size: 11px;
  font-weight: 700;
  border-radius: 12px;
  letter-spacing: 0.5px;
  box-shadow: 0 0 12px rgba(239, 68, 68, 0.8);
  animation: warningShake 0.4s infinite alternate;
}

@keyframes warningShake {
  0% { transform: translateX(-3px); }
  100% { transform: translateX(3px); }
}

/* Real-Time Miniature Preview Strip on Side */
.pano-preview-strip {
  position: absolute;
  right: 12px;
  top: 75px;
  width: 76px;
  background: rgba(15, 23, 42, 0.9);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-sm);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 18;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
}

.pano-strip-header {
  display: flex;
  flex-direction: column;
  font-size: 9.5px;
  font-weight: 700;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  line-height: 1.2;
}

.pano-counter {
  color: #34d399;
}

.pano-strip-canvas-wrapper {
  position: relative;
  width: 100%;
  height: 160px;
  background: #0f172a;
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  justify-content: center;
}

#panoLiveCanvas {
  width: 100%;
  height: auto;
  max-height: 100%;
  object-fit: contain;
  background: #1e293b;
}

.pano-strip-scanline {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: #06b6d4;
  box-shadow: 0 0 6px #06b6d4;
}

/* Shutter Button Panorama Recording State */
.shutter-button.recording {
  border-color: #ef4444 !important;
}

.shutter-button.recording .shutter-ring {
  border-color: #ef4444;
  box-shadow: 0 0 20px rgba(239, 68, 68, 0.6);
}

.shutter-button.recording .shutter-inner {
  border-radius: 6px;
  width: 26px;
  height: 26px;
  background: #ef4444;
  animation: recordingPulse 1s infinite alternate;
}

@keyframes recordingPulse {
  0% { transform: scale(1); opacity: 1; }
  100% { transform: scale(0.85); opacity: 0.8; }
}

/* Bottom Bar: Never cut off on mobile */
.camera-bottom-bar {
  min-height: 86px;
  background: rgba(10, 15, 29, 0.95);
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 10px 20px calc(10px + env(safe-area-inset-bottom, 10px));
  border-top: 1px solid var(--border-color);
  position: relative;
  z-index: 20;
  flex-shrink: 0;
}

.shutter-button {
  width: 70px;
  height: 70px;
  border-radius: 50%;
  background: transparent;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  outline: none;
}

.shutter-ring {
  width: 70px;
  height: 70px;
  border-radius: 50%;
  border: 4px solid white;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s ease;
}

.shutter-inner {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: white;
  transition: transform 0.15s ease, background-color 0.15s ease;
}

.shutter-button:active .shutter-ring {
  transform: scale(0.95);
}

.shutter-button:active .shutter-inner {
  transform: scale(0.88);
  background-color: var(--accent-blue);
}

.action-btn-circle {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.action-btn-circle:active {
  transform: scale(0.9);
  background: var(--bg-elevated);
}

/* Samples Drawer */
.samples-drawer {
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  padding: 12px 14px calc(14px + env(safe-area-inset-bottom, 10px));
  display: none;
  animation: slideUp 0.25s ease;
  flex-shrink: 0;
}

.samples-drawer.open {
  display: block;
}

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

.drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-secondary);
}

.close-text-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
}

.samples-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

@media (max-width: 340px) {
  .samples-grid {
    grid-template-columns: 1fr;
  }
}

.sample-chip {
  padding: 9px 10px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-size: 11.5px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sample-chip:active {
  background: var(--bg-elevated);
}

.sample-chip.low-acc {
  border-color: rgba(245, 158, 11, 0.4);
  background: rgba(245, 158, 11, 0.08);
}

/* =========================================================
   MODALS (Mobile Responsive Popup Cards)
   ========================================================= */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.78);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 1000;
  overflow-y: auto;
}

.modal-overlay.active {
  display: flex;
}

/* Processing Card */
.processing-card {
  width: 100%;
  max-width: 320px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 26px 20px;
  text-align: center;
  box-shadow: var(--shadow-lg);
  animation: popIn 0.25s ease;
}

@keyframes popIn {
  from { transform: scale(0.92); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.spinner-pulse {
  width: 60px;
  height: 60px;
  margin: 0 auto 16px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pulse-ring {
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 3px solid var(--accent-blue);
  opacity: 0.3;
  animation: pingRing 1.6s cubic-bezier(0, 0, 0.2, 1) infinite;
}

@keyframes pingRing {
  75%, 100% {
    transform: scale(1.6);
    opacity: 0;
  }
}

.pulse-icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
}

.processing-card h3 {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 4px;
}

.processing-card p {
  font-size: 12.5px;
  color: var(--text-secondary);
  margin-bottom: 18px;
}

.progress-bar-container {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-full);
  overflow: hidden;
  position: relative;
}

.progress-bar-indeterminate {
  width: 45%;
  height: 100%;
  background: linear-gradient(90deg, var(--accent-blue), var(--accent-purple));
  border-radius: var(--radius-full);
  position: absolute;
  animation: indeterminateBar 1.4s infinite ease-in-out;
}

@keyframes indeterminateBar {
  0% { left: -45%; }
  100% { left: 100%; }
}

/* Re-scan Card */
.rescan-card {
  width: 100%;
  max-width: 380px;
  max-height: calc(100dvh - 40px);
  overflow-y: auto;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 22px 18px;
  text-align: center;
  box-shadow: var(--shadow-lg);
}

.modal-icon-badge {
  width: 52px;
  height: 52px;
  margin: 0 auto 12px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-icon-badge.warning {
  background: rgba(245, 158, 11, 0.15);
  color: var(--accent-amber);
}

.accuracy-meter-box {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  margin-bottom: 14px;
}

.meter-header {
  display: flex;
  justify-content: space-between;
  font-size: 12.5px;
  font-weight: 600;
  margin-bottom: 6px;
}

.meter-value {
  font-family: var(--font-mono);
  color: var(--accent-amber);
  font-weight: 700;
}

.meter-track {
  width: 100%;
  height: 7px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-full);
  overflow: hidden;
  margin-bottom: 5px;
}

.meter-fill {
  height: 100%;
  background: var(--accent-amber);
  border-radius: var(--radius-full);
  transition: width 0.4s ease;
}

.threshold-hint {
  font-size: 10.5px;
  color: var(--text-muted);
}

.rescan-card h3 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 6px;
}

.rescan-desc {
  font-size: 12.5px;
  color: var(--text-secondary);
  line-height: 1.45;
  margin-bottom: 14px;
}

.rescan-meta {
  background: rgba(255, 255, 255, 0.04);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
}

.pill-tag {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--accent-amber);
}

.tip-text {
  font-size: 10.5px;
  color: var(--text-muted);
}

.modal-actions-col {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ai-recommendation-box {
  background: rgba(139, 92, 246, 0.12);
  border: 1px solid rgba(139, 92, 246, 0.3);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  margin-bottom: 12px;
}

.ai-sparkle {
  font-size: 22px;
}

.ai-text strong {
  font-size: 12.5px;
  color: #c4b5fd;
  display: block;
}

.ai-text p {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.api-key-toggle-box {
  margin-bottom: 8px;
  text-align: left;
}

.text-link-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 11.5px;
  cursor: pointer;
  text-decoration: underline;
}

.api-key-input-wrapper {
  margin-top: 6px;
}

/* Camera Permission Card */
.permission-card {
  width: 100%;
  max-width: 380px;
  max-height: calc(100dvh - 40px);
  overflow-y: auto;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px 18px;
  text-align: center;
  box-shadow: var(--shadow-lg);
}

.permission-icon-badge {
  width: 60px;
  height: 60px;
  margin: 0 auto 14px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.2), rgba(139, 92, 246, 0.2));
  border: 1px solid rgba(59, 130, 246, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #60a5fa;
}

.permission-desc {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.45;
  margin: 6px 0 16px;
}

.perm-diagnostic-box {
  background: rgba(239, 68, 68, 0.14);
  border: 1px solid rgba(239, 68, 68, 0.4);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 11.5px;
  color: #fca5a5;
  margin-bottom: 12px;
  text-align: left;
  word-break: break-word;
}

.perm-diagnostic-box .diagnostic-label {
  font-weight: 700;
  color: #f87171;
  margin-right: 4px;
}

.perm-warning-box {
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.35);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  text-align: left;
  margin-bottom: 14px;
}

.perm-warning-box .warning-icon {
  font-size: 18px;
  line-height: 1;
}

.perm-warning-box strong {
  font-size: 12px;
  color: #fcd34d;
  display: block;
  margin-bottom: 2px;
}

.perm-warning-box p {
  font-size: 11px;
  color: var(--text-secondary);
  line-height: 1.35;
}

.perm-warning-box code {
  background: rgba(0, 0, 0, 0.3);
  padding: 1px 3px;
  border-radius: 3px;
  color: #fcd34d;
  font-family: var(--font-mono);
}

.permission-actions-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.perm-guide-box {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  text-align: left;
  margin-top: 6px;
}

.guide-title {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 4px;
}

.guide-steps {
  font-size: 11px;
  color: var(--text-secondary);
  line-height: 1.45;
  padding-left: 16px;
}

.guide-steps li {
  margin-bottom: 4px;
}

.guide-steps code {
  background: rgba(255, 255, 255, 0.1);
  padding: 1px 3px;
  border-radius: 3px;
  font-family: var(--font-mono);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 16px;
  border-radius: var(--radius-md);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.15s ease;
  outline: none;
  min-height: 44px; /* Touch target accessibility */
}

.btn-block {
  width: 100%;
}

.btn-lg {
  padding: 14px 18px;
  font-size: 14.5px;
  font-weight: 700;
  min-height: 48px;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 11.5px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  min-height: 32px;
}

.btn-primary {
  background: var(--accent-blue);
  color: white;
}
.btn-primary:active {
  background: var(--accent-blue-hover);
}

.btn-success {
  background: linear-gradient(135deg, #10b981, #059669);
  color: white;
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.35);
}
.btn-success:active {
  transform: scale(0.98);
}

.btn-purple {
  background: linear-gradient(135deg, #8b5cf6, #7c3aed);
  color: white;
  box-shadow: 0 4px 14px rgba(139, 92, 246, 0.35);
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}
.btn-ghost:active {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-main);
}

/* =========================================================
   REVIEW & CONFIRMATION VIEW (Mobile Responsive)
   ========================================================= */
.review-page {
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: calc(150px + env(safe-area-inset-bottom, 20px));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.review-header-banner {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.banner-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.badge-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.badge-dot.green { background: var(--accent-green); box-shadow: 0 0 8px var(--accent-green); }
.badge-dot.amber { background: var(--accent-amber); box-shadow: 0 0 8px var(--accent-amber); }
.badge-dot.purple { background: var(--accent-purple); box-shadow: 0 0 8px var(--accent-purple); }

.banner-subtitle {
  font-size: 10.5px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.receipt-preview-bar {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 9px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.preview-thumbnail {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #000;
  cursor: pointer;
  border: 1px solid var(--border-color);
  flex-shrink: 0;
}

.preview-thumbnail img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.preview-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.preview-title {
  font-size: 12.5px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preview-meta {
  font-size: 10.5px;
  color: var(--text-muted);
}

.btn-text-sm {
  background: none;
  border: none;
  color: var(--accent-blue);
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
  padding: 6px;
}

/* Form Cards */
.form-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 11px;
}

.card-title {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text-secondary);
}

.card-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.input-group label {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-secondary);
}

.input-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

@media (max-width: 320px) {
  .input-row {
    grid-template-columns: 1fr;
  }
}

.form-control, .text-input {
  width: 100%;
  height: 40px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0 10px;
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s ease;
}

.form-control:focus, .text-input:focus {
  border-color: var(--border-focus);
}

.form-control.text-right {
  text-align: right;
  font-family: var(--font-mono);
  font-weight: 600;
}

/* Items List (Responsive Stack on Mobile) */
.items-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.item-row {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 9px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.item-row-top {
  display: flex;
  gap: 6px;
  align-items: center;
}

.item-name-input {
  flex: 1;
  min-width: 0;
}

.item-delete-btn {
  background: none;
  border: none;
  color: var(--accent-red);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 6px;
  line-height: 1;
}

.item-row-bottom {
  display: grid;
  grid-template-columns: 60px 1fr 1fr;
  gap: 6px;
  align-items: center;
}

@media (max-width: 330px) {
  .item-row-bottom {
    grid-template-columns: 50px 1fr 1fr;
    gap: 4px;
  }
}

.item-sub-label {
  font-size: 9.5px;
  color: var(--text-muted);
  display: block;
  margin-bottom: 2px;
}

/* Financials (Fluid Responsive Inputs) */
.financials-rows {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.fin-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.fin-row label {
  font-size: 12.5px;
  color: var(--text-secondary);
  font-weight: 500;
  flex: 1;
  min-width: 0;
}

.fin-input-wrap {
  width: min(52%, 180px);
  min-width: 120px;
  position: relative;
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.currency-prefix {
  position: absolute;
  left: 9px;
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  pointer-events: none;
}

.fin-input-wrap .form-control {
  padding-left: 28px;
}

.fin-row.total-highlight {
  background: rgba(59, 130, 246, 0.1);
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(59, 130, 246, 0.3);
  margin-top: 2px;
}

.fin-row.total-highlight label {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-main);
}

.total-input {
  font-size: 15px !important;
  font-weight: 700 !important;
  color: #60a5fa !important;
}

/* Confirmation Dock (Fixed bottom with Safe Area Support) */
.confirmation-dock {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-width: 500px;
  margin: 0 auto;
  background: rgba(17, 25, 45, 0.96);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border-color);
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom, 10px));
  display: flex;
  flex-direction: column;
  gap: 7px;
  z-index: 100;
}

@media (max-width: 600px) {
  .confirmation-dock {
    max-width: 100%;
  }
}

/* =========================================================
   HISTORY & DATABASE VIEW (Mobile Responsive)
   ========================================================= */
.history-page {
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(40px + env(safe-area-inset-bottom, 10px));
}

.stats-summary-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
}

@media (max-width: 340px) {
  .stats-summary-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 10px 8px;
  text-align: center;
  display: flex;
  flex-direction: column;
}

.stat-num {
  font-size: 14.5px;
  font-weight: 800;
  font-family: var(--font-mono);
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-lbl {
  font-size: 9.5px;
  color: var(--text-muted);
  margin-top: 2px;
}

.history-search-row {
  margin-bottom: 2px;
}

.receipts-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.receipt-item-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  cursor: pointer;
  transition: transform 0.15s ease, background-color 0.15s ease;
}

.receipt-item-card:active {
  transform: scale(0.98);
  background: var(--bg-elevated);
}

.receipt-card-left {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  flex: 1;
}

.receipt-card-merchant {
  font-size: 13.5px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.receipt-card-meta {
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  gap: 6px;
  white-space: nowrap;
}

.receipt-card-right {
  text-align: right;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
  flex-shrink: 0;
}

.receipt-card-amount {
  font-size: 14px;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--accent-green);
}

.receipt-card-badge {
  font-size: 9.5px;
  padding: 2px 5px;
  border-radius: 4px;
  font-weight: 600;
}
.receipt-card-badge.light_ocr { background: rgba(59, 130, 246, 0.15); color: #60a5fa; }
.receipt-card-badge.ai_enhanced, .receipt-card-badge.ai_reconstruction, .receipt-card-badge.ai_claude, .receipt-card-badge.ai_gemini { background: rgba(139, 92, 246, 0.15); color: #c4b5fd; }

/* Detail modal */
.detail-card {
  width: 100%;
  max-width: 440px;
  max-height: calc(100dvh - 40px);
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.detail-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.detail-body {
  padding: 14px 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Full Image Modal */
.full-image-container {
  max-width: 95vw;
  max-height: 90dvh;
  position: relative;
}

.full-image-container img {
  max-width: 100%;
  max-height: 80dvh;
  border-radius: var(--radius-md);
  object-fit: contain;
}

.close-img-btn {
  position: absolute;
  top: -14px;
  right: -14px;
  font-size: 22px;
  line-height: 1;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 40px 16px;
  color: var(--text-muted);
}
.empty-state svg {
  margin-bottom: 10px;
  opacity: 0.5;
}
.empty-state p {
  font-size: 13px;
}
