:root {
  /* Warm neutrals with the logo's price-tag orange as the accent; green stays for "cheapest" and the wordmark.
     --accent fills buttons (with dark --accent-ink on top), --accent-text is the darker shade for text on white. */
  --bg: #f6f5f2; --surface: #ffffff; --text: #1f2421; --muted: #5c625e; --line: #e6e3dc; --accent: #f5861f; --accent-ink: #231200; --accent-text: #b4530b;
  --brand-ink: #1b4d32; --brand-leaf: #2e9a56; --bubble: #d3f1ec; --info: #0b6a86;
  --good: #17703f; --good-bg: #e3f5ec; --warn: #8f5200; --warn-bg: #fff1d9; --bad: #b3261e; --bad-bg: #fde8e6;
  --shadow: 0 1px 2px rgb(31 36 33 / 0.06), 0 4px 14px rgb(31 36 33 / 0.05);
  --r-auchan: #d23b25; --r-carrefour: #2a63c9; --r-lidl: #c99a00; --r-mega: #1c9560; --r-metro: #23356f; --r-selgros: #b5123e;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141311; --surface: #1d1c19; --text: #ece9e3; --muted: #aaa59b; --line: #302e29; --accent: #ff9a3d; --accent-ink: #231200; --accent-text: #ffad5c;
    --brand-ink: #ece9e3; --brand-leaf: #8fd3a3; --bubble: #3a2a16; --info: #6ccbe3;
    --good: #5dd68e; --good-bg: #12301f; --warn: #f0b45a; --warn-bg: #33270f; --bad: #ff8b82; --bad-bg: #3a1815;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4); --r-auchan: #ff7a63; --r-carrefour: #7ea4ff; --r-lidl: #f0c431; --r-mega: #55cf93; --r-metro: #9aa8ff; --r-selgros: #ff6f91;
  }
}
* { box-sizing: border-box; }
/* stable gutter: the page does not shift sideways when the scrollbar goes away under an open dialog */
html { color-scheme: light dark; scrollbar-gutter: stable; -webkit-text-size-adjust: 100%; }
/* No scrolling the page behind an open dialog. */
html:has(dialog[open]) { overflow: hidden; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, select { font: inherit; color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
code { background: var(--bg); padding: 1px 5px; border-radius: 5px; font-size: 0.9em; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.topbar { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar-inner { max-width: 1280px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.brand { margin: 0; display: flex; align-items: center; gap: 8px; font-size: 20px; font-weight: 800; letter-spacing: -0.02em; line-height: 1; font-family: "Quicksand", "Nunito", system-ui, sans-serif; }
.brand img { flex: none; }
.brand-name { color: var(--brand-ink); }
.brand-name b { color: var(--brand-leaf); font-weight: inherit; }
.brand-sub { font-size: 12px; font-weight: 800; letter-spacing: 0.04em; text-transform: uppercase; color: var(--accent-ink); background: var(--accent); border: 0; padding: 4px 8px; border-radius: 999px; }
.tabs { display: flex; gap: 4px; background: var(--bg); padding: 3px; border-radius: 10px; }
.tab { border: 0; background: transparent; padding: 6px 14px; border-radius: 8px; cursor: pointer; color: var(--muted); font-weight: 600; }
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { background: var(--accent); color: var(--accent-ink); box-shadow: var(--shadow); }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.link { color: var(--accent-text); text-decoration: none; font-weight: 600; }
.link:hover { text-decoration: underline; }

.btn { border: 1px solid var(--line); background: var(--surface); padding: 7px 14px; border-radius: 9px; cursor: pointer; font-weight: 600; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: color-mix(in srgb, var(--accent) 88%, #000); }
.btn.ghost { background: transparent; }

.page { max-width: 1280px; margin: 0 auto; padding: 16px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat { text-align: left; background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--rc, var(--line)); border-radius: var(--radius); padding: 10px 12px; cursor: pointer; }
.stat[aria-pressed="true"] { outline: 2px solid var(--rc); }
.stat b { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.stat .logo { width: 20px; height: 20px; }
.stat .n { display: block; font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.stat .meta { display: block; font-size: 12px; color: var(--muted); }
.stat.total { cursor: default; border-left-color: var(--accent); }

.filters { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; display: grid; gap: 10px; }
.search input { width: 100%; padding: 10px 12px; border-radius: 9px; border: 1px solid var(--line); background: var(--bg); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 11px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); cursor: pointer; font-weight: 600; font-size: 13px; }
.chip::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--rc, var(--muted)); }
.chip[aria-pressed="true"] { background: color-mix(in srgb, var(--rc, var(--accent)) 14%, var(--surface)); border-color: var(--rc, var(--accent)); }
.row { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; }
.row.end { justify-content: flex-end; }
.select { display: grid; gap: 2px; font-size: 12px; color: var(--muted); font-weight: 600; }
.select select, .select input { padding: 7px 9px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); min-width: 150px; font-size: 14px; color: var(--text); }
.check { display: flex; gap: 6px; align-items: center; padding-bottom: 7px; cursor: pointer; font-weight: 600; font-size: 14px; }
[hidden] { display: none !important; }

.summary { color: var(--muted); margin: 14px 2px 8px; min-height: 1.4em; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; text-align: left; padding: 0; cursor: pointer; box-shadow: var(--shadow); }
.card:hover { border-color: var(--muted); }
.thumb { aspect-ratio: 1 / 1; background: #fff; display: grid; place-items: center; position: relative; border-bottom: 1px solid var(--line); }
/* Out of flow, so a very tall photo cannot stretch the square: aspect-ratio is only a minimum for content that overflows. */
.thumb > img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; padding: 8px; }
.thumb .none { color: #9aa3af; font-size: 12px; text-align: center; padding: 8px; }
.thumb .corner-left { position: absolute; top: 8px; left: 8px; }
.thumb .badge-corner { position: absolute; top: 8px; right: 8px; }
.body { padding: 10px 12px 12px; display: grid; gap: 4px; flex: 1; align-content: start; }
.name { font-weight: 600; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.sub { color: var(--muted); font-size: 12.5px; }
.price { font-size: 20px; font-weight: 700; letter-spacing: -0.02em; }
.price s { font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 6px; }
.unit { color: var(--muted); font-size: 12.5px; }
.member { font-size: 12.5px; font-weight: 600; color: var(--info); }
.elsewhere { display: grid; gap: 3px; margin-top: 4px; padding-top: 6px; border-top: 1px dashed var(--line); justify-items: start; }
.ew { width: 100%; display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 6px; font-size: 12.5px; }
.ew .ew-name { color: var(--muted); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ew .ew-price { font-weight: 700; font-variant-numeric: tabular-nums; }
.ew .ew-diff { font-size: 11.5px; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 4.5em; text-align: right; }
.ew.lower .ew-diff, .ew.lower .ew-price { color: var(--good); }
.ew.higher .ew-diff { color: var(--bad); }
.ew.out { opacity: 0.55; }

.tag { white-space: nowrap; display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--surface); border: 1px solid var(--line); }
/* Logos sit on a white tile so the dark marks (Carrefour, Mega Image) stay legible in dark mode. */
.logo { flex: none; width: 16px; height: 16px; object-fit: contain; padding: 1px; border-radius: 4px; background: #fff; }
.logo-dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--rc); }
.badge { display: inline-block; padding: 2px 7px; border-radius: 6px; font-size: 11.5px; font-weight: 700; background: var(--warn-bg); color: var(--warn); }
.badge.good { background: var(--good-bg); color: var(--good); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.blue { background: color-mix(in srgb, var(--info) 14%, var(--surface)); color: var(--info); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; background: var(--muted); }
.dot.in { background: var(--good); } .dot.out { background: var(--bad); }

.compare { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 560px), 1fr)); }
.pc { grid-template-columns: minmax(0, 1fr); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px; display: grid; gap: 10px; }
.pc-head { display: grid; grid-template-columns: 76px 1fr auto; gap: 12px; align-items: center; }
.pc-head .pimg { position: relative; width: 76px; height: 76px; background: #fff; border: 1px solid var(--line); border-radius: 10px; display: grid; place-items: center; overflow: hidden; flex: none; }
.pc-head .pimg img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; padding: 4px; }
.pc-title { font-weight: 700; font-size: 16px; }
.save { text-align: right; max-width: 190px; }
.save b { display: block; font-size: 18px; color: var(--good); }
table.offers { width: 100%; border-collapse: collapse; font-size: 14px; }
.offers th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 0 8px 4px; }
.offers td { padding: 7px 8px; border-top: 1px solid var(--line); vertical-align: middle; }
.offers tr.best td { background: var(--good-bg); }
.offers tr.out td { opacity: 0.6; }
.offers td.num, .offers th.num { text-align: right; white-space: nowrap; }
/* A price before discount goes under the price, so two cards side by side keep the table inside the card. */
.by-retailer td.num s { display: block; font-size: 12.5px; }
.offers a { color: var(--accent-text); text-decoration: none; font-weight: 600; }
.offers .when { color: var(--muted); font-size: 12px; white-space: nowrap; }

dialog { border: 1px solid var(--line); border-radius: 16px; padding: 0; background: var(--surface); color: var(--text); width: min(880px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); overflow: auto; overscroll-behavior: contain; box-shadow: 0 20px 60px rgb(0 0 0 / 0.35); }
dialog::backdrop { background: rgb(8 21 14 / 0.55); }
.dlg { padding: 18px; display: grid; gap: 14px; }
.dlg-head { display: flex; gap: 12px; justify-content: space-between; align-items: start; }
.dlg-head h2 { overflow-wrap: anywhere; }
.dlg-head h2 { margin: 0; font-size: 20px; letter-spacing: -0.01em; }
.dlg-body { display: grid; grid-template-columns: 240px 1fr; gap: 18px; }
.dlg-img { position: relative; background: #fff; border: 1px solid var(--line); border-radius: 12px; aspect-ratio: 1; display: grid; place-items: center; }
.dlg-img > img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; padding: 10px; }
dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 0; font-size: 14px; }
dl.facts dt { color: var(--muted); } dl.facts dd { margin: 0; word-break: break-word; }
.shared-img { position: absolute; inset: 0; display: grid; place-items: center; }
.shared-img img { width: 100%; height: 100%; object-fit: contain; padding: 8px; }
.shared-note { position: absolute; bottom: 6px; left: 50%; transform: translateX(-50%); white-space: nowrap; padding: 1px 7px; border-radius: 999px; font-size: 11px; font-weight: 600; background: rgb(20 23 28 / 0.72); color: #fff; }
.pc-head .shared-note, .link-row .shared-note { display: none; }
.crawls { display: grid; gap: 14px; margin-top: 14px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: grid; gap: 10px; }
.panel h2 { margin: 0; font-size: 16px; }
.panel p { margin: 0; }
.panel .inline { font-size: 14px; }
.panel .hours { width: 70px; margin: 0 4px; padding: 5px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); }
.row.spread { justify-content: space-between; align-items: center; }
.row.center { align-items: center; }
.runs-wrap { overflow-x: auto; }
.btn:disabled { opacity: 0.55; cursor: default; }
.link-panel { display: grid; gap: 8px; margin-top: 8px; }
.link-panel p { margin: 0; }
.link-results { display: grid; gap: 6px; }
.link-row { display: grid; grid-template-columns: 48px 1fr auto; gap: 10px; align-items: center; padding: 6px; border: 1px solid var(--line); border-radius: 10px; }
.link-row .pimg { position: relative; width: 48px; height: 48px; background: #fff; border-radius: 8px; display: grid; place-items: center; overflow: hidden; }
.link-row .pimg img { width: 100%; height: 100%; object-fit: contain; padding: 3px; }
.link-row .pimg .none { font-size: 0; }
.link-name { display: grid; gap: 2px; justify-items: start; min-width: 0; }
.section-title { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; margin: 6px 0 2px; }
.desc { font-size: 13.5px; color: var(--muted); max-height: 7.5em; overflow: auto; }
svg.spark { width: 100%; height: 70px; }
svg.spark polyline { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; }
svg.spark circle { fill: var(--accent); }
.key-form { padding: 18px; display: grid; gap: 12px; width: min(440px, 100%); }
.key-form h2 { margin: 0; }
.more { display: grid; place-items: center; padding: 18px 0 6px; }
.disclaimer { color: var(--muted); font-size: 12.5px; text-align: center; margin: 14px 0 30px; }
.empty { background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); padding: 40px 16px; text-align: center; color: var(--muted); }
.error { background: var(--bad-bg); color: var(--bad); border-radius: var(--radius); padding: 14px 16px; font-weight: 600; }
.skeleton { height: 120px; border-radius: var(--radius); background: linear-gradient(90deg, var(--line), var(--surface), var(--line)); background-size: 200% 100%; animation: sk 1.3s linear infinite; }
@keyframes sk { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }

/* Save is first in the DOM so Enter submits it; Cancel is shown first. */
#key-cancel { order: -1; }

/* ---- phones ---- */
@media (max-width: 640px) {
  body { font-size: 14.5px; }
  .topbar-inner { padding: 8px 12px; gap: 8px 12px; }
  .brand { font-size: 17px; gap: 6px; }
  .brand img { width: 28px; height: 28px; }
  .brand-sub { font-size: 10px; padding: 3px 6px; }
  .topbar-actions { gap: 2px; }
  .topbar-actions .link { font-size: 13px; padding: 6px; }
  .topbar-actions .btn { padding: 6px 10px; font-size: 13px; }
  .tabs { order: 1; width: 100%; }
  .tab { flex: 1; padding: 8px; }
  .page { padding: 12px; }

  /* Retailer cards scroll sideways instead of stacking a screen tall. */
  .stats { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; margin: 0 -12px 12px; padding: 0 12px 2px; gap: 8px; }
  .stats::-webkit-scrollbar { display: none; }
  .stat { flex: 0 0 auto; width: 180px; scroll-snap-align: start; scroll-margin-left: 12px; padding: 8px 10px; }
  .stat .n { font-size: 19px; }

  .filters { padding: 10px; gap: 8px; }
  /* 16px stops iOS zooming into a focused field. */
  .search input, .select select, .select input { font-size: 16px; }
  .row { gap: 8px 12px; }
  .select { flex: 1 1 140px; }
  .select select, .select input { min-width: 0; width: 100%; }
  .check { padding-bottom: 4px; }

  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .body { padding: 8px 9px 10px; gap: 3px; }
  .name { font-size: 13.5px; }
  .price { font-size: 17px; }
  .price s { display: block; margin: 0; font-size: 12px; }
  .thumb .corner-left { top: 6px; left: 6px; }
  .thumb .badge-corner { top: 6px; right: 6px; }
  .thumb .tag { font-size: 0; gap: 0; padding: 3px; } /* logo only: the name does not fit beside a discount badge */
  .ew { grid-template-columns: auto 1fr auto; }
  .ew .ew-name { display: none; }
  .ew .ew-diff { min-width: 0; }

  .pc { padding: 10px; }
  .pc-head { grid-template-columns: 60px 1fr; gap: 10px; }
  .pc-head .pimg { width: 60px; height: 60px; }
  .pc-title { font-size: 15px; }
  .save { grid-column: 1 / -1; text-align: left; max-width: none; display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
  .save b { display: inline; font-size: 16px; }

  /* The retailer price table becomes one small card per retailer. */
  table.by-retailer, .by-retailer tbody { display: block; }
  .by-retailer thead { display: none; }
  .by-retailer tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "ret price" "badges unit" "when open"; gap: 2px 10px; align-items: center; padding: 8px; border-top: 1px solid var(--line); }
  .by-retailer tr.best { background: var(--good-bg); border-radius: 8px; border-top-color: transparent; }
  .by-retailer tr.best + tr { border-top-color: transparent; }
  .by-retailer td { padding: 0; border: 0; background: none !important; }
  .by-retailer td:nth-child(1) { grid-area: ret; }
  .by-retailer td:nth-child(2) { grid-area: price; font-size: 15px; }
  .by-retailer td:nth-child(3) { grid-area: unit; font-size: 12.5px; color: var(--muted); }
  .by-retailer td:nth-child(4) { grid-area: badges; display: flex; gap: 4px; flex-wrap: wrap; }
  .by-retailer td:nth-child(5) { grid-area: when; }
  .by-retailer td:nth-child(6) { grid-area: open; text-align: right; }

  /* Crawls: one card per retailer, labelled, instead of six squeezed columns. */
  table.by-crawl, .by-crawl tbody { display: block; }
  .by-crawl thead { display: none; }
  .by-crawl tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "ret btn" "last last" "result result" "full full" "next next"; gap: 4px 10px; padding: 10px 0; border-top: 1px solid var(--line); }
  .by-crawl td { padding: 0; border: 0; white-space: normal; }
  .by-crawl td:nth-child(1) { grid-area: ret; }
  .by-crawl td:nth-child(2) { grid-area: last; }
  .by-crawl td:nth-child(3) { grid-area: result; }
  .by-crawl td:nth-child(4) { grid-area: full; }
  .by-crawl td:nth-child(5) { grid-area: next; }
  .by-crawl td:nth-child(6) { grid-area: btn; }
  .by-crawl td:nth-child(2)::before { content: "Last crawl: "; }
  .by-crawl td:nth-child(4)::before { content: "Last complete crawl: "; }
  .by-crawl td:nth-child(5)::before { content: "Next: "; }
  .by-crawl td::before { color: var(--muted); font-weight: 600; }
  .by-crawl td:is(:nth-child(2), :nth-child(4)) .sub { display: inline; margin-left: 4px; }
  .by-crawl td:is(:nth-child(2), :nth-child(4)) .sub::before { content: "· "; }

  /* The product dialog is a sheet from the bottom edge. */
  dialog#detail { width: 100%; max-width: none; max-height: 92dvh; margin: auto 0 0; border-radius: 18px 18px 0 0; border-bottom: 0; }
  .dlg { padding: 0 14px calc(16px + env(safe-area-inset-bottom)); gap: 12px; }
  .dlg-head { position: sticky; top: 0; z-index: 1; background: var(--surface); padding: 14px 0 10px; margin-bottom: -4px; border-bottom: 1px solid var(--line); }
  .dlg-head h2 { font-size: 17px; margin-top: 4px; }
  .dlg-body { grid-template-columns: 1fr; gap: 12px; }
  .dlg-img { width: min(220px, 70%); margin: 0 auto; }
  dl.facts { font-size: 13.5px; gap: 3px 10px; }
  .link-row { grid-template-columns: 40px 1fr; }
  .link-row .pimg { width: 40px; height: 40px; }
  .link-row > :last-child { grid-column: 1 / -1; }
  .panel { padding: 12px; }
  .key-form { padding: 14px; }
}
