/* ==========================================================================
   ScanSync - Mobile-First Accessible Web Application
   Design System: Clean, high-contrast, accessible (WCAG AA/AAA compliant)
   ========================================================================== */

:root {
  /* Color Palette - Accessible High Contrast Light Theme */
  --bg-primary: #f8fafc;
  --bg-surface: #ffffff;
  --bg-surface-elevated: #ffffff;
  --bg-muted: #f1f5f9;
  --bg-accent-subtle: #eff6ff;

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --text-inverse: #ffffff;

  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-active: #1e40af;
  --primary-subtle: #dbeafe;
  --primary-focus: rgba(37, 99, 235, 0.4);

  --accent-scanner: #0284c7;
  --accent-scanner-glow: rgba(2, 132, 199, 0.25);
  --success: #15803d;
  --success-bg: #dcfce7;
  --warning: #b45309;
  --warning-bg: #fef3c7;
  --danger: #b91c1c;
  --danger-bg: #fee2e2;

  --border-color: #cbd5e1;
  --border-subtle: #e2e8f0;
  --border-focus: #2563eb;

  /* Typography */
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

  /* Spacing & Sizes */
  --header-height: 64px;
  --bottom-nav-height: 68px;
  --touch-target-min: 48px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.05);
  --shadow-scanner: 0 8px 25px rgba(37, 99, 235, 0.35);

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
}

/* Dark Theme */
[data-theme="dark"] {
  --bg-primary: #090d16;
  --bg-surface: #131b2e;
  --bg-surface-elevated: #1a243d;
  --bg-muted: #1e293b;
  --bg-accent-subtle: #172554;

  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --text-inverse: #0f172a;

  --primary: #3b82f6;
  --primary-hover: #60a5fa;
  --primary-active: #93c5fd;
  --primary-subtle: #1e3a8a;
  --primary-focus: rgba(59, 130, 246, 0.5);

  --accent-scanner: #38bdf8;
  --accent-scanner-glow: rgba(56, 189, 248, 0.3);
  --success: #4ade80;
  --success-bg: #064e3b;
  --warning: #fbbf24;
  --warning-bg: #78350f;
  --danger: #f87171;
  --danger-bg: #7f1d1d;

  --border-color: #334155;
  --border-subtle: #1e293b;
  --border-focus: #60a5fa;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 8px -1px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 10px 20px -3px rgba(0, 0, 0, 0.5);
  --shadow-scanner: 0 8px 25px rgba(56, 189, 248, 0.3);
}

/* High Contrast Mode Override */
[data-contrast="high"] {
  --border-color: #000000;
  --text-primary: #000000;
  --bg-primary: #ffffff;
  --bg-surface: #ffffff;
  --primary: #0000ee;
  --border-focus: #0000ee;
}
[data-theme="dark"][data-contrast="high"] {
  --border-color: #ffffff;
  --text-primary: #ffffff;
  --bg-primary: #000000;
  --bg-surface: #000000;
  --primary: #66b2ff;
  --border-focus: #66b2ff;
}

/* Global Reset & Base */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html {
  font-size: 16px;
  line-height: 1.5;
  font-family: var(--font-family);
  color: var(--text-primary);
  background-color: var(--bg-primary);
  height: 100%;
}

body {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Accessibility: Visible Focus Rings */
:focus-visible {
  outline: 3px solid var(--border-focus);
  outline-offset: 3px;
  border-radius: 4px;
}

/* Screen reader only utility */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Skip to Content Link */
.skip-link {
  position: absolute;
  top: -100px;
  left: 1rem;
  background: var(--primary);
  color: var(--text-inverse);
  padding: 0.75rem 1.25rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  z-index: 1000;
  text-decoration: none;
  transition: top var(--transition-fast);
}
.skip-link:focus {
  top: 1rem;
}

/* Mobile-First Shell Container */
.app-container {
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-surface);
  position: relative;
  box-shadow: 0 0 25px rgba(0, 0, 0, 0.05);
}

@media (min-width: 641px) {
  body {
    background-color: var(--bg-primary);
    padding: 1.5rem 1rem;
  }
  .app-container {
    min-height: calc(100vh - 3rem);
    border-radius: 24px;
    border: 1px solid var(--border-subtle);
    overflow: hidden;
  }
}

/* Top App Header */
.app-header {
  height: var(--header-height);
  padding: 0 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--primary), var(--accent-scanner));
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  box-shadow: var(--shadow-sm);
}

.brand-title {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
}

.brand-badge {
  font-size: 0.65rem;
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 0.05em;
  background: var(--primary-subtle);
  color: var(--primary);
  padding: 0.15rem 0.45rem;
  border-radius: var(--radius-full);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Icon Buttons */
.btn-icon {
  min-width: var(--touch-target-min);
  min-height: var(--touch-target-min);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
  padding: 0.5rem;
}
.btn-icon:hover {
  background: var(--bg-muted);
  color: var(--text-primary);
}
.btn-icon:active {
  transform: scale(0.96);
}

/* Active Status Pill */
.pdf-status-banner {
  padding: 0.65rem 1.25rem;
  background: var(--bg-muted);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.85rem;
  gap: 0.75rem;
}

.pdf-status-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pdf-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--text-muted);
  flex-shrink: 0;
}
.pdf-status-dot.active {
  background-color: var(--success);
  box-shadow: 0 0 0 3px var(--success-bg);
}

.pdf-status-name {
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-link-action {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--primary);
  background: none;
  border: none;
  cursor: pointer;
  text-decoration: underline;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
}
.btn-link-action:hover {
  color: var(--primary-hover);
}

/* Main Content Views */
.main-content {
  flex: 1;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(var(--bottom-nav-height) + 1.5rem);
}

.view-section {
  display: none;
  flex-direction: column;
  gap: 1.25rem;
  animation: fadeIn 0.2s ease-in-out;
}
.view-section.active {
  display: flex;
}

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

/* ==========================================================================
   Hero Camera Scanner Button
   ========================================================================== */
.scanner-hero-card {
  background: linear-gradient(145deg, var(--bg-surface), var(--bg-accent-subtle));
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem 1.25rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 1.25rem;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}

.scanner-hero-card::before {
  content: "";
  position: absolute;
  top: -40px;
  right: -40px;
  width: 120px;
  height: 120px;
  background: var(--accent-scanner-glow);
  border-radius: 50%;
  pointer-events: none;
}

.scanner-heading {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.scanner-heading h2 {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
}

.scanner-heading p {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

/* Big Touchable Camera Scanner Button */
.btn-camera-trigger {
  width: 100%;
  min-height: 64px;
  padding: 1rem 1.5rem;
  border-radius: var(--radius-md);
  border: 2px solid transparent;
  background: linear-gradient(135deg, var(--primary), var(--accent-scanner));
  color: #ffffff;
  font-size: 1.05rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  cursor: pointer;
  box-shadow: var(--shadow-scanner);
  transition: all var(--transition-fast);
  position: relative;
}

.btn-camera-trigger:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 28px rgba(37, 99, 235, 0.45);
}

.btn-camera-trigger:active {
  transform: translateY(1px);
}

.btn-camera-trigger svg {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}

.camera-sub-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
}

.btn-sub-action {
  flex: 1;
  min-height: 44px;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-size: 0.825rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  cursor: pointer;
  transition: all var(--transition-fast);
}
.btn-sub-action:hover {
  background: var(--bg-muted);
  color: var(--text-primary);
  border-color: var(--border-focus);
}

/* ==========================================================================
   Manual Search Input Component
   ========================================================================== */
.search-container {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.search-label {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.search-count-badge {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
}

.search-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}

.search-icon {
  position: absolute;
  left: 1rem;
  color: var(--text-muted);
  pointer-events: none;
  width: 20px;
  height: 20px;
}

.search-input {
  width: 100%;
  min-height: 52px;
  padding: 0.75rem 5.5rem 0.75rem 2.85rem;
  border-radius: var(--radius-md);
  border: 2px solid var(--border-color);
  background-color: var(--bg-surface);
  color: var(--text-primary);
  font-size: 1rem;
  font-family: inherit;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.search-input::placeholder {
  color: var(--text-muted);
  opacity: 0.9;
}

.search-input:focus {
  border-color: var(--border-focus);
  outline: none;
  box-shadow: 0 0 0 4px var(--primary-focus);
}

.search-input-actions {
  position: absolute;
  right: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.btn-input-action {
  min-width: 36px;
  min-height: 36px;
  padding: 0.25rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
}
.btn-input-action:hover {
  color: var(--text-primary);
  background: var(--bg-muted);
}
.btn-input-action.hidden {
  display: none;
}

/* Quick Filter Chips */
.filter-chips-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  overflow-x: auto;
  padding-bottom: 0.25rem;
  -webkit-overflow-scrolling: touch;
}
.filter-chips-bar::-webkit-scrollbar {
  display: none;
}

.filter-chip {
  padding: 0.4rem 0.85rem;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: all var(--transition-fast);
}
.filter-chip:hover {
  border-color: var(--primary);
  color: var(--primary);
}
.filter-chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--text-inverse);
}

/* ==========================================================================
   Results & History Sections
   ========================================================================== */
.results-section {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.results-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
}

.results-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.result-card {
  padding: 1rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  transition: all var(--transition-fast);
}
.result-card:hover {
  border-color: var(--border-color);
  box-shadow: var(--shadow-md);
}

.result-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
}

.result-title-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.result-badge {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-sm);
  text-transform: uppercase;
}
.result-badge.badge-pdf {
  background: var(--primary-subtle);
  color: var(--primary);
}
.result-badge.badge-scan {
  background: var(--success-bg);
  color: var(--success);
}
.result-badge.badge-sku {
  background: var(--warning-bg);
  color: var(--warning);
}

.result-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
}

.result-snippet {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.45;
}

.result-snippet mark {
  background-color: #fef08a;
  color: #854d0e;
  padding: 0.05rem 0.25rem;
  border-radius: 2px;
  font-weight: 600;
}
[data-theme="dark"] .result-snippet mark {
  background-color: #854d0e;
  color: #fef08a;
}

.result-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border-subtle);
  font-size: 0.75rem;
  color: var(--text-muted);
}

.result-actions {
  display: flex;
  gap: 0.5rem;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 2.5rem 1.5rem;
  border-radius: var(--radius-lg);
  border: 2px dashed var(--border-color);
  background: var(--bg-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

.empty-state-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--bg-surface);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  box-shadow: var(--shadow-sm);
}

.empty-state h3 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
}

.empty-state p {
  font-size: 0.85rem;
  color: var(--text-secondary);
  max-width: 300px;
}

/* ==========================================================================
   Settings Page Component
   ========================================================================== */
.settings-header-banner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.settings-group {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.settings-group-title {
  font-size: 0.875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

/* PDF Upload Zone */
.pdf-upload-dropzone {
  border: 2px dashed var(--border-color);
  border-radius: var(--radius-lg);
  padding: 2rem 1.5rem;
  background: var(--bg-surface);
  text-align: center;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.85rem;
  transition: all var(--transition-fast);
  position: relative;
}

.pdf-upload-dropzone:hover,
.pdf-upload-dropzone.drag-over {
  border-color: var(--primary);
  background: var(--bg-accent-subtle);
  transform: translateY(-1px);
}

.pdf-upload-dropzone:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 4px var(--primary-focus);
}

.pdf-drop-icon {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  background: var(--primary-subtle);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.pdf-drop-text h3 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.25rem;
}

.pdf-drop-text p {
  font-size: 0.825rem;
  color: var(--text-secondary);
}

.pdf-file-input {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

/* PDF Loaded Card */
.pdf-loaded-card {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem;
  background: var(--bg-surface);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  box-shadow: var(--shadow-sm);
}

.pdf-card-top {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.pdf-file-icon {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: #fee2e2;
  color: #dc2626;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.pdf-meta {
  flex: 1;
  overflow: hidden;
}

.pdf-meta-name {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pdf-meta-stats {
  font-size: 0.775rem;
  color: var(--text-secondary);
  display: flex;
  gap: 0.75rem;
  margin-top: 0.2rem;
}

.pdf-actions-row {
  display: flex;
  gap: 0.5rem;
}

.btn-secondary {
  flex: 1;
  min-height: 42px;
  padding: 0.5rem 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-muted);
  color: var(--text-primary);
  font-size: 0.85rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  cursor: pointer;
  transition: all var(--transition-fast);
}
.btn-secondary:hover {
  background: var(--border-subtle);
}

.btn-danger-outline {
  min-height: 42px;
  padding: 0.5rem 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--danger);
  background: transparent;
  color: var(--danger);
  font-size: 0.85rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-fast);
}
.btn-danger-outline:hover {
  background: var(--danger-bg);
}

/* Settings Items & Toggles */
.settings-list {
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.setting-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem;
  border-bottom: 1px solid var(--border-subtle);
  gap: 1rem;
}
.setting-item:last-child {
  border-bottom: none;
}

.setting-info {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.setting-title {
  font-size: 0.925rem;
  font-weight: 600;
  color: var(--text-primary);
}

.setting-desc {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* Accessible Toggle Switch */
.switch {
  position: relative;
  display: inline-block;
  width: 52px;
  height: 32px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--border-color);
  transition: .3s;
  border-radius: 34px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 24px;
  width: 24px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  transition: .3s;
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

input:checked + .slider {
  background-color: var(--primary);
}

input:focus-visible + .slider {
  outline: 3px solid var(--border-focus);
  outline-offset: 2px;
}

input:checked + .slider:before {
  transform: translateX(20px);
}

/* ==========================================================================
   Camera Scanner Modal (Full Screen Viewfinder)
   ========================================================================== */
.scanner-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  background: #000000;
  z-index: 100;
  display: none;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
}
.scanner-modal.open {
  display: flex;
}

.scanner-video-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

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

/* Viewfinder Overlay */
.scanner-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  pointer-events: none;
  z-index: 10;
}

.scanner-modal-header {
  padding: 1.25rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: linear-gradient(180deg, rgba(0,0,0,0.7) 0%, transparent 100%);
  pointer-events: auto;
}

.scanner-header-title {
  color: #ffffff;
  font-weight: 700;
  font-size: 1rem;
  text-shadow: 0 1px 3px rgba(0,0,0,0.8);
}

.scanner-top-buttons {
  display: flex;
  gap: 0.5rem;
}

.scanner-btn-pill {
  min-width: 44px;
  min-height: 44px;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: #ffffff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-fast);
}
.scanner-btn-pill:hover {
  background: rgba(255, 255, 255, 0.35);
}

/* Viewfinder Target Reticle */
.scanner-reticle-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.scanner-reticle {
  width: 260px;
  height: 260px;
  position: relative;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.65);
  border-radius: 20px;
}

/* Reticle Corners */
.scanner-corner {
  position: absolute;
  width: 28px;
  height: 28px;
  border-color: #38bdf8;
  border-style: solid;
}
.scanner-corner.tl { top: -2px; left: -2px; border-width: 4px 0 0 4px; border-top-left-radius: 16px; }
.scanner-corner.tr { top: -2px; right: -2px; border-width: 4px 4px 0 0; border-top-right-radius: 16px; }
.scanner-corner.bl { bottom: -2px; left: -2px; border-width: 0 0 4px 4px; border-bottom-left-radius: 16px; }
.scanner-corner.br { bottom: -2px; right: -2px; border-width: 0 4px 4px 0; border-bottom-right-radius: 16px; }

/* Laser Scan Line */
.scanner-laser {
  position: absolute;
  top: 0;
  left: 5%;
  width: 90%;
  height: 3px;
  background: linear-gradient(90deg, transparent, #38bdf8, #60a5fa, transparent);
  box-shadow: 0 0 12px #38bdf8;
  animation: scanLaser 2s infinite ease-in-out;
}

@keyframes scanLaser {
  0% { top: 8%; opacity: 0.8; }
  50% { top: 88%; opacity: 1; }
  100% { top: 8%; opacity: 0.8; }
}

@media (prefers-reduced-motion: reduce) {
  .scanner-laser {
    animation: none;
    top: 50%;
  }
}

.scanner-hint-text {
  text-align: center;
  color: #ffffff;
  font-size: 0.85rem;
  font-weight: 600;
  margin-top: 1rem;
  text-shadow: 0 1px 4px rgba(0,0,0,0.8);
}

/* Scanner Bottom Controls */
.scanner-bottom-controls {
  padding: 1.5rem;
  background: linear-gradient(0deg, rgba(0,0,0,0.85) 0%, transparent 100%);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  align-items: center;
  pointer-events: auto;
}

.simulated-scan-presets {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: center;
}

.btn-preset-chip {
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.4);
  color: #ffffff;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
}
.btn-preset-chip:hover {
  background: rgba(255, 255, 255, 0.4);
}

/* ==========================================================================
   Bottom Navigation Bar (Mobile Native Style)
   ========================================================================== */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 640px;
  height: var(--bottom-nav-height);
  background: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding: 0 0.5rem;
  z-index: 25;
  box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.04);
}

.nav-item {
  flex: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
  padding: 0.25rem;
}

.nav-item:hover {
  color: var(--primary);
}

.nav-item.active {
  color: var(--primary);
}

.nav-item.active .nav-icon {
  transform: translateY(-1px);
}

.nav-label {
  font-size: 0.75rem;
  font-weight: 600;
}

/* Center Scan Button in Nav */
.nav-scan-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--accent-scanner));
  color: #ffffff;
  border: 3px solid var(--bg-surface);
  display: flex;
  align-items: center;
  justify-content: center;
  transform: translateY(-14px);
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.4);
  cursor: pointer;
  transition: all var(--transition-fast);
}
.nav-scan-btn:hover {
  transform: translateY(-16px) scale(1.05);
}
.nav-scan-btn:active {
  transform: translateY(-12px) scale(0.96);
}

/* ==========================================================================
   Document / PDF Viewer Modal
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  z-index: 110;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-backdrop.open {
  display: flex;
}

.modal-sheet {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 580px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-color);
}

.modal-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
}

.modal-body {
  padding: 1.25rem;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.modal-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

/* Toast Notification */
.toast-container {
  position: fixed;
  bottom: calc(var(--bottom-nav-height) + 1rem);
  left: 50%;
  transform: translateX(-50%);
  z-index: 99;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
  width: 90%;
  max-width: 400px;
}

.toast {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  background: #1e293b;
  color: #f8fafc;
  font-size: 0.875rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 0.65rem;
  pointer-events: auto;
  animation: slideUp 0.25s ease-out;
}
.toast.success { background: #065f46; color: #dcfce7; }
.toast.info { background: #1e40af; color: #dbeafe; }
.toast.warning { background: #92400e; color: #fef3c7; }

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

/* Accessible Details / Expandable */
details summary {
  cursor: pointer;
  font-weight: 600;
  padding: 0.5rem 0;
  color: var(--text-secondary);
}

/* ==========================================================================
   Food Sensitivity & Firebase Integration Styles
   ========================================================================== */
.sensitivity-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  box-shadow: var(--shadow-sm);
}

.sensitivity-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.sensitivity-counts-row {
  display: flex;
  gap: 0.5rem;
  width: 100%;
}

.count-box {
  flex: 1;
  padding: 0.65rem 0.5rem;
  border-radius: var(--radius-md);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-weight: 700;
}
.count-box.high {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid rgba(185, 28, 28, 0.3);
}
.count-box.medium {
  background: var(--warning-bg);
  color: var(--warning);
  border: 1px solid rgba(180, 83, 9, 0.3);
}
.count-box.none {
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid rgba(21, 128, 61, 0.3);
}

.count-box .count-num {
  font-size: 1.3rem;
  line-height: 1;
}
.count-box .count-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Category Tabs */
.category-tabs {
  display: flex;
  gap: 0.35rem;
  background: var(--bg-muted);
  padding: 0.25rem;
  border-radius: var(--radius-md);
  width: 100%;
}

.category-tab-btn {
  flex: 1;
  min-height: 38px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
}
.category-tab-btn.active {
  background: var(--bg-surface);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

.sensitivity-tags-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  max-height: 220px;
  overflow-y: auto;
  padding: 0.25rem 0;
}

.food-pill {
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.3rem 0.65rem;
  border-radius: var(--radius-full);
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  border: 1px solid transparent;
}
.food-pill.high {
  background: var(--danger-bg);
  color: var(--danger);
  border-color: rgba(185, 28, 28, 0.25);
}
.food-pill.medium {
  background: var(--warning-bg);
  color: var(--warning);
  border-color: rgba(180, 83, 9, 0.25);
}
.food-pill.none {
  background: var(--success-bg);
  color: var(--success);
  border-color: rgba(21, 128, 61, 0.25);
}

/* Firestore Sync Pill */
.firestore-status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  background: var(--bg-accent-subtle);
  border: 1px solid var(--border-color);
  font-size: 0.85rem;
  gap: 0.5rem;
}

.firestore-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-weight: 600;
  color: var(--primary);
}

/* Sensitivity Match Banner on Search */
.sensitivity-match-banner {
  border-radius: var(--radius-md);
  padding: 0.85rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  animation: fadeIn 0.2s ease-in-out;
}
.sensitivity-match-banner.danger {
  background: var(--danger-bg);
  border: 2px solid var(--danger);
  color: var(--danger);
}
.sensitivity-match-banner.warning {
  background: var(--warning-bg);
  border: 2px solid var(--warning);
  color: var(--warning);
}
.sensitivity-match-banner.success {
  background: var(--success-bg);
  border: 2px solid var(--success);
  color: var(--success);
}

/* Full phrase findings need a vertical layout on small mobile screens. */
.ingredient-analysis-banner {
  display: block;
  overflow-wrap: anywhere;
}
.ingredient-analysis-banner .result-badge {
  display: inline-block;
  margin-top: 0.5rem;
}
.ingredient-analysis-banner ul {
  padding-left: 1.25rem;
  margin: 0.5rem 0;
  max-height: 240px;
  overflow-y: auto;
}
.ingredient-analysis-banner li + li {
  margin-top: 0.4rem;
}

/* ==========================================================================
   OCR Camera Shutter & Words Display Card
   ========================================================================== */
.btn-camera-shutter {
  width: 100%;
  max-width: 320px;
  min-height: 52px;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius-full);
  border: 2px solid rgba(255, 255, 255, 0.4);
  background: linear-gradient(135deg, var(--primary), var(--accent-scanner));
  color: #ffffff;
  font-size: 0.95rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(37, 99, 235, 0.5);
  transition: all var(--transition-fast);
}
.btn-camera-shutter:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(37, 99, 235, 0.65);
  background: linear-gradient(135deg, var(--primary-hover), #0284c7);
}
.btn-camera-shutter:active {
  transform: scale(0.97);
}

/* OCR Results Card */
.ocr-results-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1rem 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  box-shadow: var(--shadow-sm);
  animation: fadeIn 0.25s ease-out;
}

.ocr-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.ocr-title-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.ocr-words-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  max-height: 180px;
  overflow-y: auto;
  padding: 0.25rem 0;
}

.ocr-word-pill {
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-full);
  background: var(--bg-muted);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: all var(--transition-fast);
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}
.ocr-word-pill:hover {
  background: var(--primary-subtle);
  border-color: var(--primary);
  color: var(--primary);
  transform: translateY(-1px);
}
.ocr-word-pill.high-alert {
  background: var(--danger-bg);
  border-color: var(--danger);
  color: var(--danger);
  font-weight: 700;
}
.ocr-word-pill.medium-alert {
  background: var(--warning-bg);
  border-color: var(--warning);
  color: var(--warning);
  font-weight: 700;
}

.ingredient-findings-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  max-height: 360px;
}
.ingredient-findings-grid .ocr-word-pill {
  display: block;
  max-width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;
  text-align: left;
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.75rem;
}

.label-ocr-sheet { max-width: 720px; }
.label-ocr-canvas {
  display: block; max-width: 100%; max-height: 42vh; width: auto; height: auto;
  margin: 0.75rem auto; touch-action: none; border: 2px solid var(--border-subtle);
}
.label-crop-controls { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.6rem; }
.label-crop-controls label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.85rem; }
.label-crop-controls input { width: 100%; }
.label-ocr-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.75rem 0; }
.label-ocr-text {
  width: 100%; resize: vertical; padding: 0.65rem; margin-top: 0.5rem;
  color: var(--text-primary); background: var(--bg-surface);
  border: 1px solid var(--border-subtle); border-radius: var(--radius-sm); font: inherit;
}
#label-ocr-review { margin-top: 1rem; }
#label-ocr-review[hidden] { display: none; }

.ocr-raw-text {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  background: var(--bg-muted);
  border: 1px solid var(--border-subtle);
  padding: 0.75rem;
  border-radius: var(--radius-sm);
  white-space: pre-wrap;
  color: var(--text-secondary);
  max-height: 120px;
  overflow-y: auto;
}

/* OCR Loading Spinner */
.ocr-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border-color);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: ocrSpin 0.75s linear infinite;
  display: inline-block;
  vertical-align: middle;
}

@keyframes ocrSpin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.ocr-loading-card {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 1rem 1.15rem;
  background: var(--bg-surface);
  border: 1px dashed var(--primary);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  animation: fadeIn 0.25s ease-out;
}
