/*
 * Мобильная версия обычного сайта (телефоны до 767 px).
 * Приложение в Telegram (body.app-mode) этот файл не загружает — у него свой mini-app.css.
 */

/* Заголовок панели фильтров нужен только в открытой панели на телефоне. */
.catalog-filters-sheet__foot,
.catalog-filters-sheet__head {
    display: none;
}

@media (max-width: 767px) {
    /* iPhone увеличивает страницу при фокусе в поле со шрифтом меньше 16 px — отсюда «уезжает». */
    input:not([type=checkbox]):not([type=radio]):not([type=range]),
    select,
    textarea {
        font-size: 16px !important;
    }

    /* ——— Шапка: компактная, верхняя строка переехала в меню ——— */
    .header-top {
        display: none;
    }

    .header-main-inner {
        min-height: 60px;
        padding-top: 8px;
        padding-bottom: 8px;
    }

    .header-nav-toggler {
        position: relative;
        width: 40px;
        height: 40px;
        padding: 11px 10px;
        gap: 4px;
        border-radius: 12px;
    }

    .header-nav-toggler__bar {
        transition: transform 0.2s ease, opacity 0.2s ease;
    }

    .header-nav-toggler.is-open .header-nav-toggler__bar:nth-child(1) {
        transform: translateY(6px) rotate(45deg);
    }

    .header-nav-toggler.is-open .header-nav-toggler__bar:nth-child(2) {
        opacity: 0;
    }

    .header-nav-toggler.is-open .header-nav-toggler__bar:nth-child(3) {
        transform: translateY(-6px) rotate(-45deg);
    }

    .header-action-btn,
    .header-cart-tasty {
        width: 40px;
        height: 40px;
    }

    /* ——— Меню-бургер: панель под шапкой поверх страницы, с нормальными отступами ——— */
    .header-mobile-nav {
        position: absolute;
        left: 0;
        right: 0;
        top: 100%;
        z-index: 1000;
        max-height: calc(100vh - 60px);
        max-height: calc(100dvh - 60px);
        overflow-y: auto;
        overscroll-behavior: contain;
        background: #fff;
        border-top: 1px solid #ececec;
        box-shadow: 0 18px 40px rgba(0, 0, 0, 0.12);
        border-radius: 0 0 20px 20px;
    }

    .header-mobile-nav[hidden] {
        display: none;
    }

    .header-mobile-nav__inner {
        gap: 16px;
        padding: 8px 20px 20px;
    }

    .header-mobile-nav__group {
        display: flex;
        flex-direction: column;
    }

    .header-mobile-nav__link {
        justify-content: space-between;
        min-height: 52px;
        padding: 0 4px;
        font-size: 17px;
        font-weight: 600;
        border-bottom: 1px solid #f0f0f0;
    }

    .header-mobile-nav__link::after {
        content: "";
        width: 8px;
        height: 8px;
        margin-left: auto;
        border-top: 2px solid #c4c4c4;
        border-right: 2px solid #c4c4c4;
        transform: rotate(45deg);
    }

    .header-mobile-nav__count {
        margin-left: 8px;
        margin-right: 12px;
        min-width: 22px;
        height: 22px;
        padding: 0 7px;
        border-radius: 11px;
        background: #000;
        color: #fff;
        font-size: 12px;
        font-weight: 700;
        line-height: 22px;
        text-align: center;
    }

    .header-mobile-nav__account {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .header-mobile-nav__logout {
        margin: 0;
    }

    .header-mobile-nav__button {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 100%;
        min-height: 48px;
        padding: 0 12px;
        border: none;
        border-radius: 14px;
        background: #000;
        color: #fff;
        font-family: inherit;
        font-size: 15px;
        font-weight: 600;
        line-height: 1.2;
        text-decoration: none;
        cursor: pointer;
    }

    .header-mobile-nav__button--light {
        background: #f2f2f2;
        color: #000;
    }

    .header-mobile-nav__contacts {
        display: flex;
        flex-direction: column;
        gap: 6px;
        padding: 14px 16px;
        border-radius: 16px;
        background: #f6f6f6;
    }

    .header-mobile-nav__phone {
        font-size: 18px;
        font-weight: 700;
        color: #000;
        text-decoration: none;
    }

    .header-mobile-nav__telegram {
        font-size: 15px;
        font-weight: 600;
        color: #2a7ab8;
        text-decoration: none;
    }

    .header-mobile-nav__note {
        margin: 4px 0 0;
        font-size: 13px;
        line-height: 1.5;
        color: #6b6b6b;
    }

    /* ——— Каталог ——— */
    .catalog-tasty {
        padding: 12px 0 40px;
    }

    .catalog-tasty__title {
        font-size: 28px;
        margin: 4px 0 14px;
    }

    /* Дубль плиток и переключателя «Все / Популярное / Новинки». */
    .catalog-tasty__tags {
        display: none;
    }

    .catalog-tasty__tiles {
        gap: 8px;
        margin: 0 -20px 12px;
        padding: 2px 20px 6px;
        scroll-padding: 0 20px;
        scrollbar-width: none;
    }

    .catalog-tasty__tiles::-webkit-scrollbar {
        display: none;
    }

    .catalog-tile {
        width: 136px;
        height: 80px;
        border-radius: 14px;
        box-shadow: none;
    }

    .catalog-tile:hover,
    .catalog-tile:hover .catalog-tile__bg {
        transform: none;
    }

    .catalog-tile__label {
        grid-template-rows: auto auto;
        gap: 2px;
        padding: 9px 11px;
        font-size: 12px;
        line-height: 1.25;
    }

    .catalog-tile__title {
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
        margin: 0;
        line-height: 1.25;
    }

    .catalog-mobile-filter-toggle:not([hidden]) {
        display: flex;
        align-items: center;
        gap: 10px;
        width: 100%;
        min-height: 46px;
        margin: 0 0 10px;
        padding: 0 16px;
        border: none;
        border-radius: 14px;
        background: #fff;
        color: #000;
        font-family: inherit;
        font-size: 15px;
        font-weight: 600;
        line-height: 1.2;
        text-align: left;
        cursor: pointer;
    }

    /* Сразу свёрнуто (класс js ставится в <head>) — страница не прыгает после загрузки скрипта. */
    html.js .catalog-tasty__sidebar {
        display: none;
    }

    /* Фильтры — панель снизу поверх каталога. */
    .catalog-filters-backdrop:not([hidden]) {
        position: fixed;
        inset: 0;
        z-index: 1090;
        background: rgba(0, 0, 0, 0.45);
    }

    html.js [data-filters-open] .catalog-tasty__sidebar {
        position: fixed;
        top: auto;
        left: 0;
        right: 0;
        bottom: 0;
        height: auto;
        min-height: 0;
        z-index: 1100;
        display: block;
        max-height: 85vh;
        max-height: 85dvh;
        overflow-y: auto;
        overscroll-behavior: contain;
        padding: 0 16px calc(16px + env(safe-area-inset-bottom, 0px));
        border-radius: 22px 22px 0 0;
        background: #f2f2f2;
        box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.18);
        animation: catalog-sheet-in 0.22s ease-out;
    }

    html.js [data-filters-open] .catalog-tasty__sidebar-sticky {
        display: flex;
        flex-direction: column;
        gap: 10px;
    }

    html.js [data-filters-open] .catalog-sidebar-card--promo {
        display: none;
    }

    html.js [data-filters-open] .catalog-filters-sheet__head {
        position: sticky;
        top: 0;
        z-index: 2;
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin: 0 -16px 10px;
        padding: 16px 16px 10px;
        background: #f2f2f2;
    }

    .catalog-filters-sheet__title {
        margin: 0;
        font-size: 20px;
        font-weight: 700;
    }

    .catalog-filters-sheet__close {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 40px;
        height: 40px;
        padding: 0;
        border: none;
        border-radius: 50%;
        background: #fff;
        color: #000;
        cursor: pointer;
    }

    html.js [data-filters-open] .catalog-filters-sheet__foot {
        position: sticky;
        bottom: calc(-16px - env(safe-area-inset-bottom, 0px));
        z-index: 2;
        display: block;
        margin: 10px -16px calc(-16px - env(safe-area-inset-bottom, 0px));
        padding: 10px 16px calc(12px + env(safe-area-inset-bottom, 0px));
        background: #f2f2f2;
        box-shadow: 0 -8px 16px rgba(0, 0, 0, 0.06);
    }

    .catalog-filters-sheet__apply {
        display: block;
        width: 100%;
        min-height: 50px;
        padding: 0 20px;
        border: none;
        border-radius: 14px;
        background: #000;
        color: #fff;
        font-family: inherit;
        font-size: 16px;
        font-weight: 600;
        cursor: pointer;
    }

    body.catalog-filters-locked {
        overflow: hidden;
    }

    /* Сегмент «Все / Популярное / Новинки» и сортировка — одной строкой. */
    .catalog-toolbar {
        flex-direction: row;
        align-items: center;
        gap: 8px;
        margin: 0 0 12px;
    }

    .catalog-segment {
        flex: 1 1 auto;
        flex-wrap: nowrap;
        width: auto;
        min-width: 0;
        padding: 3px;
        border-radius: 12px;
    }

    .catalog-segment__item {
        flex: 1 1 auto;
        min-height: 36px;
        padding: 6px 6px;
        border-radius: 9px;
        font-size: 13px;
        letter-spacing: 0;
        text-transform: none;
    }

    .catalog-sort-form,
    .catalog-sort {
        flex: 0 0 auto;
        width: auto;
    }

    .catalog-sort__select {
        width: 128px;
        min-width: 0;
        height: 42px;
        padding: 0 28px 0 12px;
        border-radius: 12px;
        background-position: right 10px center;
        text-overflow: ellipsis;
    }

    .catalog-tasty__category-title {
        font-size: 22px;
    }
}

/* ——— Товары в две колонки (телефоны) ——— */
@media (max-width: 640px) {
    .catalog-tasty__grid,
    .favorites-tasty__grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
    }

    .catalog-tasty__grid .product-card-v2,
    .favorites-tasty__grid .product-card-v2 {
        border: none;
        border-radius: 16px;
        box-shadow: none;
        animation: none;
        opacity: 1;
        transition: none;
    }

    .catalog-tasty__grid .product-card-v2:hover,
    .favorites-tasty__grid .product-card-v2:hover {
        transform: none;
        box-shadow: none;
    }

    .catalog-tasty__grid .product-image-v2,
    .favorites-tasty__grid .product-image-v2 {
        order: -1;
        margin: 0;
        padding: 10px 10px 0;
        /* Высоту задаёт квадратная рамка фото внутри; рамка 4:3 срезала низ фото. */
        aspect-ratio: auto;
    }

    /* Фиксированная рамка фото: карточки не прыгают, пока грузятся картинки. */
    .catalog-tasty__grid .product-card-carousel__viewport,
    .favorites-tasty__grid .product-card-carousel__viewport {
        aspect-ratio: 1 / 1;
        height: auto;
        border-radius: 12px;
    }

    .catalog-tasty__grid .product-card-carousel__slide img,
    .favorites-tasty__grid .product-card-carousel__slide img {
        width: 100%;
        height: 100%;
        padding: 6px;
        object-fit: contain;
    }

    .catalog-tasty__grid .product-card-carousel__btn,
    .catalog-tasty__grid .product-card-carousel__counter,
    .favorites-tasty__grid .product-card-carousel__btn,
    .favorites-tasty__grid .product-card-carousel__counter {
        display: none;
    }

    .catalog-tasty__grid .product-badges-v2,
    .favorites-tasty__grid .product-badges-v2 {
        top: 14px;
        left: 14px;
        gap: 4px;
    }

    .catalog-tasty__grid .badge-v2,
    .favorites-tasty__grid .badge-v2 {
        padding: 3px 7px;
        border-radius: 7px;
        font-size: 10px;
    }

    .catalog-tasty__grid .product-card-header,
    .favorites-tasty__grid .product-card-header {
        margin: 0;
        padding: 8px 12px 0;
    }

    .catalog-tasty__grid .product-card-label,
    .catalog-tasty__grid .product-card-right,
    .catalog-tasty__grid .product-desc-v2,
    .catalog-tasty__grid .product-packaging-v2,
    .catalog-tasty__grid .product-card-spacer,
    .catalog-tasty__grid .product-card-actions,
    .favorites-tasty__grid .product-card-label,
    .favorites-tasty__grid .product-card-right,
    .favorites-tasty__grid .product-desc-v2,
    .favorites-tasty__grid .product-packaging-v2,
    .favorites-tasty__grid .product-card-spacer,
    .favorites-tasty__grid .product-card-actions {
        display: none !important;
    }

    .catalog-tasty__grid .product-card-title-block,
    .favorites-tasty__grid .product-card-title-block {
        min-height: 0;
    }

    .catalog-tasty__grid .product-short-name,
    .favorites-tasty__grid .product-short-name {
        margin: 0;
        font-size: 14px;
        font-weight: 700;
        line-height: 1.25;
        letter-spacing: 0;
        text-transform: none;
    }

    .catalog-tasty__grid .product-short-name__link,
    .favorites-tasty__grid .product-short-name__link {
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
        color: #000;
    }

    .catalog-tasty__grid .product-type,
    .favorites-tasty__grid .product-type {
        display: block;
        margin-top: 2px;
        font-size: 12px;
        font-weight: 500;
        line-height: 1.3;
        color: #7a7a7a;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .catalog-tasty__grid .product-card-middle,
    .favorites-tasty__grid .product-card-middle {
        margin: 0;
        padding: 6px 12px 0;
    }

    .catalog-tasty__grid .product-variants-row,
    .favorites-tasty__grid .product-variants-row {
        margin: 0;
        padding: 0;
    }

    .catalog-tasty__grid .product-variants-v2,
    .favorites-tasty__grid .product-variants-v2 {
        flex-wrap: wrap;
        gap: 4px;
    }

    .catalog-tasty__grid .variant-btn-v2,
    .favorites-tasty__grid .variant-btn-v2 {
        min-height: 26px;
        padding: 4px 9px;
        border-radius: 8px;
        font-size: 12px;
        font-weight: 600;
        color: #7a7a7a;
        background: transparent;
        box-shadow: inset 0 0 0 1px #e6e6e6;
    }

    .catalog-tasty__grid .variant-btn-v2.active,
    .favorites-tasty__grid .variant-btn-v2.active {
        color: #000;
        background: #efefef;
        box-shadow: none;
    }

    .catalog-tasty__grid .product-footer-v2,
    .favorites-tasty__grid .product-footer-v2 {
        padding: 10px 12px 12px;
    }

    .catalog-tasty__grid .product-footer-v2 .product-price-pill,
    .favorites-tasty__grid .product-footer-v2 .product-price-pill {
        flex: 1 1 auto;
        width: 100%;
        justify-content: space-between;
        min-height: 40px;
        padding: 8px 10px 8px 12px;
        border-radius: 12px;
    }

    .catalog-tasty__grid .product-price-pill .current-price-v2,
    .favorites-tasty__grid .product-price-pill .current-price-v2 {
        font-size: 15px;
    }

    .favorites-tasty__grid .product-card-remove {
        top: 14px;
        right: 14px;
        opacity: 1;
    }
}

/* Самые узкие телефоны (iPhone SE и т.п.). */
@media (max-width: 380px) {
    .catalog-toolbar {
        flex-wrap: wrap;
    }

    .catalog-segment,
    .catalog-sort-form,
    .catalog-sort,
    .catalog-sort__select {
        flex: 1 1 100%;
        width: 100%;
    }

    .header-main-inner {
        gap: 2px;
    }

    .header-action-btn,
    .header-cart-tasty,
    .header-nav-toggler {
        width: 36px;
        height: 36px;
    }

    .header-nav-toggler {
        padding: 10px 9px;
    }
}

@keyframes catalog-sheet-in {
    from {
        transform: translateY(24px);
        opacity: 0;
    }
    to {
        transform: none;
        opacity: 1;
    }
}

@media (prefers-reduced-motion: reduce) {
    html.js [data-filters-open] .catalog-tasty__sidebar {
        animation: none;
    }
}
