/* =============================================================================
   Ofertazas — design tokens and components.

   The palette, the type scale, the spacing rhythm and the motion timings all
   live in `:root` as tokens. Nothing below this block uses a literal colour:
   every value is a token, so a change lands everywhere at once and the dark
   remap is a single block at the bottom of the token section.

   Every pairing here was measured, not eyeballed — the ratios are in the
   comments next to the tokens that carry meaning. The rules that matter:

     - body text sits at 4.5:1 or better on every surface it can land on;
     - borders that carry meaning (inputs, control edges) sit at 3:1 or
       better, which a decorative hairline does not have to;
     - the sale colour is a second, independent hue, never the accent and
       never the success colour, so a discount never reads as a link or as
       "in stock".

   The old token names (--bg, --panel, --panel-2, --line, --control) survive
   as aliases of the new semantic set, so anything not rewritten in this pass
   keeps working and inherits the new palette.
   ========================================================================== */

:root {
  /* --- surfaces ------------------------------------------------------- */
  --canvas: #f6f8f9;
  --surface: #ffffff;
  --surface-2: #f1f5f6;
  --surface-3: #e8eef0;

  /* --- lines ---------------------------------------------------------- */
  --border: #d7e0e3;        /* hairline, decorative only */
  --border-strong: #7c8f96; /* control edges, 3.07:1 on --surface-2 */

  /* --- text ----------------------------------------------------------- */
  --text: #0f1e22;          /* 16.04:1 on --canvas */
  --text-2: #3c4f55;
  --muted: #5b6b70;         /* 5.55:1 on --surface */

  /* --- brand ---------------------------------------------------------- */
  --accent: #20666b;        /* 6.62:1 on --surface */
  --accent-hover: #0c3b45;
  --accent-ink: #ffffff;
  --accent-soft: #e2f1f0;

  /* --- the sale colour ------------------------------------------------ */
  --sale: #d81b4a;          /* white on it: 5.03:1 */
  --sale-hover: #be123c;
  --sale-text: #be123c;     /* 6.29:1 on --surface */
  --sale-soft: #fdeaef;

  /* --- the other two signals ------------------------------------------ */
  --warn: #92400e;          /* 7.09:1 on --surface */
  --warn-soft: #fdf0dc;
  --good: #166534;          /* 7.13:1 on --surface */
  --good-soft: #e4f3ea;
  --bad: #a11616;
  --bad-soft: #fdeaea;

  /* --- elevation ------------------------------------------------------ */
  --shadow-1: 0 1px 2px rgba(15, 30, 34, 0.05), 0 1px 3px rgba(15, 30, 34, 0.04);
  --shadow-2: 0 4px 12px rgba(15, 30, 34, 0.08), 0 1px 2px rgba(15, 30, 34, 0.04);
  --shadow-3: 0 16px 40px rgba(15, 30, 34, 0.16), 0 2px 8px rgba(15, 30, 34, 0.06);

  /* --- radii ---------------------------------------------------------- */
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 18px;
  --r-xl: 24px;
  --r-full: 999px;

  /* --- spacing (4/8 rhythm) ------------------------------------------ */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;

  /* --- type ----------------------------------------------------------- */
  --fs-xs: 11px;
  --fs-sm: 12.5px;
  --fs-base: 15px;
  --fs-md: 16px;
  --fs-lg: 18px;
  --fs-xl: 22px;
  --fs-2xl: 28px;

  /* --- motion --------------------------------------------------------- */
  --dur-1: 120ms;
  --dur-2: 200ms;
  --dur-3: 320ms;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);

  /* --- stacking ------------------------------------------------------- */
  --z-header: 10;
  --z-nav: 20;
  --z-sheet: 40;
  --z-toast: 100;

  /* --- the native select arrow, as a token so dark mode can swap it --- */
  --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%235b6b70' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");

  /* --- aliases: the names the untouched parts of the app still use ---- */
  --bg: var(--canvas);
  --panel: var(--surface);
  --panel-2: var(--surface-2);
  --line: var(--border);
  --control: var(--border-strong);
  --control-hover: var(--accent-hover);
  --accent-ink-old: var(--accent-ink);
}

/* Dark mode is a remap, never an inversion: the hues stay, the lightness
   moves, and every pair is checked on its own surface. */
@media (prefers-color-scheme: dark) {
  :root {    --canvas: #0d1417;
    --surface: #131c20;
    --surface-2: #18242a;
    --surface-3: #223036;

    --border: #24333a;
    --border-strong: #5b7078;

    --text: #e8f0f2;        /* 14.97:1 on --surface */
    --text-2: #c3d2d6;
    --muted: #9db0b6;       /* 7.67:1 on --surface */

    --accent: #5ad1c4;      /* 9.35:1 on --surface */
    --accent-hover: #7ee0d5;
    --accent-ink: #06282a;
    --accent-soft: #14312f;

    --sale: #e11d48;
    --sale-hover: #fb7185;
    --sale-text: #fb7185;   /* 6.42:1 on --surface */
    --sale-soft: #33111d;

    --warn: #f0b429;        /* 9.27:1 */
    --warn-soft: #33280c;
    --good: #4ade80;        /* 9.92:1 */
    --good-soft: #0f2a1a;
    --bad: #f87171;
    --bad-soft: #331616;

    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.5);
    --shadow-2: 0 4px 14px rgba(0, 0, 0, 0.55);
    --shadow-3: 0 18px 44px rgba(0, 0, 0, 0.7);

    --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%239db0b6' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  }
}

/* The retailers photograph on white, so on a dark card the photo is a bright
   rectangle. A touch less brightness keeps it from glaring without touching
   the colours of the product. */
@media (prefers-color-scheme: dark) {
  .thumb,
  .hero-img {
    filter: brightness(0.93);
  }
}

/* =============================================================================
   Base
   ========================================================================== */

* {
  box-sizing: border-box;
}

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

/**
 * The JS hides things with the `hidden` property (ops links, the search row,
 * the sheet backdrop). Every author `display` rule beats the browser's
 * `[hidden] { display: none }`, so a styled element that is "hidden" would
 * stay visible — `.grid { display: grid }` on a hidden node, for instance. One
 * rule here is cheaper than remembering a `[hidden]` companion for every
 * component.
 */
[hidden] {
  display: none !important;
}

/** One focus ring for every interactive control. */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

body {
  margin: 0;
  /* dvh, not vh: mobile browsers shrink the viewport as their chrome scrolls,
     and 100vh is then taller than the screen. */
  min-height: 100dvh;
  background: var(--canvas);
  color: var(--text);
  font: var(--fs-base)/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
h4 {
  font-weight: 650;
  letter-spacing: -0.011em;
}

h2 {
  font-size: var(--fs-lg);
  margin: var(--sp-5) 0 var(--sp-3);
}

a {
  color: var(--accent);
}

code {
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 5px;
  font-size: 0.9em;
}

svg.icon {
  flex: 0 0 auto;
  display: block;
}

.muted {
  color: var(--muted);
}

/** Visible only to a screen reader. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/** Keyboard users land here first. */
.skip-link {
  position: absolute;
  left: var(--sp-3);
  top: -60px;
  z-index: var(--z-toast);
  padding: 10px 16px;
  border-radius: var(--r-full);
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  text-decoration: none;
  transition: top var(--dur-2) var(--ease);
}

.skip-link:focus {
  top: var(--sp-3);
}

/* =============================================================================
   App bar
   ========================================================================== */

.appbar {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 10px var(--sp-5);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  text-decoration: none;
  color: var(--text);
  flex: 0 0 auto;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: linear-gradient(160deg, var(--accent), var(--accent-hover));
  color: #fff;
  box-shadow: var(--shadow-1);
}

.brand-mark svg.icon {
  stroke-width: 2.1;
}

.brand-name {
  margin: 0;
  font-size: var(--fs-md);
  font-weight: 700;
  letter-spacing: -0.02em;
}

/* --- navigation ---------------------------------------------------------- */

nav {
  display: flex;
  gap: 2px;
  padding: 3px;
  border-radius: var(--r-full);
  background: var(--surface-2);
  border: 1px solid var(--border);
}

nav a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--r-full);
  color: var(--muted);
  font-size: var(--fs-sm);
  font-weight: 550;
  text-decoration: none;
  white-space: nowrap;
  transition: background var(--dur-1) var(--ease), color var(--dur-1) var(--ease);
}

nav a:hover {
  color: var(--text);
}

nav a.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-1);
}

/* --- store picker (operator views only) ---------------------------------- */

.store {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: var(--fs-sm);
  color: var(--muted);
}

.store > span {
  display: none;
}

.store select {
  max-width: 220px;
}

/* --- search -------------------------------------------------------------- */

.search {
  position: relative;
  display: flex;
  align-items: center;
  flex: 1 1 320px;
  max-width: 460px;
  margin-left: auto;
}

.search-icon {
  position: absolute;
  left: 12px;
  display: grid;
  place-items: center;
  color: var(--muted);
  pointer-events: none;
}

.search input[type="search"] {
  width: 100%;
  padding: 9px 40px 9px 38px;
  border-radius: var(--r-full);
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: var(--fs-sm);
  transition: border-color var(--dur-1) var(--ease), background var(--dur-1) var(--ease),
    box-shadow var(--dur-1) var(--ease);
}

.search input[type="search"]::placeholder {
  color: var(--muted);
}

.search input[type="search"]:focus {
  outline: none;
  background: var(--surface);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.search-clear {
  position: absolute;
  right: 6px;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  border-radius: var(--r-full);
  background: var(--surface-3);
  color: var(--text-2);
  cursor: pointer;
}

.search-clear:hover {
  background: var(--border);
}

/* --- install prompt ------------------------------------------------------ */

.install-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  padding: 7px 12px;
  border-radius: var(--r-full);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: var(--fs-sm);
  font-weight: 550;
  cursor: pointer;
  transition: border-color var(--dur-1) var(--ease), background var(--dur-1) var(--ease);
}

.install-btn:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

/* =============================================================================
   Page shell
   ========================================================================== */

main {
  padding: var(--sp-5);
  max-width: 1240px;
  margin: 0 auto;
  /* `clip`, not `hidden`: `hidden` computes `overflow-y: auto`, which turns
     the element into a scroll container and silently breaks `position:
     sticky` for everything inside it. `clip` does not. */
  overflow-x: clip;
}

.page-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
}

.page-head h2 {
  margin: 0;
}

/* =============================================================================
   Buttons
   ========================================================================== */

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  /* Kills the double-tap-to-zoom wait on touch without disabling pinch. */
  touch-action: manipulation;
  transition: background var(--dur-1) var(--ease), border-color var(--dur-1) var(--ease),
    color var(--dur-1) var(--ease), box-shadow var(--dur-1) var(--ease),
    transform var(--dur-1) var(--ease);
}

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

/* The plain button: a surface with a visible edge. */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 16px;
  min-height: 40px;
  border-radius: var(--r-full);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: var(--fs-sm);
  font-weight: 600;
}

.btn:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

/* The one primary action on a screen. */
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  box-shadow: var(--shadow-1);
}

.btn.primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: var(--accent-ink);
}

.btn.ghost {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.btn.ghost:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--text);
}

.btn.danger {
  border-color: color-mix(in srgb, var(--bad) 45%, transparent);
  color: var(--bad);
  background: var(--bad-soft);
}

.btn.danger:hover:not(:disabled) {
  border-color: var(--bad);
}

/* A square icon button. */
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: var(--r-full);
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
}

.icon-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

button.link {
  padding: 0;
  background: none;
  border: none;
  color: var(--muted);
  font-size: var(--fs-sm);
  text-decoration: underline;
  text-underline-offset: 3px;
}

button.link:hover {
  color: var(--text);
}

/* =============================================================================
   Form controls
   ========================================================================== */

select,
input[type="number"],
input[type="search"],
input[type="text"],
input[type="password"] {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  padding: 8px 10px;
  font-size: var(--fs-sm);
  transition: border-color var(--dur-1) var(--ease), box-shadow var(--dur-1) var(--ease);
}

select {
  appearance: none;
  padding-right: 30px;
  background-image: var(--chevron);
  background-repeat: no-repeat;
  background-position: right 9px center;
  cursor: pointer;
}

select:focus,
input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

input::placeholder {
  color: var(--muted);
}

label {
  color: var(--text-2);
}

/* =============================================================================
   Chips
   ========================================================================== */

.chips {
  display: flex;
  gap: var(--sp-2);
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
  /* A scroll container must not eat the vertical padding of the row. */
  scroll-padding-inline: var(--sp-4);
}

.chips::-webkit-scrollbar {
  display: none;
}

.chip,
button.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  max-width: 100%;
  padding: 6px 12px;
  border-radius: var(--r-full);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  font-size: var(--fs-sm);
  font-weight: 550;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: var(--shadow-1);
}

.chip:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

button.chip[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

/* The chip that clears one active filter. */
.chip.removable {
  padding-right: 6px;
}

.chip .chip-x {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: var(--r-full);
  background: color-mix(in srgb, currentColor 12%, transparent);
}

.chip .chip-x:hover {
  background: color-mix(in srgb, currentColor 22%, transparent);
}

.chip.chip-accent {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 30%, transparent);
  color: var(--accent);
}

/* =============================================================================
   Badges
   ========================================================================== */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: var(--r-full);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  font-size: var(--fs-xs);
  font-weight: 600;
  white-space: nowrap;
}

/* The discount. The one saturated pill on the card. */
.badge.off {
  background: var(--sale);
  border-color: var(--sale);
  color: #fff;
  font-size: var(--fs-sm);
  font-weight: 700;
  letter-spacing: -0.01em;
}

.badge.unit {
  background: var(--warn-soft);
  border-color: color-mix(in srgb, var(--warn) 35%, transparent);
  color: var(--warn);
}

.badge.member {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 30%, transparent);
  color: var(--accent);
}

.badge.store {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text-2);
}

.badge.price {
  background: var(--surface-2);
  color: var(--text-2);
}

.status {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--r-full);
  font-size: var(--fs-xs);
  font-weight: 650;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
}

.status.ok {
  color: var(--good);
  background: var(--good-soft);
  border-color: color-mix(in srgb, var(--good) 30%, transparent);
}

.status.error {
  color: var(--bad);
  background: var(--bad-soft);
  border-color: color-mix(in srgb, var(--bad) 30%, transparent);
}

/* =============================================================================
   Filter bar
   ========================================================================== */

.filter-bar {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-wrap: wrap;
  margin: var(--sp-4) 0 var(--sp-2);
}

.filter-trigger {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 14px;
  min-height: 40px;
  border-radius: var(--r-full);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: var(--fs-sm);
  font-weight: 600;
  box-shadow: var(--shadow-1);
}

.filter-trigger:hover {
  border-color: var(--accent);
}

.filter-count {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: var(--r-full);
  background: var(--accent);
  color: var(--accent-ink);
  font-size: var(--fs-xs);
  font-weight: 700;
}

.sort-field {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--fs-sm);
}

.sort-field > span {
  color: var(--muted);
}

.result-count {
  margin-left: auto;
  color: var(--muted);
  font-size: var(--fs-sm);
  font-variant-numeric: tabular-nums;
}

.meta-line {
  margin: 0 0 var(--sp-3);
  font-size: var(--fs-sm);
}

.active-filters {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  margin-bottom: var(--sp-4);
}

.active-filters:empty {
  display: none;
}

/* =============================================================================
   The card
   ========================================================================== */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(212px, 1fr));
  gap: var(--sp-4);
}

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: var(--shadow-1);
  transition: box-shadow var(--dur-2) var(--ease), transform var(--dur-2) var(--ease),
    border-color var(--dur-2) var(--ease);
}

@media (hover: hover) {
  .card:hover {
    box-shadow: var(--shadow-2);
    transform: translateY(-2px);
    border-color: color-mix(in srgb, var(--accent) 25%, var(--border));
  }
}

.card-media-wrap {
  position: relative;
  background: var(--surface-2);
}

.card-media {
  display: block;
  width: 100%;
  padding: 0;
  border: none;
  background: transparent;
  aspect-ratio: 1 / 1;
}

.thumb {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.thumb.placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  opacity: 0.45;
}

/* The discount, floating over the photo on the wide layout. */
.pill-overlay {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 2;
  pointer-events: none;
}

/* The add button, floating over the photo on the wide layout. */
.card-add {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 3;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: var(--r-full);
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(8px);
  color: var(--text-2);
  box-shadow: var(--shadow-1);
}

.card-add:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.card-add.in-list {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.card-add:active {
  transform: scale(0.94);
}

.card-body {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 10px 14px 14px;
  min-width: 0;
}

.card-top {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.card-store {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  color: var(--muted);
  font-size: var(--fs-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.store-dot {
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  border-radius: var(--r-full);
  background: var(--accent);
}

.card-title {
  margin: 0;
  font-size: var(--fs-base);
  font-weight: 550;
  line-height: 1.35;
}

.card-title button {
  display: block;
  width: 100%;
  padding: 0;
  border: none;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  line-height: inherit;
}

.card-title button:hover {
  color: var(--accent);
}

.meta {
  margin: 0;
  color: var(--muted);
  font-size: var(--fs-sm);
  overflow-wrap: anywhere;
}

.prices {
  margin: 2px 0 0;
  display: flex;
  align-items: baseline;
  gap: 7px;
  flex-wrap: wrap;
}

.prices .now {
  font-size: var(--fs-xl);
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.prices .now .cents {
  font-size: var(--fs-base);
  font-weight: 600;
  color: var(--text-2);
}

.prices s {
  color: var(--muted);
  font-size: var(--fs-sm);
  font-variant-numeric: tabular-nums;
}

/* What the discount is worth in pesos. The second, quieter signal. */
.save {
  margin: 1px 0 0;
  color: var(--good);
  font-size: var(--fs-sm);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* The inline discount, for the compact layout only: on the wide layout the
   same number floats over the photo instead, and showing both would repeat
   the most important thing on the card. */
.pill-inline {
  display: none;
  margin-left: auto;
}

/* =============================================================================
   The feed's other states
   ========================================================================== */

.empty {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-6) var(--sp-4);
  text-align: center;
  color: var(--muted);
}

.empty-icon {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: var(--r-full);
  background: var(--surface-2);
  color: var(--muted);
}

.empty p {
  margin: 0;
  max-width: 42ch;
}

.more {
  display: flex;
  justify-content: center;
  padding: var(--sp-5) 0 var(--sp-6);
}

.more button {
  padding: 10px 22px;
  min-height: 44px;
  border-radius: var(--r-full);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: var(--fs-sm);
  font-weight: 600;
  box-shadow: var(--shadow-1);
}

.more button:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

/* =============================================================================
   Skeletons
   ========================================================================== */

.skeleton {
  display: grid;
  gap: var(--sp-4);
}

.skeleton-row {
  height: 96px;
  border-radius: var(--r-md);
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 50%, var(--surface) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s linear infinite;
}

/* Card-shaped skeletons, so the layout does not jump when the page lands. */
.card-skeleton {
  border-radius: var(--r-lg);
  border: 1px solid var(--border);
  background: var(--surface);
  overflow: hidden;
}

.card-skeleton .sk-media {
  aspect-ratio: 1 / 1;
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s linear infinite;
}

.card-skeleton .sk-line {
  height: 10px;
  margin: 12px 14px 0;
  border-radius: var(--r-full);
  background: var(--surface-2);
}

.card-skeleton .sk-line.short {
  width: 40%;
}

.card-skeleton .sk-line.thin {
  height: 8px;
  margin-top: 8px;
  width: 70%;
}

.card-skeleton .sk-line.price {
  height: 16px;
  width: 50%;
  margin-top: 12px;
}

@keyframes shimmer {
  to {
    background-position: -200% 0;
  }
}

/* =============================================================================
   Shopping list
   ========================================================================== */

.list-view {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
}

.list-head h2 {
  margin: 0;
}

.list-actions {
  display: flex;
  gap: var(--sp-3);
}

.list-group h3 {
  margin: var(--sp-4) 0 var(--sp-2);
  font-size: var(--fs-sm);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.list-row {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) auto;
  gap: var(--sp-3);
  align-items: center;
  padding: var(--sp-2) 0;
  border-bottom: 1px solid var(--border);
}

.list-row.unavailable {
  opacity: 0.55;
}

/* The thumb box owns the 64px grid column and the photo fills it exactly:
   a wrap wider than its column would overlap the text beside it. */
.list-row .thumb-wrap {
  width: 64px;
  height: 64px;
  aspect-ratio: auto;
  overflow: hidden;
  border-radius: var(--r-sm);
  background: var(--surface-2);
}

.list-row .thumb {
  width: 100%;
  height: 100%;
}

.list-body {
  min-width: 0;
}

.list-body h4 {
  margin: 0;
  font-size: var(--fs-base);
  font-weight: 550;
}

.list-body .meta {
  margin: 2px 0;
}

.list-body .prices {
  margin: 2px 0 0;
}

.list-body .prices .now {
  font-size: var(--fs-md);
}

/* 44x44: the global button padding left this glyph around 30px tall, under
   the touch-target floor, and it is the only control in the list view. */
.remove {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: var(--r-full);
  color: var(--muted);
}

.remove:hover {
  background: var(--bad-soft);
  color: var(--bad);
}

/* =============================================================================
   Auth
   ========================================================================== */

.list-auth {
  max-width: 400px;
  width: 100%;
  margin: var(--sp-4) auto;
  padding: var(--sp-5);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-2);
}

/* Signed out, the sign-in card is the whole page: centred in it. */
body.auth-mode main {
  display: grid;
  place-items: center;
  min-height: calc(100dvh - 72px);
}

.list-auth h2 {
  margin: 0 0 var(--sp-1);
}

.list-auth > .muted {
  margin: 0 0 var(--sp-4);
  font-size: var(--fs-sm);
}

/* The two auth paths sit side by side, not as a link at the bottom of the
   form. `aria-pressed` is the same toggle the feed chips already use, so both
   paths are ordinary buttons: reachable by keyboard, announced as pressed or
   not, and no new ARIA widget to get wrong. */
.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin-bottom: var(--sp-3);
  padding: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
}

.auth-tab {
  min-height: 40px;
  padding: 0 10px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  color: var(--text-2);
  font-size: var(--fs-sm);
  font-weight: 600;
}

.auth-tab[aria-pressed="true"] {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
  box-shadow: var(--shadow-1);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.auth-form label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: var(--fs-sm);
  font-weight: 550;
}

.auth-form input {
  width: 100%;
  padding: 10px 12px;
  font-size: var(--fs-md);
  border-radius: var(--r-sm);
}

.auth-form button[type="submit"] {
  padding: 11px;
  min-height: 44px;
  border-radius: var(--r-sm);
  border: none;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 650;
}

.auth-form button[type="submit"]:hover {
  background: var(--accent-hover);
}

/* =============================================================================
   Dialogs and sheets
   ========================================================================== */

dialog {
  padding: 0;
  border: none;
  background: var(--surface);
  color: var(--text);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-3);
  overflow: hidden;
}

dialog::backdrop {
  /* A teal scrim, not neutral black: the app is teal, and a black veil over
     a mint page reads as a different app. */
  background: rgba(12, 59, 69, 0.55);
  backdrop-filter: blur(2px);
}

/* The grab handle, shown when the sheet is anchored to the bottom. */
.sheet-grip {
  display: none;
  width: 38px;
  height: 4px;
  margin: 10px auto 0;
  border-radius: var(--r-full);
  background: var(--border-strong);
}

.sheet-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.sheet-head h2 {
  margin: 0;
  font-size: var(--fs-lg);
}

.sheet-head .muted {
  margin: 2px 0 0;
  font-size: var(--fs-sm);
}

.sheet-body {
  padding: var(--sp-5);
  overflow: auto;
  max-height: min(64dvh, 620px);
}

/* --- the product sheet --------------------------------------------------- */

#product {
  width: min(760px, 94vw);
}

.product-hero {
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr);
  gap: var(--sp-5);
  align-items: start;
  margin-bottom: var(--sp-4);
}

.hero-img-wrap {
  aspect-ratio: 1 / 1;
  border-radius: var(--r-md);
  background: var(--surface-2);
  overflow: hidden;
}

.hero-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.product-price {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--sp-2);
}

.product-price .prices .now {
  font-size: var(--fs-2xl);
}

.product-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  margin-bottom: var(--sp-4);
}

.promo-labels {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: var(--sp-4);
}

.promo-labels:empty {
  display: none;
}

.spark-wrap {
  margin: var(--sp-4) 0 var(--sp-2);
  color: var(--accent);
}

.spark {
  width: 100%;
  height: 72px;
  display: block;
}

.spark-legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-4);
  margin: 0 0 var(--sp-4);
  font-size: var(--fs-sm);
  color: var(--muted);
}

.spark-legend b {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* --- the filter sheet ---------------------------------------------------- */

#filters {
  width: min(520px, 94vw);
}

.filter-fields {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: var(--fs-sm);
  font-weight: 600;
}

.field > span {
  color: var(--muted);
  font-weight: 550;
}

.field select {
  width: 100%;
  padding: 10px 12px;
  font-size: var(--fs-md);
}

.field-hint {
  font-size: var(--fs-sm);
  color: var(--muted);
  font-weight: 400;
}

.kind-options {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
}

.sheet-actions {
  display: flex;
  gap: var(--sp-2);
  margin-top: var(--sp-5);
  padding-top: var(--sp-4);
  border-top: 1px solid var(--border);
}

.sheet-actions .btn.primary {
  flex: 1 1 auto;
}

/* =============================================================================
   Tables
   ========================================================================== */

/* The scroll container, so a wide table scrolls instead of being clipped. */
.table-wrap {
  overflow-x: auto;
  margin: var(--sp-2) 0 var(--sp-5);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-sm);
}

th,
td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

thead th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 600;
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr:hover td {
  background: var(--surface-2);
}

td.num,
th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* =============================================================================
   Toast
   ========================================================================== */

.toast {
  position: fixed;
  left: 50%;
  bottom: var(--sp-4);
  transform: translateX(-50%) translateY(20px);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  max-width: calc(100vw - 32px);
  padding: 10px 14px;
  border-radius: var(--r-full);
  background: var(--text);
  color: var(--canvas);
  box-shadow: var(--shadow-3);
  font-size: var(--fs-sm);
  font-weight: 550;
  opacity: 0;
  transition: opacity var(--dur-2) var(--ease), transform var(--dur-2) var(--ease);
  z-index: var(--z-toast);
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

.toast-action {
  padding: 4px 10px;
  border: none;
  border-radius: var(--r-full);
  background: color-mix(in srgb, var(--canvas) 22%, transparent);
  color: inherit;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.toast-action:hover {
  background: color-mix(in srgb, var(--canvas) 34%, transparent);
}

/* =============================================================================
   Errors and offline
   ========================================================================== */

.error {
  padding: var(--sp-4);
  border: 1px solid color-mix(in srgb, var(--bad) 40%, transparent);
  border-radius: var(--r-md);
  background: var(--bad-soft);
}

.error b {
  color: var(--bad);
}

.error p {
  margin: 6px 0 var(--sp-3);
  color: var(--text-2);
}

.offline-note {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin: var(--sp-3) 0;
  padding: 10px 14px;
  border-radius: var(--r-md);
  background: var(--warn-soft);
  color: var(--warn);
  font-size: var(--fs-sm);
  font-weight: 550;
}

/* =============================================================================
   Touch and motion
   ========================================================================== */

/* Rather than wrapping every :hover in `@media (hover: hover)`, they are reset
   here: these selectors match the originals and come later in the file, so they
   win, and the desktop rules stay readable. Without this a phone keeps the last
   tapped card looking hovered until something else is tapped. */
@media (hover: none) {
  nav a:hover {
    color: var(--muted);
  }
  nav a.active:hover {
    color: var(--text);
  }
  .card:hover {
    box-shadow: var(--shadow-1);
    transform: none;
  }
  .card-add:hover {
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    color: var(--text-2);
  }
  .card-add.in-list:hover {
    background: var(--accent);
    color: var(--accent-ink);
  }
  .btn:hover:not(:disabled) {
    border-color: var(--border-strong);
    background: var(--surface);
  }
  .btn.primary:hover:not(:disabled) {
    background: var(--accent);
    border-color: var(--accent);
  }
  .chip:hover {
    border-color: var(--border);
    color: var(--text-2);
  }
  button.chip[aria-pressed="true"]:hover {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-ink);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }

  .skeleton-row,
  .card-skeleton .sk-media {
    animation: none;
  }
}

/* =============================================================================
   Compact (phones)

   One breakpoint, mirrored in app.js:

     const COMPACT = window.matchMedia("(max-width: 640px)")

   Change both. If the JS constant is wider than this, the router will let an
   ops view open on a screen whose tabs to leave it are hidden.
   ========================================================================== */

@media (max-width: 640px) {
  /* Two columns so the search field can take a full row of its own, and the
     nav can leave the flow entirely for the bottom bar below. */
  .appbar {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px 10px;
    padding: 10px 14px;
    /* No backdrop-filter here. A filter on an ancestor makes it the
       containing block for `position: fixed` descendants, which would anchor
       the bottom bar to the app bar instead of the viewport. */
    backdrop-filter: none;
    background: var(--surface);
  }

  .brand-name {
    font-size: var(--fs-base);
  }

  .brand-mark {
    width: 30px;
    height: 30px;
  }

  .store {
    grid-column: 2;
    min-width: 0;
  }

  .store select {
    width: 100%;
    max-width: none;
  }

  .search {
    grid-column: 1 / -1;
    grid-row: 2;
    max-width: none;
    margin-left: 0;
  }

  .install-btn {
    grid-column: 3;
    grid-row: 1;
    width: 40px;
    height: 40px;
    padding: 0;
    justify-content: center;
    font-size: 0;
    gap: 0;
  }

  .install-btn svg.icon {
    width: 20px;
    height: 20px;
  }

  /* --- bottom bar ------------------------------------------------------- */
  nav {
    position: fixed;
    inset: auto 0 0 0;
    z-index: var(--z-nav);
    gap: 0;
    /* Clears the home indicator on the devices that have one. */
    padding-bottom: env(safe-area-inset-bottom);
    border-radius: 0;
    border-top: 1px solid var(--border);
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: saturate(1.4) blur(12px);
  }

  nav a {
    flex: 1;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 6px 4px;
    min-height: 56px;
    border-radius: 0;
    font-size: 11px;
    font-weight: 600;
    color: var(--muted);
  }

  nav a svg.icon {
    width: 22px;
    height: 22px;
  }

  /* On the top edge, because the bar is on the bottom. */
  nav a.active {
    background: transparent;
    box-shadow: inset 0 2px 0 var(--accent);
    color: var(--accent);
  }

  /* Clears the bar plus the home indicator. */
  main {
    padding: 14px 14px calc(78px + env(safe-area-inset-bottom));
  }

  /* When the bottom bar is hidden (one consumer destination left), reclaim its
     padding so the feed reaches the screen edge. */
  body.no-nav main {
    padding-bottom: calc(14px + env(safe-area-inset-bottom));
  }

  /* 16px, not 13: iOS zooms the whole page when a focused control is smaller,
     and the user has to pinch back out to read anything. */
  body {
    font-size: var(--fs-md);
  }

  select,
  input[type="number"],
  input[type="search"],
  input[type="text"],
  input[type="password"],
  .btn,
  .icon-btn {
    min-height: 44px;
    font-size: 16px;
  }

  .icon-btn {
    width: 44px;
    height: 44px;
  }

  .btn {
    padding: 10px 18px;
  }

  /* Chips are their own touch targets and must not inherit the 44px floor,
     but they still get a generous hit area through the pseudo-element below. */
  button.chip,
  .chip {
    min-height: auto;
    font-size: var(--fs-sm);
    padding: 8px 13px;
  }

  .chips {
    margin-inline: -14px;
    padding-inline: 14px;
  }

  /* ---------------------------------------------------------- feed cards */
  .grid {
    grid-template-columns: 1fr;
    gap: var(--sp-3);
  }

  .card {
    display: grid;
    grid-template-columns: 88px minmax(0, 1fr) 44px;
    align-items: center;
    gap: var(--sp-3);
    padding: 10px;
    border-radius: var(--r-md);
  }

  .card-media-wrap {
    grid-column: 1;
    border-radius: var(--r-sm);
    overflow: hidden;
  }

  .card-media {
    aspect-ratio: 1 / 1;
  }

  .card-body {
    grid-column: 2;
    padding: 0;
    gap: 2px;
  }

  /* The add button leaves the overlay and becomes the row's third column. */
  .card-add {
    position: static;
    grid-column: 3;
    width: 44px;
    height: 44px;
    background: var(--surface-2);
    backdrop-filter: none;
  }

  .card:hover {
    transform: none;
  }

  /* The discount pill moves out of the photo and into the row. */
  .pill-overlay {
    display: none;
  }

  .pill-inline {
    display: inline-flex;
    margin-left: auto;
  }

  .card-title {
    font-size: var(--fs-base);
  }

  .prices .now {
    font-size: var(--fs-lg);
  }

  /* ---------------------------------------------------------- filter bar */
  .filter-bar {
    margin-top: var(--sp-3);
    gap: var(--sp-2);
  }

  .result-count {
    width: 100%;
    margin-left: 0;
  }

  .sort-field > span {
    display: none;
  }

  /* --------------------------------------------------------------- sheets */
  dialog {
    width: 100%;
    max-width: 100%;
    /* Bottom-anchored rather than centred. */
    margin: auto auto 0;
    max-height: 92dvh;
    border-radius: var(--r-xl) var(--r-xl) 0 0;
  }

  .sheet-grip {
    display: block;
  }

  .sheet-head {
    padding: var(--sp-3) var(--sp-4);
  }

  .sheet-body {
    padding: var(--sp-4);
    max-height: calc(92dvh - 140px);
    /* Leaves the last field clear of the home indicator. */
    padding-bottom: calc(var(--sp-4) + env(safe-area-inset-bottom));
  }

  .product-hero {
    grid-template-columns: 1fr;
    gap: var(--sp-3);
  }

  .hero-img-wrap {
    max-width: 220px;
    margin-inline: auto;
  }

  .product-actions .btn {
    flex: 1 1 100%;
  }

  /* The history table becomes label/value rows. The DOM stays a real table
     and the header cells stay in the markup — only the display changes. */
  dialog table,
  dialog tbody,
  dialog tr,
  dialog td {
    display: block;
  }

  dialog thead {
    display: none;
  }

  dialog tr {
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
  }

  dialog td {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    padding: 3px 0;
    border: 0;
  }

  dialog td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: var(--fs-sm);
  }

  /* The ops tables scroll sideways instead of being clipped. */
  .table-wrap {
    border-radius: var(--r-sm);
  }

  th,
  td {
    padding: 8px 10px;
  }

  /* --------------------------------------------------------------- misc */
  .list-auth {
    margin: var(--sp-4) 0;
    padding: var(--sp-4);
    border-radius: var(--r-lg);
  }

  .list-row {
    grid-template-columns: 56px minmax(0, 1fr) auto;
  }

  .list-row .thumb-wrap {
    width: 56px;
    height: 56px;
  }

  .toast {
    bottom: calc(84px + env(safe-area-inset-bottom));
  }
}
