:root {
  --bg: #0a0a0f;
  --bg-card: #14141f;
  --bg-card-hover: #1a1a2e;
  --bg-input: #1e1e30;
  --border: #2a2a3e;
  --text: #e4e4ed;
  --text-dim: #8888a0;
  --text-muted: #5a5a72;
  --purple: #7c3aed;
  --purple-glow: #8b5cf6;
  --green: #10b981;
  --green-bg: rgba(16, 185, 129, 0.12);
  --yellow: #f59e0b;
  --yellow-bg: rgba(245, 158, 11, 0.12);
  --orange: #f97316;
  --orange-bg: rgba(249, 115, 22, 0.12);
  --red: #ef4444;
  --red-bg: rgba(239, 68, 68, 0.12);
  --pink: #ec4899;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

/* ── Header ──────────────────────────────────────────────── */

header {
  padding: 20px 20px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
}

.logo-icon {
  width: 40px; height: 40px;
  background: linear-gradient(135deg, var(--purple), #a855f7);
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  box-shadow: 0 0 20px rgba(124, 58, 237, 0.3);
}

.logo h1 {
  font-size: 18px; font-weight: 700;
  letter-spacing: -0.3px;
}

.logo span {
  display: block;
  font-size: 11px; font-weight: 400;
  color: var(--text-dim);
}

.nav-btn {
  width: 40px; height: 40px;
  border-radius: 12px; border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s;
}

.nav-btn:hover, .nav-btn.active {
  background: var(--bg-card-hover);
  color: var(--text);
  border-color: var(--purple);
}

/* ── Tabs ─────────────────────────────────────────────────── */

.tabs { padding: 16px 20px; display: flex; gap: 6px; }

.tab {
  flex: 1;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  font-size: 13px; font-weight: 500; font-family: var(--font);
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
}

.tab.active {
  background: var(--purple);
  border-color: var(--purple);
  color: #fff;
  box-shadow: 0 0 16px rgba(124, 58, 237, 0.25);
}

.tab:hover:not(.active) {
  background: var(--bg-card);
  color: var(--text);
}

/* ── Main ─────────────────────────────────────────────────── */

main { padding: 12px 20px 100px; max-width: 600px; margin: 0 auto; }

.tab-content { animation: fadeIn 0.2s ease-out; }

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ── Scanner View ─────────────────────────────────────────── */

.scanner-box {
  background: #000;
  border-radius: var(--radius);
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
  overflow: hidden;
  aspect-ratio: 4/3;
  max-height: 340px;
}

.scanner-box.idle {
  background: var(--bg-card);
  border: 2px dashed var(--border);
  display: flex; align-items: center; justify-content: center;
}

.scanner-box.idle:hover { border-color: var(--purple); background: var(--bg-card-hover); }

.scanner-box.active {
  border: none;
}

.scanner-box video {
  position: absolute; inset: 0;
  width: 100%; height: 100%; object-fit: cover;
  border-radius: var(--radius);
}

/* Laser scan line */
.scan-laser {
  position: absolute; left: 10%; right: 10%;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--red), transparent);
  box-shadow: 0 0 8px var(--red), 0 0 20px rgba(239,68,68,0.4);
  animation: laserSweep 2s ease-in-out infinite;
  z-index: 2;
  pointer-events: none;
}

@keyframes laserSweep {
  0%, 100% { top: 20%; }
  50% { top: 80%; }
}

/* Corner guides */
.scanner-corners {
  position: absolute;
  top: 12%; left: 8%; right: 8%; bottom: 12%;
  z-index: 2;
  pointer-events: none;
}

.scanner-corners::before,
.scanner-corners::after {
  content: '';
  position: absolute;
  width: 24px; height: 24px;
  border-color: var(--purple);
  border-style: solid;
}

.scanner-corners::before {
  top: 0; left: 0;
  border-width: 3px 0 0 3px;
  border-radius: 4px 0 0 0;
}

.scanner-corners::after {
  top: 0; right: 0;
  border-width: 3px 3px 0 0;
  border-radius: 0 4px 0 0;
}

/* Bottom corners */
.scanner-corners-bottom {
  position: absolute;
  top: 12%; left: 8%; right: 8%; bottom: 12%;
  z-index: 2;
  pointer-events: none;
}

.scanner-corners-bottom::before,
.scanner-corners-bottom::after {
  content: '';
  position: absolute;
  width: 24px; height: 24px;
  border-color: var(--purple);
  border-style: solid;
}

.scanner-corners-bottom::before {
  bottom: 0; left: 0;
  border-width: 0 0 3px 3px;
  border-radius: 0 0 0 4px;
}

.scanner-corners-bottom::after {
  bottom: 0; right: 0;
  border-width: 0 3px 3px 0;
  border-radius: 0 0 4px 0;
}

/* Scanner hint text */
.scanner-hint {
  position: absolute; bottom: 16px; left: 0; right: 0;
  text-align: center;
  font-size: 12px; font-weight: 500;
  color: rgba(255,255,255,0.7);
  text-shadow: 0 0 8px rgba(0,0,0,0.8);
  z-index: 2;
  pointer-events: none;
}

/* Barcode detection ping */
.scanner-ping {
  position: absolute; inset: 0;
  z-index: 3;
  pointer-events: none;
  display: flex; align-items: center; justify-content: center;
}

.scanner-ping::after {
  content: '✓';
  font-size: 48px;
  color: var(--green);
  background: rgba(0,0,0,0.7);
  width: 80px; height: 80px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  animation: pingPop 0.4s ease-out;
  border: 3px solid var(--green);
  box-shadow: 0 0 30px rgba(16,185,129,0.5);
}

@keyframes pingPop {
  0% { transform: scale(0.3); opacity: 0; }
  50% { transform: scale(1.1); }
  100% { transform: scale(1); opacity: 1; }
}

/* Flashlight & controls */
.scanner-toolbar {
  position: absolute; top: 12px; right: 12px;
  display: flex; gap: 8px;
  z-index: 3;
}

.scanner-toolbar button {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(8px);
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s;
}

.scanner-toolbar button:hover {
  background: rgba(0,0,0,0.7);
}

.scanner-toolbar button.flashlight-on {
  background: rgba(255,200,50,0.3);
  color: #ffc832;
  box-shadow: 0 0 12px rgba(255,200,50,0.3);
}

/* Override old scan region */
.scanner-box .scan-region { display: none; }

/* ── Manual Input ─────────────────────────────────────────── */

.manual-input {
  margin-top: 16px;
  display: flex; gap: 10px;
}

.manual-input input {
  flex: 1;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  font-size: 15px; font-family: var(--font);
  outline: none;
  transition: border-color 0.2s;
}

.manual-input input:focus { border-color: var(--purple); }
.manual-input input::placeholder { color: var(--text-muted); }

.manual-input button {
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--purple);
  color: #fff;
  font-size: 14px; font-weight: 600; font-family: var(--font);
  cursor: pointer;
  transition: all 0.2s;
}

.manual-input button:hover { background: var(--purple-glow); }

/* ── Search View ──────────────────────────────────────────── */

.search-box {
  display: flex; gap: 10px; margin-bottom: 16px;
}

.search-box input {
  flex: 1;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  font-size: 15px; font-family: var(--font);
  outline: none;
}

.search-box input:focus { border-color: var(--purple); }

.search-box button {
  padding: 14px 24px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--purple);
  color: #fff;
  font-size: 14px; font-weight: 600; font-family: var(--font);
  cursor: pointer;
}

.search-results { display: flex; flex-direction: column; gap: 8px; }

.search-result {
  display: flex; gap: 12px; align-items: center;
  padding: 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  cursor: pointer;
  transition: all 0.2s;
}

.search-result:hover { border-color: var(--purple); background: var(--bg-card-hover); }

.search-result img {
  width: 48px; height: 48px;
  border-radius: 8px;
  background: var(--bg-input);
  object-fit: cover;
  flex-shrink: 0;
}

.search-result .info { flex: 1; min-width: 0; }
.search-result .name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-result .brand { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.search-result .has-ingredients { font-size: 11px; color: var(--green); margin-top: 2px; }

/* ── Photo Scan View ──────────────────────────────────────── */

.photo-area {
  background: var(--bg-card);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 48px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  min-height: 250px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}

.photo-area:hover { border-color: var(--purple); }

.photo-area img {
  max-width: 100%; max-height: 300px;
  border-radius: var(--radius-sm);
}

.photo-area .icon { font-size: 48px; margin-bottom: 12px; }

.photo-area h3 { font-size: 16px; margin-bottom: 4px; }
.photo-area p { font-size: 13px; color: var(--text-dim); }

/* ── Results Card ─────────────────────────────────────────── */

.result-card {
  margin-top: 20px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-card);
  overflow: hidden;
  animation: slideUp 0.3s ease-out;
}

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

.result-header {
  padding: 20px;
  display: flex; gap: 16px;
  align-items: flex-start;
}

.result-header img {
  width: 80px; height: 80px;
  border-radius: 12px;
  background: var(--bg-input);
  object-fit: cover;
  flex-shrink: 0;
}

.result-header .meta { flex: 1; }
.result-header .product-name { font-size: 18px; font-weight: 700; letter-spacing: -0.3px; }
.result-header .product-brand { font-size: 13px; color: var(--text-dim); margin-top: 2px; }
.result-header .product-category { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

/* Grade badge */
.grade {
  display: inline-flex; align-items: center; justify-content: center;
  width: 64px; height: 64px;
  border-radius: 50%;
  font-size: 32px; font-weight: 800;
  flex-shrink: 0;
}

.grade-a { background: var(--green-bg); color: var(--green); border: 2px solid var(--green); }
.grade-b { background: var(--green-bg); color: var(--green); border: 2px solid var(--green); opacity: 0.8; }
.grade-c { background: var(--yellow-bg); color: var(--yellow); border: 2px solid var(--yellow); }
.grade-d { background: var(--orange-bg); color: var(--orange); border: 2px solid var(--orange); }
.grade-f { background: var(--red-bg); color: var(--red); border: 2px solid var(--red); }

.score-bar {
  margin: 0 20px 8px;
  height: 6px; border-radius: 3px;
  background: var(--bg-input);
  overflow: hidden;
}

.score-fill {
  height: 100%; border-radius: 3px;
  transition: width 0.6s ease-out;
}

.score-label {
  margin: 0 20px 16px;
  font-size: 13px; font-weight: 600;
}

/* Summary */
.result-summary {
  margin: 0 20px 16px;
  padding: 14px;
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-dim);
  font-style: italic;
}

/* Key ingredients */
.section-title {
  margin: 0 20px 10px;
  font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 1px; color: var(--text-muted);
}

.ingredient-list {
  margin: 0 20px 16px;
  display: flex; flex-direction: column; gap: 8px;
}

.ingredient-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--bg-input);
}

.ingredient-item .dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
}

.ingredient-item .dot.risk-low { background: var(--green); }
.ingredient-item .dot.risk-moderate { background: var(--yellow); }
.ingredient-item .dot.risk-high { background: var(--red); }

.ingredient-item .ing-name { font-size: 13px; font-weight: 600; }
.ingredient-item .ing-func { font-size: 11px; color: var(--text-dim); }
.ingredient-item .ing-note { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* Tags */
.tag-row {
  margin: 0 20px 12px;
  display: flex; flex-wrap: wrap; gap: 6px;
}

.tag {
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 11px; font-weight: 500;
}

.tag-good { background: var(--green-bg); color: var(--green); }
.tag-bad { background: var(--red-bg); color: var(--red); }
.tag-warn { background: var(--yellow-bg); color: var(--yellow); }
.tag-allergen { background: rgba(236, 72, 153, 0.12); color: var(--pink); }

/* Full ingredients */
.ingredients-full {
  margin: 0 20px 16px;
  padding: 14px;
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  font-size: 12px;
  line-height: 1.7;
  color: var(--text-dim);
  max-height: 200px;
  overflow-y: auto;
}

/* Conflicts */
.conflict-box {
  margin: 0 20px 16px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--red-bg);
  border: 1px solid rgba(239,68,68,0.3);
}

.conflict-box .cf-title {
  font-size: 12px; font-weight: 700; color: var(--red);
  text-transform: uppercase; letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.conflict-box .cf-item {
  font-size: 13px; color: var(--text-dim);
}

/* ── Spinner ──────────────────────────────────────────────── */

.spinner {
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  padding: 40px 20px;
}

.spinner-ring {
  width: 40px; height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--purple);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.spinner-text { font-size: 14px; color: var(--text-dim); }

/* ── Error ────────────────────────────────────────────────── */

.error-card {
  margin-top: 20px;
  padding: 16px;
  border-radius: var(--radius-sm);
  background: var(--red-bg);
  border: 1px solid rgba(239,68,68,0.3);
  color: var(--red);
  font-size: 14px;
}

/* ── Toast ────────────────────────────────────────────────── */

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  padding: 12px 20px;
  border-radius: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow);
  z-index: 1000;
  animation: toastIn 0.3s ease-out;
  max-width: 90vw;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(20px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ── History ──────────────────────────────────────────────── */

.history-item {
  padding: 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  margin-bottom: 8px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex; align-items: center; gap: 10px;
}

.history-item:hover { border-color: var(--purple); }
.history-item .scan-type { font-size: 11px; color: var(--text-muted); }
.history-item .scan-name { font-size: 14px; font-weight: 600; }

/* ── Empty State ──────────────────────────────────────────── */

.empty-state {
  text-align: center; padding: 40px 20px;
}

.empty-state .icon { font-size: 48px; margin-bottom: 12px; opacity: 0.5; }
.empty-state h3 { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.empty-state p { font-size: 13px; color: var(--text-dim); }

/* ── Ingredient Detail Panel ──────────────────────────────── */

.ingredient-panel {
  position: fixed; inset: 0; z-index: 999;
  display: flex; align-items: flex-end;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s ease-out;
}

.ingredient-panel.open {
  opacity: 1;
  pointer-events: auto;
}

.ingredient-panel-overlay {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
}

.ingredient-panel-card {
  position: relative;
  width: 100%; max-height: 80dvh;
  background: var(--bg-card);
  border-radius: var(--radius) var(--radius) 0 0;
  border-top: 1px solid var(--border);
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform 0.3s ease-out;
}

.ingredient-panel.open .ingredient-panel-card {
  transform: translateY(0);
}

.ingredient-panel-header {
  display: flex; justify-content: flex-end;
  padding: 12px 16px;
  position: sticky; top: 0;
  background: var(--bg-card);
  z-index: 1;
}

.ingredient-panel-close {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-dim);
  font-size: 16px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s;
}

.ingredient-panel-close:hover {
  background: var(--bg-card-hover);
  color: var(--text);
}

/* Detail content */
.ingredient-detail {
  padding: 8px 20px 32px;
}

.ingredient-detail-name {
  font-size: 24px; font-weight: 700;
  letter-spacing: -0.5px;
  margin-bottom: 4px;
}

.ingredient-detail-risk {
  font-size: 11px; font-weight: 700;
  letter-spacing: 1.5px;
  margin-bottom: 20px;
}

.ingredient-detail-meta {
  display: flex; flex-direction: column; gap: 8px;
  margin-bottom: 16px;
}

.detail-row {
  display: flex; justify-content: space-between;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--bg-input);
}

.detail-label {
  font-size: 12px; font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.5px;
}

.detail-value {
  font-size: 13px; font-weight: 500;
}

.ingredient-detail-desc {
  padding: 14px;
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-dim);
  margin-bottom: 20px;
  font-style: italic;
}

.detail-section-title {
  font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.detail-products {
  display: flex; flex-direction: column; gap: 8px;
}

.detail-product-item {
  display: flex; gap: 10px; align-items: center;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-input);
  cursor: pointer;
  transition: all 0.15s;
}

.detail-product-item:hover {
  border-color: var(--purple);
  background: var(--bg-card-hover);
}

.detail-product-item img,
.detail-product-img-placeholder {
  width: 36px; height: 36px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--bg-card);
}

.detail-product-info { flex: 1; min-width: 0; }
.detail-product-name {
  font-size: 13px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.detail-product-brand {
  font-size: 11px; color: var(--text-dim);
}

.detail-no-products {
  padding: 20px;
  text-align: center;
  font-size: 13px; color: var(--text-muted);
}

/* Make ingredients look clickable */
.ingredient-item {
  cursor: pointer;
  transition: all 0.15s;
}

.ingredient-item:hover {
  background: var(--bg-card-hover);
  border: 1px solid var(--purple);
  margin: -1px;
}

.ingredient-item::after {
  content: '→';
  margin-left: auto;
  color: var(--text-muted);
  font-size: 14px;
  opacity: 0;
  transition: opacity 0.15s;
}

.ingredient-item:hover::after {
  opacity: 1;
}

/* ── Profile Tab ──────────────────────────────────────────── */

.profile-section {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  margin-bottom: 12px;
  overflow: hidden;
}

.profile-section-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 16px;
  font-size: 14px; font-weight: 600;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}

.profile-section-header:hover { background: var(--bg-card-hover); }

.profile-section-toggle {
  font-size: 10px; color: var(--text-muted);
  transition: transform 0.2s;
}

.profile-section.collapsed .profile-section-toggle { transform: rotate(-90deg); }
.profile-section.collapsed .profile-section-body { display: none; }

.profile-section-body { padding: 0 16px 16px; }

.profile-summary {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin-bottom: 12px;
}

.profile-tag {
  padding: 6px 12px;
  border-radius: 8px;
  background: var(--purple);
  color: #fff;
  font-size: 12px; font-weight: 500;
  text-transform: capitalize;
}

.profile-btn {
  padding: 10px 16px;
  border-radius: 10px;
  border: none;
  background: var(--purple);
  color: #fff;
  font-size: 13px; font-weight: 600; font-family: var(--font);
  cursor: pointer;
  transition: all 0.15s;
}

.profile-btn:hover { background: var(--purple-glow); }

.quiz-question { font-size: 15px; font-weight: 600; margin-bottom: 10px; }

.quiz-options { display: flex; flex-direction: column; gap: 6px; }

.quiz-option {
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  cursor: pointer;
  transition: all 0.15s;
}

.quiz-option:hover { border-color: var(--purple); background: var(--bg-card-hover); }

.quiz-option-label { font-size: 14px; font-weight: 500; display: flex; align-items: center; gap: 8px; }

.quiz-check {
  width: 20px; height: 20px;
  border-radius: 6px;
  border: 2px solid var(--border);
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s;
}

.quiz-option.selected .quiz-check {
  background: var(--purple);
  border-color: var(--purple);
}

.quiz-option.selected .quiz-check::after {
  content: '✓';
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}

.quiz-option.selected {
  border-color: var(--purple) !important;
  background: rgba(124,58,237,0.15) !important;
  box-shadow: 0 0 0 1px var(--purple);
}

.quiz-option-desc { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

.allergen-list { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }

.allergen-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--red-bg);
  border: 1px solid rgba(239,68,68,0.3);
  font-size: 12px;
}

.allergen-severity {
  font-size: 9px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.5px;
  padding: 1px 5px; border-radius: 4px;
}

.severity-mild { background: var(--yellow-bg); color: var(--yellow); }
.severity-moderate { background: var(--orange-bg); color: var(--orange); }
.severity-severe { background: var(--red-bg); color: var(--red); }

.allergen-remove {
  width: 18px; height: 18px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.1);
  color: var(--text-muted);
  font-size: 10px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}

.add-allergen-row { display: flex; gap: 6px; }

.add-allergen-row input {
  flex: 1;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  font-size: 16px;
  font-family: var(--font);
  outline: none;
  -webkit-appearance: none;
}

.add-allergen-row input::placeholder {
  color: var(--text-muted);
  font-size: 14px;
}

.add-allergen-row input:focus { border-color: var(--purple); }

.add-allergen-row select {
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  font-size: 12px; font-family: var(--font);
}

.product-shelf { display: flex; flex-direction: column; gap: 6px; }

.shelf-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--bg-input);
}

.shelf-item img, .shelf-img-placeholder {
  width: 36px; height: 36px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
}

.shelf-img-placeholder {
  background: var(--bg-card);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
}

.shelf-info { flex: 1; min-width: 0; }
.shelf-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.shelf-brand { font-size: 11px; color: var(--text-dim); }

.shelf-status {
  font-size: 10px; font-weight: 600;
  padding: 3px 8px; border-radius: 6px;
  text-transform: uppercase; letter-spacing: 0.5px;
  flex-shrink: 0;
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
}

.shelf-status:hover {
  filter: brightness(1.3);
  transform: scale(1.05);
}

.status-using { background: var(--green-bg); color: var(--green); }
.status-used { background: var(--bg-input); color: var(--text-dim); }
.status-want_to_try { background: var(--yellow-bg); color: var(--yellow); }

.shelf-remove {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 11px;
  cursor: pointer;
}

.reaction-timeline { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }

.reaction-item {
  padding: 12px;
  border-radius: 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
}

.reaction-header { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }

.reaction-type { font-size: 13px; font-weight: 600; }

.reaction-severity {
  font-size: 9px; font-weight: 700;
  padding: 1px 6px; border-radius: 4px;
  text-transform: uppercase;
}

.reaction-date { font-size: 11px; color: var(--text-muted); margin-left: auto; }
.reaction-product { font-size: 12px; color: var(--text-dim); margin-bottom: 4px; }
.reaction-notes { font-size: 13px; color: var(--text-dim); font-style: italic; }
.reaction-photo { max-width: 100%; border-radius: 8px; margin-top: 8px; }

.reaction-remove {
  margin-top: 6px;
  font-size: 11px;
  color: var(--text-muted);
  background: none; border: none;
  cursor: pointer;
}

.reaction-form input, .reaction-form select, .reaction-form textarea {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  font-size: 13px; font-family: var(--font);
  outline: none;
  width: 100%;
}

.reaction-form input:focus, .reaction-form select:focus, .reaction-form textarea:focus {
  border-color: var(--purple);
}

@media (max-width: 400px) {
  .result-header { flex-direction: column; align-items: center; text-align: center; }
  .result-header .meta { text-align: center; }
}

/* ── Autofill Dropdown ────────────────────────────────────── */

.autofill-dropdown {
  position: absolute; top: 100%; left: 0; right: 0;
  margin-top: 4px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  max-height: 320px;
  overflow-y: auto;
  z-index: 100;
  box-shadow: var(--shadow);
}

.autofill-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  cursor: pointer;
  transition: background 0.1s;
  border-bottom: 1px solid var(--border);
}

.autofill-item:last-child { border-bottom: none; }

.autofill-item:hover, .autofill-item.highlighted {
  background: var(--bg-card-hover);
}

.autofill-item img, .autofill-img-placeholder {
  width: 36px; height: 36px;
  border-radius: 6px;
  object-fit: cover;
  flex-shrink: 0;
}

.autofill-img-placeholder { background: var(--bg-input); }

.autofill-info { flex: 1; min-width: 0; }

.autofill-name {
  font-size: 13px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.autofill-brand {
  font-size: 11px; color: var(--text-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.autofill-mark {
  background: rgba(124, 58, 237, 0.25);
  color: var(--purple-glow);
  padding: 1px 2px;
  border-radius: 3px;
}

/* ── Skin Report Dashboard ─────────────────────────────────── */

.skin-report-stats {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}

.skin-report-stat {
  padding: 14px;
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  text-align: center;
}

.skin-report-stat .stat-number {
  font-size: 28px; font-weight: 800;
  letter-spacing: -1px;
}

.skin-report-stat .stat-label {
  font-size: 10px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 1px;
  margin-top: 2px;
}

/* ── Onboarding Overlay ───────────────────────────────────── */

.onboard-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.85);
  backdrop-filter: blur(8px);
  z-index: 999;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  animation: fadeIn 0.3s ease-out;
}

.onboard-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 22px;
  max-width: 400px;
  width: 100%;
  max-height: 90dvh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}

/* ── Phase 4: Skin Journal ──────────────────────────── */

.journal-container { padding: 0 4px; }
.journal-header { text-align: center; padding: 16px 12px 8px; }
.journal-header h2 { font-size: 18px; margin-bottom: 4px; }
.journal-header p { font-size: 13px; color: var(--text-dim); }

.journal-capture-btn { transition: transform 0.15s, opacity 0.15s; }
.journal-capture-btn:active { transform: scale(0.97); opacity: 0.85; }

/* Timeline card */
.timeline-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 12px; padding: 16px; margin-bottom: 12px;
}
.timeline-trend { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.timeline-scores { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-dim); margin-bottom: 10px; }
.timeline-dots { display: flex; align-items: flex-end; gap: 3px; height: 50px; }
.timeline-dot { flex: 1; min-width: 4px; border-radius: 2px 2px 0 0; transition: height 0.3s; }

/* Photo grid */
.journal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; }
.journal-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px; text-align: center; cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
}
.journal-card:hover { border-color: var(--purple); transform: translateY(-2px); }
.journal-card-score { font-size: 28px; font-weight: 800; margin-bottom: 2px; }
.journal-card-date { font-size: 11px; color: var(--text-dim); margin-bottom: 6px; }
.journal-card-metrics { display: flex; flex-wrap: wrap; gap: 3px; justify-content: center; }
.metric { font-size: 10px; background: rgba(124,58,237,0.1); padding: 2px 6px; border-radius: 4px; color: var(--text-dim); }
.journal-card-area { font-size: 10px; color: var(--text-dim); margin-top: 4px; text-transform: capitalize; }

/* Journal modal */
.journal-modal-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,0.8); display: flex; align-items: center; justify-content: center;
  padding: 16px; animation: fadeIn 0.2s;
}
.journal-modal {
  background: var(--bg); border: 1px solid var(--border); border-radius: 16px;
  width: 100%; max-width: 420px; max-height: 90dvh; overflow-y: auto;
  padding: 20px; position: relative;
}
.journal-modal-close {
  position: absolute; top: 12px; right: 12px;
  width: 32px; height: 32px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--bg-card);
  color: var(--text); font-size: 16px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.journal-modal-img {
  width: 100%; border-radius: 12px; margin-bottom: 16px;
  max-height: 280px; object-fit: cover;
}
.journal-modal-meta { margin-bottom: 12px; }
.journal-modal-meta h3 { font-size: 16px; margin-bottom: 4px; }
.journal-modal-score { font-size: 14px; color: var(--text-dim); }
.journal-modal-notes {
  background: rgba(124,58,237,0.08); border-left: 3px solid var(--purple);
  padding: 12px 14px; border-radius: 0 8px 8px 0; font-size: 13px; line-height: 1.6;
  margin-bottom: 12px; color: var(--text);
}
.journal-modal-details { margin-bottom: 12px; }
.detail-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 0; border-bottom: 1px solid rgba(255,255,255,0.04);
  font-size: 12px; gap: 8px;
}
.detail-row span:first-child { color: var(--text-dim); white-space: nowrap; }
.detail-row span:last-child { text-align: right; color: var(--text); font-size: 11px; }
.journal-modal-recs {
  background: rgba(16,185,129,0.08); border: 1px solid rgba(16,185,129,0.15);
  border-radius: 10px; padding: 12px 14px;
}
.journal-modal-recs h4 { font-size: 13px; margin-bottom: 6px; color: var(--success); }
.journal-modal-recs p { font-size: 12px; line-height: 1.5; margin: 4px 0; color: var(--text-dim); }

#journalUploadStatus .spinner {
  width: 24px; height: 24px; border: 3px solid var(--border); border-top-color: var(--purple);
  border-radius: 50%; animation: spin 0.8s linear infinite; margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Phase 4: Dermatologist Report ────────────────────── */

.report-overlay {
  position: fixed; inset: 0; z-index: 2000;
  background: rgba(0,0,0,0.85); overflow-y: auto;
  padding: 16px;
}
.report-page {
  max-width: 700px; margin: 0 auto 16px;
  background: #fff; color: #1a1a2e;
  border-radius: 12px; padding: 40px 36px;
  font-family: 'Georgia', 'Times New Roman', serif;
  line-height: 1.7; box-shadow: 0 8px 40px rgba(0,0,0,0.3);
}
.report-header { text-align: center; border-bottom: 2px solid #7c3aed; padding-bottom: 20px; margin-bottom: 24px; }
.report-logo { font-size: 18px; color: #7c3aed; font-weight: 700; margin-bottom: 8px; }
.report-title { font-size: 22px; font-weight: 700; color: #1a1a2e; margin-bottom: 4px; }
.report-date { font-size: 12px; color: #888; }
.report-disclaimer { font-size: 10px; color: #999; margin-top: 8px; font-style: italic; }

.report-section { margin-bottom: 20px; page-break-inside: avoid; }
.report-section h3 { font-size: 15px; color: #7c3aed; margin-bottom: 10px; font-family: -apple-system, sans-serif; }
.report-section p { font-size: 13px; color: #444; }
.report-section.highlight { background: #f5f0ff; border-left: 4px solid #7c3aed; padding: 14px 16px; border-radius: 0 8px 8px 0; }

.report-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.report-item { padding: 8px 10px; background: #f8f9fa; border-radius: 6px; }
.report-item span { display: block; font-size: 10px; color: #888; text-transform: uppercase; letter-spacing: .5px; }
.report-item strong { font-size: 13px; color: #1a1a2e; }

.report-row { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid #eee; font-size: 12px; }
.report-tag { display: inline-block; background: #fee2e2; color: #dc2626; padding: 2px 8px; border-radius: 4px; font-size: 11px; margin: 2px; }

.report-footer { border-top: 1px solid #e5e5e5; margin-top: 24px; padding-top: 16px; text-align: center; font-size: 11px; color: #999; }

.report-actions { max-width: 700px; margin: 0 auto; display: flex; justify-content: center; gap: 8px; padding-bottom: 24px; }

@media print {
  .report-overlay { position: static; background: #fff; padding: 0; }
  .report-page { box-shadow: none; border-radius: 0; max-width: 100%; }
  .no-print, .journal-modal-overlay, header, .tabs { display: none !important; }
  body { background: #fff; }
}
