/* ── Карточки и сетка (стабилизация CLS и памяти под iOS) ──────────────── */
.grid{
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}

/* Reserve the detached category capsule and safe-area; reserve a second lane only for a visible cart FAB. */
@media (max-width: 820px),
       (min-width: 821px) and (orientation: landscape) and (max-height: 480px) {
  #grid,
  #deliveryGrid {
    padding-bottom: calc(var(--rail-total-h) + 16px);
    scroll-padding-bottom: calc(var(--rail-total-h) + 16px);
  }

  body:has(#cartFab.visible:not([hidden])):not(.is-cashier):not(.is-admin) #grid,
  body:has(#cartFab.visible:not([hidden])):not(.is-cashier):not(.is-admin) #deliveryGrid {
    padding-bottom: calc(var(--rail-total-h) + 12px + 64px + 16px);
    scroll-padding-bottom: calc(var(--rail-total-h) + 12px + 64px + 16px);
  }

  body.cart-open #grid,
  body.cart-open #deliveryGrid {
    padding-bottom: 16px;
    scroll-padding-bottom: 16px;
  }
}
@media (min-width: 1181px){
  .grid{
    grid-template-columns: repeat(3, 1fr);
  }
}
@media (min-width: 1600px){
  .grid{
    grid-template-columns: repeat(4, 1fr);
  }
}
.card{
  background: var(--card-bg, #FFFFFF);
  border: var(--card-border, 1.5px solid rgba(62, 143, 208, 0.25));
  border-radius: var(--card-radius, 18px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform var(--motion-duration-state, 180ms) var(--motion-ease-standard, cubic-bezier(.2,.8,.2,1)), opacity var(--motion-duration-state, 180ms) var(--motion-ease-standard, cubic-bezier(.2,.8,.2,1));
  animation: card-enter var(--motion-duration-state, 180ms) var(--motion-ease-standard, cubic-bezier(.2,.8,.2,1)) backwards;
  animation-delay: var(--d, 0ms);
  position: relative;
  box-shadow: var(--card-shadow, 0 6px 20px rgba(18, 58, 107, 0.08));
  min-height: 340px;
}
/* Entrance reveals the card without scaling its visual or interactive bounds. */
@keyframes card-enter {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
@media (hover: hover) and (pointer: fine){
  .card:hover{
    transform: translateY(-4px);
    box-shadow: var(--card-hover-shadow, 0 10px 28px rgba(18, 58, 107, 0.15));
    border-color: var(--card-hover-border, #3E8FD0);
  }
  .card:hover .media img{
    transform: scale(1.07);
  }
}
body.editing .card{
  border-style: dashed;
  border-color: #9FB4C8;
}
body.editing .card:hover{
  transform: none;
}
/* ── Медиа-зона карточки ────────────────────────────────────────────────── */
.media{
  height: 180px;
  min-height: 180px;
  position: relative;
  overflow: hidden;
  background: linear-gradient(180deg, rgba(62, 143, 208, 0.08), transparent);
  display: grid;
  place-items: center;
  contain: layout style;
}
.media img{
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform .5s;
}
.media .em{
  font-size: 56px;
  text-shadow: 0 8px 10px rgba(16, 20, 24, 0.22);
  transition: transform .3s;
}
/* ── Метки / Теги (WCAG AA для .tag.hit) ────────────────────────────────── */
.tag{
  position: absolute;
  top: 10px;
  left: 10px;
  font: 700 9.5px "Unbounded", "Golos Text", sans-serif;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 4px 9px;
  border-radius: 999px;
  color: #fff;
  z-index: 2;
  background: var(--tag-bg, #1B4F8A);
}
.tag.hit{ background: var(--tag-hit-bg, #1B5E8A); color: #FFFFFF; }
.tag.new{ background: #2F7D4F; color: #FFFFFF; }
.tag.vegan{ background: #557F42; color: #FFFFFF; }
.tag.spicy{ background: #A6322A; color: #FFFFFF; }
.tag.recommended{ background: #1B5E8A; color: #FFFFFF; }
.tag.seasonal{ background: #6C4A8E; color: #FFFFFF; }
.tag.limited{ background: #7C3E62; color: #FFFFFF; }
.tag.decaf{ background: #53636F; color: #FFFFFF; }
.tag.neutral{ background: #53636F; color: #FFFFFF; }
.tag.popular{ background: #7656A6; color: #FFFFFF; }
.tag.signature{ background: #81533B; color: #FFFFFF; }
.tag.share{ background: #287A70; color: #FFFFFF; }
.tag.hearty{ background: #A35B2A; color: #FFFFFF; }
.tag.light{ background: #4B806F; color: #FFFFFF; }
.tag.recommended,
.tag.seasonal,
.tag.limited,
.tag.decaf,
.tag.neutral{
  letter-spacing: 0.02em;
}
.stopped .media img,
.stopped .media .em{
  filter: grayscale(1);
  opacity: 0.5;
}
.stopbadge{
  position: absolute;
  top: 10px;
  right: 10px;
  background: #D63939;
  color: #FFFFFF;
  font: 800 10px "Unbounded", "Golos Text", sans-serif;
  letter-spacing: 0.12em;
  padding: 5px 10px;
  border-radius: 999px;
  z-index: 2;
}
/* ── Тело карточки ──────────────────────────────────────────────────────── */
.cbody{
  padding: 13px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}
.cbody h3{
  font: 700 15.5px/1.3 "Golos Text", sans-serif;
  color: #123A6B;
}
.cbody .desc{
  font-size: 12.5px;
  color: var(--soft);
  /* Описание разной длины не должно разносить высоту карточек: режем на 2 строки
     и держим постоянный резерв высоты (иначе в ряду часть карточек выше).
     line-height и min-height заданы явно: резерв в em плавал бы вместе с метриками
     шрифта (до загрузки Golos Text и после) и давал высоты 35/38px вперемешку. */
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 37px;
}
/* In delivery pizza cards, .desc is the canonical full composition (not a short teaser).
   Desktop gets the full wrapped text; grid rows stretch neighboring cards to the same height.
   Coffee descriptions keep the shared two-line clamp. */
@media (min-width: 821px) {
  #deliveryGrid .card .cbody .desc {
    display: block;
    -webkit-line-clamp: unset;
    line-clamp: unset;
    -webkit-box-orient: initial;
    overflow: visible;
    min-height: 0;
  }
}
/* Single-column mobile delivery cards have no row-height alignment constraint.
   Show the canonical pizza composition in full instead of reserving only two teaser lines. */
@media (max-width: 519px) {
  #deliveryGrid .cbody .desc {
    display: block;
    -webkit-line-clamp: unset;
    line-clamp: unset;
    -webkit-box-orient: initial;
    overflow: visible;
    min-height: 0;
  }
}
/* Full descriptions have natural, variable heights; don't reserve the old fixed
   card size for skipped off-screen items or they jump when content becomes visible. */
@media (max-width: 519px) {
  #deliveryGrid .card:nth-child(n+5) {
    content-visibility: visible;
  }
}
.comp{
  display: flex;
  flex-wrap: nowrap;
  gap: 5px;
  margin-top: 2px;
  /* Мобильные (≤820px): состав разной длины не должен менять высоту карточки: чипсы в одну
     строку, лишнее обрезается по правому краю. С flex-wrap: wrap карточка с тремя длинными
     чипсами вырастала на строку (+4px) и ломала одинаковую высоту рядов. На desktop — см. ниже. */
  overflow: hidden;
}
.comp i{
  font-style: normal;
  background: var(--composition-chip-bg, #EAF1F9);
  border: 1px solid var(--composition-chip-border, rgba(62, 143, 208, 0.25));
  border-radius: 999px;
  padding: 3px 9px;
  font: 600 10.5px "Golos Text";
  color: var(--composition-chip-color, #123A6B);
  flex: 0 0 auto;
}
/* Desktop: карточки узкие (в кофейне справа ещё панель 350px), и чипсы в одну строку
   обрезались по краю. Здесь состав переносится целиком; на мобильных остаётся одна строка.
   Ряд сетки растягивает карточки до самой высокой, поэтому высоты в ряду не расходятся.
   Зеркало для доставки — в critical CSS public/index.html. */
@media (min-width: 821px){
  .comp{ flex-wrap: wrap; }
}
.cbody .vol{
  font: 600 11px "Golos Text";
  color: #5B6874;
  letter-spacing: 0.04em;
  /* К низу карточки прижимает .cfoot (margin-top: auto). Если оставить auto и здесь,
     свободное место делится пополам и объём «повисает» в середине карточки. */
  margin-top: 2px;
}
.cfoot{
  display: flex;
  align-items: center;
  justify-content: space-between;
  /* auto + flex:1 у .cbody: цена/кнопка всегда прижаты к низу карточки,
     даже если описание короткое или .vol отсутствует. */
  margin-top: auto;
  padding-top: 6px;
}
.price{ font: 700 16px "Golos Text"; font-variant-numeric: tabular-nums; color: var(--price-color, #123A6B); }
/* ── Корзина: тач-таргеты степпера (>= 44x44px) ────────────────────────── */
/* ── Степпер строго внутри карточек товаров (.card .steprow) ── */
.card .steprow {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  margin-top: auto;
  padding-top: 8px;
}
.card .steprow .cta {
  flex: 1 1 auto;
  min-width: 0;
  margin-top: 0;
  text-align: center;
}

/* The quantity stepper appears beside the CTA on first add. Keep its label on one
   compact line so the cart state cannot increase the card's height on narrow screens. */
#deliveryGrid .card .steprow .cta.incart,
#grid .card .steprow .cta.incart {
  box-sizing: border-box;
  width: auto;
  min-width: 44px;
  max-width: 100%;
  flex: 1 1 auto;
  height: 44px;
  min-height: 44px;
  max-height: 44px;
  padding: 0 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  line-height: 1;
  font-size: 11px;
  letter-spacing: -0.02em;
}
.card .steprow .step:not([hidden]),
.card .steprow [data-step]:not([hidden]) {
  /* 44×44px — минимум тач-таргета (было 40×40: формально проходило тест с порогом 40,
     но не дотягивало до цели аудита карточек). */
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  flex: 0 0 44px;
  border-radius: var(--radius-sm, 10px);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 700;
  line-height: 1;
  text-align: center;
  cursor: pointer;
  padding: 0;
  border: var(--cta-border, 1.5px solid var(--line));
  background: var(--cart-qty-bg, var(--panel));
  color: var(--cart-qty-color, var(--ink));
  box-shadow: var(--cta-shadow, none);
  user-select: none;
  touch-action: manipulation;
  transition: transform var(--motion-duration-micro, 120ms) var(--motion-ease-standard, cubic-bezier(.2,.8,.2,1)), background-color var(--motion-duration-micro, 120ms) ease;
}
.card .steprow .step:active,
.card .steprow [data-step]:active {
  transform: scale(0.96);
  filter: brightness(0.96);
}


/* Keep the delivery in-cart label compact against the brand CTA shorthand in 160-06. */


@media (min-width: 821px) and (orientation: landscape) and (max-height: 480px) {
  #grid > .card > .cbody,
  #deliveryGrid > .card > .cbody {
    padding-top: 6px;
    gap: 2px;
  }

  /* Keep the full delivery text visible while removing desktop-only reserved slots. */
  #deliveryView #deliveryGrid .card .cbody > h3 {
    display: block;
    block-size: auto;
    min-block-size: 0;
    flex: 0 0 auto;
    font-size: 14px;
    line-height: 1.2;
    -webkit-line-clamp: unset;
    -webkit-box-orient: initial;
    overflow: visible;
  }

  #deliveryView #deliveryGrid .card .cbody .desc {
    font-size: 11px;
    line-height: 1.2;
  }
}

@media (prefers-reduced-motion: reduce) {
  #grid .card,
  #deliveryGrid .card {
    animation: none;
    transition: none;
  }

  .card:hover {
    transform: none;
  }

  .card .media img,
  .card .media .em,
  .card .steprow .step:not([hidden]),
  .card .steprow [data-step]:not([hidden]) {
    transition: none;
  }

  .card .steprow .step:active,
  .card .steprow [data-step]:active {
    transform: none;
    filter: brightness(0.96);
  }
}
