/* ── Спринт 5: Компактные 2-строчные плашки опций пиццы (.opts button) без переноса на 3-ю строку ── */
#deliveryGrid .card .opts button,
#deliveryGrid .card .opts label.opt-btn,
#deliveryGrid .card .opts .opt-btn {
  padding: 7px 9px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
}
#deliveryGrid .card .opts .opt-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px;
  width: 100%;
  white-space: nowrap;
}
#deliveryGrid .card .opts .opt-size {
  font-size: 12.5px;
  font-weight: 800;
  white-space: nowrap;
}
#deliveryGrid .card .opts .opt-crust {
  font-size: 11px;
  font-weight: 600;
  opacity: 0.82;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* The option button is split into two columns inside each pizza card.
   Keep the size label intrinsic and give the crust label the remaining measured width. */
@media (min-width: 821px) {
  #deliveryGrid .card .opts label.opt-btn,
  #deliveryGrid .card .opts .opt-btn {
    padding-inline: 6px;
  }
  #deliveryGrid .card .opts .opt-row.opt-top {
    display: grid;
    grid-template-columns: max-content minmax(0, 1fr);
    align-items: baseline;
    column-gap: 2px;
    min-width: 0;
  }
  #deliveryGrid .card .opts .opt-size {
    min-width: 0;
    font-size: 11px;
    line-height: 1.15;
  }
  #deliveryGrid .card .opts .opt-crust {
    min-width: 0;
    justify-self: end;
    font-size: 9.5px;
    line-height: 1.15;
    overflow: hidden;
    text-overflow: clip;
    text-align: right;
  }
  /* Delivery pizza compositions can be longer on desktop; render all cards eagerly so
     variable content cannot jump against the old fixed 502px lazy-card reservation. */
  #deliveryGrid .card:nth-child(n+5) {
    content-visibility: visible;
    contain-intrinsic-block-size: auto;
  }
}
#deliveryGrid .card .opts .opt-weight {
  font-size: 10.5px;
  opacity: 0.7;
  white-space: nowrap;
}
#deliveryGrid .card .opts .opt-price {
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

/* Desktop delivery cards: fixed content slots keep semantic rows aligned across a grid row.
   Pizza uses title (2 lines) + full description (4 lines) before its options.
   Rolls use title (2 lines) + up to 3 ingredient-chip rows before weight/price.
   Fixed flex-basis is intentional: min-height alone lets short content pull later rows upward. */
@media (min-width: 821px) {
  #deliveryGrid .card .cbody:has(> .opts) > h3,
  #deliveryGrid .card .cbody:has(> .single-meta) > h3 {
    block-size: 2.6em;
    min-block-size: 2.6em;
    flex: 0 0 2.6em;
    box-sizing: border-box;
  }

  #deliveryGrid .card .cbody:has(> .opts) > .desc {
    block-size: 5.8em;
    min-block-size: 5.8em;
    flex: 0 0 5.8em;
    box-sizing: border-box;
    overflow: visible;
  }

  #deliveryGrid .card .cbody > .desc {
    display: -webkit-box;
    block-size: 37px;
    min-block-size: 37px;
    flex: 0 0 37px;
    box-sizing: border-box;
    line-height: 1.45;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  #deliveryGrid .card .cbody:has(> .single-meta) > .comp {
    block-size: 100px;
    min-block-size: 100px;
    flex: 0 0 100px;
    box-sizing: border-box;
    align-content: flex-start;
    overflow: visible;
  }

  #deliveryGrid .card .cbody:has(> .single-meta) > .single-meta {
    min-block-size: 30px;
    box-sizing: border-box;
    align-self: stretch;
  }
}
/* ── F5.81: ЕДИНЫЙ КАНОНИЧЕСКИЙ КАСКАД СЕТКИ, РЕЙЛА, ШАПКИ И МЕНЮ (БЕЗ ДУБЛЕЙ) ── */

/* 1. Отключаем лишний 56px отступ в Telegram Mini App (WebView уже ниже нативной шапки TG) */
body.in-tg header.topbar,
body.in-tg .topbar {
  min-height: calc(60px + env(safe-area-inset-top, 0px));
  padding-top: calc(env(safe-area-inset-top, 0px) + 4px);
}

/* 2. Единая стабильная сетка карточек для Кофейни (#grid) и Доставки (#deliveryGrid) */
#grid,
#deliveryGrid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
  align-items: stretch;
  /* Hydration replaces the SSR card; don't let scroll anchoring move the first viewport. */
  overflow-anchor: none;
}
@media (min-width: 520px) and (max-width: 820px) {
  #grid,
  #deliveryGrid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
  }
}
@media (min-width: 821px) and (max-width: 1180px) {
  #grid,
  #deliveryGrid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
  }
}
@media (min-width: 1181px) {
  #grid,
  #deliveryGrid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
  }
}
@media (min-width: 1600px) {
  #grid,
  #deliveryGrid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}
#grid .card,
#deliveryGrid .card {
  min-width: 0;
  width: 100%;
  box-sizing: border-box;
}

/* 3. Единый каркас .wrap и центрированный без обрезания шапкой рейл (#rail / #deliveryRail) */
@media (min-width: 821px) and (max-width: 1180px) and (min-height: 481px) {
  html body div.wrap,
  .wrap {
    display: grid;
    grid-template-columns: 80px minmax(0, 1fr);
    gap: 10px;
    padding: 10px 0 32px;
    align-items: start;
  }
}
html body div.wrap > .rail,
html body div.wrap > #rail,
html body div.wrap > #deliveryRail {
  grid-column: 1;
  position:relative;
  top:auto;
  transform: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-self:start;
  width:80px;
  min-width: 80px;
  height: fit-content;
  max-height: calc(100dvh - var(--topbar-h, 60px) - env(safe-area-inset-top, 0px) - 24px);
  margin: 0;
  padding: 4px;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: none;
  z-index: 10;
}
@media (min-width: 1181px) {
  html body div.wrap > .rail,
  html body div.wrap > #rail,
  html body div.wrap > #deliveryRail {
    width: 80px;
    min-width: 80px;
  }
}
/* Тап-таргеты карточек доставки ≥ 44px по высоте (проверка pwa-responsive.spec.js: 40px минимум) */
#deliveryGrid .card .cta[data-add],
#deliveryGrid .card button.cta {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
#deliveryGrid .card .opts button,
#deliveryGrid .card .opts .opt-btn {
  min-height: 44px;
}


/* Compact landscape has horizontal category navigation and a full-width catalog. */
@media (min-width: 821px) and (orientation: landscape) and (max-height: 480px) {
  /* Compact landscape is a touch viewport: reserve a single compact topbar row. */
  html body header.topbar {
    box-sizing: border-box;
    height: 56px;
    min-height: 56px;
    max-height: 56px;
    padding: 0 12px;
    gap: 6px;
    flex-wrap: nowrap;
  }
  html body header.topbar .venueToggle {
    height: 40px;
    min-height: 40px;
    max-height: 40px;
    font-size: 13px;
  }
  html body header.topbar .brand .mark {
    height: 40px;
    min-height: 40px;
    max-height: 40px;
    width: auto;
    max-width: min(34vw, 180px);
  }
  html body header.topbar #profileTopBtn {
    width: 40px;
    min-width: 40px;
    height: 40px;
    min-height: 40px;
  }
  html body header.topbar .brand b,
  html body header.topbar #brandTitle {
    font-size: 15px;
    line-height: 1;
  }
  html body .ticker {
    height: 28px;
    min-height: 28px;
  }
  html body div.wrap,
  .wrap {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto;
    gap: 6px;
    padding: 4px 12px 24px;
  }
  html body div.wrap > section {
    grid-column: 1;
    grid-row: auto;
    width: 100%;
    min-width: 0;
  }

  /* A short landscape viewport cannot spend two rows on the menu header:
     put title and search in one row so the first product title clears the bottom rail. */
  html[data-brand] body :is(#menuView, #deliveryView) .menu-head {
    box-sizing: border-box;
    height: auto;
    min-height: 0;
    max-height: none;
    margin-bottom: 4px;
    padding: 4px 14px;
  }

  html[data-brand] body :is(#menuView, #deliveryView) .menu-head .mh-top {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    gap: 12px;
    width: 100%;
    min-width: 0;
    height: 44px;
    min-height: 44px;
    max-height: 44px;
  }

  html[data-brand] body :is(#menuView, #deliveryView) .menu-head .mh-top > div:first-child {
    flex: 0 0 auto;
    width: auto;
    min-width: 0;
  }

  /* Coffee title normally fills an entire flex row; in landscape it must become intrinsic. */
  html body #menuView .menu-head .mh-top h1 {
    flex: 0 0 auto;
    width: auto;
    max-width: none;
    white-space: nowrap;
  }

  html[data-brand] body :is(#menuView, #deliveryView) .menu-head .mh-top > .mh-right {
    flex: 1 1 0%;
    width: auto;
    min-width: 0;
    max-width: none;
    flex-wrap: nowrap;
    margin-left: 0;
  }

  html[data-brand] body :is(#menuView, #deliveryView) .menu-head .mh-top > .mh-right > .search {
    flex: 1 1 0%;
    min-width: 0;
  }

  html body #deliveryView #deliverySubFilterViewport {
    box-sizing:border-box;
    height:44px;
    min-height:44px;
    max-height:44px;
  }

  /* Short landscape has room for a compact image row and the complete first title above the fixed capsule. */
  html body #menuView #grid > .card > .media,
  html body #deliveryView #deliveryGrid > .card > .media {
    box-sizing: border-box;
    flex: 0 0 20px;
    width: 100%;
    height: 20px;
    min-height: 20px;
    max-height: 20px;
    aspect-ratio: auto;
  }

  /* Two readable columns keep long delivery names on one line in a short viewport. */
  html body #grid,
  html body #deliveryGrid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }

  html body #grid .card .media .em,
  html body #deliveryGrid .card .media .em {
    font-size: 20px;
    line-height: 1;
  }
}

/* Desktop category navigation: one rail surface, fixed icon chips, no tab pills. */
@media (min-width: 821px) and (min-height: 481px) {
  html body div.wrap > #rail,
  html body div.wrap > #deliveryRail {
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    align-self: start;
    justify-self: stretch;
    width: 100%;
    min-width: 0;
    height: fit-content;
    min-height: 0;
    max-height: calc(100dvh - var(--topbar-h, 60px) - env(safe-area-inset-top, 0px) - 24px);
    gap: 6px;
    padding: 4px;
    border: 0;
    border-radius: 16px;
    background: var(--category-rail-bg, var(--panel, #fff));
    box-shadow: none;
    overflow: visible;
  }

  html body div.wrap > #rail button,
  html body div.wrap > #deliveryRail button {
    box-sizing: border-box;
    position: relative;
    display: flex;
    flex: 0 0 auto;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 4px;
    width: 100%;
    min-width: 0;
    max-width: none;
    height: auto;
    min-height: 64px;
    max-height: none;
    padding: 6px 2px 7px;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    transition: color 180ms ease, transform 180ms ease;
    color: var(--category-tab-color, var(--ink, #20252b));
    font-family: var(--category-label-font, "Golos Text", system-ui, sans-serif);
    font-size: var(--category-label-size, 10px);
    font-weight: var(--category-label-weight, 700);
    line-height: 1.15;
    text-align: center;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  html body div.wrap > #rail button.on,
  html body div.wrap > #deliveryRail button.on {
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    color: var(--category-tab-active-color, var(--ink, #20252b));
    font-weight: 800;
    transform: none;
  }

  html body div.wrap > #rail .re,
  html body div.wrap > #deliveryRail .re {
    display: grid;
    flex: 0 0 var(--category-icon-size, 32px);
    place-items: center;
    width: var(--category-icon-size, 32px);
    min-width: var(--category-icon-size, 32px);
    height: var(--category-icon-size, 32px);
    border: 0;
    border-radius: var(--category-icon-radius, 50%);
    background: transparent;
    color: var(--category-icon-color, currentColor);
    font-size: 23px;
    line-height: 1;
    transition: background-color 180ms ease, color 180ms ease;
  }

  html body div.wrap > #rail button.on .re,
  html body div.wrap > #deliveryRail button.on .re {
    border: var(--category-icon-active-border, 0);
    border-radius: var(--category-icon-radius, 50%);
    background: var(--category-icon-active-bg, transparent);
    color: var(--category-icon-active-color, currentColor);
  }

  /* Beat the legacy active-tab typography in 160-01 without !important. */
  html body div.wrap > #rail button.on[aria-pressed="true"],
  html body div.wrap > #deliveryRail button.on[aria-pressed="true"] {
    font-size: var(--category-label-size, 10px);
    font-family: var(--category-label-font, "Golos Text", system-ui, sans-serif);
    font-weight: var(--category-label-active-weight, 800);
  }

  html body div.wrap > #rail button.on::after,
  html body div.wrap > #deliveryRail button.on::after {
    content: "";
    position: absolute;
    left: 50%;
    bottom: 2px;
    width: 28px;
    height: 3px;
    border-radius: 2px;
    background: var(--category-indicator-color, currentColor);
    transform: translateX(-50%);
  }

  html body div.wrap > #rail button:active,
  html body div.wrap > #deliveryRail button:active {
    transform: none;
  }

  html body div.wrap > #rail button:focus-visible,
  html body div.wrap > #deliveryRail button:focus-visible {
    outline: 2px solid var(--focus, currentColor);
    outline-offset: 2px;
    z-index: 1;
  }

  @media (hover: hover) {
    html body div.wrap > #rail button:not(.on):hover,
    html body div.wrap > #deliveryRail button:not(.on):hover {
      color: var(--category-tab-active-color, currentColor);
    }
  }
}

/* Horizontal floating capsules do not use the desktop active underline. */
@media (max-width: 820px), (min-width: 821px) and (orientation: landscape) and (max-height: 480px) {
  html body div.wrap > #rail button.on::after,
  html body div.wrap > #deliveryRail button.on::after {
    content: none;
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  html body div.wrap > #rail button,
  html body div.wrap > #deliveryRail button,
  html body div.wrap > #rail .re,
  html body div.wrap > #deliveryRail .re {
    transition: none;
  }
}

/* Mobile wrapper geometry is owned by the early fallback in 160-04. */
