/* =========================================================
   Фильтр каталога (components/filter.php) — новый дизайн
   Подключать ПОСЛЕ css/style.css
   Десктоп (от 993px): одна белая плашка с тенью — фильтры + сортировка
   Мобила (до 992px): «Выберите город» + «Все фильтры» со счётчиком
   ========================================================= */

/* ===== Общие элементы ===== */
.filter__item-opener {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0;
}

.filter .filter__item .filter__item-opener .filter__item-icon {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    margin: 0 8px 0 0;
    stroke: #e0408a;
    fill: none;
    transform: none;
}

.sort-by__label {
    font-size: 12px;
    line-height: 1.2;
    color: #8a8a8a;
}

.catalog__filter-count {
    display: none;
}

.city-pick {
    display: none;
}

/* Шапка шторки и значения в строках — только для мобилы */
.filter__sheet-head,
.filter__item-value {
    display: none;
}

/* Выбранные фильтры (чипсы) */
.filter__selected-item {
    min-width: 0;
    min-height: 32px;
    padding: 2px 6px 2px 14px;
    background-color: #fdeef5;
    color: #c2185b;
    border-radius: 20px;
    font-size: 13px;
}

.filter__selected-item a {
    color: inherit;
}

.filter__selected-remove::before,
.filter__selected-remove::after {
    width: 12px;
    background-color: #c2185b;
}

.filter__selected-reset {
    color: #e0408a;
    font-weight: 600;
}

/* =========================================================
   ДЕСКТОП
   ========================================================= */
@media (min-width: 993px) {

    .catalog__head {
        display: none;
    }

    .filter__elements {
        margin-top: 24px;
        padding: 14px 16px;
        display: flex;
        flex-wrap: nowrap;
        align-items: center;
        gap: 10px 6px;
        background: #fff;
        border-radius: 20px;
        box-shadow: 0 6px 24px rgba(110, 32, 78, 0.10);
    }

    .filter__item {
        flex: 0 1 auto;
        min-width: 0;
    }

    .filter__item:not(:last-child) {
        margin-right: 0;
    }

    .filter__item-opener {
        height: 44px;
        padding: 0 10px;
        width: auto;
        background: #fff;
        border: 1px solid #f0e4ea;
        border-radius: 14px;
        font-size: 14px;
        font-weight: 500;
        color: #2a2a2a;
        white-space: nowrap;
    }

    .filter__item-opener svg {
        margin-left: 8px;
        stroke: #555;
    }

    .filter__item-opener:hover,
    .filter__item.opened .filter__item-opener {
        background-color: #fdeef5;
        border-color: #e0408a;
        color: #c2185b;
    }

    .filter__item-opener:hover svg,
    .filter__item.opened .filter__item-opener svg {
        stroke: #c2185b;
    }

    /* Выпадающая панель */
    .filter__item-content {
        top: calc(100% + 12px);
        padding: 20px 22px;
        border-radius: 18px;
        box-shadow: 0 10px 30px rgba(110, 32, 78, 0.14);
    }

    /* Сортировка справа через разделитель */
    .filter__sort {
        flex-shrink: 0;
        margin-left: auto;
        padding-left: 16px;
        border-left: 1px solid #f0e4ea;
        display: flex;
        flex-direction: column;
        justify-content: center;
        min-height: 40px;
    }

    .filter__sort .sort-by__opener {
        padding: 0;
        font-size: 14px;
        font-weight: 600;
        line-height: 1.3;
        color: #2a2a2a;
    }

    .filter__sort .sort-by__opener svg {
        margin-left: 10px;
        stroke: #2a2a2a;
    }

    .filter__sort .sort-by__list {
        top: calc(100% + 10px);
        width: 240px;
        background: #fff;
        box-shadow: 0 10px 30px rgba(110, 32, 78, 0.14);
        z-index: 5;
    }

    .filter__selected {
        margin-top: 12px;
    }
}

/* Узкий десктоп — если не влезает, переносим на вторую строку */
@media (min-width: 993px) and (max-width: 1199px) {
    .filter__elements {
        flex-wrap: wrap;
    }
}

/* =========================================================
   МОБИЛА / ПЛАНШЕТ
   ========================================================= */
@media (max-width: 992px) {

    .catalog__head {
        display: block;
    }

    .catalog__selections {
        margin: 0;
        display: flex;
        align-items: stretch;
        gap: 10px;
        width: 100%;
    }

    /* Выбор города */
    .city-pick {
        position: relative;
        flex: 1.25 1 0;
        min-width: 0;
        display: block;
    }

    .city-pick__btn {
        display: flex;
        align-items: center;
        gap: 8px;
        width: 100%;
        height: 54px;
        padding: 0 12px;
        background: #fff;
        border: 1px solid #f0e4ea;
        border-radius: 14px;
        box-shadow: 0 4px 16px rgba(110, 32, 78, 0.08);
        font-family: inherit;
        text-align: left;
        cursor: pointer;
    }

    .city-pick.is-open .city-pick__btn {
        border-color: #e0408a;
    }

    .city-pick__pin {
        flex-shrink: 0;
        color: #e0408a;
    }

    .city-pick__text {
        display: flex;
        flex-direction: column;
        min-width: 0;
        flex: 1;
    }

    .city-pick__label {
        font-size: 11px;
        line-height: 1.2;
        color: #8a8a8a;
    }

    .city-pick__name {
        font-size: 15px;
        font-weight: 600;
        line-height: 1.3;
        color: #2a2a2a;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .city-pick__arrow {
        flex-shrink: 0;
        color: #555;
        transition: transform 0.2s;
    }

    .city-pick.is-open .city-pick__arrow {
        transform: rotate(180deg);
        color: #e0408a;
    }

    /* Выпадающий список — открывается вниз */
    .city-pick__dropdown {
        position: absolute;
        top: calc(100% + 8px);
        left: 0;
        z-index: 60;
        width: min(calc(100vw - 20px), 420px);
        padding: 8px;
        background: #fff;
        border-radius: 16px;
        box-shadow: 0 14px 36px rgba(110, 32, 78, 0.18);
        opacity: 0;
        visibility: hidden;
        transform: translateY(-6px);
        transition: opacity 0.2s, transform 0.2s, visibility 0.2s;
    }

    .city-pick.is-open .city-pick__dropdown {
        opacity: 1;
        visibility: visible;
        transform: translateY(0);
    }

    .city-pick__search {
        display: flex;
        align-items: center;
        gap: 8px;
        margin-bottom: 6px;
        padding: 0 12px;
        height: 42px;
        background: #f6f2f4;
        border-radius: 12px;
        color: #9a9a9a;
    }

    .city-pick__search input {
        flex: 1;
        min-width: 0;
        border: none;
        background: transparent;
        outline: none;
        font-family: inherit;
        font-size: 16px;
        color: #2a2a2a;
    }

    .city-pick__list {
        max-height: min(55vh, 360px);
        margin: 0;
        padding: 0;
        list-style: none;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .city-pick__option {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 10px;
        padding: 12px 12px;
        border-radius: 10px;
        color: #2a2a2a;
        font-size: 15px;
        text-decoration: none;
    }

    .city-pick__option:hover,
    .city-pick__option:active {
        background: #fdeef5;
        color: #c2185b;
        text-decoration: none;
    }

    .city-pick__option.is-active {
        background: #fdeef5;
        color: #c2185b;
        font-weight: 600;
    }

    .city-pick__option svg {
        flex-shrink: 0;
        color: #e0408a;
    }

    /* Кнопка «Все фильтры» */
    .catalog__filter-btn {
        position: relative;
        flex: 1 1 0;
        min-width: 0;
        max-width: none;
        margin: 0;
        height: 54px;
        padding: 0 14px;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        border: none;
        border-radius: 14px;
        background: linear-gradient(135deg, #e0408a 0%, #9B1B6E 100%);
        color: #fff;
        font-size: 15px;
        font-weight: 600;
        box-shadow: 0 6px 16px rgba(155, 27, 110, 0.25);
    }

    .catalog__filter-btn svg {
        margin: 0;
        width: 20px;
        height: 20px;
        fill: none;
        stroke: #fff;
    }

    .catalog__filter-btn:hover,
    .catalog__filter-btn:focus,
    .catalog__filter-btn:active,
    .catalog__filter-btn.active {
        background: linear-gradient(135deg, #e0408a 0%, #9B1B6E 100%);
    }

    .catalog__filter-count.is-visible {
        position: absolute;
        top: -7px;
        right: -5px;
        display: flex;
        align-items: center;
        justify-content: center;
        min-width: 22px;
        height: 22px;
        padding: 0 6px;
        border-radius: 11px;
        background: #e0408a;
        border: 2px solid #fff;
        color: #fff;
        font-size: 12px;
        font-weight: 700;
        line-height: 1;
    }

    /* Раскрывающаяся панель фильтров */
    .filter {
        margin-top: 12px;
    }

    .filter__elements {
        padding: 6px 16px 14px;
        background: #fff;
        border-radius: 18px;
        box-shadow: 0 6px 24px rgba(110, 32, 78, 0.10);
    }

    .filter__item {
        border-bottom: 1px solid #f4ecf0;
    }

    .filter__item-opener {
        justify-content: flex-start;
        width: 100%;
        padding: 14px 0;
        font-size: 15px;
        color: #2a2a2a;
    }

    .filter__item-opener svg {
        margin-left: auto;
        stroke: #555;
    }

    .filter__item-opener:hover,
    .filter__item.opened .filter__item-opener {
        color: #c2185b;
    }

    /* Сортировка внутри панели */
    .filter__sort {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 10px;
        padding: 14px 0 4px;
    }

    .filter__sort .sort-by__label {
        font-size: 15px;
        font-weight: 500;
        color: #2a2a2a;
    }

    .filter__sort .sort-by__opener {
        font-size: 14px;
        font-weight: 600;
        color: #c2185b;
    }

    .filter__sort .sort-by__list {
        width: 240px;
        background: #fff;
        box-shadow: 0 10px 30px rgba(110, 32, 78, 0.14);
        z-index: 5;
    }

    .filter__selected {
        margin-top: 4px;
    }

    /* ===== Полноэкранная шторка фильтров ===== */
    body.filter-sheet-open {
        overflow: hidden;
    }

    body.filter-sheet-open .filter__elements {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 10000;
        margin: 0;
        padding: 0 18px 110px;
        width: 100%;
        border-radius: 0;
        box-shadow: none;
        background: #fff;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .filter__sheet-head {
        position: sticky;
        top: 0;
        z-index: 3;
        display: flex;
        align-items: center;
        gap: 12px;
        margin: 0 -18px;
        padding: 16px 18px 14px;
        background: #fff;
        border-bottom: 1px solid #f4ecf0;
    }

    .filter__sheet-title {
        flex: 1;
        font-size: 22px;
        font-weight: 700;
        color: #2a1020;
    }

    .filter__sheet-reset {
        padding: 6px 2px;
        border: none;
        background: none;
        color: #e0408a;
        font-family: inherit;
        font-size: 15px;
        font-weight: 600;
        cursor: pointer;
    }

    .filter__sheet-close {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 36px;
        height: 36px;
        padding: 0;
        border: none;
        border-radius: 50%;
        background: #f4f0f2;
        color: #2a2a2a;
        cursor: pointer;
    }

    /* Строка фильтра: иконка — название — значение — стрелка */
    body.filter-sheet-open .filter__item-opener {
        padding: 16px 0;
        font-size: 15px;
        font-weight: 600;
    }

    body.filter-sheet-open .filter__item-value {
        display: block;
        margin-left: auto;
        padding-left: 10px;
        max-width: 50%;
        font-size: 13px;
        font-weight: 400;
        color: #9a9a9a;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    body.filter-sheet-open .filter__item-value.is-active {
        color: #c2185b;
        font-weight: 600;
    }

    body.filter-sheet-open .filter__item-opener .filter__item-value + svg {
        margin-left: 8px;
    }

    body.filter-sheet-open .filter__item-content {
        padding: 2px 0 14px;
    }

    body.filter-sheet-open .filter__item-inpgroup {
        gap: 10px 14px;
    }

    /* Кнопка «Показать анкеты» внизу на всю ширину */
    body.filter-sheet-open .filter__btns {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 4;
        margin: 0;
        padding: 12px 18px calc(12px + env(safe-area-inset-bottom));
        display: flex !important;
        background: #fff;
        box-shadow: 0 -4px 18px rgba(0, 0, 0, 0.06);
    }

    body.filter-sheet-open .filter__btns .filter__apply {
        display: flex !important;
        align-items: center;
        justify-content: center;
        width: 100%;
        height: 54px;
        margin: 0;
        border: none;
        border-radius: 16px;
        background: linear-gradient(135deg, #e0408a 0%, #9B1B6E 100%);
        color: #fff;
        font-size: 16px;
        font-weight: 700;
        opacity: 1 !important;
    }

    body.filter-sheet-open .filter__btns .filter__reset {
        display: none !important;
    }

    body.filter-sheet-open .filter__sort {
        border-bottom: none;
    }
}

@media (max-width: 576px) {
    .city-pick__btn,
    .catalog__filter-btn {
        height: 50px;
    }

    .city-pick__name {
        font-size: 14px;
    }

    .catalog__filter-btn {
        font-size: 14px;
    }
}