/* [fix-all v6] F5.63 */
/* ─────────────────────────────────────────────────────────────────────────
   F5.63 BRAND-CENTER: 1fr auto 1fr → brand всегда по центру topbar.
   mbonus+profile — прямые дети .topbar (обёртки нет). */

@media (min-width: 821px) {
  .topbar {
  height: auto;
  min-height: 96px;
}
  }
/* [fix-all v6] END F5.63 */

/* Оптимизация медиа-зоны карточек доставки и кофейни */
.card .media img{
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
  cursor: zoom-in;
  transition: transform 0.3s ease;
}


/* ── F6.5: Стабилизация геометрии карточек для CLS = 0 ── */
.card .media {
  height: 180px;
  min-height: 180px;
  aspect-ratio: 16 / 10;
  contain: layout size;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(18, 58, 107, 0.04);
}
.skeleton-card .media {
  height: 180px;
  min-height: 180px;
  aspect-ratio: 16 / 10;
}

/* ── CLS-FIX: Базовый мобильный макет .wrap и .panel (защита от FOUC на мобильных) ── */
@media (max-width: 820px) {
  /* First paint mirrors the one-column mobile wrapper: the category rail is
     moved into the menu view, so no 64px desktop sidebar column is reserved. */
  html body div.wrap {
    width: 100%;
    min-width: 0;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto;
    gap: 10px;
    padding: 10px 12px 28px;
    align-items: start;
  }
  html body div.wrap > section {
    grid-column: 1;
    grid-row: auto;
    width: 100%;
    min-width: 0;
  }
  .panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 120;
    width: min(340px, calc(100vw - 24px));
    max-height: none;
    border-radius: 22px 0 0 22px;
    transform: translateX(105%);
    transition: transform 0.35s cubic-bezier(0.2, 1, 0.3, 1);
    padding-top: calc(env(safe-area-inset-top, 0px) + 6px);
  }
  .panel.open {
    transform: none;
  }
}

/* Compact landscape uses the same one-column wrapper as mobile; the rail is fixed. */
@media (min-width: 821px) and (orientation: landscape) and (max-height: 480px) {
  html body div.wrap {
    width: 100%;
    min-width: 0;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto;
    gap: 10px;
    padding: 10px 12px 28px;
    align-items: start;
  }
  html body div.wrap > section {
    grid-column: 1;
    grid-row: auto;
    width: 100%;
    min-width: 0;
  }
  html body div.wrap > .panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 120;
    width: min(400px, 100%);
    max-height: none;
    border-radius: 22px 0 0 22px;
    transform: translateX(105%);
    transition: transform 0.35s cubic-bezier(0.2, 1, 0.3, 1);
  }
  html body div.wrap > .panel.open { transform: none; }
}

/* ── CLS-AND-HEADER-SEARCH-STABILIZATION ── */

/* 1. Мобильная шапка (<= 690px): фиксированная геометрия без скачков при смене бренда */
@media (max-width: 690px) {
  header.topbar {
    position: sticky;
    top: 0;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    padding-top: calc(env(safe-area-inset-top, 0px) + 4px);
    height: calc(60px + env(safe-area-inset-top, 0px));
    min-height: calc(60px + env(safe-area-inset-top, 0px));
    padding-left: 12px;
    padding-right: 12px;
    padding-bottom: 4px;
    box-sizing: border-box;
  }
  body.is-cashier header.topbar,
  body.is-admin header.topbar,
  header.topbar:has(#modeSeg:not([hidden])) {
    height: auto;
  }

  header.topbar div.venueWrap {
    position: relative;
    transform: none;
    flex: 0 0 auto;
    order: 1;
    z-index: 50;
  }
  header.topbar button#venueToggle.venueToggle {
    height: 38px;
    padding: 0 10px;
    border-radius: 999px;
    font-size: 15px;
    gap: 4px;
    background: #FFFFFF;
    border: 1.5px solid var(--line);
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  header.topbar button#venueToggle.venueToggle span.vt-label {
    display: none;
  }
  header.topbar button#venueToggle.venueToggle span.vt-arrow {
    display: inline-block;
    font-size: 11px;
    margin-left: 2px;
  }

  header.topbar .venueWrap #brandSeg {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    box-sizing: border-box;
    display: none;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    width: max-content;
    min-width: min(180px, calc(100vw - 24px));
    max-width: min(232px, calc(100vw - 24px));
    max-height: calc(100dvh - env(safe-area-inset-top, 0px) - 72px);
    padding: 7px;
    overflow: hidden;
    border-radius: 16px;
    background: var(--venue-menu-bg, #FFFFFF);
    border: var(--venue-menu-border, 1px solid rgba(18, 58, 107, 0.12));
    box-shadow: var(--venue-menu-shadow, 0 12px 28px rgba(16, 20, 24, 0.16));
    z-index: 1000;
    transform-origin: top left;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(-5px) scale(.985);
    transition: opacity 180ms cubic-bezier(.2, .8, .2, 1),
                transform 180ms cubic-bezier(.2, .8, .2, 1),
                visibility 0s linear 180ms;
  }
  header.topbar .venueWrap #brandSeg.open {
    display: flex;
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0) scale(1);
    transition-delay: 0s;
  }
  header.topbar .venueWrap #brandSeg > button {
    box-sizing: border-box;
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: flex-start;
    gap: 9px;
    width: auto;
    max-width: 100%;
    min-width: 0;
    align-self: stretch;
    min-height: 44px;
    padding: 10px 12px;
    border: 1px solid transparent;
    border-radius: 10px;
    background: transparent;
    color: var(--venue-option-color, #30465C);
    font: 650 13px/1.2 var(--venue-option-font, "Golos Text"), system-ui, sans-serif;
    text-align: left;
    white-space: nowrap;
    transition: background-color 150ms ease, border-color 150ms ease, color 150ms ease, transform 150ms ease;
  }
  header.topbar .venueWrap #brandSeg > button:hover {
    background: var(--venue-option-hover-bg, #F3F7FC);
  }
  header.topbar .venueWrap #brandSeg > button.on {
    border: var(--venue-option-active-border, 1px solid rgba(18, 58, 107, 0.16));
    background: var(--venue-option-active-bg, #EAF2FB);
    color: var(--venue-option-active-color, #123A6B);
    box-shadow: var(--venue-option-active-shadow, none);
    border-radius: 9px;
    font-weight: 750;
  }
  @media (prefers-reduced-motion: reduce) {
    header.topbar .venueWrap #brandSeg,
    header.topbar .venueWrap #brandSeg > button {
      animation: none;
      transition: none;
      transform: none;
    }
  }

  header.topbar button#profileTopBtn.ava {
    position: static;
    transform: none;
    margin: 0;
    order: 3;
    z-index: 2;
  }

  header.topbar div#headerBrand.brand {
    grid-column: 2;
    grid-row: 1;
    justify-self: center;
    position: static;
    transform: none;
    margin: 0;
    width: min(196px, 60vw);
    min-width: min(196px, 60vw);
    max-width: min(196px, 60vw);
    min-height: 44px;
    height: auto;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 8px;
    z-index: 1;
    overflow: visible;
  }


  header.topbar div#headerBrand.brand div.mark {
    width: var(--mark-w, 42px);
    height: var(--mark-h, 42px);
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  header.topbar div#headerBrand.brand div.mark img,
  header.topbar div#headerBrand.brand div.mark svg {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
  }

  header.topbar div#headerBrand.brand .brand-text,
  header.topbar div#headerBrand.brand .title,
  header.topbar div#headerBrand.brand span:not(.mark),
  header.topbar div#headerBrand.brand div:not(.mark) {
    display: flex;
    flex-direction: column;
    justify-content: center;
    font-size: 13.5px;
    font-weight: 700;
    line-height: 1.15;
    color: var(--ink);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  header.topbar #modeSeg {
    order: 10;
    flex: 1 1 100%;
    width: 100%;
    margin-top: 6px;
    position: relative;
    z-index: 5;
  }

  
  html body div.wrap > nav.rail .re,
  html body div.wrap > nav#deliveryRail .re {
    font-size: 24px;
    margin-bottom: 2px;
  }
  .skeleton-card {
  min-height: 380px;
  contain: layout size;
}
/* На мобильных (<= 690px) шторка корзины строго прижата к низу (top: auto, bottom: 0) */
.cartPanel {
  position: fixed;
  top: auto;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  max-width: 100%;
  height: 90dvh;
  max-height: 90dvh;
  border-radius: 22px 22px 0 0;
  transform: translateY(105%);
  z-index: 330;
}
.cartPanel.open {
  transform: translateY(0);
}

/* Вынос шторки профиля из потока документа ТОЛЬКО на мобильных */
@media (max-width: 820px) {
  .panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(340px, calc(100vw - 24px));
    transform: translateX(105%);
    transition: transform 0.35s cubic-bezier(0.2, 1, 0.3, 1);
    z-index: 120;
  }
  .panel.open {
    transform: none;
  }
}
}

/* Profile drawer: preserve off-canvas/open transforms but remove spatial travel for reduced motion. */
@media (prefers-reduced-motion: reduce) {
  html body div.wrap > aside#panel.panel,
  html body .panel {
    transition: none;
  }
}
