:root {
  --bg-primary: #f8fafc;
  --bg-secondary: #f1f5f9;
  --bg-surface: #ffffff;
  --bg-card: #ffffff;
  --border-color: #e2e8f0;
  --border-hover: #cbd5e1;
  --border-focus: #3b82f6;
  
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  
  --primary-50: #eff6ff;
  --primary-100: #dbeafe;
  --primary-500: #3b82f6;
  --primary-600: #2563eb;
  --primary-700: #1d4ed8;
  
  --success-50: #ecfdf5;
  --success-100: #d1fae5;
  --success-600: #059669;
  --success-700: #047857;
  
  --error-50: #fff1f2;
  --error-100: #ffe4e6;
  --error-600: #e11d48;
  
  --radius-xs: 6px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 9999px;
  
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.06), 0 2px 4px -1px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.06), 0 4px 6px -2px rgba(0, 0, 0, 0.03);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.08), 0 10px 10px -5px rgba(0, 0, 0, 0.03);
  
  --font-family: 'Plus Jakarta Sans', 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  font-family: var(--font-family);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background-image: 
    radial-gradient(at 10% 10%, rgba(219, 234, 254, 0.5) 0px, transparent 50%),
    radial-gradient(at 90% 90%, rgba(241, 245, 249, 0.8) 0px, transparent 50%);
  background-attachment: fixed;
}

.app-container {
  max-width: 860px;
  margin: 0 auto;
  padding: 24px 16px 48px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.logo-wrapper {
  display: flex;
  align-items: center;
  gap: 14px;
}

.logo-icon {
  width: 40px;
  height: 40px;
  background: var(--text-primary);
  color: #ffffff;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
}

.logo-text h1 {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.logo-text p {
  font-size: 0.775rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.badge-live {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--success-50);
  border: 1px solid var(--success-100);
  color: var(--success-700);
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
}

.pulse-dot {
  width: 7px;
  height: 7px;
  background-color: var(--success-600);
  border-radius: 50%;
  box-shadow: 0 0 0 2px var(--success-100);
}

/* Hero Section */
.hero-scanner-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: 32px 24px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}

.hero-title {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.03em;
  margin-bottom: 8px;
}

.hero-subtitle {
  color: var(--text-secondary);
  font-size: 0.925rem;
  margin-bottom: 24px;
  max-width: 520px;
  margin-inline: auto;
  line-height: 1.6;
}

/* Scan Buttons */
.btn-scan-main {
  width: 100%;
  max-width: 340px;
  margin: 0 auto;
  padding: 14px 24px;
  background: var(--primary-600);
  color: #ffffff;
  border: 1px solid var(--primary-700);
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
  box-shadow: var(--shadow-sm), 0 2px 4px rgba(37, 99, 235, 0.2);
  transition: var(--transition);
}

.btn-scan-main:hover {
  background: var(--primary-700);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md), 0 4px 10px rgba(37, 99, 235, 0.25);
}

.btn-scan-main:active {
  transform: translateY(0);
}

.quick-tools {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 18px;
}

.btn-secondary {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
}

.btn-secondary:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border-color: var(--border-hover);
}

/* Scanner Viewport */
.scanner-viewport-container {
  display: none;
  background: #090d16;
  border: 1px solid #1e293b;
  border-radius: var(--radius-xl);
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-xl);
  margin-bottom: 20px;
  animation: fadeIn 0.25s ease-out;
}

.scanner-viewport-container.active {
  display: block;
}

#reader {
  width: 100% !important;
  border: none !important;
}

#reader video {
  width: 100% !important;
  max-height: 60vh !important;
  object-fit: cover !important;
  border-radius: var(--radius-xl);
}

.scanner-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.scan-target-box {
  width: min(80%, 280px);
  height: min(80%, 200px);
  border: 2px solid rgba(255, 255, 255, 0.7);
  border-radius: var(--radius-md);
  position: relative;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.55);
}

.scan-laser-line {
  position: absolute;
  left: 4%;
  right: 4%;
  height: 2px;
  background: #38bdf8;
  box-shadow: 0 0 10px #38bdf8, 0 0 18px #0284c7;
  animation: laserScan 2s infinite ease-in-out alternate;
}

@keyframes laserScan {
  0% { top: 6%; }
  100% { top: 90%; }
}

.corner {
  position: absolute;
  width: 14px;
  height: 14px;
  border-color: #38bdf8;
  border-style: solid;
}
.corner-tl { top: -2px; left: -2px; border-width: 3px 0 0 3px; border-top-left-radius: 6px; }
.corner-tr { top: -2px; right: -2px; border-width: 3px 3px 0 0; border-top-right-radius: 6px; }
.corner-bl { bottom: -2px; left: -2px; border-width: 0 0 3px 3px; border-bottom-left-radius: 6px; }
.corner-br { bottom: -2px; right: -2px; border-width: 0 3px 3px 0; border-bottom-right-radius: 6px; }

.scanner-controls {
  position: absolute;
  bottom: 16px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  z-index: 10;
}

.camera-ctrl-btn {
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #ffffff;
  padding: 8px 14px;
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  backdrop-filter: blur(8px);
  transition: var(--transition);
}

.camera-ctrl-btn:hover {
  background: rgba(15, 23, 42, 0.95);
  border-color: rgba(255, 255, 255, 0.4);
}

.camera-ctrl-btn.btn-close-scanner {
  background: rgba(225, 29, 72, 0.85);
  border-color: transparent;
}

.camera-ctrl-btn.btn-close-scanner:hover {
  background: rgba(190, 18, 60, 0.95);
}

/* Manual Input Card */
.manual-input-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: none;
  box-shadow: var(--shadow-sm);
  animation: fadeIn 0.2s ease-out;
}

.manual-input-card.active {
  display: block;
}

.input-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.input-group {
  display: flex;
  gap: 8px;
}

.gtin-input-field {
  flex: 1;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: var(--text-primary);
  font-size: 0.95rem;
  font-family: monospace;
  letter-spacing: 0.04em;
  outline: none;
  transition: var(--transition);
}

.gtin-input-field:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.btn-input-submit {
  background: var(--text-primary);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: var(--transition);
}

.btn-input-submit:hover {
  background: #1e293b;
}

/* Sample Barcodes */
.sample-barcodes {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
  align-items: center;
}

.sample-title {
  font-size: 0.775rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.sample-pill {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-size: 0.775rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: var(--transition);
}

.sample-pill:hover {
  background: var(--primary-50);
  border-color: var(--primary-100);
  color: var(--primary-600);
}

/* Status Notifications */
.status-banner {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 500;
  display: none;
  align-items: center;
  gap: 10px;
}

.status-banner.active {
  display: flex;
}

.status-banner.loading {
  background: var(--primary-50);
  border: 1px solid var(--primary-100);
  color: var(--primary-700);
}

.status-banner.error {
  background: var(--error-50);
  border: 1px solid var(--error-100);
  color: var(--error-600);
}

.status-banner.success {
  background: var(--success-50);
  border: 1px solid var(--success-100);
  color: var(--success-700);
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Result Card */
.result-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: 24px;
  box-shadow: var(--shadow-md);
  display: none;
  animation: scaleUp 0.25s ease-out;
}

.result-card.active {
  display: block;
}

.result-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 18px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.gtin-display-badge {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.gtin-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 0.05em;
}

.gtin-code-value {
  font-size: 1.35rem;
  font-family: monospace;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: 0.04em;
}

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

.btn-icon {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
}

.btn-icon:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border-color: var(--border-hover);
}

/* Product Layout */
.product-details-grid {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 24px;
  align-items: start;
}

@media (max-width: 640px) {
  .product-details-grid {
    grid-template-columns: 1fr;
  }
}

.product-image-container {
  width: 100%;
  aspect-ratio: 1;
  max-width: 180px;
  margin: 0 auto;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.product-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 8px;
}

.image-fallback {
  color: var(--text-muted);
  font-size: 0.775rem;
  font-weight: 500;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.product-info-content {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.product-brand {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--primary-600);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.product-name {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.3;
}

.product-category {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.data-badge-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}

.info-pill {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.775rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.info-pill-label {
  color: var(--text-muted);
  font-size: 0.675rem;
  font-weight: 600;
  text-transform: uppercase;
}

.info-pill-val {
  font-weight: 600;
  color: var(--text-primary);
}

/* GS1 License Box (Light Mode High-End) */
.gs1-license-card {
  margin-top: 18px;
  padding: 16px 18px;
  background: #f0fdfa;
  border: 1px solid #ccfbf1;
  border-radius: var(--radius-lg);
}

.gs1-license-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.gs1-license-title {
  font-size: 0.875rem;
  color: #0f766e;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.gs1-fields-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  font-size: 0.825rem;
}

.gs1-field-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.gs1-field-label {
  color: #0d9488;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
}

.gs1-field-val {
  color: #134e4a;
  font-weight: 600;
  word-break: break-word;
}

/* GS1 Decoded Table */
.gs1-decoded-section {
  margin-top: 20px;
  border-top: 1px solid var(--border-color);
  padding-top: 16px;
}

.section-subhead {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.gs1-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.825rem;
}

.gs1-table th, .gs1-table td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

.gs1-table th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  background: var(--bg-secondary);
}

.gs1-ai-tag {
  background: var(--primary-50);
  color: var(--primary-700);
  border: 1px solid var(--primary-100);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: monospace;
  font-weight: 700;
}

/* JSON Drawer */
.details-accordion {
  margin-top: 16px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.details-summary {
  padding: 10px 14px;
  background: var(--bg-secondary);
  font-size: 0.8rem;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
  font-weight: 600;
}

.json-pre {
  background: #0f172a;
  padding: 12px;
  font-family: monospace;
  font-size: 0.75rem;
  color: #38bdf8;
  overflow-x: auto;
  max-height: 240px;
}

/* History Section */
.history-section {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.history-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 280px;
  overflow-y: auto;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
}

.history-item:hover {
  background: var(--primary-50);
  border-color: var(--primary-100);
}

.history-item-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.history-item-name {
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--text-primary);
}

.history-item-gtin {
  font-family: monospace;
  font-size: 0.75rem;
  color: var(--primary-600);
}

.history-item-date {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.history-empty {
  text-align: center;
  padding: 20px;
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* Toast */
.toast-container {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  pointer-events: none;
}

.toast {
  background: var(--text-primary);
  color: #ffffff;
  padding: 10px 18px;
  border-radius: var(--radius-full);
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.25s ease-out;
}

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

@keyframes scaleUp {
  from { opacity: 0; transform: scale(0.98); }
  to { opacity: 1; transform: scale(1); }
}

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