/* Grocery Goggles - mobile-first, high-contrast for store lighting */

:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --header: #1f2937;
  --accent: #2563eb;

  --red: #dc2626;
  --red-bg: #fef2f2;
  --yellow: #d97706;
  --yellow-bg: #fffbeb;
  --green: #16a34a;
  --green-bg: #f0fdf4;

  --nav-h: 60px;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 17px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

h1, h2 { margin: 0 0 0.5em; font-weight: 700; }
h1 { font-size: 1.2rem; }
h2 { font-size: 1.1rem; }
a { color: var(--accent); }
.hidden { display: none !important; }
.muted { color: var(--muted); }

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--header);
  color: #fff;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
}
.app-header h1 { margin: 0; color: #fff; }
.icon-btn {
  background: transparent;
  border: 0;
  color: inherit;
  font-size: 1.4rem;
  line-height: 1;
  padding: 6px 10px;
  cursor: pointer;
  border-radius: 8px;
}
.icon-btn:active { background: rgba(255,255,255,0.15); }

/* Layout */
main {
  padding: 16px;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 24px);
  max-width: 640px;
  margin: 0 auto;
}
.view { animation: fade 0.15s ease; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* Cards / buttons */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.card ol { padding-left: 1.2em; margin: 0.5em 0 1em; }
.card li { margin: 0.3em 0; }

button { font-family: inherit; font-size: 1rem; }

.primary, .danger {
  display: inline-block;
  width: 100%;
  padding: 14px;
  border: 0;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
}
.primary { background: var(--accent); color: #fff; }
.primary:active { filter: brightness(0.92); }
.danger { background: var(--red-bg); color: var(--red); border: 1px solid #fecaca; }

label {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  margin: 14px 0 6px;
}
input[type="password"], input[type="text"], textarea {
  width: 100%;
  padding: 12px;
  font-size: 16px; /* >=16px stops iOS zoom-on-focus */
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
}
textarea { resize: vertical; }
.hint { font-size: 0.82rem; color: var(--muted); margin: 6px 0 0; }
.error { color: var(--red); font-weight: 600; }
.disclaimer {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 14px;
  line-height: 1.35;
}

/* Scan button */
.big-primary {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 32px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font-size: 1.15rem;
  font-weight: 600;
  cursor: pointer;
}
.big-primary:active { background: #f1f5f9; }
.big-primary-icon { font-size: 2.6rem; line-height: 1; }

/* Scan result */
#scan-result { margin-top: 16px; }
#scan-photo {
  width: 100%;
  max-height: 40vh;
  object-fit: contain;
  border-radius: var(--radius);
  background: #000;
  display: block;
}
.meta {
  font-weight: 700;
  font-size: 1.1rem;
  margin: 14px 0 4px;
}

/* Status / spinner */
.status {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 0;
  color: var(--muted);
}
.status-error { color: var(--red); font-weight: 600; }
.spinner {
  width: 22px;
  height: 22px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Ingredient list */
#ingredient-list, #history-list { list-style: none; padding: 0; margin: 8px 0 0; }

.ingredient {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  margin-bottom: 8px;
  border-radius: 12px;
  border-left: 5px solid transparent;
}
.ingredient .dot {
  flex: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  margin-top: 6px;
}
.ing-text { flex: 1; min-width: 0; }
.ing-name { font-weight: 600; overflow-wrap: anywhere; }
.ing-reason { font-size: 0.88rem; color: var(--muted); margin-top: 2px; }

.verdict-red    { background: var(--red-bg);    border-left-color: var(--red); }
.verdict-red    .dot { background: var(--red); }
.verdict-yellow { background: var(--yellow-bg); border-left-color: var(--yellow); }
.verdict-yellow .dot { background: var(--yellow); }
.verdict-green  { background: var(--green-bg);  border-left-color: var(--green); }
.verdict-green  .dot { background: var(--green); }

/* History */
.history-card {
  display: flex;
  gap: 12px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  margin-bottom: 10px;
  cursor: pointer;
  text-align: left;
  width: 100%;
}
.hc-thumb {
  width: 56px;
  height: 56px;
  flex: none;
  object-fit: cover;
  border-radius: 8px;
  background: #000;
}
.hc-body { flex: 1; min-width: 0; }
.hc-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hc-time { font-size: 0.8rem; color: var(--muted); }
.hc-tally { font-size: 0.9rem; margin-top: 2px; }
.chip { margin-right: 10px; white-space: nowrap; }
.chip-red { color: var(--red); }
.chip-yellow { color: var(--yellow); }
.chip-green { color: var(--green); }
.hc-detail { margin: 0 0 10px; }

/* Bottom nav */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  padding: 10px 0;
  min-height: var(--nav-h);
  cursor: pointer;
}
.tab.active { color: var(--accent); }

/* Settings drawer */
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  width: min(420px, 88vw);
  background: var(--surface);
  box-shadow: -4px 0 24px rgba(0,0,0,0.18);
  display: flex;
  flex-direction: column;
  transform: translateX(0);
}
.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 14px) 16px 14px;
  border-bottom: 1px solid var(--border);
}
.drawer-header h2 { margin: 0; }
.drawer-header .icon-btn { color: var(--ink); }
.drawer-body {
  padding: 16px;
  overflow-y: auto;
  padding-bottom: calc(env(safe-area-inset-bottom) + 24px);
}
.drawer-body hr { border: 0; border-top: 1px solid var(--border); margin: 22px 0; }
.backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(15,23,42,0.4);
}

/* Secondary button */
.secondary {
  display: inline-block;
  width: 100%;
  padding: 13px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
}
.secondary:active { background: #f1f5f9; }
.primary:disabled { opacity: 0.5; }

/* Capture tray */
.tray { margin-top: 8px; }
.tray-thumbs { display: flex; flex-wrap: wrap; gap: 12px; }
.tray-thumb { position: relative; width: 88px; height: 88px; }
.tray-thumb img { width: 100%; height: 100%; object-fit: cover; border-radius: 10px; background: #000; }
.tray-remove {
  position: absolute;
  top: -8px; right: -8px;
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 2px solid var(--surface);
  background: var(--ink);
  color: #fff;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}
.tray-actions { display: flex; gap: 10px; margin-top: 6px; }
.tray-actions .secondary, .tray-actions .primary { margin-top: 0; }

/* Nutrition table */
.nutrition {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  margin: 14px 0;
}
.nutri-head { font-weight: 700; font-size: 1.05rem; }
.nutri-serving { font-size: 0.85rem; color: var(--muted); margin-top: 2px; }
.nutri-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 10px;
  font-variant-numeric: tabular-nums;
}
.nutri-table thead th { text-align: right; font-size: 0.8rem; color: var(--muted); font-weight: 600; padding: 0 0 6px; }
.nutri-table thead th:first-child { text-align: left; }
.nutri-table th[scope="row"] { text-align: left; font-weight: 600; padding: 6px 8px 6px 0; }
.nutri-table td { text-align: right; padding: 6px 0 6px 12px; white-space: nowrap; }
.nutri-table tbody tr { border-top: 1px solid var(--border); }
.nutri-table tr.sub th[scope="row"] { padding-left: 14px; font-weight: 400; color: var(--muted); }
.nutri-note { font-size: 0.82rem; color: var(--muted); margin-top: 10px; }
.chip-stat { color: var(--accent); font-weight: 600; }
.plain-list { list-style: none; padding: 0; margin: 8px 0 0; }

/* Timing readout (tap-to-result) */
.timing { font-size: 0.78rem; color: var(--muted); margin: 8px 0 0; text-align: right; }

/* Single-scan headline verdict */
.verdict-headline { font-weight: 700; padding: 8px 0 2px; }
.vh-clean { color: var(--green); }
.vh-warn { color: var(--yellow); }
.vh-bad { color: var(--red); }

/* Segmented Fast/Quality toggle */
.seg { display: flex; gap: 0; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.seg-opt { flex: 1; text-align: center; padding: 10px; font-weight: 600; cursor: pointer; margin: 0; }
.seg-opt input { display: none; }
.seg-opt:has(input:checked) { background: var(--accent); color: #fff; }
.seg-opt + .seg-opt { border-left: 1px solid var(--border); }

/* Inline comparison verdict + highlights */
.cmp-verdict { font-weight: 700; font-size: 1.05rem; background: var(--green-bg); border: 1px solid #bbf7d0; border-radius: 12px; padding: 12px 14px; margin: 4px 0 10px; }
.cmp-highlights { margin: 0 0 12px; padding-left: 1.1em; }
.cmp-highlights li { margin: 4px 0; }
.cmp-detail { border-top: 1px solid var(--border); margin-top: 12px; padding-top: 6px; }
.cmp-detail summary { font-weight: 600; padding: 8px 0; cursor: pointer; }

/* Compare */
.cmp-pick { display: flex; align-items: center; gap: 10px; padding: 9px 4px; border-bottom: 1px solid var(--border); cursor: pointer; }
.cmp-pick input { width: 20px; height: 20px; flex: none; }
.cmp-thumb { width: 36px; height: 36px; object-fit: cover; border-radius: 6px; background: #000; flex: none; }
.cmp-label { font-size: 0.95rem; }
.cmp-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 14px;
  font-variant-numeric: tabular-nums;
}
.cmp-table thead th { vertical-align: bottom; padding: 0 6px 8px; font-size: 0.9rem; text-align: right; }
.cmp-table thead th:first-child { text-align: left; }
.cmp-basis { font-size: 0.72rem; color: var(--muted); font-weight: 400; }
.cmp-table th[scope="row"] { text-align: left; font-weight: 600; padding: 8px 8px 8px 0; }
.cmp-table td { text-align: right; padding: 8px 6px; white-space: nowrap; border-top: 1px solid var(--border); }
.cmp-table tr.sub th[scope="row"] { padding-left: 14px; font-weight: 400; color: var(--muted); }
.cmp-better { background: var(--green-bg); color: var(--green); font-weight: 700; border-radius: 6px; }
.cmp-worse { background: var(--red-bg); color: var(--red); }
