/*
 * Velkgram stylesheet: theme tokens and the Material 3 Expressive layer on top of Beer CSS 5.0.3.
 *
 * Two themes, one token set of light-dark() pairs, from the Velk brand kit: ink and paper
 * neutrals and pastels, with sky blue as Velkgram's own colour. On light, text roles are darkened
 * for AA and only containers are pastel. tests/apps/web/test_contrast.py checks every pair.
 */

@font-face {
  font-family: "Google Sans Flex";
  src: url("/static/fonts/google-sans-flex-latin-ext.woff2") format("woff2");
  font-weight: 400 800; font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Google Sans Flex";
  src: url("/static/fonts/google-sans-flex-latin.woff2") format("woff2");
  font-weight: 400 800; font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ---- Fonts, shape and motion tokens ---- */
:root {
  --font: "Google Sans Flex", system-ui, sans-serif;
  --shape-xl: 12px;      /* cards, sheets, panels */
  --shape-control: 8px;  /* buttons, chips, fields, segmented controls */
  --shape-pressed: 4px;
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --spring-time: 360ms;
}

/* ---- Colour: one token set, light-dark() pairs. Velk brand palette.
   System mode follows the device; the body.light / body.dark classes force a theme. ---- */
/* `:not(.themed)` lifts specificity to tie Beer CSS's body.light / body.dark, which this file wins by order. */
body:not(.themed) {
  color-scheme: light dark;
  --primary: light-dark(#1f5f85, #a9d8f5);
  --on-primary: light-dark(#ffffff, #1b1a1e);
  --primary-container: light-dark(#a9d8f5, #2c4a5e);
  --on-primary-container: light-dark(#1b1a1e, #dcf0fc);
  --secondary: light-dark(#5b478f, #cbbaf2);
  --on-secondary: light-dark(#ffffff, #1b1a1e);
  --secondary-container: light-dark(#cbbaf2, #453a5e);
  --on-secondary-container: light-dark(#1b1a1e, #e7defa);
  --tertiary: light-dark(#2c6641, #a8e0b7);
  --on-tertiary: light-dark(#ffffff, #1b1a1e);
  --tertiary-container: light-dark(#a8e0b7, #2f4a38);
  --on-tertiary-container: light-dark(#1b1a1e, #d6f2de);
  --error: light-dark(#a3333d, #f2a0a0);
  --on-error: light-dark(#ffffff, #1b1a1e);
  --error-container: light-dark(#f2a0a0, #5c3032);
  --on-error-container: light-dark(#1b1a1e, #fcdada);
  --success: light-dark(#2c6641, #a8e0b7);
  --warning: light-dark(#8c431b, #f8bfa0);
  --amber: light-dark(#715500, #f7d78a);
  --amber-fill: light-dark(#8f6d00, #f7d78a);
  --background: light-dark(#f6f4f1, #1b1a1e);
  --on-background: light-dark(#1b1a1e, #f6f4f1);
  --surface: light-dark(#f6f4f1, #1b1a1e);
  --on-surface: light-dark(#1b1a1e, #f6f4f1);
  --surface-variant: light-dark(#ece9e5, #34323a);
  --on-surface-variant: light-dark(#55525c, #c3c0ca);
  --outline: light-dark(#7c7884, #8f8b97);
  --outline-variant: light-dark(#c9c5cd, #4a4751);
  --shadow: light-dark(#000000, #000000);
  --scrim: light-dark(#000000, #000000);
  --inverse-surface: light-dark(#28262d, #f6f4f1);
  --inverse-on-surface: light-dark(#f6f4f1, #1b1a1e);
  --inverse-primary: light-dark(#a9d8f5, #1f5f85);
  --surface-dim: light-dark(#e4e1dd, #151418);
  --surface-bright: light-dark(#ffffff, #3a3841);
  --surface-container-lowest: light-dark(#ffffff, #151418);
  --surface-container-low: light-dark(#ffffff, #222126);
  --surface-container: light-dark(#efece8, #28262d);
  --surface-container-high: light-dark(#e8e5e1, #323038);
  --surface-container-highest: light-dark(#e0dcd8, #3c3a43);
  --elev-a: light-dark(rgb(27 26 30 / 0.14), transparent);
  --elev-b: light-dark(rgb(27 26 30 / 0.08), transparent);
  font-family: var(--font);
  font-optical-sizing: auto;
  background-color: var(--surface);
  color: var(--on-surface);
}
/* Filled buttons stay pastel in both themes; --primary is the readable shade for text. */
:is(button, a.button):not(.transparent, .border, .tonal, .chip, .circle, .coupon-code, .vg-menu button) {
  background-color: #a9d8f5;
  color: #1b1a1e;
}
body.light { color-scheme: light; }
body.dark { color-scheme: dark; }

/* ---- Base ---- */

:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.sr-only:focus-visible {
  inline-size: auto;
  block-size: auto;
  margin: 0;
  padding: 0.75rem 1rem;
  clip-path: none;
  z-index: 1000;
  inset: 0.5rem auto auto 0.5rem;
  border-radius: var(--shape-control);
  background-color: var(--primary);
  color: var(--on-primary);
}

/* ---- Expressive layer (spec 8.3) ---- */
h1, h2, h3, h4, h5, h6 {
  font-weight: 700;
  letter-spacing: -0.01em;
}

h1 { font-size: clamp(1.75rem, 1.2rem + 2vw, 2.5rem); line-height: 1.15; }

article, dialog, .sheet, .card {
  border-radius: var(--shape-xl);
}

/* Pill buttons that morph to a rounded square while pressed. */
button:not(.circle, .square, .chip),
a.button {
  border-radius: var(--shape-control);
  transition: border-radius var(--spring-time) var(--spring), background-color 150ms linear;
}

button:not(.circle, .square, .chip):active,
a.button:active {
  border-radius: var(--shape-pressed);
}

.chip {
  border-radius: var(--shape-control);
  transition: background-color 150ms linear, border-radius var(--spring-time) var(--spring);
}

/* The navigation indicator springs in when a destination becomes current. */
nav a > i {
  transition: background-color 150ms linear, padding var(--spring-time) var(--spring);
}

/* ---- Layout shell (spec 8.4): compact bottom bar, rail from 600 px ---- */
.shell {
  display: grid;
  min-block-size: 100dvh;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "bar" "main";
  grid-template-rows: auto 1fr;
}

.shell > .appbar { grid-area: bar; }
.shell > main { grid-area: main; }
.shell > nav.left { grid-area: rail; }

.appbar {
  position: sticky;
  inset-block-start: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-block-size: 4rem;
  padding-inline: 1rem 0.5rem;
  background-color: var(--surface);
}

.appbar .title {
  flex: 1;
  margin: 0;
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.shell > main {
  inline-size: 100%;
  max-inline-size: 72rem;
  margin-inline: auto;
  padding: 1rem 1rem 6.5rem;
}

nav.bottom {
  position: fixed;
  inset: auto 0 0 0;
  grid-area: auto;
  block-size: 4.5rem;
  background-color: var(--surface-container);
}

nav.left {
  position: sticky;
  inset-block-start: 0;
  block-size: 100dvh;
  gap: 0.5rem;
  background-color: var(--surface);
}

nav.left { display: none; }

@media (min-width: 600px) {
  .shell {
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas: "rail bar" "rail main";
  }
  nav.bottom { display: none; }
  nav.left { display: flex; justify-content: flex-start; padding-block-start: 1rem; }
  .shell > main { padding: 1.5rem 1.5rem 3rem; }
  .appbar { padding-inline: 1.5rem 1rem; }
}

nav.bottom a, nav.left a {
  min-block-size: 3rem;
}

/* Signed-out pages (login): one centered column, no bars. */
.auth {
  inline-size: 100%;
  max-inline-size: 24rem;
  margin: 0 auto;
  padding: 3rem 1rem;
}

/* ---- Theme menu ---- */
.theme-menu-wrap, .row-menu-wrap { position: relative; }
.vg-menu {
  /* Top layer, placed by velkgram.js next to its button; `inset: auto` drops the UA centring. */
  inset: auto;
  margin: 0;
  min-inline-size: 13rem;
  padding: 0.5rem;
  border: 0;
  border-radius: var(--shape-xl);
  background-color: var(--surface-container);
  color: var(--on-surface);
  box-shadow: 0 4px 16px rgb(0 0 0 / 0.25);
}
.theme-menu form, .row-menu form { display: contents; }
.theme-menu button, .row-menu button {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  inline-size: 100%;
  min-block-size: 3rem;
  justify-content: flex-start;
  background: transparent;
  color: var(--on-surface);
  border: 0;
  box-shadow: none;
  padding-inline: 0.75rem;
}
.theme-menu button[aria-current="true"] {
  background-color: var(--secondary-container);
  color: var(--on-secondary-container);
}

/* Swatches: system is split light | dark; the others show the theme's base and primary. */
.swatch {
  flex: none;
  inline-size: 1.5rem;
  block-size: 1.5rem;
  border-radius: 50%;
  border: 2px solid var(--outline);
}
.swatch-system { background: linear-gradient(90deg, #f2e5bc 50%, #282828 50%); }
.swatch-light { background: linear-gradient(135deg, #f2e5bc 50%, #5d6728 50%); }
.swatch-dark { background: linear-gradient(135deg, #282828 50%, #bab979 50%); }

/* ---- Shared page bits ---- */
.error { color: var(--error); margin: 0.5rem 0; }
.muted { color: var(--on-surface-variant); }
.inline { display: inline; }
.list-page { display: flex; flex-direction: column; gap: 1rem; }
.list-page h1 { margin-block: 0; }
.list-page .section-title { margin-block-end: 0.5rem; }

/* Compact (< 600 px) hides secondary columns; the rail layout starts at 600 px. */
.show-compact { display: block; }
@media (max-width: 599.98px) { .hide-compact { display: none !important; } }
@media (min-width: 600px) { .show-compact { display: none !important; } }

.table-wrap { overflow-x: auto; border: 1px solid var(--outline-variant); border-radius: var(--shape-xl); background-color: var(--surface-container-low); }
table.data { inline-size: 100%; border-collapse: collapse; }
table.data th, table.data td { text-align: start; padding: 0.75rem 1rem; vertical-align: middle; border-block-end: 1px solid var(--outline-variant); }
table.data th { font-weight: 600; font-size: 0.875rem; color: var(--on-surface-variant); white-space: nowrap; }
table.data tbody tr:last-child td { border-block-end: 0; }
table.data .num { font-variant-numeric: tabular-nums; }
table.data .chip { margin: 0; }
/* Wish cell: coupon / above-limit chips sit on their own wrapping line; long codes break inside the pill. */
table.data .wish-cell { min-inline-size: 11rem; max-inline-size: 20rem; overflow-wrap: anywhere; }
.wish-flags { display: flex; flex-wrap: wrap; gap: 0.25rem; margin-block-start: 0.25rem; }
.wish-flags .chip { block-size: auto; min-block-size: 2rem; max-inline-size: 100%; padding-block: 0.25rem; white-space: normal; overflow-wrap: anywhere; line-height: 1.3; }
.wish-flags .chip > i { flex: none; }
/* Compact: each alert is a card (when / status / price, then wish and chips) so nothing hides in the scroller. */
@media (max-width: 599.98px) {
  table.alerts-table, table.alerts-table tbody { display: block; }
  table.alerts-table thead { display: none; }
  table.alerts-table tr { display: grid; grid-template-columns: auto 1fr; gap: 0.375rem 0.75rem; align-items: center; padding: 0.75rem; border-block-end: 1px solid var(--outline-variant); border-radius: 0; }
  table.alerts-table tbody tr:last-child { border-block-end: 0; }
  table.data.alerts-table td, table.data.alerts-table tbody tr:last-child td { display: block; padding: 0; border: 0; min-inline-size: 0; }
  table.alerts-table .alert-when { grid-column: 1 / -1; }
  table.alerts-table .wish-cell { grid-column: 1 / -1; max-inline-size: none; min-inline-size: 0; }
}
table.data .button.small { min-block-size: 3rem; margin: 0; }

.add-row { display: flex; align-items: center; gap: 0.75rem; }
.add-row .field { flex: 1; margin: 0; }
.add-row label { margin: 0; font-weight: inherit; }
.add-row button { min-block-size: 3rem; margin: 0; }
.list-page .error[role="alert"] { display: flex; align-items: center; gap: 0.5rem; padding: 0.75rem 1rem; border-radius: var(--shape-xl); background-color: var(--error-container); color: var(--on-error-container); }
@media (max-width: 599.98px) {
  table.data th, table.data td { padding: 0.625rem 0.5rem; }
}

.pager { display: flex; align-items: center; justify-content: center; gap: 1rem; }
.pager .button { min-block-size: 3rem; margin: 0; }

.status-card { padding: 1rem 1.25rem; border-radius: var(--shape-xl); background-color: var(--surface-container-low); border: 1px solid var(--outline-variant); }
.status-card > * { margin: 0; }
.status-card > * + * { margin-block-start: 0.5rem; }
.status-card .section-title { margin-block-end: 0; }
.status-line { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
.status-line .chip { margin: 0; }
.status-sent { background-color: var(--primary-container); color: var(--on-primary-container); }
.status-failed { background-color: var(--error-container); color: var(--on-error-container); font-weight: 600; }
.status-pending, .status-expired { background-color: var(--surface-container-highest); color: var(--on-surface); }

/* ---- Collector health banner ---- */
.health {
  --tint: var(--success);
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.25rem 1.5rem;
  border-radius: var(--shape-xl);
  color: var(--on-surface);
  background-color: color-mix(in oklab, var(--tint) 20%, var(--surface));
  border: 1px solid color-mix(in oklab, var(--tint) 45%, var(--surface));
}
.health-warning { --tint: var(--amber-fill); }
.health-warning > i { color: var(--amber); }
.health-error { --tint: var(--error); }
.health > i { flex: none; font-size: 2.5rem; line-height: 1; color: var(--tint); }
.health > div > * { margin: 0; }
.health-title { font-size: 1.5rem; font-weight: 800; letter-spacing: -0.02em; line-height: 1.2; }
.health-detail { color: var(--on-surface-variant); line-height: 1.4; margin-block-start: 0.25rem !important; }

/* ---- Login ---- */
.login-card {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 2rem 1.5rem;
  border-radius: var(--shape-xl);
  background-color: var(--surface-container-low);
  border: 1px solid var(--outline-variant);
}
.login-card > * { margin: 0; }
.login-brand { font-size: 1.5rem; font-weight: 800; letter-spacing: -0.02em; color: var(--primary); }
.login-card h1 { font-size: 1.75rem; }
.login-card .stack button { min-block-size: 3.5rem; }
.login-card .error { display: flex; align-items: center; gap: 0.5rem; padding: 0.75rem 1rem; border-radius: var(--shape-xl); background-color: var(--error-container); color: var(--on-error-container); }

/* ---- Feed (offers) ---- */
.feed-page h1 { margin-block: 0 1rem; }
.feed-page label { margin: 0; font-weight: inherit; }
.feed-page .field > label { margin: 0; }

.filters-bar { display: flex; align-items: center; gap: 0.75rem; }
.filters-search { flex: 1 1 0; min-inline-size: 0; margin: 0; }
.feed-page input[type="search"]::-webkit-search-cancel-button { display: none; }
.filters-open { flex: 0 0 auto; min-block-size: 3rem; margin: 0; }
.view-toggle { display: none; }

/* The filter panel is a bottom sheet on compact and an inline block from 600 px. */
.filters-panel { z-index: 300; max-block-size: 85dvh; overflow-y: auto; display: flex; flex-direction: column; gap: 1rem; padding: 1rem 1.25rem 1.5rem; }
.filters-panel-head { display: flex; align-items: center; justify-content: space-between; }
.filters-panel-head h2 { margin: 0; font-size: 1.25rem; }
.filter-label { margin: 0 0 0.5rem !important; font-weight: 600; }
.chip-row { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.chip-row .chip { position: relative; margin: 0; min-block-size: 2.5rem; padding-inline: 1rem; }
.chip-row .chip input {
  position: absolute;
  inset: 0;
  inline-size: 100%;
  block-size: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.chip-row .chip:has(input:checked) {
  background-color: var(--secondary-container);
  color: var(--on-secondary-container);
  border-color: transparent;
}
.chip-row .chip:has(input:checked) span::before {
  content: "\2713";
  margin-inline-end: 0.4rem;
  font-weight: 700;
}
.chip-row .chip:has(input:focus-visible) { outline: 3px solid var(--primary); outline-offset: 2px; }
.filter-switch { align-self: flex-start; min-block-size: 3rem; gap: 0.75rem; }
.filter-switch > span { padding-inline-start: 0.75rem; }
.filter-prices { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0.75rem; }
.filter-prices .field { min-inline-size: 0; margin: 0 !important; }
.filter-channel, .filter-prices .field { margin: 0; }
.filters-done { align-self: stretch; min-block-size: 3rem; }

/* Compact: a native modal <dialog>, a bottom sheet. Its backdrop and Escape come with the platform. */
@media (max-width: 599.98px) {
  dialog.filters-panel {
    position: fixed;
    inset: auto 0 0 0;
    margin: 0;
    inline-size: 100%;
    max-inline-size: none;
    border: 0;
    border-radius: var(--shape-xl) var(--shape-xl) 0 0;
    background-color: var(--surface-container-low);
    color: var(--on-surface);
    visibility: visible;
    opacity: 1;
    transform: none;
  }
  dialog.filters-panel:not([open]) { display: none; }
  dialog.filters-panel::backdrop { background: rgb(0 0 0 / 0.5); }
}

@media (min-width: 600px) {
  .filters-open, .filters-done, .filters-panel-head { display: none; }
  dialog.filters-panel {
    position: static;
    display: flex;
    visibility: visible;
    opacity: 1;
    transform: none;
    inset: auto;
    inline-size: auto;
    max-inline-size: none;
    block-size: auto;
    max-block-size: none;
    /* Inline block, not a sheet: it must never scroll on its own. */
    overflow: visible;
    margin: 0.75rem 0 0;
    padding: 0;
    box-shadow: none;
    background: transparent;
    border-radius: 0;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem 1rem;
  }
  .filter-group { flex: 1 1 100%; }
  .filter-prices { grid-template-columns: 10rem 10rem; }
  .filter-channel { min-inline-size: 14rem; }
}

@media (min-width: 840px) {
  .view-toggle {
    display: inline-flex;
    flex: none;
    border: 1px solid var(--outline);
    border-radius: var(--shape-control);
    overflow: hidden;
  }
  .view-option { position: relative; margin: 0; }
  .view-option input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
  .view-option span {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    min-block-size: 3rem;
    padding-inline: 1rem;
    font-weight: 600;
  }
  .view-option span i { font-size: 1.25rem; }
  .view-option input:checked + span {
    background-color: var(--secondary-container);
    color: var(--on-secondary-container);
  }
  .view-option input:focus-visible + span { outline: 3px solid var(--primary); outline-offset: -3px; }
}

.note {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 1rem 0 0;
  color: var(--on-surface-variant);
}

.feed { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0.75rem; margin-block-start: 1rem; }
@media (min-width: 600px) { .feed { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; } }
@media (min-width: 840px) { .feed-cards { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

.offer {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin: 0;
  padding: 1rem 1.25rem 1rem;
  background-color: var(--surface-container-low);
  color: var(--on-surface);
  box-shadow: none;
  border: 1px solid var(--outline-variant);
}
.offer > * { margin: 0 !important; }
.feed > article.offer { margin: 0 !important; }

.offer-price {
  font-size: 1.875rem;
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  color: var(--primary);
}
.offer-price-unknown { font-size: 1rem; line-height: 1.3; font-weight: 600; letter-spacing: 0; color: var(--on-surface-variant); }
.offer-title {
  font-size: 1rem;
  font-weight: 500;
  letter-spacing: 0;
  line-height: 1.5 !important;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
  overflow-wrap: anywhere;
  /* Breathing room inside the clamp box: overflow:hidden would clip ascenders, descenders
     and the first glyph; the negative margins keep the visual position unchanged. */
  /* line-height 1.5 leaves ~0.16em of room above and below each line; the 0.1em bottom
     padding protects descenders without exposing the clamped third line. */
  padding: 0.15em 0.3em 0.1em;
}
.offer > .offer-title { margin: -0.15em -0.3em -0.1em !important; }
.offer-meta, .offer-flags { display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem 0.75rem; color: var(--on-surface-variant); font-size: 0.875rem; }
.offer-flags { gap: 0.5rem; }
.offer .chip { margin: 0; }
.offer .tonal-chip { background-color: var(--secondary-container); color: var(--on-secondary-container); }
.offer .flag-warn { background-color: var(--surface); color: var(--warning); font-weight: 600; }
.offer .flag-error { background-color: var(--error-container); color: var(--on-error-container); font-weight: 600; }
.offer-channel { display: inline-block; max-inline-size: 11rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* No comparable price (coupon, several prices, none found): the price steps back. */
.offer-quiet .offer-price { font-size: 1.125rem; font-weight: 600; letter-spacing: 0; color: var(--on-surface-variant); }
.offer-quiet .offer-price.offer-price-unknown { font-size: 0.875rem; font-weight: 400; }
.offer-gone .offer-price, .offer-gone .offer-title { text-decoration: line-through; color: var(--on-surface-variant); }
.offer-thumb {
  inline-size: 6rem;
  block-size: 6rem;
  object-fit: contain;
  background-color: var(--surface-container);
  border-radius: var(--shape-control);
}
.chip-muted { color: var(--on-surface-variant); background-color: var(--surface-container); }
.offer-actions { display: flex; gap: 0.5rem; margin-block-start: auto !important; padding-block-start: 0.5rem; }
.offer-actions .button { min-block-size: 3rem; margin: 0; gap: 0.375rem; padding-inline: 1rem 1.25rem; }
.offer-actions .button.circle { inline-size: 3rem; padding: 0; border-radius: var(--shape-control); background-color: var(--secondary-container); color: var(--on-secondary-container); }

@media (min-width: 840px) { .feed-list { grid-template-columns: minmax(0, 1fr); gap: 0.5rem; } }

.empty {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 3rem 1rem;
  text-align: center;
}
.empty > i { font-size: 3rem; color: var(--on-surface-variant); }
.empty > p { margin: 0; }
.empty-title { font-size: 1.25rem; font-weight: 700; }

/* ---- Product page ---- */
.product-page { display: flex; flex-direction: column; gap: 1.25rem; }
.product-head { padding: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.product-head > * { margin: 0; }
.product-title { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.75rem; }
.product-title h1 { margin: 0; overflow-wrap: anywhere; }
.product-title .chip, .product-terms .chip { margin: 0; }
.state-on { background-color: var(--primary-container); color: var(--on-primary-container); }
.state-off { background-color: var(--surface-container-highest); color: var(--on-surface); }
.product-terms { display: flex; flex-wrap: wrap; gap: 0.375rem; }
.product-terms .tonal-chip { background-color: var(--secondary-container); color: var(--on-secondary-container); }
.product-terms .flag-error { background-color: var(--error-container); color: var(--on-error-container); }
.product-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-block-start: 0.25rem; }
.product-actions { align-items: center; }
.product-actions form { display: flex; margin: 0; }
.product-actions .button, .product-actions button { min-block-size: 3rem; margin: 0; }
.terms-label { font-size: 0.875rem; color: var(--on-surface-variant); align-self: center; margin-inline-end: 0.25rem; }

.chart-block { display: flex; flex-direction: column; gap: 0.75rem; }
.insight {
  --tint: var(--secondary);
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 0.75rem 1rem;
  padding: 1rem 1.25rem;
  border-radius: var(--shape-xl);
  color: var(--on-surface);
  background-color: color-mix(in oklab, var(--tint) 20%, var(--surface));
  border: 1px solid color-mix(in oklab, var(--tint) 40%, var(--surface));
}
.insight-below { --tint: var(--success); }
.insight-above { --tint: var(--error); }
.insight-unknown { --tint: var(--outline); }
.insight > i { font-size: 2rem; color: var(--on-surface); align-self: start; }
/* Beer's icon box is 24 px with overflow hidden: enlarged icons need a box that grows with them. */
.empty > i, .health > i, .insight > i { inline-size: 1.15em; block-size: 1.15em; line-height: 1; }
.insight-body > * { margin: 0; }
.insight-label { font-size: 0.875rem; color: var(--on-surface-variant); }
.insight-main { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.125rem 0.75rem; }
.insight-price { font-size: 1.875rem; font-weight: 800; line-height: 1.15; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; white-space: nowrap; }
.insight-verdict { font-size: 1.125rem; font-weight: 600; }
.insight-sub { font-size: 0.875rem; color: var(--on-surface-variant); }
.stats-mini { border-radius: 0; grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 0.25rem 2rem; margin: 0; padding-block-start: 0.75rem; border-block-start: 1px solid color-mix(in oklab, var(--tint) 40%, var(--surface)); }
.stats-mini > div { border-radius: 0; display: flex; flex-direction: column-reverse; gap: 0.125rem; }
.stats-mini dt { font-size: 0.875rem; color: var(--on-surface-variant); }
.stats-mini dd { margin: 0; font-size: 1.125rem; font-weight: 700; font-variant-numeric: tabular-nums; }
@media (min-width: 840px) {
  .insight { grid-template-columns: auto minmax(0, 1fr) auto; }
  .stats-mini { grid-column: auto; padding: 0 0 0 1.5rem; border-block-start: 0; border-inline-start: 1px solid color-mix(in oklab, var(--tint) 40%, var(--surface)); gap: 0.75rem 2rem; }
}

.range-switch { gap: 0; display: inline-flex; align-self: flex-start; border: 1px solid var(--outline); border-radius: var(--shape-control); overflow: hidden; }
.range-switch a {
  display: inline-flex; align-items: center; justify-content: center; min-block-size: 3rem; min-inline-size: 4.5rem;
  padding-inline: 1rem; color: var(--on-surface); text-decoration: none; font-weight: 500;
}
.range-switch a { border-radius: 0; margin: 0; }
.range-switch a + a { border-inline-start: 1px solid var(--outline); }
.range-switch a[aria-current="true"] { background-color: var(--secondary-container); color: var(--on-secondary-container); font-weight: 700; }
.range-switch a:focus-visible { outline: 3px solid var(--primary); outline-offset: -3px; }
.chart-frame { padding: 0.5rem; border-radius: var(--shape-xl); background-color: var(--surface-container-low); border: 1px solid var(--outline-variant); }
.chart-frame svg { display: none; max-inline-size: 100%; block-size: auto; }
.chart-frame .chart-svg-compact { display: block; }
@media (min-width: 600px) {
  .chart-frame .chart-svg-compact { display: none; }
  .chart-frame .chart-svg-medium { display: block; }
}
@media (min-width: 840px) {
  .chart-frame .chart-svg-medium { display: none; }
  .chart-frame .chart-svg-wide { display: block; }
}
.chart-key { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin: 0; font-size: 0.875rem; }
.key-line { inline-size: 1.25rem; block-size: 0; border-block-start: 2px solid var(--primary); }
.key-avg { inline-size: 1.25rem; block-size: 0; border-block-start: 1px solid var(--outline); margin-inline-start: 0.75rem; }
.key-dash { inline-size: 1.25rem; block-size: 0; border-block-start: 2px dashed var(--tertiary); margin-inline-start: 0.75rem; }

.retro { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin: 0; color: var(--on-surface-variant); }
.retro button { margin: 0; min-block-size: 3rem; }
.retro-done > i { color: var(--success); }
.retro-failed { color: var(--on-surface); }
.retro-failed > i { color: var(--error); }
.retro-running > i { animation: retro-spin 1s linear infinite; }
@keyframes retro-spin { to { transform: rotate(360deg); } }

.section-title { font-size: 1.25rem; margin: 0; }
.product-page .feed { margin-block-start: 0.75rem; }
.offer .source-live { background-color: var(--surface-container-highest); color: var(--on-surface); }
.offer .source-retro { background-color: var(--tertiary-container); color: var(--on-tertiary-container); }

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

/* ---- Wishes (product cards) ---- */
.wishes-page h1, .form-page h1 { margin-block: 0 1rem; }
.wish-grid { margin-block-start: 0; padding-block-end: 4.5rem; }
@media (min-width: 840px) { .wish-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.wish-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  margin: 0;
  padding: 1rem 1.25rem;
  background-color: var(--surface-container-low);
  color: var(--on-surface);
  border: 1px solid var(--outline-variant);
  box-shadow: none;
}
.wish-card > * { margin: 0 !important; }
.wish-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 0.75rem; }
.wish-name { font-size: 1.125rem; font-weight: 600; letter-spacing: 0; line-height: 1.3; overflow-wrap: anywhere; }
.wish-name a { color: inherit; text-decoration: none; }
/* The whole card opens the product page; the toggle stays above the stretched link. */
.wish-name a::after { content: ""; position: absolute; inset: 0; border-radius: inherit; }
.wish-name a:focus-visible { outline: none; }
.wish-name a:focus-visible::after { outline: 3px solid var(--primary); outline-offset: 2px; }
.wish-head .chip { flex: none; margin: 0; }
.wish-price { font-size: 1.875rem; font-weight: 800; line-height: 1.1; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; color: var(--primary); }
.wish-price-unknown { font-size: 0.875rem; line-height: 1.3; font-weight: 400; letter-spacing: 0; color: var(--on-surface-variant); }
.wish-signals { display: flex; flex-wrap: wrap; align-items: center; gap: 0.375rem 0.75rem; min-block-size: 2rem; }
.wish-delta { display: inline-flex; align-items: center; gap: 0.125rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.wish-delta i { font-size: 1.25rem; }
/* Success/error on the card tone fall under 4.5:1 for text on Latte, so only the arrow carries the colour. */
.wish-delta-down i { color: var(--success); }
.wish-delta-up i { color: var(--error); }
.wish-card .chip.wish-below { margin: 0; background-color: var(--secondary-container); color: var(--on-secondary-container); font-weight: 600; }
.wish-spark svg { display: block; inline-size: 100%; max-inline-size: 9rem; block-size: auto; }
.wish-count, .wish-limit { font-size: 0.875rem; color: var(--on-surface-variant); }
.wish-paused .wish-price, .wish-paused .wish-name { color: var(--on-surface-variant); }
.wish-paused .wish-spark { opacity: 0.55; }
.wish-actions { position: relative; z-index: 1; display: flex; margin-block-start: auto !important; padding-block-start: 0.5rem; }
.wish-actions { flex-wrap: wrap; gap: 0.5rem; }
.wish-actions button, .wish-actions .button { min-block-size: 3rem; margin: 0; }
.wish-count a { color: inherit; text-decoration: none; }
.wish-limit { font-weight: 400; }

.fab {
  position: fixed;
  inset-inline-end: 1rem;
  inset-block-end: 5.75rem;
  z-index: 100;
  min-block-size: 3.5rem;
  padding-inline: 1.5rem;
  margin: 0;
  gap: 0.5rem;
  border-radius: 1rem;
  box-shadow: var(--elevate2, 0 2px 8px rgb(0 0 0 / 0.25));
}
@media (min-width: 600px) { .fab { inset-inline-end: 1.5rem; inset-block-end: 1.5rem; } }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-block-end: 1rem; }
.page-head h1 { margin: 0; }
.page-action { display: none; margin: 0; gap: 0.5rem; min-block-size: 3rem; }
@media (min-width: 840px) {
  .page-action { display: inline-flex; }
  .fab { display: none; }
  .wish-grid { padding-block-end: 0; }
}

/* ---- Forms ---- */
.form-page { max-inline-size: 36rem; }
.stack { display: flex; flex-direction: column; gap: 1rem; }
.stack .field { margin: 0; }
.stack label { margin: 0; font-weight: inherit; }
.form-actions { display: flex; flex-wrap: wrap; gap: 0.75rem; }
.form-actions .button, .form-actions button { min-block-size: 3rem; margin: 0; }
.error[role="alert"] { display: flex; align-items: center; gap: 0.5rem; padding: 0.75rem 1rem; border-radius: var(--shape-xl); background-color: var(--error-container); color: var(--on-error-container); }

.compact-sub { font-size: 0.875rem; }
@media (max-width: 599.98px) {
  .compact-sub { display: block; }
  table.data .num { white-space: nowrap; }
  table.data .button.small { min-inline-size: 3rem; padding-inline: 0; }
}
@media (max-width: 599.98px) {
  a.compact-sub { display: flex; align-items: center; min-block-size: 3rem; font-weight: 600; }
}

/* ---- Polish pass: density, status, empty states, elevation ---- */
.appbar form.inline { display: flex; align-items: center; margin: 0; }
.appbar button { margin: 0; }
.theme-menu-wrap { display: flex; align-items: center; }

.empty-compact { padding-block: 1.5rem; }
.kv { display: flex; flex-direction: column; margin: 0; }
.kv-row { border-radius: 0; display: grid; grid-template-columns: minmax(0, 11rem) minmax(0, 1fr); align-items: center; gap: 0.75rem; padding-block: 0.5rem; border-block-end: 1px solid var(--outline-variant); }
.kv-row:last-child { border-block-end: 0; }
.kv dt { display: flex; align-items: center; gap: 0.5rem; color: var(--on-surface-variant); }
.kv dt i { font-size: 1.25rem; }
.kv dd { margin: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; font-variant-numeric: tabular-nums; }
.kv dd .chip { margin: 0; }
@media (max-width: 599.98px) { .kv-row { grid-template-columns: minmax(0, 1fr); gap: 0.125rem; } }


.auth { min-block-size: 100dvh; display: flex; flex-direction: column; justify-content: center; }
.form-page .stack { gap: 1.25rem; }

/* Cards lift off the page in the light theme; dark relies on tone alone. */
.offer, .wish-card, .status-card, .table-wrap, .chart-frame, .login-card, .channel-list, .alert-card {
  box-shadow: 0 1px 2px var(--elev-a), 0 2px 8px var(--elev-b);
}

/* Compact offer rows: tighter, price and open action share a line on the product page. */
@media (max-width: 599.98px) {
  .offer { gap: 0.375rem; padding: 0.875rem 1rem; }
  .offer-price { font-size: 1.5rem; }
  .offer-actions { padding-block-start: 0.25rem; }
}

.add-row .field { min-inline-size: 0; }
.add-row button { flex: none; }

/* ---- Pass 3: alignment ---- */
form.inline { margin: 0 !important; }
.channel-name, .channel-handle { display: block; }
.channel-handle { font-size: 0.875rem; }
.filter-switch { translate: -0.75rem 0; }
.filter-channel { margin: 0 !important; }

/* ---- Channels: an M3 list instead of a table ---- */
/* Beer adds a top margin to any block after a sibling; the hint belongs to the field above. */
.add-hint { margin: -0.5rem 0 0 1rem !important; font-size: 0.875rem; }
.channel-list { list-style: none; margin: 0; padding: 0; overflow: visible; border-radius: var(--shape-xl); background-color: var(--surface-container-low); border: 1px solid var(--outline-variant); }
.channel-item { display: flex; align-items: center; gap: 0.75rem; min-block-size: 4.5rem; margin: 0; padding: 0.75rem 0.5rem 0.75rem 1rem; border-radius: 0; }
.channel-item + .channel-item { border-block-start: 1px solid var(--outline-variant); }
.channel-item:first-child { border-start-start-radius: var(--shape-xl); border-start-end-radius: var(--shape-xl); }
.channel-item:last-child { border-end-start-radius: var(--shape-xl); border-end-end-radius: var(--shape-xl); }
.channel-main { flex: 1; min-inline-size: 0; display: flex; flex-direction: column; gap: 0.125rem; }
.channel-name { font-weight: 600; overflow-wrap: anywhere; }
.channel-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem 0.5rem; font-size: 0.875rem; color: var(--on-surface-variant); }
.channel-meta .chip { margin: 0; }
.channel-paused .channel-name { color: var(--on-surface-variant); }
.channel-switch { flex: none; margin: 0; }
.row-menu-wrap { flex: none; display: flex; align-items: center; }
.row-menu-wrap > button { margin: 0; }

/* ---- Shell: on compact the app bar names the page, so the big H1 steps aside ---- */
.appbar .title { display: flex; align-items: baseline; gap: 0.5rem; }
@media (max-width: 599.98px) {
  .appbar .title:has(.page-title) .brand { display: none; }
  main.has-page-title h1 {
    position: absolute;
    inline-size: 1px;
    block-size: 1px;
    margin: -1px;
    padding: 0;
    clip-path: inset(50%);
    white-space: nowrap;
  }
  main.has-page-title .page-head { margin: 0; }
}
@media (min-width: 600px) { .appbar .page-title { display: none; } }

/* ---- Filters: switch, select and price fields share one height and centre line ---- */
@media (min-width: 600px) {
  .filters-panel > .filter-switch,
  .filters-panel > .filter-channel,
  .filters-panel .filter-prices .field { block-size: 3rem; min-block-size: 3rem; }
  .filters-panel { align-items: center; }
}

/* ---- Forms: helper text lines up with the field's text, textareas grow with their lines ---- */
.stack .field > .helper { margin-inline: 1rem; }
.stack .field.textarea > textarea { field-sizing: content; min-block-size: 6.5rem; padding-block-end: 1rem; }

/* Squarer fields (Beer's default border fields), matching --shape-control. */
.field.border > :is(input, select, textarea) { border-radius: var(--shape-control); }

/* ---- Coupons: copyable code chips, coupon cards, the active strip, full post text ---- */
.offer-with-coupon { display: inline-block; margin-inline-start: 0.25em; font-size: 1rem; font-weight: 600; letter-spacing: 0; color: var(--on-surface-variant); }
.coupon-codes { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.coupon-wrap { position: relative; display: inline-flex; }
.offer .coupon-code {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-block-size: 3rem;
  margin: 0;
  padding: 0 0.875rem 0 1rem;
  border: 2px dashed currentColor;
  border-radius: var(--shape-control);
  background-color: var(--tertiary-container);
  color: var(--on-tertiary-container);
  font-family: ui-monospace, "SF Mono", "Roboto Mono", Menlo, Consolas, monospace;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
  box-shadow: none;
}
.offer .coupon-code:hover { filter: brightness(0.97); }
.offer .coupon-code:active { border-radius: var(--shape-pressed); }
.offer .coupon-code:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
.coupon-text { overflow-wrap: anywhere; user-select: all; }
.coupon-code > i { flex: none; font-size: 1.25rem; }
/* A small tag on the chip's top edge: the code underneath stays readable. */
.copy-status {
  position: absolute;
  inset-block-start: 0;
  inset-inline-end: 0.5rem;
  translate: 0 -55%;
  z-index: 2;
  padding: 0.125rem 0.5rem;
  border-radius: var(--shape-control);
  background-color: var(--on-surface);
  color: var(--surface);
  font-size: 0.8125rem;
  font-weight: 700;
  line-height: 1.3;
  white-space: nowrap;
  pointer-events: none;
}
.copy-status:empty { display: none; }

.offer-coupon { background-color: var(--tertiary-container); color: var(--on-tertiary-container); border-color: transparent; }
.offer-coupon .offer-meta { color: inherit; }
.offer-coupon .chip { background-color: var(--surface); color: var(--on-surface); }
.offer-coupon .coupon-code { background-color: var(--surface); color: var(--on-surface); }
.offer-coupon .offer-actions .button.tonal { background-color: var(--surface); color: var(--on-surface); }
.coupon-discount { font-size: 2.25rem; font-weight: 800; line-height: 1.05; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.coupon-terms { font-size: 0.9375rem; line-height: 1.4; }
.offer.offer-coupon > .offer-title { font-size: 0.9375rem; line-height: 1.4; font-weight: 400; }
.offer .offer-actions { flex-wrap: wrap; }
@media (min-width: 840px) {
  .feed-list .offer.offer-coupon { display: flex; flex-direction: column; align-items: stretch; padding-block: 1rem; }
}
.product-page .offer.offer-coupon { display: flex; flex-direction: column; align-items: stretch; }

/* Feed tabs (Ofertas / Cupons): real links in a primary-tabs row. */
nav.tabs.feed-tabs { margin-block: 0 1rem; border-block-end: 1px solid var(--outline-variant); }
.feed-tabs > a { flex: 1 1 0; min-block-size: 3rem; justify-content: center; margin: 0; }
@media (min-width: 600px) {
  nav.tabs.feed-tabs { justify-content: flex-start; }
  .feed-tabs > a { flex: 0 0 auto; inline-size: auto; min-inline-size: 9rem; }
}

.coupon-filters { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem 1rem; }
.coupon-filters .filters-search { flex: 1 1 16rem; }
.coupon-filters .filter-channel { flex: 1 1 12rem; margin: 0; }
.coupon-filters .filter-switch { margin: 0; }
.offer .store-coupons { text-decoration: none; background-color: var(--primary-container); color: var(--on-primary-container); font-weight: 600; }

.post-full { font-size: 0.875rem; }
.post-full > summary {
  display: flex;
  align-items: center;
  min-block-size: 2.5rem;
  font-weight: 600;
  color: var(--on-surface-variant);
  cursor: pointer;
}
.post-full > summary:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; border-radius: var(--shape-control); }
.offer-coupon .post-full > summary { color: inherit; }
.post-text { padding-block: 0.25rem 0.5rem; color: var(--on-surface); white-space: pre-line; overflow-wrap: anywhere; line-height: 1.5; }
.post-text a { color: inherit; text-decoration: underline; }
.post-full:not([open]) > .post-text { display: none; }
.offer-coupon .offer-actions { flex-wrap: wrap; gap: 0.5rem; }
.coupon-tiers { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.625rem; font-size: 0.9375rem; font-weight: 500; line-height: 1.4; }
.coupon-tiers-more { font-weight: 400; opacity: 0.85; }
.coupon-tiers > li { display: flex; flex-direction: column; gap: 0.375rem; }
.tier-text { font-variant-numeric: tabular-nums; }

/* ---- Paged lists: "Carregar mais", end of list and back to top ---- */
.load-more, .load-end { grid-column: 1 / -1; }
.load-more {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  justify-self: center;
  gap: 0.5rem;
  min-block-size: 3rem;
  margin: 0.5rem auto;
}
.load-more .load-more-error { display: none; }
.load-more.is-error .load-more-label { display: none; }
.load-more.is-error { background-color: var(--error-container); color: var(--on-error-container); }
.load-more.is-error .load-more-error { display: inline; }
.load-more .htmx-indicator { display: none; margin: 0; color: var(--on-secondary-container); }
.load-more.htmx-request .htmx-indicator { display: inline-block; }
.load-more.htmx-request .load-more-label, .load-more.htmx-request .load-more-error { display: none; }
.load-end { text-align: center; margin: 1rem 0; }
.feed-list, .feed-cards { padding-block-end: 4.5rem; }

.top-fab {
  position: fixed;
  inset-inline-end: 1rem;
  inset-block-end: 5.75rem;
  z-index: 100;
  inline-size: 3.5rem;
  block-size: 3.5rem;
  margin: 0;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 1rem;
  background-color: var(--secondary-container);
  color: var(--on-secondary-container);
  box-shadow: var(--elevate2, 0 2px 8px rgb(0 0 0 / 0.25));
}
.top-fab[hidden] { display: none; }
@media (min-width: 600px) { .top-fab { inset-inline-end: 1.5rem; inset-block-end: 1.5rem; } }

.live { position: sticky; inset-block-start: 4.5rem; z-index: 80; display: flex; justify-content: center; pointer-events: none; }
.live:empty { display: none; }
.live-pill {
  pointer-events: auto;
  margin: 0 0 0.75rem;
  gap: 0.5rem;
  border-radius: 999px;
  background-color: var(--primary);
  color: var(--on-primary);
  box-shadow: var(--elevate2, 0 2px 8px rgb(0 0 0 / 0.25));
}

/* ---- Offer product card: image and name lead, the coupon strip sits above the actions ----
   Wide card (grid, wide screens): image on top. Phone: image left, text beside it.
   Wide list rows: image left, actions right. Coupon cards keep their own layout. */
.offer-product { display: flex; flex-direction: column; align-items: stretch; gap: 0.75rem; padding: 1rem; }
.offer-media {
  position: relative;
  display: grid;
  place-items: center;
  inline-size: 100%;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border-radius: var(--shape-control);
  background-color: var(--surface-container);
  color: var(--outline);
}
.offer-media > i { font-size: 2.5rem; }
/* The image covers the placeholder icon; if it fails to load, velkgram.js hides it. */
.offer-media .offer-thumb {
  position: absolute;
  inset: 0;
  inline-size: 100%;
  block-size: 100%;
  padding: 0.5rem;
  object-fit: contain;
  background-color: #fff;
  border-radius: 0;
}
.offer-media .offer-thumb.is-broken { display: none; }
.offer-body { display: flex; flex-direction: column; align-items: flex-start; gap: 0.375rem; min-inline-size: 0; }
.offer-body > * { margin: 0 !important; max-inline-size: 100%; }
.offer-body .offer-meta { align-items: center; gap: 0.25rem 0.5rem; font-size: 0.8125rem; line-height: 1.5; }
/* Store chip: tinted with the store's brand colour. Tint and border are mixed into the theme
   surface, so the text stays on-surface and keeps its contrast in every flavour. */
.store-chip {
  --store: var(--primary);
  gap: 0.375rem;
  font-weight: 700;
  color: var(--on-surface);
  background-color: color-mix(in srgb, var(--store) 24%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--store) 60%, transparent);
}
.store-chip::before { content: ""; flex: none; inline-size: 0.5rem; block-size: 0.5rem; border-radius: 50%; background-color: var(--store); }
.store-chip[data-store="amazon"] { --store: #ff9900; }
.store-chip[data-store="mercadolivre"] { --store: #ffd400; }
.store-chip[data-store="shopee"] { --store: #ee4d2d; }
.store-chip[data-store="kabum"] { --store: #ff6500; }
.store-chip[data-store="magalu"] { --store: #0086ff; }
.store-chip[data-store="aliexpress"] { --store: #e62e04; }
.store-chip[data-store="pichau"] { --store: #d4001a; }
.store-chip[data-store="terabyte"] { --store: #1fa84f; }
.store-chip[data-store="casasbahia"] { --store: #1a56c4; }
.store-chip[data-store="americanas"] { --store: #e60014; }
.store-chip[data-store="carrefour"] { --store: #2a6fd6; }
.store-chip[data-store="netshoes"] { --store: #8a4dff; }
.offer-when { color: var(--on-surface-variant); }
.offer-body .offer-title {
  align-self: stretch;
  padding: 0.1em 0 0.15em;
  font-size: 1.0625rem;
  font-weight: 600;
  -webkit-line-clamp: 3;
  line-clamp: 3;
}
.offer-product .offer-price {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 0.5rem;
  font-size: 1.5rem;
  line-height: 1.15;
}
.offer-product.offer-quiet .offer-price { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.03em; }
.offer-product.offer-quiet .offer-price.offer-price-unknown { font-size: 1rem; font-weight: 600; letter-spacing: 0; }
.offer-product .offer-with-coupon { margin: 0; font-size: 0.8125rem; font-weight: 600; }
.offer-body .offer-flags { gap: 0.375rem; }
.offer-body .store-coupons { padding-inline: 0; border: 0; background-color: transparent; color: var(--primary); font-weight: 600; }
.offer-body .store-coupons:hover { text-decoration: underline; }
/* Coupon strip: the code button reads as a coupon on its own; no label. */
.offer-product > .coupon-codes { align-items: center; gap: 0.375rem 0.5rem; }
.offer-product .coupon-code { min-block-size: 2.25rem; padding: 0 0.625rem 0 0.75rem; gap: 0.375rem; font-size: 0.875rem; border-width: 1px; }
.offer-product > .offer-actions { margin: auto 0 0 !important; padding: 0; }
.offer-product .offer-actions .button { min-block-size: 2.5rem; }

@media (max-width: 599.98px) {
  .offer-product {
    display: grid;
    grid-template-columns: 6.5rem minmax(0, 1fr);
    grid-template-areas: "media body" "codes codes" "actions actions" "post post";
    align-items: start;
    gap: 0 0.875rem;
  }
  .offer-product > * { margin-block-start: 0.75rem; }
  .offer-product > .offer-media { grid-area: media; margin: 0; aspect-ratio: 1; }
  .offer-product > .offer-body { grid-area: body; margin: 0; }
  .offer-product > .coupon-codes { grid-area: codes; }
  .offer-product > .offer-actions { grid-area: actions; margin: 0.75rem 0 0 !important; }
  .offer-product > .post-full { grid-area: post; margin-block-start: 0.25rem; }
  .offer-body .offer-title { -webkit-line-clamp: 2; line-clamp: 2; }
}

@media (min-width: 840px) {
  .feed-list .offer-product {
    display: grid;
    grid-template-columns: 7rem minmax(0, 1fr) auto;
    grid-template-areas: "media body actions" "media codes actions" "post post post";
    align-items: start;
    gap: 0 1.25rem;
    padding-block: 0.875rem;
  }
  .feed-list .offer-product > * { margin-block-start: 0.5rem; }
  .feed-list .offer-product > .offer-media { grid-area: media; margin: 0; aspect-ratio: 1; }
  .feed-list .offer-product > .offer-body { grid-area: body; margin: 0; }
  .feed-list .offer-product > .coupon-codes { grid-area: codes; }
  .feed-list .offer-product > .offer-actions { grid-area: actions; align-self: center; margin: 0 !important; }
  .feed-list .offer-product > .post-full { grid-area: post; }
  .feed-list .offer-product .offer-title { -webkit-line-clamp: 2; line-clamp: 2; }
}

/* ---- Wishes: aligned cards, terms as chips, one footer line ---- */
.feed > .wish-card { margin: 0 !important; }
.wish-terms { display: flex; flex-wrap: wrap; gap: 0.25rem; }
.wish-terms .chip { margin: 0; }
.wish-card .tonal-chip { background-color: var(--secondary-container); color: var(--on-secondary-container); }
.wish-card .wish-price { font-size: 1.75rem; }
.wish-card .wish-price.wish-price-unknown { font-size: 0.9375rem; font-weight: 400; line-height: 1.3; letter-spacing: 0; }
.wish-foot { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 0.125rem 0.75rem; padding-block-start: 0.5rem; border-radius: 0; border-block-start: 1px solid var(--outline-variant); }
.wish-foot .wish-count { font-weight: 600; }
.wish-foot:not(:has(.wish-count)) { justify-content: flex-start; }
.wish-actions button, .wish-actions .button { min-block-size: 2.75rem; }

/* ---- Alerts: one card per alert, status icon on the left, actions on the right ---- */
.alert-list { display: flex; flex-direction: column; gap: 0.5rem; margin: 0; padding: 0; list-style: none; }
.alert-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-areas: "icon body" "actions actions";
  align-items: start;
  gap: 0.75rem 1rem;
  margin: 0;
  padding: 1rem;
  border: 1px solid var(--outline-variant);
  border-radius: var(--shape-xl);
  background-color: var(--surface-container-low);
  color: var(--on-surface);
}
.alert-icon {
  grid-area: icon;
  display: grid;
  place-items: center;
  inline-size: 2.75rem;
  block-size: 2.75rem;
  border-radius: 50%;
  background-color: var(--primary-container);
  color: var(--on-primary-container);
}
.alert-failed .alert-icon { background-color: var(--error-container); color: var(--on-error-container); }
.alert-pending .alert-icon, .alert-expired .alert-icon { background-color: var(--surface-container-highest); color: var(--on-surface); }
.alert-body { grid-area: body; display: flex; flex-direction: column; gap: 0.25rem; min-inline-size: 0; }
.alert-body > * { margin: 0 !important; }
.alert-head { display: flex; flex-wrap: wrap; align-items: center; gap: 0.375rem 0.5rem; }
.alert-wish { font-size: 1.0625rem; font-weight: 600; overflow-wrap: anywhere; }
.alert-head .chip { margin: 0; block-size: auto; min-block-size: 1.75rem; padding-block: 0.125rem; white-space: normal; overflow-wrap: anywhere; line-height: 1.3; }
.alert-price { font-size: 1.5rem; font-weight: 800; line-height: 1.15; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; color: var(--primary); }
.alert-price-unknown { font-size: 1rem; font-weight: 600; letter-spacing: 0; color: var(--on-surface-variant); }
.alert-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem 0.5rem; font-size: 0.8125rem; color: var(--on-surface-variant); }
.alert-meta .chip { margin: 0; }
.alert-channel { display: block; max-inline-size: 11rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.alert-tech { font-size: 0.8125rem; color: var(--on-surface-variant); font-variant-numeric: tabular-nums; }
.alert-actions { grid-area: actions; display: flex; flex-wrap: wrap; gap: 0.5rem; }
.alert-actions .button { min-block-size: 2.5rem; margin: 0; }
@media (min-width: 600px) {
  .alert-card { grid-template-columns: auto minmax(0, 1fr) auto; grid-template-areas: "icon body actions"; align-items: center; }
  .alert-actions { flex-wrap: nowrap; }
}

/* A failed alert whose cause the user can fix (e.g. no Telegram chat configured). */
.alert-note { display: flex; align-items: center; gap: 0.375rem; margin: 0.25rem 0 0; font-size: 0.8125rem; color: var(--error); }
.alert-note > i { font-size: 1rem; }

/* Profile and user admin: section headings sized for a card, the id field and its button share a row. */
.profile-section { margin-block: 1rem; }
.profile-section > h2 { font-size: 1.25rem; line-height: 1.75rem; margin: 0 0 0.5rem; }
.profile-section .row { margin-block-start: 0.25rem; }
.generated code { font-size: 1.125rem; user-select: all; }
.notice { display: flex; align-items: center; gap: 0.375rem; color: var(--primary); }


/* Result of the broadcast test alert: one line per user. */
.test-results { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.375rem; }
.test-results li { display: flex; align-items: center; gap: 0.5rem; }
.test-ok > i { color: var(--primary); }
.test-fail > i { color: var(--error); }

/* Very narrow phones (320px): the admin's five destinations and the extra top icons must fit. */
@media (max-width: 359px) {
  .appbar { gap: 0.125rem; padding-inline: 0.75rem 0.25rem; }
  .appbar form.inline button { min-inline-size: 0; padding-inline: 0.5rem; }
  .appbar form.inline button > span { display: none !important; }
  nav.bottom { gap: 0; padding-inline: 0.25rem; }
  nav.bottom a { flex: 1 1 0; min-inline-size: 0; padding-inline: 0; }
  nav.bottom a > span { font-size: 0.6875rem; }
}

/* User admin list: one card per user; the id field and the three buttons share one row, all 2.5rem tall.
   Beer CSS gives a form that follows another one a top margin, hence the explicit resets. */
.alert-card.user-card { display: block; }
.user-card .alert-head { margin: 0; }
.user-card .alert-tech { margin: 0.25rem 0 0; }
.user-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin-block-start: 0.75rem; }
.user-controls > form { display: flex; align-items: center; gap: 0.5rem; margin: 0 !important; padding: 0; }
.user-controls .user-chat { flex: 1 1 15rem; min-inline-size: 0; }
.user-controls .field { flex: 1 1 8rem; min-inline-size: 0; margin: 0 !important; block-size: 2.5rem !important; min-block-size: 0 !important; }
.user-controls .field > input { block-size: 2.5rem !important; min-block-size: 0 !important; }
.user-controls button { margin: 0; block-size: 2.5rem; min-block-size: 2.5rem; }

/* Same product across stores: the line on a card and the product page. */
.offer-peers { margin: 0.125rem 0 0; font-size: 0.8125rem; }
.offer-peers a { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 0.25rem 0.5rem; color: var(--on-surface-variant); text-decoration: none; }
.offer-peers .peer { white-space: nowrap; }
.offer-peers .peer-cheaper { color: var(--primary); font-weight: 600; }
.offer-peers i { font-size: 1rem; }
.compare-title { font-size: 1.5rem; line-height: 2rem; margin-block-end: 0.5rem; }
.compare-lowest { display: flex; align-items: center; gap: 0.375rem; margin: 0 0 1rem; color: var(--primary); }
.store-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.75rem; }
.alert-card.store-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "head spark" "price spark" "meta meta" "open open"; gap: 0.25rem 1rem; align-items: center; }
.store-row .store-head { grid-area: head; margin: 0; display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.store-row .store-price { grid-area: price; margin: 0; font-size: 1.5rem; font-weight: 700; }
.store-row .store-meta { grid-area: meta; margin: 0; font-size: 0.8125rem; color: var(--on-surface-variant); }
.store-row .store-spark { grid-area: spark; }
.store-row > .button { grid-area: open; justify-self: start; margin: 0.25rem 0 0; min-block-size: 2.5rem; }
.store-cheapest .store-price { color: var(--primary); }

/* Product page / card fixes: fixed-size sparkline, the lowest-price line as one text, left-aligned peers. */
.store-row .store-spark { justify-self: end; }
.store-row .store-spark svg { inline-size: 96px; block-size: 28px; max-inline-size: 96px; }
.alert-card.store-row { grid-template-columns: minmax(0, 1fr) auto; }
.store-row .store-head .chip { white-space: nowrap; }
.compare-lowest > span { flex: 1 1 auto; min-inline-size: 0; }
.compare-lowest > i { flex: none; }
.offer-peers, .offer-peers a { text-align: start; justify-content: flex-start; }

/* Product page: history of every offer, newest first. A grid keeps the open button on the row. */
.offer-history { list-style: none; margin: 0; padding: 0; display: grid; gap: 0; }
.offer-history li {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-areas: "store price open" "store when open";
  align-items: center;
  gap: 0 0.75rem;
  padding-block: 0.5rem;
  border-block-end: 1px solid var(--outline-variant);
}
.offer-history .store-chip { grid-area: store; align-self: center; }
.offer-history .offer-history-price { grid-area: price; font-size: 1.0625rem; }
.offer-history time { grid-area: when; font-size: 0.8125rem; }
.offer-history .button { grid-area: open; margin: 0; min-block-size: 2.5rem; }
@media (max-width: 599px) {
  .offer-history .button { inline-size: 2.5rem; padding-inline: 0; }
  .offer-history .button > span { display: none; }
}

/* The card title opens the product page. */
.offer-title-link { color: inherit; text-decoration: none; }
.offer-title-link:hover, .offer-title-link:focus-visible { text-decoration: underline; text-underline-offset: 0.2em; }

/* ---- Tap targets: 40 px at least on phones ---- */
/* Vertical padding on an inline link grows its hit area without moving the text. */
.offer-title-link, .wish-name a, .wish-count a { padding-block: 0.5rem; }
.appbar .button.circle { flex: none; min-inline-size: 2.5rem; }
.channel-switch { min-block-size: 2.5rem; align-items: center; }
.wish-name a, .wish-count a { padding-block: 0.6rem; }
/* Narrow phones with the admin's extra icon: logout keeps its icon and drops the word. */
@media (max-width: 419.98px) {
  .appbar form.inline button { padding-inline: 0.75rem; }
  .appbar form.inline button span { display: none; }
}

/* ---- Feed feel: a filter change dims the old results and shows a thin progress bar; the swap
   itself is a short cross-fade (htmx `transition:true`). ---- */
#results { transition: opacity 150ms ease; }
.feed-page:has(#feed-filters.htmx-request) #results { opacity: 0.55; }
.feed-page:has(#feed-filters.htmx-request)::before {
  content: "";
  position: fixed;
  inset: 0 0 auto 0;
  block-size: 3px;
  z-index: 400;
  background: linear-gradient(90deg, transparent, var(--primary), transparent);
  background-size: 40% 100%;
  background-repeat: no-repeat;
  animation: feed-progress 1s ease-in-out infinite;
}
@keyframes feed-progress { from { background-position: -40% 0; } to { background-position: 140% 0; } }
::view-transition-group(root) { animation-duration: 160ms; }
@media (prefers-reduced-motion: reduce) {
  #results { transition: none; }
  .feed-page:has(#feed-filters.htmx-request)::before { animation: none; background-size: 100% 100%; }
  ::view-transition-group(root) { animation-duration: 0.01ms; }
}

/* ---- Chart tooltip (velkgram.js) ---- */
.chart-frame { position: relative; }
.chart-frame svg[data-points] { touch-action: pan-y; cursor: crosshair; }
.chart-guide { stroke: var(--outline); stroke-width: 1; stroke-dasharray: 3 3; pointer-events: none; }
.chart-hover-dot { fill: var(--primary); stroke: var(--surface); stroke-width: 2; pointer-events: none; }
.chart-tip {
  position: absolute;
  z-index: 2;
  padding: 0.375rem 0.625rem;
  border-radius: var(--shape-control);
  background-color: var(--inverse-surface);
  color: var(--inverse-on-surface);
  font-size: 0.875rem;
  white-space: nowrap;
  pointer-events: none;
}
.chart-tip strong { font-variant-numeric: tabular-nums; }
