/* ============================================
   Barcode Scanner — Styles
   ============================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #7C3AED;
  --primary-light: #A78BFA;
  --accent: #10B981;
  --accent-glow: rgba(16,185,129,0.2);
  --danger: #EF4444;
  --warning: #F59E0B;
  --bg: #0B0E11;
  --bg-card: rgba(255,255,255,0.04);
  --bg-glass: rgba(255,255,255,0.06);
  --border: rgba(255,255,255,0.08);
  --border-hover: rgba(255,255,255,0.16);
  --text: #E8E8E8;
  --text-dim: #9CA3AF;
  --text-muted: #6B7280;
  --radius: 12px;
  --radius-sm: 8px;
  --font: 'Inter', system-ui, -apple-system, sans-serif;
  --mono: 'JetBrains Mono', 'Fira Code', monospace;
  --shadow: 0 4px 24px rgba(0,0,0,0.3);
  --transition: 250ms ease;
}

html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: var(--font); background: var(--bg); color: var(--text);
  line-height: 1.6; min-height: 100vh; -webkit-font-smoothing: antialiased;
}

/* --- Header --- */
.header {
  position: sticky; top: 0; z-index: 100;
  background: rgba(11,14,17,0.85); backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
}
.header__inner {
  max-width: 700px; margin: 0 auto; padding: 0.75rem 1.5rem;
  display: flex; align-items: center; justify-content: space-between;
}
.header__brand { display: flex; align-items: center; gap: 0.6rem; }
.header__icon { font-size: 1.3rem; }
.header__title { font-size: 1.15rem; font-weight: 700; }
.header__actions { display: flex; align-items: center; gap: 0.75rem; }

/* --- Buttons --- */
.btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  border: none; cursor: pointer; font-family: var(--font);
  font-size: 0.85rem; font-weight: 500; border-radius: var(--radius-sm);
  transition: all var(--transition);
}
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn--ghost {
  background: var(--bg-glass); color: var(--text-dim);
  padding: 0.5rem 0.85rem; border: 1px solid var(--border);
}
.btn--ghost:hover { background: rgba(255,255,255,0.1); color: var(--text); }
.btn--accent {
  background: var(--accent); color: #0B0E11;
  padding: 0.6rem 1.2rem; font-weight: 600;
}
.btn--accent:hover { filter: brightness(1.15); transform: translateY(-1px); }
.btn--lg { font-size: 0.95rem; padding: 0.7rem 1.5rem; }
.btn--sm { font-size: 0.78rem; padding: 0.35rem 0.7rem; }
.btn--danger { background: var(--danger); color: #fff; }

/* --- Toggle --- */
.toggle {
  display: flex; align-items: center; gap: 0.5rem; cursor: pointer;
  font-size: 0.82rem; color: var(--text-dim);
}
.toggle input { display: none; }
.toggle__slider {
  width: 36px; height: 20px; background: var(--bg-glass);
  border: 1px solid var(--border); border-radius: 999px;
  position: relative; transition: all var(--transition);
}
.toggle__slider::after {
  content: ''; position: absolute; top: 2px; left: 2px;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--text-dim); transition: all var(--transition);
}
.toggle input:checked + .toggle__slider {
  background: var(--accent); border-color: var(--accent);
}
.toggle input:checked + .toggle__slider::after {
  transform: translateX(16px); background: #fff;
}
.toggle__label { font-weight: 500; }

/* --- Main --- */
.main { max-width: 700px; margin: 0 auto; padding: 1.25rem 1.5rem 3rem; }

/* --- Scanner Viewport --- */
.scanner-section { margin-bottom: 1.5rem; }
.scanner-viewport {
  position: relative; border-radius: var(--radius);
  overflow: hidden; background: #111; aspect-ratio: 4/3;
  border: 1px solid var(--border);
}
.scanner-viewport video {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.scanner-overlay {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%;
  pointer-events: none;
}

/* Scanner frame */
.scanner-frame {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 65%; height: 65%; pointer-events: none;
}
.scanner-frame__corner {
  position: absolute; width: 24px; height: 24px;
  border-color: var(--accent); border-style: solid;
}
.scanner-frame__corner--tl { top: 0; left: 0; border-width: 3px 0 0 3px; }
.scanner-frame__corner--tr { top: 0; right: 0; border-width: 3px 3px 0 0; }
.scanner-frame__corner--bl { bottom: 0; left: 0; border-width: 0 0 3px 3px; }
.scanner-frame__corner--br { bottom: 0; right: 0; border-width: 0 3px 3px 0; }

.scanner-line {
  position: absolute; left: 0; width: 100%; height: 2px;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent-glow), 0 0 24px var(--accent-glow);
  animation: scanMove 2s ease-in-out infinite;
}

@keyframes scanMove {
  0%, 100% { top: 0; }
  50% { top: 100%; }
}

.scanner-status {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: rgba(0,0,0,0.7); padding: 0.5rem 1rem;
  font-size: 0.82rem; color: var(--text-dim); text-align: center;
}
.scanner-controls {
  display: flex; gap: 0.75rem; margin-top: 0.75rem;
  justify-content: center; align-items: center;
}

/* --- Last Scan --- */
.last-scan {
  background: var(--bg-card); border: 1px solid var(--accent);
  border-radius: var(--radius); padding: 1rem;
  margin-bottom: 1.5rem; animation: slideIn 300ms ease;
}
.last-scan[hidden] { display: none; }
.last-scan__badge {
  display: inline-block; font-size: 0.68rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.05em;
  background: rgba(16,185,129,0.15); color: var(--accent);
  padding: 0.2rem 0.6rem; border-radius: 999px; margin-bottom: 0.5rem;
}
.last-scan__value {
  font-family: var(--mono); font-size: 0.92rem;
  word-break: break-all; margin-bottom: 0.65rem;
}
.last-scan__actions { display: flex; gap: 0.5rem; }

/* --- History --- */
.history-section { margin-top: 1rem; }
.history-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 0.75rem;
}
.section-title { font-size: 0.9rem; font-weight: 600; }
.history-count { font-size: 0.78rem; color: var(--text-muted); }
.history-list { display: flex; flex-direction: column; gap: 0.5rem; }

.history-item {
  display: flex; align-items: center; gap: 0.75rem;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 0.75rem;
  transition: all var(--transition); animation: fadeIn 250ms ease backwards;
}
.history-item:hover { border-color: var(--border-hover); }
.history-item__icon {
  width: 36px; height: 36px; border-radius: var(--radius-sm);
  background: rgba(124,58,237,0.15); display: flex;
  align-items: center; justify-content: center; font-size: 1rem;
  flex-shrink: 0;
}
.history-item__content { flex: 1; min-width: 0; }
.history-item__value {
  font-family: var(--mono); font-size: 0.82rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.history-item__meta {
  font-size: 0.7rem; color: var(--text-muted);
  display: flex; gap: 0.5rem; margin-top: 0.15rem;
}
.history-item__actions { display: flex; gap: 0.35rem; flex-shrink: 0; }

/* --- Empty State --- */
.empty-state { text-align: center; padding: 2.5rem 1.5rem; }
.empty-state[hidden] { display: none; }
.empty-state__icon { font-size: 2.5rem; display: block; margin-bottom: 0.75rem; }
.empty-state__title { font-size: 1rem; font-weight: 600; margin-bottom: 0.25rem; }
.empty-state__desc { font-size: 0.85rem; color: var(--text-dim); }

/* --- Toast --- */
.toast {
  position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%);
  background: var(--primary); color: #fff;
  padding: 0.6rem 1.25rem; border-radius: var(--radius);
  font-size: 0.85rem; font-weight: 500; box-shadow: var(--shadow); z-index: 500;
  animation: toastIn 300ms ease;
}
.toast[hidden] { display: none; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* --- Responsive --- */
@media (max-width: 600px) {
  .main { padding: 1rem; }
  .header__inner { padding: 0.6rem 1rem; }
  .btn__text { display: none; }
  .scanner-viewport { aspect-ratio: 1/1; }
}

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 999px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
