/* ===== TOKENS ===== */
:root {
  --bg: #0a0e1a;
  --bg-card: #111827;
  --bg-input: #1a2235;
  --bg-tab: #1e2a3d;
  --accent: #6366f1;
  --accent-light: #818cf8;
  --accent-glow: rgba(99, 102, 241, 0.35);
  --accent-2: #06b6d4;
  --success: #10b981;
  --danger: #f43f5e;
  --danger-bg: rgba(244, 63, 94, 0.15);
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --text-dim: #475569;
  --border: rgba(255, 255, 255, 0.07);
  --border-accent: rgba(99, 102, 241, 0.4);
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 25px 60px rgba(0, 0, 0, 0.5);
  --font: "Inter", system-ui, sans-serif;
  --transition: 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ===== RESET ===== */
*,
*::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: 100vh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 2rem 1rem 4rem;
  overflow-x: hidden;
  position: relative;
}

/* ===== BACKGROUND ORBS ===== */
.bg-orbs {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
}
.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.45;
  animation: float 8s ease-in-out infinite;
}
.orb-1 {
  width: 500px;
  height: 500px;
  background: radial-gradient(circle, #6366f1, transparent 70%);
  top: -150px;
  left: -150px;
  animation-delay: 0s;
}
.orb-2 {
  width: 400px;
  height: 400px;
  background: radial-gradient(circle, #06b6d4, transparent 70%);
  bottom: -100px;
  right: -100px;
  animation-delay: -3s;
}
.orb-3 {
  width: 300px;
  height: 300px;
  background: radial-gradient(circle, #8b5cf6, transparent 70%);
  top: 40%;
  left: 60%;
  animation-delay: -5s;
}
@keyframes float {
  0%,
  100% {
    transform: translate(0, 0) scale(1);
  }
  33% {
    transform: translate(20px, -25px) scale(1.05);
  }
  66% {
    transform: translate(-15px, 18px) scale(0.97);
  }
}

/* ===== LAYOUT ===== */
.container {
  width: 100%;
  max-width: 560px;
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* ===== HEADER ===== */
.header {
  text-align: center;
}
.logo {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 1.75rem;
  font-weight: 700;
  background: linear-gradient(
    135deg,
    var(--accent-light) 0%,
    var(--accent-2) 100%
  );
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 0.4rem;
  letter-spacing: -0.02em;
}
.logo-icon {
  width: 2.2rem;
  height: 2.2rem;
  color: var(--accent-light);
  -webkit-text-fill-color: unset;
  flex-shrink: 0;
}
.tagline {
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 400;
}

/* ===== CARD ===== */
.card {
  background: rgba(17, 24, 39, 0.85);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow:
    var(--shadow),
    0 0 0 1px rgba(255, 255, 255, 0.03) inset;
  overflow: hidden;
}

/* ===== TABS ===== */
.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--bg-tab);
  border-bottom: 1px solid var(--border);
  gap: 0;
}
.tab {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 1rem;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition:
    color var(--transition),
    background var(--transition);
  position: relative;
  outline: none;
}
.tab svg {
  width: 1.1rem;
  height: 1.1rem;
  flex-shrink: 0;
}
.tab:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}
.tab-active {
  color: var(--accent-light);
  background: rgba(99, 102, 241, 0.08);
}
.tab-active::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: 2px 2px 0 0;
}
.tab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

/* ===== PANELS ===== */
.panel {
  padding: 1.75rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}
.panel.hidden {
  display: none;
}
.panel-active {
  display: flex;
}

/* ===== FORM ELEMENTS ===== */
.section-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}
.section-label svg {
  width: 0.9rem;
  height: 0.9rem;
}
.input-wrapper {
  position: relative;
}
.textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.95rem;
  line-height: 1.6;
  padding: 0.9rem 1rem 2rem;
  resize: vertical;
  min-height: 120px;
  transition:
    border-color var(--transition),
    box-shadow var(--transition);
  outline: none;
}
.textarea::placeholder {
  color: var(--text-dim);
}
.textarea:focus {
  border-color: var(--border-accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.char-counter {
  position: absolute;
  bottom: 0.6rem;
  right: 0.75rem;
  font-size: 0.72rem;
  color: var(--text-dim);
  pointer-events: none;
}

/* ===== BUTTONS ===== */
.btn-group {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.7rem 1.3rem;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.92rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all var(--transition);
  outline: none;
  white-space: nowrap;
  position: relative;
  overflow: hidden;
}
.btn svg {
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
}
.btn::before {
  content: "";
  position: absolute;
  inset: 0;
  background: white;
  opacity: 0;
  transition: opacity 0.15s;
}
.btn:active::before {
  opacity: 0.07;
}
.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent) 0%, #4f46e5 100%);
  color: white;
  box-shadow: 0 4px 15px rgba(99, 102, 241, 0.35);
  flex: 1;
}
.btn-primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.5);
}
.btn-primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

.btn-ghost {
  background: var(--bg-input);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover {
  color: var(--text);
  border-color: rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.07);
}

.btn-danger {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid rgba(244, 63, 94, 0.3);
  flex: 1;
}
.btn-danger:hover {
  background: rgba(244, 63, 94, 0.22);
  box-shadow: 0 0 12px rgba(244, 63, 94, 0.2);
}

.btn-download {
  width: 100%;
  justify-content: center;
  background: linear-gradient(135deg, #059669, #0d9488);
  color: white;
  box-shadow: 0 4px 14px rgba(5, 150, 105, 0.3);
  padding: 0.8rem 1.5rem;
}
.btn-download:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(5, 150, 105, 0.45);
}

.btn-sm {
  padding: 0.5rem 0.9rem;
  font-size: 0.85rem;
}

/* ===== QR OUTPUT ===== */
.qr-output {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  animation: fadeSlideIn 0.4s ease;
}
.qr-output.hidden {
  display: none;
}
.qr-card {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}
.qr-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  text-align: center;
}
.qr-label svg {
  width: 0.9rem;
  height: 0.9rem;
  flex-shrink: 0;
}
.qr-canvas-wrapper {
  background: white;
  border-radius: 12px;
  padding: 16px;
  display: inline-block;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
  line-height: 0;
}
.qr-canvas-wrapper canvas,
.qr-canvas-wrapper img {
  display: block;
  border-radius: 4px;
}
.qr-meta {
  font-size: 0.78rem;
  color: var(--text-dim);
  text-align: center;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0 0.5rem;
}

/* ===== SCANNER ===== */
.scan-info {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: rgba(6, 182, 212, 0.08);
  border: 1px solid rgba(6, 182, 212, 0.2);
  border-radius: var(--radius-sm);
  padding: 0.8rem 1rem;
  font-size: 0.88rem;
  color: var(--accent-2);
}
.scan-info svg {
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
}
.scanner-wrapper {
  position: relative;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  background: #000;
}
.scanner-wrapper.hidden {
  display: none;
}

/* Override html5-qrcode default styles */
#qr-reader {
  border: none !important;
  width: 100% !important;
}
#qr-reader video {
  width: 100% !important;
  object-fit: cover !important;
  border-radius: 0 !important;
}
#qr-reader__scan_region {
  border: none !important;
}
#qr-reader__dashboard {
  display: none !important;
}
#qr-reader__header_message {
  display: none !important;
}

.scan-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.scan-corner {
  position: absolute;
  width: 28px;
  height: 28px;
  border-color: var(--accent-light);
  border-style: solid;
  border-width: 0;
}
.scan-corner.tl {
  top: 20px;
  left: 20px;
  border-top-width: 3px;
  border-left-width: 3px;
  border-radius: 4px 0 0 0;
}
.scan-corner.tr {
  top: 20px;
  right: 20px;
  border-top-width: 3px;
  border-right-width: 3px;
  border-radius: 0 4px 0 0;
}
.scan-corner.bl {
  bottom: 20px;
  left: 20px;
  border-bottom-width: 3px;
  border-left-width: 3px;
  border-radius: 0 0 0 4px;
}
.scan-corner.br {
  bottom: 20px;
  right: 20px;
  border-bottom-width: 3px;
  border-right-width: 3px;
  border-radius: 0 0 4px 0;
}
.scan-line {
  position: absolute;
  left: 20px;
  right: 20px;
  height: 2px;
  background: linear-gradient(
    90deg,
    transparent,
    var(--accent-light),
    transparent
  );
  top: 20px;
  animation: scanLine 2.5s ease-in-out infinite;
  border-radius: 2px;
}
@keyframes scanLine {
  0% {
    top: 20px;
    opacity: 0;
  }
  10% {
    opacity: 1;
  }
  90% {
    opacity: 1;
  }
  100% {
    top: calc(100% - 20px);
    opacity: 0;
  }
}

/* ===== SCAN RESULT ===== */
.scan-result {
  background: rgba(16, 185, 129, 0.06);
  border: 1px solid rgba(16, 185, 129, 0.25);
  border-radius: var(--radius-sm);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  animation: fadeSlideIn 0.4s ease;
}
.scan-result.hidden {
  display: none;
}
.result-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  color: var(--success);
  font-size: 0.92rem;
}
.result-icon {
  width: 1.2rem;
  height: 1.2rem;
  background: var(--success);
  border-radius: 50%;
  padding: 3px;
  color: white;
  flex-shrink: 0;
}
.result-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}
.result-text {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.85rem 1rem;
  font-size: 0.93rem;
  line-height: 1.6;
  color: var(--text);
  word-break: break-all;
  max-height: 140px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.result-actions {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

/* ===== SCAN ERROR ===== */
.scan-error {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: rgba(244, 63, 94, 0.08);
  border: 1px solid rgba(244, 63, 94, 0.25);
  border-radius: var(--radius-sm);
  padding: 0.9rem 1rem;
  font-size: 0.88rem;
  color: var(--danger);
}
.scan-error svg {
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
}
.scan-error.hidden {
  display: none;
}

/* ===== FOOTER ===== */
.footer {
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.sep {
  opacity: 0.4;
}

/* ===== TOAST ===== */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(30px);
  background: rgba(30, 41, 59, 0.95);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.75rem 1.5rem;
  border-radius: 100px;
  font-size: 0.88rem;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: all 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 9999;
  white-space: nowrap;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===== ANIMATIONS ===== */
@keyframes fadeSlideIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar {
  width: 5px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 10px;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 480px) {
  body {
    padding: 1rem 0.75rem 3rem;
  }
  .panel {
    padding: 1.25rem;
  }
  .logo {
    font-size: 1.5rem;
  }
  .btn-group {
    flex-direction: column;
  }
  .btn-primary,
  .btn-danger {
    flex: unset;
    width: 100%;
    justify-content: center;
  }
}
