:root {
  --bg: #f7f7f5;
  --card: #ffffff;
  --ink: #1f2328;
  --muted: #63676d;
  --line: #e4e4e0;
  --accent: #2f6f4f;
  --accent-ink: #ffffff;
  --danger: #b3441e;
  --warn: #b38b1e;
  --ok: #2f6f4f;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

header {
  padding: 20px 24px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--card);
}

header h1 {
  margin: 0 0 4px;
  font-size: 1.4rem;
}

header p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

/* The product-count line still updates (loadStats() in app.js writes to
   it, and other code reads/writes it too) -- just not shown up top
   anymore, per request to keep the header to just the app name. */
#stats-line {
  display: none;
}

main {
  max-width: 960px;
  margin: 0 auto;
  padding: 20px 16px 60px;
}

.search-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.search-row input[type="text"] {
  flex: 1 1 200px;
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 1rem;
}

@media (max-width: 480px) {
  .search-row {
    flex-direction: column;
  }
  .search-row input[type="text"],
  .search-row button {
    width: 100%;
    /* flex-basis applies to whichever axis is "main" -- in row layout
       that's width (why 1 1 200px was set on the input above), but this
       media query switches to flex-direction: column, making the main
       axis vertical. Without this override, that same 200px basis (plus
       flex-grow: 1) was being applied as a *height*, ballooning the
       search input to ~200px+ tall on phones. Reset to natural,
       content-based sizing here instead. */
    flex: 0 0 auto;
  }
}

button {
  padding: 12px 16px;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 0.95rem;
  cursor: pointer;
}

button.secondary {
  background: #eceae4;
  color: var(--ink);
}

button:disabled {
  opacity: 0.5;
  cursor: default;
}

.filters {
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.filter-section {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}

.filter-section h3 {
  margin: 0 0 8px;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.filter-section h4 {
  margin: 12px 0 6px;
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 600;
}

.gout-section {
  border: 1px solid #ecdcae;
  background: #fbf6ea;
}

.gout-section h3 {
  color: #8a6a12;
}

#database-section {
  margin-bottom: 16px;
}

.progress-bar-track {
  width: 100%;
  height: 14px;
  background: #eceae4;
  border-radius: 999px;
  overflow: hidden;
  margin: 10px 0 8px;
}

.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.4s ease;
}

#progress-text {
  font-size: 0.88rem;
  color: var(--ink);
  margin: 0;
}

#import-done-text {
  font-size: 0.9rem;
  color: var(--ok);
  margin: 0;
}

.section-note {
  font-size: 0.82rem;
  color: var(--muted);
  margin: 0 0 10px;
}

#ingredient-section input[type="text"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 0.95rem;
}

#apply-filters-btn {
  align-self: flex-start;
}

.allergen-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 6px 12px;
  margin-bottom: 12px;
}

.allergen-grid label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9rem;
}

.purine-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.purine-row select {
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
}

.disclaimer {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 8px;
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.tabs button {
  background: #eceae4;
  color: var(--ink);
}

.tabs button.active {
  background: var(--accent);
  color: var(--accent-ink);
}

.results-meta {
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 10px;
}

.product-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.product-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  cursor: pointer;
}

.product-card:hover {
  border-color: var(--accent);
}

.product-card h4 {
  margin: 0 0 4px;
  font-size: 1rem;
}

.product-card .brand {
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 8px;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}

.tag {
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: #f1ded6;
  color: var(--danger);
  border: 1px solid #e6c3b6;
}

.tag.trace {
  background: #f6ecd6;
  color: var(--warn);
  border-color: #ecdcae;
}

.tag.trigger {
  background: #e5e1f5;
  color: #4b3f9e;
  border-color: #cfc7ea;
}

.tag.purine-high { background: #f1ded6; color: var(--danger); border-color: #e6c3b6; }
.tag.purine-moderate { background: #f6ecd6; color: var(--warn); border-color: #ecdcae; }
.tag.purine-low { background: #dfeee2; color: var(--ok); border-color: #c3e0c9; }
.tag.purine-unknown { background: #eceae4; color: var(--muted); border-color: var(--line); }

#scanner-wrap {
  display: none;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 16px;
}

#scanner-wrap.open { display: block; }

#reader {
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
}

.modal {
  background: var(--card);
  border-radius: var(--radius);
  max-width: 560px;
  width: 100%;
  padding: 20px;
}

.modal h2 {
  margin-top: 0;
}

.modal .close-btn {
  float: right;
}

.empty-state, .loading-state, .error-state {
  color: var(--muted);
  padding: 30px 10px;
  text-align: center;
}

.error-state { color: var(--danger); }
