:root {
  --bg: #10141f;
  --surface: #1a2030;
  --surface-2: #232b40;
  --text: #eef1f8;
  --text-dim: #9aa3b8;
  --accent: #4f8cff;
  --accent-dark: #3a6fd8;
  --danger: #e5484d;
  --warning: #f5a623;
  --safe: #30a46c;
  --unknown: #8b8fa3;
  --radius: 14px;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}

.app-header {
  text-align: center;
  padding: 20px 16px 8px;
}
.app-header h1 { font-size: 1.4rem; }
.tagline { color: var(--text-dim); font-size: 0.85rem; margin-top: 2px; }

main { max-width: 560px; margin: 0 auto; padding: 12px 16px; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

h2 { font-size: 1.1rem; margin: 8px 0 4px; }
.hint { color: var(--text-dim); font-size: 0.85rem; margin-bottom: 12px; }

/* Scanner */
#scanner-box { margin-bottom: 16px; }
#reader {
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 10px;
}
#reader video { border-radius: var(--radius); }

/* Buttons */
.btn {
  border: none;
  border-radius: var(--radius);
  padding: 12px 18px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
  background: var(--surface-2);
  transition: opacity 0.15s;
}
.btn:active { opacity: 0.75; }
.btn-primary { background: var(--accent); }
.btn-primary:active { background: var(--accent-dark); }
.btn-big { width: 100%; padding: 16px; font-size: 1.05rem; }
.btn-ghost { background: transparent; color: var(--text-dim); width: 100%; }
.btn-ai {
  background: linear-gradient(135deg, #7c5cff, #4f8cff);
  width: 100%;
  margin-top: 10px;
}

/* Manual form */
#manual-form label {
  display: block;
  color: var(--text-dim);
  font-size: 0.85rem;
  margin: 14px 0 6px;
  text-align: center;
}
.input-row { display: flex; gap: 8px; }
.input-row input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--surface-2);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 1.05rem;
  padding: 12px 14px;
  min-width: 0;
}
.input-row input:focus { outline: 2px solid var(--accent); border-color: transparent; }

/* Loading */
#loading { text-align: center; padding: 28px 0; color: var(--text-dim); }
.spinner {
  width: 34px; height: 34px;
  border: 3px solid var(--surface-2);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 0 auto 12px;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Result card */
.verdict {
  border-radius: var(--radius);
  padding: 18px 16px;
  text-align: center;
  margin: 14px 0;
}
.verdict h3 { font-size: 1.25rem; margin-bottom: 4px; }
.verdict p { font-size: 0.9rem; opacity: 0.95; }
.verdict-danger  { background: var(--danger); }
.verdict-warning { background: var(--warning); color: #1c1400; }
.verdict-safe    { background: var(--safe); }
.verdict-unknown { background: var(--surface-2); color: var(--text-dim); }

.product-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  gap: 12px;
  align-items: center;
}
.product-card img {
  width: 64px; height: 64px;
  object-fit: contain;
  border-radius: 8px;
  background: #fff;
  flex-shrink: 0;
}
.product-card .p-name { font-weight: 700; }
.product-card .p-brand { color: var(--text-dim); font-size: 0.85rem; }
.product-card .p-code { color: var(--text-dim); font-size: 0.75rem; margin-top: 2px; }

.detail-block {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px;
  margin-top: 10px;
}
.detail-block h4 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  margin-bottom: 8px;
}
.detail-block .ingredients { font-size: 0.85rem; color: var(--text-dim); line-height: 1.5; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 0.85rem;
  font-weight: 600;
  background: var(--surface-2);
}
.chip-hit { background: var(--danger); }
.chip-trace { background: var(--warning); color: #1c1400; }
.chip-ai-contains { background: var(--danger); }
.chip-ai-may { background: var(--warning); color: #1c1400; }

.recall-block { border: 1px solid var(--danger); }
.recall-item { margin-bottom: 10px; }
.recall-reason { font-size: 0.9rem; font-weight: 600; line-height: 1.4; }
.recall-meta { font-size: 0.75rem; color: var(--text-dim); margin-top: 2px; line-height: 1.4; }

.ai-note {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-top: 8px;
  line-height: 1.4;
}
.ai-evidence { font-size: 0.85rem; margin-top: 8px; line-height: 1.5; }
.ai-evidence li { margin: 4px 0 4px 18px; }

.error-box {
  background: var(--surface);
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  padding: 14px;
  margin-top: 14px;
  font-size: 0.9rem;
}

/* Profile */
#allergen-list { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.allergen-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 2px solid transparent;
  border-radius: var(--radius);
  padding: 12px;
  cursor: pointer;
  user-select: none;
  font-size: 0.95rem;
}
.allergen-toggle input { display: none; }
.allergen-toggle.on {
  border-color: var(--accent);
  background: var(--surface-2);
}
.allergen-toggle .emoji { font-size: 1.2rem; }

.toast {
  position: fixed;
  bottom: calc(90px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--safe);
  padding: 8px 20px;
  border-radius: 999px;
  font-weight: 600;
  z-index: 20;
}

/* History */
.history-item {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}
.history-item .h-name { font-weight: 600; font-size: 0.95rem; }
.history-item .h-date { color: var(--text-dim); font-size: 0.75rem; }
.badge {
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
}
.badge-danger  { background: var(--danger); }
.badge-warning { background: var(--warning); color: #1c1400; }
.badge-safe    { background: var(--safe); }
.badge-unknown { background: var(--surface-2); color: var(--text-dim); }

.empty { color: var(--text-dim); text-align: center; padding: 24px 0; font-size: 0.9rem; }

/* Tab bar */
.tab-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--surface);
  border-top: 1px solid var(--surface-2);
  display: flex;
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
}
.tab-btn {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.3rem;
  padding: 10px 0 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.tab-btn span { font-size: 0.7rem; font-weight: 600; }
.tab-btn.active { color: var(--accent); }

.disclaimer {
  max-width: 560px;
  margin: 20px auto 0;
  padding: 0 16px;
  font-size: 0.72rem;
  color: var(--text-dim);
  text-align: center;
  line-height: 1.5;
}
.disclaimer a { color: var(--text-dim); }

.hidden { display: none !important; }
