/* ---------------------------------------------------------------------------
   Spinneys Kitchen & Bakery Encyclopedia — design system
   No framework, no CDN, no external font. Everything here ships with the app.
   Light + dark via a data-theme attribute on <html>, defaulting to the OS.
--------------------------------------------------------------------------- */

:root {
  color-scheme: light dark;

  /* Neutrals — warm greys, premium grocery feel rather than clinical blue */
  --bg: 250 249 247;
  --surface: 255 255 255;
  --surface-2: 244 242 239;
  --border: 228 224 218;
  --text: 28 26 23;
  --muted: 110 104 96;

  /* Brand — Spinneys' identity is green; kept restrained, used for emphasis
     only, never as large fills. */
  --brand: 22 101 62;
  --brand-strong: 15 78 47;
  --accent: 176 122 48;

  /* Evidence colours — deliberately distinct from brand so an evidence badge
     never reads as decoration. */
  --ev-verified: 22 101 62;
  --ev-product: 30 96 145;
  --ev-likely: 154 106 20;
  --ev-inferred: 138 71 26;
  --ev-insufficient: 140 38 38;

  --radius: 14px;
  --radius-lg: 22px;
  --shadow: 0 1px 2px rgb(28 26 23 / 0.04), 0 8px 24px -14px rgb(28 26 23 / 0.14);
  --shadow-lift: 0 4px 14px -6px rgb(28 26 23 / 0.12), 0 24px 48px -28px rgb(28 26 23 / 0.24);
  --maxw: 1180px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: 18 18 17;
    --surface: 26 26 25;
    --surface-2: 36 36 34;
    --border: 52 51 48;
    --text: 240 238 234;
    --muted: 158 153 145;
    --brand: 92 183 132;
    --brand-strong: 122 202 157;
    --accent: 214 168 92;
    --ev-verified: 92 183 132;
    --ev-product: 116 175 226;
    --ev-likely: 214 176 92;
    --ev-inferred: 214 148 104;
    --ev-insufficient: 226 122 122;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 8px 24px -14px rgb(0 0 0 / 0.6);
    --shadow-lift: 0 4px 14px -6px rgb(0 0 0 / 0.4), 0 24px 48px -28px rgb(0 0 0 / 0.7);
  }
}

:root[data-theme="dark"] {
  --bg: 18 18 17;
  --surface: 26 26 25;
  --surface-2: 36 36 34;
  --border: 52 51 48;
  --text: 240 238 234;
  --muted: 158 153 145;
  --brand: 92 183 132;
  --brand-strong: 122 202 157;
  --accent: 214 168 92;
  --ev-verified: 92 183 132;
  --ev-product: 116 175 226;
  --ev-likely: 214 176 92;
  --ev-inferred: 214 148 104;
  --ev-insufficient: 226 122 122;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 8px 24px -14px rgb(0 0 0 / 0.6);
  --shadow-lift: 0 4px 14px -6px rgb(0 0 0 / 0.4), 0 24px 48px -28px rgb(0 0 0 / 0.7);
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background: rgb(var(--bg));
  color: rgb(var(--text));
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 {
  font-family: ui-serif, Georgia, "Times New Roman", serif;
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -0.01em;
  margin: 0;
}
h1 { font-size: clamp(1.9rem, 1.3rem + 2.4vw, 2.9rem); }
h2 { font-size: clamp(1.35rem, 1.1rem + 1vw, 1.7rem); }
h3 { font-size: 1.1rem; }

p { margin: 0; }
a { color: inherit; }

:focus-visible {
  outline: 2px solid rgb(var(--brand));
  outline-offset: 2px;
  border-radius: 6px;
}

.skip-link {
  position: absolute; left: -9999px;
  background: rgb(var(--brand)); color: #fff;
  padding: 0.6rem 1rem; border-radius: 0 0 var(--radius) 0; z-index: 100;
}
.skip-link:focus { left: 0; top: 0; }

.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 1.25rem; }

/* --- Header ------------------------------------------------------------- */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: rgb(var(--surface) / 0.86);
  backdrop-filter: saturate(1.6) blur(14px);
  border-bottom: 1px solid rgb(var(--border));
}
.header-inner {
  display: flex; align-items: center; gap: 1rem;
  height: 64px; max-width: var(--maxw); margin: 0 auto; padding: 0 1.25rem;
}
.brand { display: flex; align-items: center; gap: 0.6rem; text-decoration: none; font-weight: 600; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px; flex: none;
  background: rgb(var(--brand)); color: #fff;
  display: grid; place-items: center; font-size: 1rem;
  font-family: ui-serif, Georgia, serif;
}
.brand-text { font-family: ui-serif, Georgia, serif; font-size: 1.05rem; }
.brand-text small { display: block; font-family: inherit; font-size: 0.7rem; color: rgb(var(--muted)); font-weight: 400; letter-spacing: 0.06em; text-transform: uppercase; }

.header-search { flex: 1; max-width: 460px; margin-left: auto; position: relative; }
.header-search input {
  width: 100%; height: 40px; padding: 0 2.4rem 0 0.9rem;
  border: 1px solid rgb(var(--border)); border-radius: 999px;
  background: rgb(var(--surface-2)); color: inherit; font: inherit; font-size: 0.9rem;
}
.header-search input::placeholder { color: rgb(var(--muted)); }
.header-search kbd {
  position: absolute; right: 0.55rem; top: 50%; transform: translateY(-50%);
  font: inherit; font-size: 0.7rem; color: rgb(var(--muted));
  border: 1px solid rgb(var(--border)); border-radius: 5px; padding: 0.05rem 0.32rem;
  background: rgb(var(--surface));
}

.icon-btn {
  width: 40px; height: 40px; flex: none; display: grid; place-items: center;
  border: 1px solid rgb(var(--border)); border-radius: 50%;
  background: rgb(var(--surface)); color: inherit; cursor: pointer; font-size: 1rem;
}
.icon-btn:hover { border-color: rgb(var(--brand) / 0.5); }

/* --- Nav ---------------------------------------------------------------- */
.catnav { border-bottom: 1px solid rgb(var(--border)); background: rgb(var(--surface)); }
.catnav-inner {
  display: flex; gap: 0.35rem; overflow-x: auto; scrollbar-width: none;
  max-width: var(--maxw); margin: 0 auto; padding: 0.55rem 1.25rem;
}
.catnav-inner::-webkit-scrollbar { display: none; }
.catnav button {
  flex: none; padding: 0.45rem 0.9rem; border-radius: 999px;
  border: 1px solid transparent; background: transparent; color: rgb(var(--muted));
  font: inherit; font-size: 0.875rem; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.catnav button:hover { background: rgb(var(--surface-2)); color: rgb(var(--text)); }
.catnav button[aria-current="true"] {
  background: rgb(var(--brand) / 0.1); color: rgb(var(--brand)); border-color: rgb(var(--brand) / 0.28);
}

/* --- Cards -------------------------------------------------------------- */
.grid {
  display: grid; gap: 1.1rem;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
}
.card {
  background: rgb(var(--surface)); border: 1px solid rgb(var(--border));
  border-radius: var(--radius-lg); box-shadow: var(--shadow);
  overflow: hidden; text-align: left; cursor: pointer; padding: 0;
  color: inherit; font: inherit; display: flex; flex-direction: column;
  transition: box-shadow 0.2s, transform 0.2s;
}
.card:hover { box-shadow: var(--shadow-lift); transform: translateY(-2px); }
.card-thumb {
  height: 130px; position: relative; display: grid; place-items: center;
  font-size: 2.6rem;
}
.card-body { padding: 0.9rem 1rem 1rem; display: flex; flex-direction: column; gap: 0.4rem; flex: 1; }
.card-cat { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.1em; color: rgb(var(--muted)); }
.card-title { font-family: ui-serif, Georgia, serif; font-size: 1.05rem; line-height: 1.25; }
.card-meta { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: auto; padding-top: 0.3rem; }

/* --- Badges ------------------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.18rem 0.55rem; border-radius: 999px;
  font-size: 0.7rem; font-weight: 600; letter-spacing: 0.01em;
  background: rgb(var(--surface-2)); color: rgb(var(--muted));
  border: 1px solid transparent;
}
.badge--verified   { background: rgb(var(--ev-verified) / 0.12);   color: rgb(var(--ev-verified));   border-color: rgb(var(--ev-verified) / 0.28); }
.badge--product    { background: rgb(var(--ev-product) / 0.12);    color: rgb(var(--ev-product));    border-color: rgb(var(--ev-product) / 0.28); }
.badge--likely     { background: rgb(var(--ev-likely) / 0.14);     color: rgb(var(--ev-likely));     border-color: rgb(var(--ev-likely) / 0.3); }
.badge--inferred   { background: rgb(var(--ev-inferred) / 0.13);   color: rgb(var(--ev-inferred));   border-color: rgb(var(--ev-inferred) / 0.3); }
.badge--insufficient { background: rgb(var(--ev-insufficient) / 0.12); color: rgb(var(--ev-insufficient)); border-color: rgb(var(--ev-insufficient) / 0.3); }

/* --- Evidence panel ----------------------------------------------------- */
.evidence {
  border: 1px solid rgb(var(--border)); border-radius: var(--radius);
  background: rgb(var(--surface-2)); padding: 1rem 1.1rem;
}
.evidence-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.confidence-track {
  height: 6px; border-radius: 999px; background: rgb(var(--border));
  overflow: hidden; margin-top: 0.7rem;
}
.confidence-fill { height: 100%; border-radius: 999px; background: rgb(var(--brand)); }

/* Provenance chip — appears next to any derived data block. This is the
   visual half of the anti-fabrication contract: no number without a source. */
.prov {
  display: inline-flex; align-items: center; gap: 0.28rem;
  font-size: 0.68rem; font-weight: 600; letter-spacing: 0.02em;
  color: rgb(var(--muted)); text-transform: uppercase;
}
.prov::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: currentColor; flex: none;
}
.prov--official_declaration { color: rgb(var(--ev-verified)); }
.prov--official_published   { color: rgb(var(--ev-verified)); }
.prov--third_party_reported { color: rgb(var(--ev-product)); }
.prov--estimated_from_ingredients { color: rgb(var(--ev-likely)); }
.prov--culinary_inference   { color: rgb(var(--ev-inferred)); }
.prov--unknown              { color: rgb(var(--ev-insufficient)); }

/* --- Gaps ledger -------------------------------------------------------- */
.gaps {
  border: 1px dashed rgb(var(--ev-insufficient) / 0.4);
  background: rgb(var(--ev-insufficient) / 0.05);
  border-radius: var(--radius); padding: 0.9rem 1.05rem;
}
.gaps h3 { font-size: 0.95rem; color: rgb(var(--ev-insufficient)); }
.gaps ul { margin: 0.5rem 0 0; padding-left: 1.1rem; color: rgb(var(--muted)); font-size: 0.875rem; }

/* --- Sections ----------------------------------------------------------- */
.section { margin-top: 2.4rem; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin-bottom: 0.9rem; }
.eyebrow { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.14em; color: rgb(var(--muted)); font-weight: 600; }

.panel {
  background: rgb(var(--surface)); border: 1px solid rgb(var(--border));
  border-radius: var(--radius-lg); padding: 1.25rem; box-shadow: var(--shadow);
}

.muted { color: rgb(var(--muted)); }
.small { font-size: 0.875rem; }
.tiny { font-size: 0.78rem; }

/* --- Buttons ------------------------------------------------------------ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.45rem;
  height: 42px; padding: 0 1.1rem; border-radius: 999px;
  border: 1px solid transparent; font: inherit; font-size: 0.9rem; font-weight: 500;
  cursor: pointer; white-space: nowrap; text-decoration: none;
}
.btn--primary { background: rgb(var(--brand)); color: #fff; }
.btn--primary:hover { background: rgb(var(--brand-strong)); }
.btn--secondary { background: rgb(var(--surface)); border-color: rgb(var(--border)); color: inherit; }
.btn--secondary:hover { border-color: rgb(var(--brand) / 0.5); }
.btn--ghost { background: transparent; color: rgb(var(--muted)); }
.btn--ghost:hover { background: rgb(var(--surface-2)); color: rgb(var(--text)); }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

/* --- Illustrative image caption (never imply official photography) ------ */
.illustrative {
  font-size: 0.7rem; color: rgb(var(--muted)); font-style: italic;
  margin-top: 0.35rem;
}

/* --- Empty / loading ---------------------------------------------------- */
.empty { text-align: center; padding: 3.5rem 1rem; color: rgb(var(--muted)); }

/* --- Research dashboard: stat tiles + data table ------------------------ */
.stat-grid {
  display: grid; gap: 0.9rem;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
}
.stat-tile {
  background: rgb(var(--surface)); border: 1px solid rgb(var(--border));
  border-radius: var(--radius); padding: 0.9rem 1rem; box-shadow: var(--shadow);
}
.stat-tile .n { font-family: ui-serif, Georgia, serif; font-size: 1.7rem; line-height: 1.1; }
.stat-tile .label { font-size: 0.75rem; color: rgb(var(--muted)); margin-top: 0.25rem; }

.data-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.data-table th, .data-table td {
  text-align: left; padding: 0.55rem 0.7rem; border-bottom: 1px solid rgb(var(--border));
  white-space: nowrap;
}
.data-table th {
  font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.08em;
  color: rgb(var(--muted)); font-weight: 600; cursor: pointer; user-select: none;
}
.data-table th:hover { color: rgb(var(--text)); }
.data-table tbody tr:hover { background: rgb(var(--surface-2)); }
.data-table td.name { white-space: normal; max-width: 320px; }

.score-bar {
  display: inline-block; width: 60px; height: 6px; border-radius: 999px;
  background: rgb(var(--border)); overflow: hidden; vertical-align: middle; margin-right: 0.4rem;
}
.score-bar > span { display: block; height: 100%; background: rgb(var(--brand)); }

.table-controls { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; margin-bottom: 0.9rem; }
.table-controls input, .table-controls select {
  height: 38px; padding: 0 0.8rem; border: 1px solid rgb(var(--border));
  border-radius: 999px; background: rgb(var(--surface)); color: inherit; font: inherit; font-size: 0.85rem;
}

/* --- Print -------------------------------------------------------------- */
@media print {
  .site-header, .catnav, .no-print { display: none !important; }
  body { background: #fff; color: #000; }
  .panel, .card { box-shadow: none; border-color: #ccc; break-inside: avoid; }
  a[href]::after { content: " (" attr(href) ")"; font-size: 0.75em; color: #555; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
