/* ── Reset & Base ─────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --clr-bg:       #0f172a;
  --clr-surface:  #1e293b;
  --clr-surface2: #334155;
  --clr-accent:   #38bdf8;
  --clr-accent2:  #818cf8;
  --clr-danger:   #f87171;
  --clr-warn:     #fbbf24;
  --clr-success:  #34d399;
  --clr-text:     #f1f5f9;
  --clr-muted:    #94a3b8;
  --radius:       12px;
  --radius-sm:    8px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

html, body {
  height: 100%;
  height: 100dvh;
  font-family: var(--font);
  background: var(--clr-bg);
  color: var(--clr-text);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  height: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.hidden { display: none !important; }

/* ── Header ──────────────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: var(--clr-surface);
  border-bottom: 1px solid var(--clr-surface2);
  position: sticky;
  top: 0;
  z-index: 50;
}
.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.header-icon {
  width: 32px;
  height: 32px;
  color: var(--clr-accent);
}
.header-title {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.header-subtitle {
  font-size: 0.7rem;
  color: var(--clr-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.btn-icon {
  background: none;
  border: none;
  color: var(--clr-muted);
  cursor: pointer;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background 0.2s;
}
.btn-icon:hover { background: var(--clr-surface2); }
.btn-icon svg { width: 20px; height: 20px; }

/* ── Camera / Scanner ────────────────────────────── */
.scanner-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;          /* allow flex child to shrink below content size */
  overflow: hidden;
}

.camera-container {
  position: relative;
  flex: 1;
  background: #000;
  overflow: hidden;
  min-height: 0;          /* shrink to fit within viewport */
}
.camera-container video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scan-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.scan-frame {
  width: 260px;
  height: 160px;
  position: relative;
}
.corner {
  position: absolute;
  width: 24px;
  height: 24px;
  border-color: var(--clr-accent);
  border-style: solid;
  border-width: 0;
}
.corner.tl { top: 0; left: 0;   border-top-width: 3px; border-left-width: 3px; border-radius: 4px 0 0 0; }
.corner.tr { top: 0; right: 0;  border-top-width: 3px; border-right-width: 3px; border-radius: 0 4px 0 0; }
.corner.bl { bottom: 0; left: 0;  border-bottom-width: 3px; border-left-width: 3px; border-radius: 0 0 0 4px; }
.corner.br { bottom: 0; right: 0; border-bottom-width: 3px; border-right-width: 3px; border-radius: 0 0 4px 0; }

@keyframes pulse-frame {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}
.scanning .scan-frame .corner {
  animation: pulse-frame 1.2s ease-in-out infinite;
  border-color: var(--clr-warn);
}

.scan-hint {
  margin-top: 18px;
  font-size: 0.85rem;
  color: var(--clr-muted);
  text-align: center;
  text-shadow: 0 1px 4px rgba(0,0,0,0.8);
}

.scanner-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  background: var(--clr-surface);
  border-top: 1px solid var(--clr-surface2);
}

/* Auto-scan status indicator */
.scan-status {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--clr-muted);
}
.scan-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--clr-success);
  animation: pulse-dot 1.5s ease-in-out infinite;
}
@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ── Buttons ─────────────────────────────────────── */
.btn-primary {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 20px;
  border: none;
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--clr-accent), var(--clr-accent2));
  color: #fff;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
}
.btn-primary:active { transform: scale(0.97); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-svg { width: 18px; height: 18px; }

.btn-secondary {
  width: 52px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--clr-surface2);
  border-radius: var(--radius);
  background: var(--clr-surface);
  color: var(--clr-muted);
  cursor: pointer;
  transition: background 0.2s;
}
.btn-secondary svg { width: 20px; height: 20px; }
.btn-secondary:hover { background: var(--clr-surface2); }

.btn-full { width: 100%; }

/* ── Processing ──────────────────────────────────── */
.processing-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 40px 20px;
}

.processing-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--clr-surface2);
  border-top-color: var(--clr-accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.processing-text {
  color: var(--clr-muted);
  font-size: 0.95rem;
}

/* ── Results ─────────────────────────────────────── */
.results-section {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  min-height: 0;
}

.result-card {
  background: var(--clr-surface);
  border-radius: var(--radius);
  padding: 24px 20px;
}

.result-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
}
.result-badge {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--clr-accent), var(--clr-accent2));
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.result-badge svg { width: 24px; height: 24px; color: #fff; }

.result-name {
  font-size: 1.3rem;
  font-weight: 700;
}
.result-dosage {
  font-size: 0.85rem;
  color: var(--clr-accent);
  font-weight: 600;
}

/* Tags */
.result-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}
.tag {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
}
.tag-otc      { background: rgba(52,211,153,0.15); color: var(--clr-success); }
.tag-nsaid    { background: rgba(56,189,248,0.15); color: var(--clr-accent); }
.tag-warning  { background: rgba(248,113,113,0.15); color: var(--clr-danger); }

/* Info blocks */
.info-block {
  margin-bottom: 18px;
}
.info-block h3 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--clr-muted);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.info-block p {
  font-size: 0.92rem;
  line-height: 1.55;
  color: var(--clr-text);
}
.inline-icon { width: 16px; height: 16px; }

.warning-block {
  background: rgba(248,113,113,0.08);
  border-left: 3px solid var(--clr-danger);
  padding: 12px 14px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.warning-block h3 { color: var(--clr-danger); }

.disclaimer {
  margin-top: 20px;
  margin-bottom: 20px;
  padding: 10px 12px;
  background: var(--clr-surface2);
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  color: var(--clr-muted);
  line-height: 1.5;
}

/* ── Modal ───────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.6);
}
.modal-content {
  position: relative;
  width: 100%;
  max-width: 480px;
  background: var(--clr-surface);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 28px 24px;
}
.modal-content h2 {
  font-size: 1.15rem;
  margin-bottom: 12px;
}
.modal-content p {
  font-size: 0.9rem;
  color: var(--clr-muted);
  line-height: 1.5;
  margin-bottom: 12px;
}

/* ── Desktop Gate ─────────────────────────────────── */
.desktop-gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  background:
    radial-gradient(ellipse at 30% 20%, rgba(56,189,248,0.08) 0%, transparent 60%),
    radial-gradient(ellipse at 70% 80%, rgba(129,140,248,0.08) 0%, transparent 60%),
    var(--clr-bg);
}

.gate-card {
  max-width: 420px;
  width: 100%;
  text-align: center;
}

.gate-brand {
  margin-bottom: 32px;
}
.gate-logo {
  width: 48px;
  height: 48px;
  color: var(--clr-accent);
  margin-bottom: 12px;
}
.gate-title {
  font-size: 2.2rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  background: linear-gradient(135deg, var(--clr-accent), var(--clr-accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.gate-subtitle {
  display: block;
  font-size: 0.8rem;
  color: var(--clr-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-top: 2px;
}

.gate-phone-icon {
  margin: 0 auto 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--clr-surface);
  display: flex;
  align-items: center;
  justify-content: center;
}
.gate-phone-icon svg {
  width: 28px;
  height: 28px;
  color: var(--clr-accent);
}

.gate-heading {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 10px;
}

.gate-description {
  font-size: 0.95rem;
  color: var(--clr-muted);
  line-height: 1.6;
  margin-bottom: 32px;
}

.gate-qr-wrapper {
  display: inline-flex;
  padding: 20px;
  background: var(--clr-surface);
  border-radius: var(--radius);
  border: 1px solid var(--clr-surface2);
  margin-bottom: 16px;
}
.gate-qr-wrapper canvas {
  display: block;
  border-radius: 4px;
}

.gate-url {
  font-size: 0.8rem;
  color: var(--clr-accent);
  word-break: break-all;
  font-family: 'SF Mono', 'Fira Code', monospace;
  margin-bottom: 32px;
}

.gate-disclaimer {
  font-size: 0.75rem;
  color: var(--clr-muted);
  opacity: 0.7;
  line-height: 1.5;
}

/* ── Utilities ───────────────────────────────────── */
@media (min-width: 481px) {
  .camera-container { min-height: 400px; }
}
