/*
 * Listo stylesheet — warm "liquid glass".
 * Finch-inspired cozy pastels (peach / lavender / mint), frosted translucent
 * panels over a soft gradient canvas, floaty rounded cards. Hand-rolled design
 * system with @layer ordering and OKLCH tokens — no Tailwind.
 *
 * Light/dark: every color is a light-dark() pair. Which side renders is driven
 * by `color-scheme` on :root — `light dark` follows the OS, and the theme
 * toggle pins it to `light` or `dark` (persisted in localStorage; applied
 * pre-paint by an inline <head> script).
 */

@layer reset, base, components, utilities;

:root {
  color-scheme: light dark;

  /* Warm pastel palette */
  --canvas:        light-dark(oklch(97% 0.02 70),   oklch(23% 0.02 40));
  --ink:           light-dark(oklch(32% 0.03 40),   oklch(94% 0.02 70));
  --ink-soft:      light-dark(oklch(53% 0.03 45),   oklch(78% 0.02 70));
  --line:          light-dark(oklch(89% 0.02 60),   oklch(42% 0.02 40));

  --accent:        light-dark(oklch(70% 0.14 32),   oklch(76% 0.13 32));  /* peach/coral — primary */
  --accent-strong: light-dark(oklch(62% 0.17 32),   oklch(72% 0.15 32));
  --accent-2:      light-dark(oklch(72% 0.11 300),  oklch(74% 0.12 300)); /* lavender */
  --accent-3:      light-dark(oklch(80% 0.11 165),  oklch(74% 0.12 165)); /* mint */
  --accent-ink:    light-dark(oklch(99% 0.01 70),   oklch(20% 0.02 40));  /* text on accent fill */
  --danger:        light-dark(oklch(60% 0.18 25),   oklch(68% 0.17 25));

  /* Liquid glass */
  --glass-bg:      light-dark(oklch(100% 0 0 / 0.55), oklch(32% 0.02 40 / 0.42));
  --glass-strong:  light-dark(oklch(100% 0 0 / 0.72), oklch(36% 0.02 40 / 0.6));
  --glass-border:  light-dark(oklch(100% 0 0 / 0.75), oklch(100% 0 0 / 0.12));
  --glass-blur:    blur(16px) saturate(1.5);
  --glass-hi:      inset 0 1px 0 light-dark(oklch(100% 0 0 / 0.65), oklch(100% 0 0 / 0.08));
  --shadow-card:   0 1px 2px light-dark(oklch(40% 0.04 40 / 0.06), oklch(0% 0 0 / 0.4)),
                   0 10px 28px light-dark(oklch(45% 0.08 40 / 0.10), oklch(0% 0 0 / 0.32));
  --shadow-pop:    0 8px 22px light-dark(color-mix(in oklch, var(--accent) 34%, transparent), oklch(0% 0 0 / 0.5));

  /* Space & radius — cozy, rounded */
  --space:     1rem;
  --radius:    0.9rem;
  --radius-lg: 1.4rem;

  /* Type — fluid, mobile-first */
  --font:         "Nunito", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-display: "Fredoka", var(--font);
  --text:         clamp(1rem, 0.95rem + 0.3vw, 1.125rem);
  --text-lg:      clamp(1.9rem, 1.5rem + 1.8vw, 2.9rem);

  /* Motion */
  --ease: cubic-bezier(0.2, 0, 0, 1);
  --dur:  200ms;
}

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  * { margin: 0; }
  html { -webkit-text-size-adjust: 100%; }
  /* Kill the blue/grey tap-flash browsers show when touching an element. */
  html { -webkit-tap-highlight-color: transparent; }
  button, input, select, textarea { font: inherit; color: inherit; }
}

@layer base {
  body {
    font-family: var(--font);
    font-size: var(--text);
    line-height: 1.5;
    color: var(--ink);
    background-color: var(--canvas);
    min-height: 100dvh;
    overflow-x: hidden;
    padding: max(var(--space), env(safe-area-inset-top)) var(--space) calc(var(--space) * 2);
  }
  /* Soft pastel mesh — the colorful backdrop the frosted panels blur. Painted on
     its own fixed compositor layer instead of `background-attachment: fixed`,
     which (with the panels' backdrop-filter) repaints on every Turbo view swap
     and flickers, especially on mobile. A fixed layer stays put and doesn't. */
  body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    background-image:
      radial-gradient(42rem 42rem at 12% -8%,  color-mix(in oklch, var(--accent)   40%, transparent), transparent 60%),
      radial-gradient(40rem 40rem at 105% 8%,  color-mix(in oklch, var(--accent-2) 42%, transparent), transparent 60%),
      radial-gradient(46rem 46rem at 50% 118%, color-mix(in oklch, var(--accent-3) 40%, transparent), transparent 62%);
  }

  h1, h2 { font-family: var(--font-display); font-weight: 700; }
  h1 { font-size: var(--text-lg); letter-spacing: -0.01em; color: var(--ink); line-height: 1.1; }

  p { color: var(--ink-soft); }
  a { color: var(--accent-strong); }
}

/* ---- Shared glass surface ---------------------------------------------- */
@layer components {
  .list-row, .entry, .cat-row, .suggestion, .brand-row, .flash, .history-card, .history-row,
  .field input, .field textarea, .qty__input,
  input[type="text"], input[type="number"], input[type="search"], textarea, select {
    background: var(--glass-bg);
    -webkit-backdrop-filter: var(--glass-blur);
    backdrop-filter: var(--glass-blur);
    border: 1px solid var(--glass-border);
    box-shadow: var(--shadow-card), var(--glass-hi);
    border-radius: var(--radius-lg);
  }

  /* Page containers */
  .lists, .list-show, .list-form, .settings, .product-merge, .shopping, .extras,
  .categories, .category-form, .product-edit, .history {
    display: grid;
    gap: var(--space);
    max-width: 40rem;
    margin-inline: auto;
  }
  /* Play the entrance animation on the first (full) page load only. `html` is
     added `.visited` after the first Turbo render, so subsequent view swaps
     don't re-animate the whole page — which read as a flicker. */
  html:not(.visited) :is(.lists, .list-show, .list-form, .settings, .product-merge,
  .shopping, .extras, .categories, .category-form, .product-edit, .history) {
    animation: fade-slide-in var(--dur) var(--ease);
  }
  /* Let single-column grid children shrink to the track instead of overflowing
     (default grid/flex min-width is `auto`), so inner flex-wrap can do its job. */
  .lists > *, .list-show > *, .list-form > *, .settings > *, .product-merge > *,
  .shopping > *, .extras > *,
  .categories > *, .category-form > *, .product-edit > * { min-width: 0; }

  /* Settings hub rows (override .list-row's block display) */
  .settings .list-row { display: grid; gap: 0.15em; }
  .settings__label { font-weight: 700; color: var(--ink); }

  /* Lists index: name + "Ir às compras" cart pill */
  .list-item { display: flex; align-items: stretch; gap: 0.5em; }
  .list-item__name { flex: 1; min-width: 0; text-align: center; }
  .shop-pill {
    display: inline-flex; align-items: center; gap: 0.4em;
    padding: 0 1em; border-radius: var(--radius-lg);
    background: var(--accent-strong); color: var(--accent-ink);
    text-decoration: none; font-weight: 700; font-size: 0.85em; white-space: nowrap;
    box-shadow: var(--shadow-pop);
    transition: transform var(--dur) var(--ease), filter var(--dur) var(--ease);
  }
  @media (hover: hover) { .shop-pill:hover { transform: translateY(-2px); filter: brightness(1.03); } }

  /* Used lists: a quieter section under the active ones. The row opens the
     record; the pill is a button, so reset its chrome to match the link pill. */
  .used-lists { display: grid; gap: 0.6em; margin-top: var(--space); }
  .used-lists__heading { font-size: 0.95rem; color: var(--ink-soft); }
  .used-lists .list-hint { margin-top: -0.3em; }
  .list-row.list-item__name--used { display: grid; gap: 0.1em; color: var(--ink-soft); }
  .list-item__meta { font-size: 0.75em; font-weight: 600; }
  .list-item__form { display: flex; margin: 0; }
  .shop-pill--copy {
    font-family: inherit; cursor: pointer;
    background: var(--glass-bg); color: var(--ink);
    border: 1px solid var(--glass-border); box-shadow: var(--glass-hi);
  }

  /* Management row: tapping the name (a <details> summary) reveals the note editor */
  /* Zero basis, like .entry__body: a long note wraps instead of pushing the
     row's actions onto their own line. */
  .note-toggle { flex: 1 1 0; min-width: 0; }
  .note-toggle > summary { list-style: none; cursor: pointer; }
  .note-toggle > summary::-webkit-details-marker { display: none; }
  .entry__link {
    display: flex; flex-direction: column; align-items: flex-start; gap: 0.1em;
    min-width: 0; color: var(--ink); font-weight: 700; text-decoration: none;
  }
  .entry__note-preview {
    font-weight: 400; font-size: 0.8em; color: var(--ink-soft);
    line-height: 1.3; overflow-wrap: anywhere;
  }
  /* Shopping row: the note sits under the name and is itself the edit toggle, so
     fixing a note mid-trip never crosses the item off. */
  .entry__body .entry__note-preview {
    display: flex; align-items: center; gap: 0.4em;
    padding: 0.2em 0 0.2em 1.95rem;  /* aligned under the name, with a tappable band */
  }
  /* Filled notepad glyph in a fixed slot at the start of the band, centered on
     the element, so it never drifts with the length of the note text. */
  .entry__note-edit {
    flex: 0 0 auto;
    display: inline-grid; place-items: center;
    width: 1.2em; height: 1.2em;
    color: var(--accent-strong);
  }
  .entry__note-edit svg { width: 100%; height: 100%; display: block; }
  /* No note yet: the notepad alone, dimmed so a list of blank rows stays quiet. */
  .entry__note-preview--empty .entry__note-edit { opacity: 0.45; }
  .note-toggle[open] .entry__note-edit { opacity: 1; }
  .entry__note-editor { display: none; flex-basis: 100%; margin-top: 0.5em; }
  .entry:has(.note-toggle[open]) .entry__note-editor { display: block; }
  .entry:has(.note-toggle[open]) { box-shadow: var(--shadow-card), var(--glass-hi), inset 0 0 0 1.5px color-mix(in oklch, var(--accent) 40%, transparent); }

  /* "novo" tag on on-the-go items in the shopping view */
  .tag--new {
    margin-left: 0.5em; padding: 0.05em 0.5em; border-radius: 999px;
    background: color-mix(in oklch, var(--accent-3) 55%, transparent);
    color: var(--ink); font-size: 0.7em; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.04em; vertical-align: middle;
  }

  /* Extras prompt actions */
  .extras__actions { display: flex; flex-wrap: wrap; gap: 0.6em; }
  .button.button--ghost {
    background: var(--glass-bg); color: var(--ink); box-shadow: var(--glass-hi);
    border: 1px solid var(--glass-border);
  }

  /* ---- Nav: floating glass bar ---------------------------------------- */
  .nav {
    position: sticky;
    top: max(0.5rem, env(safe-area-inset-top));
    z-index: 10;
    display: flex;
    align-items: center;
    gap: var(--space);
    padding: 0.55rem 0.9rem;
    margin-bottom: calc(var(--space) * 1.5);
    background: var(--glass-strong);
    -webkit-backdrop-filter: var(--glass-blur);
    backdrop-filter: var(--glass-blur);
    border: 1px solid var(--glass-border);
    border-radius: 999px;
    box-shadow: var(--shadow-card), var(--glass-hi);
    transition: transform var(--dur) var(--ease), opacity var(--dur) var(--ease);
    will-change: transform;
  }
  /* Toggled by the nav-hide controller: slide up + fade out when scrolling down. */
  .nav--hidden {
    transform: translateY(-130%);
    opacity: 0;
    pointer-events: none;
  }
  .nav__brand {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--accent-strong);
    text-decoration: none;
  }
  .nav__logo { height: 1.7em; width: auto; display: block; }
  .nav__actions { display: flex; gap: 0.6rem; margin-left: auto; align-items: center; }
  .nav a { text-decoration: none; color: var(--ink-soft); font-weight: 600; }

  /* ---- Buttons -------------------------------------------------------- */
  .button, input[type="submit"] {
    display: inline-block;
    padding: 0.6em 1.2em;
    border: 0;
    border-radius: 999px;
    background: var(--accent-strong);
    color: var(--accent-ink);
    text-align: center;
    text-decoration: none;
    font-family: var(--font);
    font-weight: 700;
    cursor: pointer;
    box-shadow: var(--shadow-pop);
    transition: transform var(--dur) var(--ease), filter var(--dur) var(--ease);
  }
  .button--danger { background: var(--danger); }

  /* Compact "add" affordance: same accent pill, shrunk to a round + icon. */
  .button--add {
    justify-self: center;
    align-self: center;
    display: inline-grid;
    place-items: center;
    width: 2.9rem;
    height: 2.9rem;
    flex: 0 0 auto;
    padding: 0;
  }
  .button--add svg { width: 1.35rem; height: 1.35rem; display: block; }

  @media (hover: hover) {
    .button:hover, input[type="submit"]:hover { transform: translateY(-2px); filter: brightness(1.03); }
    .button:active, input[type="submit"]:active { transform: translateY(0); }
    .list-row:hover, .cat-row:hover, .suggestion:hover { transform: translateY(-2px); }
    .icon-btn:hover { transform: scale(1.08); color: var(--accent-strong); }
    .entry__toggle:hover .entry__check { border-color: var(--accent-strong); }
  }

  /* ---- Lists ---------------------------------------------------------- */
  .list-row {
    display: block;
    padding: 1em 1.15em;
    color: var(--ink);
    text-decoration: none;
    font-weight: 700;
    transition: transform var(--dur) var(--ease);
  }

  .empty { color: var(--ink-soft); }

  /* ---- Purchase history --------------------------------------------- */
  /* Main-page teaser card: a few most-recently-bought items + a link to all. */
  .history-card {
    display: grid;
    gap: 0.5em;
    margin-top: var(--space);
    padding: 0.9em 1.1em;
    color: var(--ink);
    text-decoration: none;
    transition: transform var(--dur) var(--ease);
  }
  @media (hover: hover) { .history-card:hover { transform: translateY(-2px); } }
  .history-card__head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space); }
  .history-card__head h2 { font-size: 0.95rem; color: var(--accent-strong); }
  .history-card__more { font-size: 0.8em; font-weight: 700; color: var(--accent-strong); white-space: nowrap; }
  .history-card__items { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.3em; }
  .history-card__items li { display: flex; align-items: baseline; justify-content: space-between; gap: 0.75em; }
  .history-card__name { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .history-card__ago { flex: 0 0 auto; font-size: 0.8em; color: var(--ink-soft); }

  /* Dedicated history page: category groups reuse .category / .cat-list. */
  .history-row { padding: 0.7em 1.1em; }
  .history-trips > summary { list-style: none; cursor: pointer; }
  .history-trips > summary::-webkit-details-marker { display: none; }
  .history-row__head {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: baseline;
    gap: 0.15em var(--space);
  }
  .history-row__name { font-weight: 700; min-width: 0; }
  .history-row__qty {
    justify-self: end;
    padding: 0.05em 0.55em;
    border-radius: 999px;
    background: color-mix(in oklch, var(--accent) 30%, transparent);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
  }
  /* The product's note, one line under the name. */
  .history-row__note {
    grid-column: 1 / -1;
    font-size: 0.85em;
    color: var(--ink-soft);
    min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .history-row__meta {
    grid-column: 1 / -1;
    display: flex;
    flex-wrap: wrap;
    gap: 0.15em 0.6em;
    font-size: 0.85em;
    color: var(--ink-soft);
  }
  /* Middot between the "bought x days ago" and "n units across m trips" facts. */
  .history-row__totals::before { content: "·"; margin-right: 0.6em; }

  /* Per-trip breakdown, revealed by tapping the row. */
  .history-trips__list { list-style: none; padding: 0.6em 0 0; margin: 0; display: grid; gap: 0.3em; }
  .history-trips__trip {
    display: grid;
    grid-template-columns: 2.5rem 1fr auto auto;
    align-items: center;
    gap: 0.5em;
    font-size: 0.85em;
    color: var(--ink-soft);
  }
  .history-trips__qty { font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; }
  .history-trips__ago { text-align: right; }
  /* Per-trip delete: the button_to form melts away so the ✕ sits on the grid. */
  .history-trips__form { display: contents; }
  .history-trips__delete { width: 1.6rem; height: 1.6rem; font-size: 0.8rem; }
  .history-trips__older { font-size: 0.8em; color: var(--ink-soft); font-style: italic; }
  .history-row:has(.history-trips[open]) {
    box-shadow: var(--shadow-card), var(--glass-hi), inset 0 0 0 1.5px color-mix(in oklch, var(--accent) 40%, transparent);
  }

  /* Search + category filter above the history groups. */
  .history-filters { display: grid; grid-template-columns: 1fr auto; gap: 0.5em 0.4em; align-items: center; }
  .history__results { display: grid; gap: var(--space); }
  .history__clear { justify-self: start; font-size: 0.85em; font-weight: 600; }

  /* Category filter chips: a hidden checkbox with the label as the whole pill.
     Sort chips reuse the same pill look with radios underneath. */
  .cat-chips, .sort-chips { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 0.35em; }
  .cat-chip, .sort-chip {
    padding: 0.3em 0.8em;
    border: 1px solid var(--glass-border);
    border-radius: 999px;
    background: var(--glass-bg);
    box-shadow: var(--glass-hi);
    font-size: 0.85em; font-weight: 700; color: var(--ink-soft);
    cursor: pointer; user-select: none; -webkit-user-select: none;
  }
  .cat-chip input, .sort-chip input { appearance: none; width: 0; height: 0; margin: 0; opacity: 0; }
  .cat-chip:has(input:checked), .sort-chip:has(input:checked) {
    border-color: transparent;
    background: color-mix(in oklch, var(--accent) 45%, transparent);
    color: var(--ink);
  }
  .cat-chip:has(input:focus-visible), .sort-chip:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 1px; }

  /* ---- Confirm dialog (replaces the native confirm) -------------------- */
  .confirm {
    margin: auto;
    width: min(90vw, 22rem);
    padding: 1.2em;
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    background: var(--canvas);
    color: var(--ink);
    box-shadow: var(--shadow-card);
  }
  .confirm::backdrop { background: oklch(0% 0 0 / 0.45); backdrop-filter: blur(3px); }
  .confirm__message { margin: 0 0 1em; line-height: 1.45; font-weight: 600; }
  .confirm__actions { display: flex; gap: 0.6em; }
  .confirm__actions .button { flex: 1; }
  .confirm__cancel {
    border: 1px solid var(--glass-border);
    background: var(--glass-strong);
    color: var(--ink);
    box-shadow: var(--glass-hi);
  }
  /* A prompt that offers a choice rather than confirming one thing: it carries a
     heading and the list at stake, and stacks its actions so the longer labels
     stay readable. */
  .confirm--prompt { width: min(90vw, 24rem); }
  .confirm__title {
    margin: 0 0 0.4em;
    font-family: var(--font-display); font-size: 1.15em; color: var(--ink);
  }
  .confirm__items {
    margin: 0 0 1.1em; padding: 0.7em 0.9em;
    max-height: 9.5rem; overflow-y: auto;
    list-style: none;
    border-radius: var(--radius);
    background: var(--glass-bg); border: 1px solid var(--glass-border);
    font-weight: 600; line-height: 1.6;
  }
  .confirm__actions--stacked { flex-direction: column; }
  .confirm__actions--stacked .button { flex: none; width: 100%; text-align: center; }
  .confirm__actions--stacked form { width: 100%; }
  .confirm__field { display: block; width: 100%; margin: 0 0 1em; }

  /* ---- Listas inteligentes ------------------------------------------- */
  .smart-card .list-hint { margin-top: -0.2em; }
  .smart-lists { display: grid; gap: var(--space); }
  .smart-list { display: grid; gap: 0.6em; margin: 0; }
  .smart-list__head { display: grid; gap: 0.2em; }
  .smart-list__head h2 { font-size: 1.05rem; color: var(--accent-strong); }
  .smart-list .entries { margin: 0; }
  /* The whole row toggles the item; the real checkbox stays for forms and a11y. */
  .smart-item { padding-block: 0.55em; }
  .smart-item__label { display: flex; align-items: center; gap: 0.6em; width: 100%; cursor: pointer; }
  .smart-item__box { position: absolute; opacity: 0; pointer-events: none; }
  .smart-item__box:checked + .entry__check {
    background: var(--accent-strong); border-color: var(--accent-strong);
    box-shadow: inset 0 0 0 3px var(--glass-bg);
  }
  .smart-item__box:focus-visible + .entry__check { outline: 2px solid var(--accent); outline-offset: 2px; }
  .smart-item:not(:has(.smart-item__box:checked)) { opacity: 0.55; }
  .smart-item__text { flex: 1 1 0; min-width: 0; display: grid; gap: 0.1em; font-weight: 700; }
  .smart-item__reason { font-weight: 400; font-size: 0.8em; color: var(--ink-soft); line-height: 1.3; }
  .smart-item__qty { flex: 0 0 auto; font-weight: 700; color: var(--accent-strong); }
  /* Upcoming items are a preview: no check to tick, slightly quieter. */
  .smart-item--upcoming { opacity: 0.8; }

  /* ---- Forms ---------------------------------------------------------- */
  .field { display: grid; gap: 0.35em; }
  .field label { font-weight: 700; color: var(--ink-soft); font-size: 0.9em; }
  /* Space the submit button off the field it follows (new/edit forms, note form). */
  .field + input[type="submit"], .field + .button { margin-top: var(--space); }
  input[type="text"], input[type="number"], input[type="search"], textarea, select {
    padding: 0.65em 0.9em;
    max-width: 100%;
    border-radius: var(--radius);
  }
  /* Stacked form contexts (.field / .add-item are grids) stretch their field to
     full width automatically; inline controls inside entries keep their natural
     width so rows don't overflow. */
  .duplicate input[type="text"] { flex: 1; min-width: 0; }
  .add-brand input[type="text"] { flex: 1; min-width: 8rem; }
  .trip-brand select { max-width: 9rem; }
  input:focus-visible, textarea:focus-visible, select:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
  }
  .errors { color: var(--danger); list-style-position: inside; }

  /* ---- Entries -------------------------------------------------------- */
  .entries { list-style: none; padding: 0; display: grid; gap: 0.6em; }
  .entry {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5em 0.75em;
    padding: 0.7em 0.9em;
    transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
  }
  /* Name and quantity share one row; the brand picker (when crossed off) wraps below. */
  /* Zero basis: a long note wraps inside the body instead of pushing the stepper
     onto its own line. */
  .entry__body { flex: 1 1 0; min-width: 0; display: grid; gap: 0.1em; }

  /* The name is the check toggle — tap it to mark bought / unbought. */
  .entry__toggle-form { margin: 0; }
  /* The whole name row is the target, tall enough for a thumb in the aisle. */
  .entry__toggle {
    display: flex; align-items: center; gap: 0.6em;
    width: 100%; min-height: 2.6rem; padding: 0; text-align: left;
    background: none; border: 0; cursor: pointer; box-shadow: none;
    color: var(--ink); font-weight: 700; font-size: 1em;
    touch-action: manipulation;
  }
  .entry__check {
    flex: 0 0 auto;
    width: 1.7rem; height: 1.7rem; border-radius: 50%;
    border: 2px solid var(--line);
    transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease),
                transform var(--dur) var(--ease);
  }
  .entry__toggle:active .entry__check { transform: scale(0.88); }
  .entry__name { min-width: 0; }
  .entry__meta {
    color: var(--ink-soft); font-size: 0.85em; padding-left: 2.3rem;
    animation: fade-slide-in var(--dur) var(--ease);
  }
  .entry--checked { opacity: 0.7; }
  /* Already in the cart, so out of the way: what's left to pick up stays on top.
     Grid honours `order`, so this reflows on its own after Turbo swaps one row —
     no re-render of the category needed. The server sorts the same way for a
     fresh load (see List#shopping_entries_by_category). The shopping controller
     slides each row from its old place to its new one when that happens. */
  .entries > .entry--checked { order: 1; }
  /* `--picking` / `--unpicking` are painted on submit, before the server answers,
     so the check lands under the finger. The row keeps its place until the swap. */
  .entry--checked .entry__name, .entry--picking .entry__name { text-decoration: line-through; color: var(--ink-soft); }
  .entry--checked .entry__check, .entry--picking .entry__check {
    background: var(--accent-strong); border-color: var(--accent-strong);
    box-shadow: inset 0 0 0 3px var(--glass-bg);
  }
  .entry--unpicking .entry__name { text-decoration: none; color: var(--ink); }
  .entry--unpicking .entry__check { background: none; border-color: var(--line); box-shadow: none; }
  /* The row on the move rides above the ones sliding past it. */
  .entry--moving { position: relative; z-index: 10; }

  .entry__controls { display: flex; align-items: center; gap: 0.4em; flex-shrink: 0; }

  /* Compact category chip-select (auto-saves on change). */
  .cat-pick { margin: 0; }
  .cat-pick__select {
    padding: 0.3em 0.6em; font-size: 0.8em; font-weight: 600;
    border-radius: 999px; border: 1px solid var(--glass-border);
    color: var(--accent-strong); max-width: 8rem;
    box-shadow: var(--glass-hi);
  }

  /* Small round icon buttons (⋯ details, × remove). */
  .icon-btn {
    display: inline-grid; place-items: center;
    width: 2rem; height: 2rem; padding: 0;
    border: 1px solid var(--glass-border); border-radius: 50%;
    background: var(--glass-bg); color: var(--ink-soft);
    font-size: 1.1rem; line-height: 1; text-decoration: none; cursor: pointer;
    box-shadow: var(--glass-hi);
  }
  .icon-btn--danger { color: var(--danger); }
  .icon-btn form, form.button_to { margin: 0; }

  /* Compact management row: name + inline actions on one line. */
  .entry--compact { align-items: center; gap: 0.5em; }
  .entry--compact .entry__name { flex: 1 1 auto; }
  .entry__actions { display: flex; align-items: center; gap: 0.35em; flex-shrink: 0; }

  /* Category as an icon; tap to reveal a dropdown that re-files the item. */
  .cat-menu { position: relative; margin: 0; }
  .cat-menu > summary { list-style: none; cursor: pointer; }
  .cat-menu > summary::-webkit-details-marker { display: none; }
  .cat-menu__icon {
    display: inline-grid; place-items: center;
    width: 2rem; height: 2rem; border-radius: 50%;
    border: 1px solid var(--glass-border); background: var(--glass-bg);
    box-shadow: var(--glass-hi); font-size: 1.05rem; line-height: 1;
  }
  .cat-menu__panel {
    position: absolute; right: 0; top: calc(100% + 0.35em); z-index: 20;
    padding: 0.5em; min-width: 11rem;
    background: var(--glass-strong);
    -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur);
    border: 1px solid var(--glass-border); border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card), var(--glass-hi);
    animation: fade-slide-in var(--dur) var(--ease);
  }
  .cat-menu__panel select { width: 100%; }
  /* Each .entry has backdrop-filter (its own stacking context), which would trap
     the popover behind later entries. Lift the entry whose menu is open. */
  .entry:has(.cat-menu[open]) { position: relative; z-index: 40; }

  /* ---- Categories ----------------------------------------------------- */
  .category { display: grid; gap: 0.6em; }

  /* Shopping trip: each category is a disclosure. One with nothing left to pick
     up sinks below the pending ones but stays open, so finishing a category is
     visible rather than tucked away. "Nothing left" is `:has` over the rows, so
     the ✓ and the sink react live to a Turbo row swap. */
  .shopping__categories { display: grid; gap: var(--space); }
  .category--trip > .category__summary {
    display: flex; align-items: center; gap: 0.4em;
    list-style: none; cursor: pointer;
  }
  .category--trip > .category__summary::-webkit-details-marker { display: none; }
  .category__chevron {
    flex: 0 0 auto; color: var(--ink-soft); font-size: 1.1em; line-height: 1;
    transition: transform var(--dur) var(--ease);
  }
  .category--trip[open] > .category__summary .category__chevron { transform: rotate(90deg); }
  .category__done { color: var(--accent-3); font-weight: 700; opacity: 0; transition: opacity var(--dur) var(--ease); }
  .category--trip:not(:has(.entry:not(.entry--checked))) {
    order: 1;                     /* everything picked up — drop below the pending ones */
    opacity: 0.75;
  }
  .category--trip:not(:has(.entry:not(.entry--checked))) .category__done { opacity: 1; }
  .category__name {
    display: inline-flex;
    align-items: center;
    gap: 0.4em;
    font-family: var(--font-display);
    font-size: 0.8em;
    color: var(--accent-strong);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 600;
  }
  /* Drag affordance on draggable category headers. touch-action: none is what
     makes touch dragging possible at all — it stops the browser claiming the
     gesture as a scroll — and the callout/selection resets stop iOS popping the
     text magnifier when you hold the grip. */
  .drag-handle {
    color: var(--ink-soft); cursor: grab; flex: 0 0 auto; opacity: 0.7;
    touch-action: none;
    user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  }
  .dragging .drag-handle { cursor: grabbing; }
  /* A 14px grip is a fine mouse target and a poor finger one; pad the hit area on
     touch devices and pull the padding back out of the layout. */
  @media (pointer: coarse) {
    .drag-handle { padding: 0.55em; margin: -0.55em -0.2em -0.55em -0.55em; }
  }
  .cat-list { list-style: none; padding: 0; display: grid; gap: 0.6em; }
  .cat-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space);
    padding: 0.75em 1.1em;
    transition: transform var(--dur) var(--ease);
  }
  .cat-row__name { font-weight: 700; }
  .cat-actions { display: flex; gap: 0.6em; align-items: center; }
  .cat-actions a { color: var(--ink-soft); text-decoration: none; font-weight: 600; }

  /* ---- Add item + suggestions ---------------------------------------- */
  /* field + submit rows use grid `1fr auto` — grid's 1fr is minmax(0,1fr), so
     the field shrinks to fit and the button is never pushed off-screen. */
  .add-item { display: grid; gap: 0.4em; }
  .add-item form, .merge { display: grid; grid-template-columns: 1fr auto; gap: 0.4em; align-items: center; }
  .add-item form label { grid-column: 1 / -1; }
  .suggestions { list-style: none; padding: 0; margin: 0.35em 0 0; display: grid; gap: 0.4em; animation: fade-slide-in var(--dur) var(--ease); }
  .suggestion {
    width: 100%;
    text-align: left;
    padding: 0.65em 1em;
    color: var(--ink);
    font-weight: 600;
    cursor: pointer;
    transition: transform var(--dur) var(--ease);
  }
  .suggestion--seed { color: var(--ink-soft); font-weight: 400; }

  .categories-sortable { display: grid; gap: calc(var(--space) * 1.25); }
  [data-sortable-target="item"] { cursor: grab; }
  .dragging { opacity: 0.5; }

  /* ---- Product edit --------------------------------------------------- */
  .brand-list { list-style: none; padding: 0; display: grid; gap: 0.6em; }
  .brand-row { display: flex; align-items: center; justify-content: space-between; gap: var(--space); padding: 0.7em 1em; }
  .trip-brand { flex-basis: 100%; margin-top: 0.3em; display: flex; gap: 0.4em; align-items: center; flex-wrap: wrap; }
  .add-brand { display: grid; grid-template-columns: 1fr auto; gap: 0.4em; align-items: center; }
  .add-brand label { grid-column: 1 / -1; }
  .duplicate { display: grid; grid-template-columns: 1fr auto; gap: 0.4em; align-items: center; }
  .qty { display: flex; gap: 0.4em; align-items: center; margin: 0; }

  /* Touch-friendly quantity picker: tap − / + or swipe the number. */
  .stepper {
    display: inline-flex; align-items: center;
    border: 1px solid var(--glass-border); border-radius: 999px;
    background: var(--glass-bg); box-shadow: var(--glass-hi);
  }
  .stepper__btn {
    width: 2rem; height: 2rem; padding: 0; border: 0; background: none;
    color: var(--accent-strong); font-size: 1.15rem; font-weight: 700;
    line-height: 1; cursor: pointer; border-radius: 50%;
  }
  .stepper__value {
    min-width: 1.6rem; padding: 0.3em 0.1em; text-align: center;
    font-weight: 700; font-variant-numeric: tabular-nums;
    cursor: ew-resize; touch-action: pan-y; user-select: none; -webkit-user-select: none;
  }
  .stepper--dragging { box-shadow: var(--glass-hi), 0 0 0 2px var(--accent); }
  .stepper--dragging .stepper__value { color: var(--accent-strong); }

  /* ---- List header + actions menu ------------------------------------ */
  .list-show__head { display: grid; gap: 0.25em; }
  .list-show__title { display: flex; align-items: center; justify-content: space-between; gap: var(--space); }

  /* The list name is a plain heading that wraps; renaming lives behind the pencil. */
  .list-show__name { flex: 1 1 auto; min-width: 0; margin: 0; overflow-wrap: anywhere; }

  /* Always-visible list actions (duplicate / delete) replacing the old menu. */
  .list-actions { display: flex; align-items: center; gap: 0.6em; flex-shrink: 0; }
  .list-actions__form { margin: 0; }

  /* Explains the duplicate icon, which isn't self-evident on its own. */
  .list-hint {
    margin: 0; color: var(--ink-soft);
    font-size: 0.85em; line-height: 1.4; text-wrap: pretty;
  }
  .list-hint svg { vertical-align: -0.2em; }

  .button--confirm { width: 100%; text-align: center; padding-block: 0.8em; font-size: 1.05em; }

  /* ---- Flash ---------------------------------------------------------- */
  .flash {
    padding: 0.8em 1.1em;
    background: color-mix(in oklch, var(--accent-3) 60%, var(--glass-strong));
    color: var(--ink);
    font-weight: 700;
    animation: fade-slide-in var(--dur) var(--ease);
  }

  /* ---- Theme toggle (ported from Gustia) ------------------------------ */
  .theme-switch {
    display: inline-flex; align-items: center; gap: 0.5rem;
    padding: 0.15rem; background: none; border: 0; cursor: pointer; line-height: 0;
  }
  .theme-switch__icon { width: 1.15rem; height: 1.15rem; color: var(--ink-soft); transition: color 0.2s; }
  .theme-switch__track {
    position: relative; width: 3rem; height: 1.65rem; border-radius: 999px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    box-shadow: inset 0 1px 3px color-mix(in oklch, var(--ink) 18%, transparent);
    transition: background 0.2s;
  }
  .theme-switch__knob {
    position: absolute; top: 50%; left: 0.16rem; transform: translateY(-50%);
    width: 1.25rem; height: 1.25rem; border-radius: 50%;
    background: light-dark(oklch(99% 0 0), oklch(82% 0.02 70));
    box-shadow: 0 1px 3px color-mix(in oklch, var(--ink) 35%, transparent);
    transition: transform 0.22s cubic-bezier(0.4, 0, 0.2, 1);
  }

  /* Which side the knob sits on — and which icon lights up — reads the theme off
     :root, which the inline <head> script stamps before paint. Keying this off
     the button's own aria-checked instead would slide the knob across on every
     Turbo render, because JS can only set that attribute after the new body is
     painted with the knob still in its light-mode spot. aria-checked stays for
     assistive tech; nothing visual depends on it. */
  :root[data-theme="dark"] .theme-switch__knob { transform: translate(1.35rem, -50%); }
  :root[data-theme="dark"] .theme-switch__icon--moon,
  :root[data-theme="light"] .theme-switch__icon--sun { color: var(--accent-strong); }

  /* No saved choice: the OS preference is what `color-scheme: light dark` renders. */
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme]) .theme-switch__knob { transform: translate(1.35rem, -50%); }
    :root:not([data-theme]) .theme-switch__icon--moon { color: var(--accent-strong); }
  }
  @media (prefers-color-scheme: light) {
    :root:not([data-theme]) .theme-switch__icon--sun { color: var(--accent-strong); }
  }
}

@layer utilities {
  /* Available to assistive tech, invisible on screen — for controls whose only
     visible content is an icon. */
  .sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0;
  }
}

/* Motion: subtle, presentational, transform/opacity only. */
@keyframes fade-slide-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* Respect the user's motion preference — disable motion, keep functionality. */
@media (prefers-reduced-motion: reduce) {
  :root { --dur: 0ms; }
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
  ::view-transition-group(*),
  ::view-transition-old(*),
  ::view-transition-new(*) { animation: none !important; }
}
