:root {
  --bg: #f0fdf4;
  --bg-2: #ecfdf5;
  --card: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --teal: #0f766e;
  --teal-2: #14b8a6;
  --teal-soft: #ccfbf1;
  --good: #15803d;
  --good-bg: #dcfce7;
  --okay: #a16207;
  --okay-bg: #fef9c3;
  --caution: #b91c1c;
  --caution-bg: #fee2e2;
  --border: #d1fae5;
  --shadow: 0 10px 30px rgba(15, 118, 110, 0.08);
  --radius: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: linear-gradient(180deg, var(--bg-2) 0%, var(--bg) 40%, #fff 100%);
  color: var(--ink);
  min-height: 100dvh;
  line-height: 1.45;
}

.app { max-width: 560px; margin: 0 auto; padding: 16px 16px calc(28px + var(--safe-b)); }

.topbar { margin-bottom: 16px; }
.brand { display: flex; gap: 12px; align-items: center; }
.logo {
  width: 48px; height: 48px; border-radius: 14px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--teal), var(--teal-2));
  font-size: 24px; box-shadow: var(--shadow);
}
.brand h1 { margin: 0; font-size: 1.45rem; letter-spacing: -0.02em; }
.tagline { margin: 2px 0 0; color: var(--muted); font-size: 0.9rem; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.card h2 { margin: 0 0 8px; font-size: 1.1rem; }
.hint, .muted { color: var(--muted); font-size: 0.9rem; margin: 0 0 14px; }

.btn {
  appearance: none; border: none; border-radius: 12px;
  padding: 12px 16px; font-weight: 600; font-size: 1rem;
  cursor: pointer; transition: transform .12s ease, opacity .12s ease;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--teal); color: #fff; }
.btn-primary:hover { background: #0d9488; }
.btn-secondary { background: var(--teal-soft); color: var(--teal); }
.btn-block { width: 100%; }

.actions { margin: 8px 0 14px; }

.reader-wrap {
  margin-bottom: 12px;
  border-radius: 14px;
  overflow: hidden;
  background: #0f172a;
}
#reader { width: 100%; }
#reader video {
  width: 100% !important;
  border-radius: 14px;
  object-fit: cover;
}
#btn-stop-scan { margin-top: 8px; border-radius: 0 0 14px 14px; }

.manual-form label {
  display: block; font-size: 0.85rem; font-weight: 600;
  margin-bottom: 6px; color: var(--muted);
}
.row { display: flex; gap: 8px; }
.row input {
  flex: 1; min-width: 0;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 1rem;
  background: #fff;
}
.row input:focus {
  outline: none;
  border-color: var(--teal-2);
  box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.2);
}

.demo-row {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  margin-top: 14px; font-size: 0.85rem; color: var(--muted);
}
.chip {
  border: 1px solid var(--border);
  background: var(--bg-2);
  color: var(--teal);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}
.chip:hover { background: var(--teal-soft); }

.alert {
  border-radius: 12px;
  padding: 12px 14px;
  margin: 10px 0 14px;
  font-size: 0.92rem;
}
.alert-warn { background: var(--okay-bg); color: #854d0e; border: 1px solid #fde047; }
.alert-error { background: var(--caution-bg); color: #991b1b; border: 1px solid #fecaca; }

.status {
  text-align: center;
  padding: 18px;
  margin-bottom: 16px;
  border-radius: var(--radius);
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--muted);
}
.spinner {
  width: 28px; height: 28px; margin: 0 auto 10px;
  border: 3px solid var(--teal-soft);
  border-top-color: var(--teal);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.product .card { margin-bottom: 12px; }

.product-hero {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 14px;
  align-items: start;
}
.product-hero img {
  width: 96px; height: 96px; object-fit: contain;
  background: #f8fafc; border-radius: 12px; border: 1px solid var(--border);
}
.product-hero .placeholder {
  width: 96px; height: 96px; border-radius: 12px;
  background: var(--teal-soft); display: grid; place-items: center; font-size: 2rem;
}
.product-hero h2 { margin: 0 0 4px; font-size: 1.2rem; line-height: 1.25; }
.brand-line { margin: 0; color: var(--muted); font-size: 0.92rem; }
.barcode-line { margin: 6px 0 0; font-size: 0.8rem; color: #94a3b8; font-family: ui-monospace, monospace; }

.verdict {
  display: flex; gap: 12px; align-items: flex-start;
  border-radius: var(--radius);
  padding: 16px;
  border: 1px solid transparent;
  margin-bottom: 12px;
}
.verdict.good { background: var(--good-bg); border-color: #86efac; }
.verdict.okay { background: var(--okay-bg); border-color: #fde047; }
.verdict.caution { background: var(--caution-bg); border-color: #fca5a5; }
.verdict-badge {
  flex-shrink: 0;
  min-width: 72px; text-align: center;
  font-weight: 800; font-size: 0.95rem;
  padding: 10px 8px; border-radius: 12px;
  background: rgba(255,255,255,0.7);
}
.verdict.good .verdict-badge { color: var(--good); }
.verdict.okay .verdict-badge { color: var(--okay); }
.verdict.caution .verdict-badge { color: var(--caution); }
.verdict ul { margin: 6px 0 0; padding-left: 18px; font-size: 0.92rem; }
.verdict h3 { margin: 0; font-size: 1rem; }
.verdict .why { margin: 0; color: var(--muted); font-size: 0.85rem; }

.badges { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 10px; border-radius: 999px;
  font-size: 0.82rem; font-weight: 700;
  background: #f1f5f9; color: #334155;
}
.pill.ns-a, .pill.nova-1 { background: #dcfce7; color: #166534; }
.pill.ns-b { background: #d9f99d; color: #3f6212; }
.pill.ns-c { background: #fef9c3; color: #854d0e; }
.pill.ns-d { background: #ffedd5; color: #9a3412; }
.pill.ns-e { background: #fee2e2; color: #991b1b; }
.pill.nova-2 { background: #e0f2fe; color: #075985; }
.pill.nova-3 { background: #ffedd5; color: #9a3412; }
.pill.nova-4 { background: #fee2e2; color: #991b1b; }
.pill.unknown { background: #f1f5f9; color: #64748b; }

.nutrition-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.nut-item {
  background: var(--bg-2);
  border-radius: 12px;
  padding: 10px 12px;
}
.nut-item .label { display: block; font-size: 0.75rem; color: var(--muted); }
.nut-item .value { font-weight: 700; font-size: 1rem; }
.nut-item.warn { background: #fff7ed; }
.nut-item.goodish { background: #ecfdf5; }

.ingredients {
  white-space: pre-wrap;
  font-size: 0.92rem;
  background: #f8fafc;
  border-radius: 12px;
  padding: 12px;
  border: 1px solid #e2e8f0;
}

.flag-list { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; list-style: none; }
.flag {
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.85rem;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
}
.flag.concern { background: #fee2e2; border-color: #fecaca; color: #991b1b; }
.flag.allergen { background: #ffedd5; border-color: #fed7aa; color: #9a3412; }
.flag.ok { background: #ecfdf5; border-color: #a7f3d0; color: #115e59; }

.section-title { margin: 0 0 10px; font-size: 1rem; }

.history-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 8px;
}
.history-head h2 { margin: 0; }
.linkish {
  background: none; border: none; color: var(--teal);
  font-weight: 600; cursor: pointer; font-size: 0.9rem;
}
.history-list { list-style: none; margin: 0; padding: 0; }
.history-list li {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  gap: 10px; align-items: center;
  padding: 10px 0;
  border-top: 1px solid var(--border);
  cursor: pointer;
}
.history-list li:first-child { border-top: none; }
.history-list img, .history-list .ph {
  width: 48px; height: 48px; border-radius: 10px; object-fit: contain;
  background: #f8fafc; border: 1px solid var(--border);
}
.history-list .ph { display: grid; place-items: center; font-size: 1.2rem; }
.history-list .meta strong { display: block; font-size: 0.92rem; }
.history-list .meta span { color: var(--muted); font-size: 0.8rem; }
.history-list .mini-verdict {
  font-size: 0.72rem; font-weight: 800; text-transform: uppercase;
  padding: 4px 8px; border-radius: 999px;
}
.history-list .mini-verdict.good { background: var(--good-bg); color: var(--good); }
.history-list .mini-verdict.okay { background: var(--okay-bg); color: var(--okay); }
.history-list .mini-verdict.caution { background: var(--caution-bg); color: var(--caution); }

.footer {
  text-align: center; color: var(--muted); font-size: 0.78rem;
  padding: 8px 4px 0;
}
.footer a { color: var(--teal); }

.hidden { display: none !important; }

@media (min-width: 480px) {
  .nutrition-grid { grid-template-columns: 1fr 1fr 1fr; }
}
