/* =========================================
   QR Scanner — style.css
   TweeLabs Premium Design System
   ========================================= */

/* 1. TOKENS & RESET */
:root {
  --bg: #0d0f17;
  --surface: #131622;
  --surface-2: #1a1e2e;
  --surface-3: #222738;
  --border: rgba(255,255,255,0.07);
  --border-hover: rgba(255,255,255,0.14);
  --text: #f0f2ff;
  --text-2: #9399b8;
  --text-3: #5e647f;
  --accent: #6c63ff;
  --accent-2: #a78bfa;
  --accent-glow: rgba(108,99,255,0.35);
  --success: #10b981;
  --success-glow: rgba(16,185,129,0.3);
  --warn: #f59e0b;
  --error: #ef4444;
  --radius: 16px;
  --radius-sm: 10px;
  --radius-xs: 6px;
  --shadow: 0 4px 32px rgba(0,0,0,0.5);
  --shadow-glow: 0 0 40px var(--accent-glow);
  --transition: 0.22s cubic-bezier(0.4,0,0.2,1);
  --font: 'Inter', system-ui, sans-serif;
}

[data-theme="light"] {
  --bg: #f0f2ff;
  --surface: #ffffff;
  --surface-2: #f5f6ff;
  --surface-3: #eaecff;
  --border: rgba(0,0,0,0.08);
  --border-hover: rgba(0,0,0,0.16);
  --text: #1a1d2e;
  --text-2: #4a4f6a;
  --text-3: #8b90aa;
  --accent-glow: rgba(108,99,255,0.15);
  --shadow: 0 4px 32px rgba(0,0,0,0.1);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  line-height: 1.6;
  overflow-x: hidden;
  transition: background var(--transition), color var(--transition);
}

/* 2. BACKGROUND BLOBS */
.bg-blobs {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}
.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.18;
  animation: blobFloat 8s ease-in-out infinite alternate;
}
[data-theme="light"] .blob { opacity: 0.10; }
.blob-1 {
  width: 500px; height: 500px;
  background: radial-gradient(circle, #6c63ff, #a78bfa);
  top: -100px; left: -100px;
  animation-delay: 0s;
}
.blob-2 {
  width: 400px; height: 400px;
  background: radial-gradient(circle, #10b981, #34d399);
  bottom: 0; right: -80px;
  animation-delay: -3s;
}
.blob-3 {
  width: 300px; height: 300px;
  background: radial-gradient(circle, #f59e0b, #fbbf24);
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  animation-delay: -6s;
}
@keyframes blobFloat {
  from { transform: scale(1) translate(0, 0); }
  to   { transform: scale(1.15) translate(30px, -20px); }
}
.blob-3 { animation-name: blobFloat3; }
@keyframes blobFloat3 {
  from { transform: translate(-50%, -50%) scale(1); }
  to   { transform: translate(-50%, -50%) scale(1.2); }
}

/* 3. HEADER */
.header {
  position: sticky; top: 0; z-index: 100;
  padding: 0 1.5rem;
  backdrop-filter: blur(20px) saturate(180%);
  background: rgba(13,15,23,0.75);
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
[data-theme="light"] .header { background: rgba(240,242,255,0.8); }
.header-inner {
  max-width: 640px;
  margin: 0 auto;
  height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo { display: flex; align-items: center; gap: 10px; }
.logo-icon {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-radius: var(--radius-xs);
  display: grid; place-items: center;
  box-shadow: 0 0 20px var(--accent-glow);
}
.logo-icon svg { width: 20px; height: 20px; color: #fff; }
.logo-text { font-size: 1.2rem; font-weight: 800; letter-spacing: -0.5px; color: var(--text); }
.logo-accent { color: var(--accent); }

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

/* 4. BUTTON SYSTEM */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 22px;
  border-radius: var(--radius-sm);
  border: none; cursor: pointer;
  font-family: var(--font);
  font-size: 0.9rem; font-weight: 600;
  transition: all var(--transition);
  white-space: nowrap;
  text-decoration: none;
}
.btn svg { width: 16px; height: 16px; flex-shrink: 0; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  box-shadow: 0 4px 20px var(--accent-glow);
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 8px 30px var(--accent-glow); filter: brightness(1.1); }
.btn-primary:active { transform: translateY(0); }

.btn-ghost {
  background: var(--surface-3);
  color: var(--text-2);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--border-hover); color: var(--text); border-color: var(--border-hover); }

.btn-sm { padding: 7px 14px; font-size: 0.82rem; }
.btn-text { background: none; border: none; color: var(--text-3); font-family: var(--font); font-size: 0.85rem; font-weight: 500; cursor: pointer; padding: 6px 10px; border-radius: var(--radius-xs); transition: color var(--transition), background var(--transition); }
.btn-text:hover { color: var(--error); background: rgba(239,68,68,0.08); }

.btn-icon {
  width: 38px; height: 38px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-2);
  display: grid; place-items: center;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
}
.btn-icon svg { width: 18px; height: 18px; }
.btn-icon:hover { border-color: var(--accent); color: var(--accent); background: rgba(108,99,255,0.1); }

.history-badge {
  position: absolute; top: -6px; right: -6px;
  width: 18px; height: 18px;
  background: var(--accent);
  color: #fff;
  font-size: 0.65rem; font-weight: 700;
  border-radius: 50%;
  display: grid; place-items: center;
}

/* 5. MAIN LAYOUT */
.main {
  max-width: 640px;
  margin: 0 auto;
  padding: 1.5rem 1rem 6rem;
  position: relative; z-index: 1;
}

/* 6. TAB BAR */
.tab-bar {
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 5px;
  margin-bottom: 1.25rem;
  gap: 4px;
  box-shadow: var(--shadow);
}
.tab {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px;
  border: none; border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-3);
  font-family: var(--font); font-size: 0.9rem; font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}
.tab svg { width: 16px; height: 16px; }
.tab:hover { color: var(--text-2); background: var(--surface-2); }
.tab.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  box-shadow: 0 4px 16px var(--accent-glow);
}

/* 7. SCANNER CARD */
.scanner-card, .upload-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: border-color var(--transition);
}
.scanner-card:hover, .upload-card:hover { border-color: var(--border-hover); }

.scanner-viewport {
  position: relative;
  width: 100%;
  aspect-ratio: 4/3;
  background: #000;
  overflow: hidden;
}

#cameraFeed {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}

/* Camera off state */
.camera-off {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px;
  background: var(--surface-2);
  color: var(--text-3);
  cursor: pointer;
  transition: background var(--transition);
}
.camera-off:hover, .camera-off:active { background: var(--surface-3); }
.camera-off-icon {
  width: 72px; height: 72px;
  border: 2px solid var(--border);
  border-radius: 50%;
  display: grid; place-items: center;
  margin-bottom: 4px;
}
.camera-off-icon svg { width: 36px; height: 36px; }
.camera-off p { font-size: 1rem; font-weight: 600; color: var(--text-2); }
.camera-off small { font-size: 0.8rem; color: var(--text-3); }

/* Scanner overlay */
.scanner-overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px;
  pointer-events: none;
}

.scanner-frame {
  width: 220px; height: 220px;
  position: relative;
}

.corner {
  position: absolute;
  width: 26px; height: 26px;
  border-color: var(--accent);
  border-style: solid;
  border-radius: 3px;
}
.corner.tl { top: 0; left: 0; border-width: 3px 0 0 3px; }
.corner.tr { top: 0; right: 0; border-width: 3px 3px 0 0; }
.corner.bl { bottom: 0; left: 0; border-width: 0 0 3px 3px; }
.corner.br { bottom: 0; right: 0; border-width: 0 3px 3px 0; }

.scan-line {
  position: absolute;
  left: 4px; right: 4px;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), var(--accent-2), var(--accent), transparent);
  border-radius: 1px;
  box-shadow: 0 0 12px var(--accent);
  animation: scanAnim 2.4s ease-in-out infinite;
  top: 0;
}
@keyframes scanAnim {
  0%   { top: 4px; opacity: 0.7; }
  50%  { opacity: 1; }
  100% { top: calc(100% - 6px); opacity: 0.7; }
}

.scan-hint {
  color: rgba(255,255,255,0.85);
  font-size: 0.82rem; font-weight: 500;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(8px);
  padding: 6px 14px;
  border-radius: 20px;
  letter-spacing: 0.02em;
}

/* Success flash animation */
@keyframes successFlash {
  0%   { background: rgba(16,185,129,0) }
  30%  { background: rgba(16,185,129,0.35) }
  100% { background: rgba(16,185,129,0) }
}
.scan-success-flash { animation: successFlash 0.6s ease-out; }

/* Scanner controls */
.scanner-controls {
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* 8. UPLOAD CARD */
.drop-zone {
  margin: 1.25rem;
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 2.5rem 1.5rem;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; text-align: center;
  cursor: pointer;
  transition: all var(--transition);
}
.drop-zone:hover, .drop-zone.dragover {
  border-color: var(--accent);
  background: rgba(108,99,255,0.06);
}
.drop-zone:focus { outline: 2px solid var(--accent); outline-offset: 2px; }

.drop-icon {
  width: 64px; height: 64px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: grid; place-items: center;
  margin-bottom: 4px;
  transition: all var(--transition);
}
.drop-icon svg { width: 28px; height: 28px; color: var(--accent); }
.drop-zone:hover .drop-icon { background: rgba(108,99,255,0.1); border-color: var(--accent); transform: scale(1.05); }

.drop-zone h3 { font-size: 1rem; font-weight: 700; color: var(--text); }
.drop-zone p { font-size: 0.85rem; color: var(--text-3); }
.drop-formats {
  font-size: 0.75rem; color: var(--text-3);
  background: var(--surface-2);
  padding: 4px 12px; border-radius: 20px;
  letter-spacing: 0.05em;
}

.upload-preview {
  margin: 0 1.25rem 0;
  border-radius: var(--radius-sm);
  overflow: hidden;
  position: relative;
  border: 1px solid var(--border);
}
.upload-preview img {
  width: 100%; height: 260px;
  object-fit: contain;
  background: var(--surface-2);
  display: block;
}
#clearUploadBtn {
  position: absolute; top: 10px; right: 10px;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(8px);
  color: #fff;
  border-color: rgba(255,255,255,0.2);
}
#clearUploadBtn:hover { background: var(--error); }

#scanUploadBtn {
  display: flex;
  width: calc(100% - 2.5rem);
  margin: 1rem 1.25rem 1.25rem;
  justify-content: center;
}

/* 9. RESULT CARD */
.result-card {
  margin-top: 1.25rem;
  background: var(--surface);
  border: 1px solid var(--success);
  border-radius: var(--radius);
  box-shadow: 0 0 32px var(--success-glow), var(--shadow);
  overflow: hidden;
  animation: resultSlide 0.4s cubic-bezier(0.34,1.56,0.64,1);
}
@keyframes resultSlide {
  from { opacity: 0; transform: translateY(20px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.result-header {
  padding: 12px 16px;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}

.result-type-badge {
  font-size: 0.72rem; font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 4px 10px;
  border-radius: 20px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
}

.result-actions-top { display: flex; gap: 6px; }
.result-close:hover { border-color: var(--error); color: var(--error); background: rgba(239,68,68,0.08); }

.result-content {
  padding: 1.25rem 1.25rem 1rem;
  display: flex; gap: 12px; align-items: flex-start;
}
.result-icon {
  width: 40px; height: 40px; flex-shrink: 0;
  border-radius: var(--radius-xs);
  background: rgba(108,99,255,0.12);
  border: 1px solid rgba(108,99,255,0.25);
  display: grid; place-items: center;
  color: var(--accent);
}
.result-icon svg { width: 20px; height: 20px; }

.result-text {
  font-size: 0.9rem; color: var(--text);
  word-break: break-all;
  flex: 1;
  line-height: 1.65;
  padding-top: 8px;
}

.result-footer {
  padding: 0 1.25rem 1.25rem;
  display: flex; flex-wrap: wrap; gap: 8px;
}

/* 10. HISTORY PANEL */
.history-panel {
  position: fixed;
  top: 0; right: 0;
  width: min(400px, 90vw);
  height: 100dvh;
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 200;
  display: flex; flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.35s cubic-bezier(0.4,0,0.2,1);
  box-shadow: -8px 0 40px rgba(0,0,0,0.4);
}
.history-panel.open { transform: translateX(0); }

.history-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  z-index: 199;
  opacity: 0; pointer-events: none;
  transition: opacity 0.35s;
}
.history-overlay.open { opacity: 1; pointer-events: all; }

.history-header {
  padding: 1rem 1.25rem;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.history-header h2 { font-size: 1rem; font-weight: 700; }
.history-header-actions { display: flex; align-items: center; gap: 6px; }

.history-list {
  flex: 1; overflow-y: auto;
  padding: 0.75rem;
  display: flex; flex-direction: column; gap: 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--surface-3) transparent;
}

.history-empty {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; color: var(--text-3);
  padding: 3rem 1rem;
}
.history-empty svg { width: 48px; height: 48px; }
.history-empty p { font-size: 0.9rem; }

.history-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  cursor: pointer;
  transition: all var(--transition);
  display: flex; gap: 10px; align-items: flex-start;
  animation: histItemIn 0.3s ease;
}
@keyframes histItemIn {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}
.history-item:hover { border-color: var(--accent); background: rgba(108,99,255,0.06); }
.history-item-icon {
  width: 34px; height: 34px; flex-shrink: 0;
  border-radius: var(--radius-xs);
  background: var(--surface-3);
  display: grid; place-items: center;
  color: var(--accent);
}
.history-item-icon svg { width: 16px; height: 16px; }
.history-item-body { flex: 1; min-width: 0; }
.history-item-text {
  font-size: 0.83rem; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-weight: 500;
}
.history-item-meta { font-size: 0.72rem; color: var(--text-3); margin-top: 3px; }
.history-item-type {
  font-size: 0.68rem; font-weight: 700; letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent); margin-top: 3px;
}
.history-item-delete {
  width: 26px; height: 26px;
  display: grid; place-items: center;
  border-radius: var(--radius-xs);
  border: none; background: none;
  color: var(--text-3); cursor: pointer;
  transition: all var(--transition);
  flex-shrink: 0;
}
.history-item-delete svg { width: 14px; height: 14px; }
.history-item-delete:hover { color: var(--error); background: rgba(239,68,68,0.1); }

/* 11. TOAST */
.toast {
  position: fixed;
  bottom: 2rem; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--surface-3);
  color: var(--text);
  padding: 10px 20px;
  border-radius: 40px;
  font-size: 0.85rem; font-weight: 500;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  border: 1px solid var(--border);
  opacity: 0; pointer-events: none;
  transition: all 0.3s cubic-bezier(0.34,1.56,0.64,1);
  z-index: 300; white-space: nowrap;
  display: flex; align-items: center; gap: 8px;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); pointer-events: all; }
.toast.success { border-color: var(--success); }
.toast.error   { border-color: var(--error); }

/* 12. LOADING SPINNER */
.spinner {
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* 13. SCROLLBAR */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 3px; }

/* 14. RESPONSIVE */
@media (max-width: 480px) {
  .main { padding: 1rem 0.75rem 5rem; }
  .header { padding: 0 1rem; }
  .scanner-frame { width: 180px; height: 180px; }
  .tab { font-size: 0.82rem; padding: 10px; }
}

/* 15. FOCUS VISIBLE */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button:focus:not(:focus-visible) { outline: none; }

/* PANEL — section visibility base rule */
.panel {
  display: block;
}

/* 16. CREATE PANEL & FORMS */
.create-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}
.create-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  gap: 10px;
}
.create-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
}
.form-select, .form-input, .form-textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.9rem;
  transition: all var(--transition);
  -webkit-appearance: none;
  appearance: none;
}
.form-select:focus, .form-input:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}
.form-textarea {
  resize: vertical;
  min-height: 80px;
}
.form-group {
  margin-bottom: 1rem;
}
.form-group label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 6px;
}
.generated-qr-container {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  animation: resultSlide 0.4s cubic-bezier(0.34,1.56,0.64,1);
}
.generated-qr-container canvas {
  background: #fff;
  padding: 10px;
  border-radius: var(--radius-sm);
  box-shadow: 0 4px 20px rgba(0,0,0,0.2);
  max-width: 100%;
}
.generated-qr-actions {
  display: flex;
  gap: 10px;
}

/* Create forms container */
.create-forms {
  display: flex;
  flex-direction: column;
  gap: 0;
}
