/* ============================================================================
   Фильтр каталога на мобильном — новый дизайн.
   Макет: Figma «Чистовик», фреймы «Фильтры» 21408:72598 и «Бренды» 21408:72662.

   Только ≤767px: на десктопе фильтр остаётся колонкой слева (стили .nd-filter*
   в css/newdesign.css). Обвязку панели строит js/newdesign-filter-mobile.js.

   Размеры из макета: шапка 64, поля 16, чипы значений 39 с рамкой 2px
   rgba(82,82,100,.25) и радиусом 4, выбранный — рамка #a80000 и заливка
   rgba(198,0,0,.05); нижняя панель 12/6, кнопки 48, «Применить» #c60000.
   ========================================================================= */

@media (max-width: 767px) {

    /* ---------- Панель ----------
       Тема кладёт фильтр в свою шторку #mobilefilter (fixed, 320px) и ставит
       самому фильтру инлайновый display:block — отсюда !important. */
    body #mobilefilter {
        width: 100% !important;
        max-width: none !important;
        height: 100% !important;
        top: 0 !important;
        bottom: 0 !important;
        overflow: hidden !important;
        background: #fff;
    }

    /* Пока шторку не открывали, фильтр лежит в левой колонке, и тема его там
       прячет (.bx_filter.bx_filter_vertical{display:none} в media.css). Наши
       правила не должны его возвращать: колонка нулевой высоты, а шапка и
       кнопки панели абсолютные — внизу списка товаров торчал их кусок. */
    body .bx_filter.nd-filter {
        display: none !important;
    }

    /* Раскладка панели — абсолютом, а не флексом: внутри шторки тема ставит
       детям свои position/top, и флекс-колонка складывала шапку, список и
       кнопки друг на друга. */
    body #mobilefilter .bx_filter.nd-filter,
    body #mobilefilter .nd-filter {
        display: block !important;
        position: relative !important;
        width: 100% !important;
        max-width: none !important;
        height: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        background: #fff;
        font-family: 'Nunito Sans', 'Nunito Fallback', Arial, sans-serif;
    }

    /* штатная «крестик»-кнопка шторки не нужна — она есть в нашей шапке */
    body #mobilefilter > .close,
    body #mobilefilter > .mobilefilter_close,
    body #mobilefilter .bx_filter_title {
        display: none !important;
    }

    /* заголовок десктопной колонки заменяет шапка */
    body .nd-filter .nd-filter__title {
        display: none !important;
    }

    /* ---------- Шапка ---------- */
    .nd-fm-head {
        display: flex !important;
        align-items: center;
        position: absolute !important;
        top: 0;
        left: 0;
        right: 0;
        z-index: 3;
        width: 100%;
        margin: 0;
        height: 64px;
        padding: 0 6px;
        border-bottom: 1px solid rgba(82, 82, 100, .15);
        background: #fff;
    }

    .nd-fm-head__back,
    .nd-fm-head__close {
        display: flex;
        align-items: center;
        justify-content: center;
        flex: 0 0 auto;
        width: 44px;
        height: 44px;
        padding: 0;
        border: 0;
        background: none;
        color: #101014;
        cursor: pointer;
    }

    .nd-fm-head__title {
        flex: 1 1 auto;
        min-width: 0;
        text-align: center;
        color: #101014;
        font-size: 18px;
        line-height: 22px;
        font-weight: 700;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* на главном экране стрелка «назад» закрывает панель — оставляем её,
       чтобы шапка не прыгала, когда уходим на экран значения */

    /* ---------- Прокручиваемая середина ---------- */
    .nd-fm-scroll {
        position: absolute !important;
        top: 64px;
        bottom: 128px;
        left: 0;
        right: 0;
        width: 100%;
        margin: 0;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Секция фильтра внутри прокрутки — на всю ширину, без полей темы.
       position:static обязателен: в своей шторке тема кладёт список свойств
       абсолютом с top:64 (под собственную шапку) — у нас шапка своя, и из-за
       этого сверху зияла пустая полоса, а высота списка не считалась. */
    body .nd-fm-scroll .bx_filter_section,
    body .nd-fm-scroll .bx_filter_parameters,
    body .nd-fm-scroll form.smartfilter {
        position: static !important;
        top: auto !important;
        bottom: auto !important;
        width: 100% !important;
        height: auto !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow: visible !important;
    }

    /* ---------- Чипы выбранного ---------- */
    .nd-fm-chips {
        display: none;
    }

    .nd-fm-chips.is-filled {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        padding: 16px;
        border-bottom: 1px solid rgba(82, 82, 100, .15);
    }

    /* Выбранные значения — серые плашки без рамки, а «Сбросить фильтры»
       рядом с ними — белая кнопка с рамкой (макет «Фильтры», Ирина,
       18 августа 2026). */
    .nd-fm-chip {
        display: inline-flex;
        align-items: center;
        gap: 6px;
        height: 28px;
        margin: 0;
        padding: 0 8px;
        background: rgba(82, 82, 100, .1);
        border: 0;
        border-radius: 4px;
        color: #101014;
        font-size: 12px;
        line-height: 16px;
        font-weight: 700;
        cursor: pointer;
    }

    .nd-fm-chip--reset {
        background: #fff;
        border: 1px solid rgba(82, 82, 100, .25);
    }

    /* Значок бренда в чипе — 20×20, как в списке значений (макет 21408:72598). */
    .nd-fm-chip__logo {
        flex: 0 0 20px;
        width: 20px;
        height: 20px;
        object-fit: contain;
    }

    .nd-fm-chip__x {
        width: 12px;
        height: 12px;
        background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='none' stroke='%23101014' stroke-width='1.6' stroke-linecap='round' d='M2 2l8 8M10 2l-8 8'/%3E%3C/svg%3E") center/contain no-repeat;
    }

    /* ---------- Группы ---------- */
    /* Группы: белый фон и одна разделительная линия. Тема подкрашивает
       раскрытые группы серым — на мобильном это лишнее. */
    body .nd-filter .bx_filter_parameters_box,
    body .nd-filter .bx_filter_parameters_box.active,
    body .nd-filter .bx_filter_parameters_box .bx_filter_block {
        background: #fff !important;
        box-shadow: none !important;
    }

    body .nd-filter .bx_filter_parameters_box {
        padding: 16px !important;
        border-bottom: 1px solid rgba(82, 82, 100, .15) !important;
    }

    body .nd-filter .bx_filter_parameters_box_title {
        display: flex;
        align-items: baseline;
        gap: 8px;
        padding: 0 0 12px !important;
        font-size: 16px !important;
        line-height: 19px !important;
        font-weight: 700 !important;
    }

    /* шеврон свёртки на мобильном не нужен — группы раскрыты */
    body .nd-filter .bx_filter_parameters_box_title:after {
        content: none !important;
    }

    body .nd-filter .bx_filter_parameters_box_title > div {
        flex: 1 1 auto;
        min-width: 0;
    }

    .nd-fm-all {
        flex: 0 0 auto;
        color: #e8292c;
        font-size: 14px;
        line-height: 20px;
        font-weight: 400;
        cursor: pointer;
    }

    /* группы на мобильном всегда раскрыты (свёртка — только на десктопе) */
    body .nd-filter .bx_filter_parameters_box:not(.active) > .bx_filter_block {
        display: block;
    }

    body .nd-filter .bx_filter_block.limited_block,
    body .nd-filter .bx_filter_parameters_box_container {
        max-height: none !important;
        height: auto !important;
        padding: 0 !important;
        overflow: visible !important;
    }

    /* ---------- Значения — чипами ---------- */
    body .nd-filter .bx_filter_parameters_box_container {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
    }

    body .nd-filter .bx_filter_param_label,
    body .nd-filter .bx_filter_param_label.nab,
    body .nd-filter .bx_filter_param_label.pal {
        display: inline-flex !important;
        align-items: center;
        margin: 0 !important;
        padding: 6px 8px !important;
        border: 2px solid rgba(82, 82, 100, .25);
        border-radius: 4px;
        background: none;
    }

    body .nd-filter .bx_filter_input_checkbox {
        gap: 6px;
        font-size: 16px;
        line-height: 24px;
    }

    /* Подписи значений на телефоне живут в чипах и берут кегль от чипа. На
       десктопе он задан прямо подписи (newdesign.css, разбор радио-групп), а
       у медиазапроса своего веса нет — повторяем селектор с запасом, иначе
       строка в чипе получала бы десктопный интерлиньяж 20. */
    body .nd-filter .bx_filter_block .bx_filter_param_label .bx_filter_input_checkbox > span {
        line-height: 24px;
    }

    /* квадрат чекбокса в чипе не рисуем — состояние показывает рамка */
    body .nd-filter .bx_filter_input_checkbox:before {
        content: none !important;
    }

    body .nd-filter input[type="checkbox"]:checked + .bx_filter_param_label,
    body .nd-filter input[type="radio"]:checked + .bx_filter_param_label,
    body .nd-filter .bx_filter_param_label.active {
        border-color: #a80000;
        background: rgba(198, 0, 0, .05);
    }

    /* «Лишние» значения тема сама складывает в .hidden_values — на главном
       экране держим их скрытыми, а её ссылку «Показать ещё» заменяет «Все». */
    body .nd-filter .bx_filter_parameters_box:not(.nd-fm-open) .hidden_values {
        display: none !important;
    }

    body .nd-filter .inner_expand_text,
    body .nd-filter .expand_block {
        display: none !important;
    }

    /* ---------- Цена ---------- */
    /* На десктопе «Цену» теперь можно свернуть (newdesign.css), а свёртку тема
       помнит в куке — на телефоне поля цены показываем всегда (19.10.2026). */
    body .nd-filter .price_numbers .bx_filter_block {
        display: block !important;
    }
    body .nd-filter .price_numbers .bx_filter_parameters_box_container {
        display: block;
    }

    body .nd-filter .price_numbers .wrapp_change_inputs {
        display: flex;
        gap: 8px;
    }

    body .nd-filter .price_numbers .bx_filter_parameters_box_container_block {
        flex: 1 1 0;
        min-width: 0;
        margin: 0;
    }

    body .nd-filter .price_numbers input {
        width: 100%;
        height: 48px;
        padding: 0 12px;
        border: 1px solid rgba(82, 82, 100, .25);
        border-radius: 4px;
        background: #fff;
        color: #101014;
        font-size: 16px;
    }

    body .nd-filter .price_numbers .divider,
    body .nd-filter .price_numbers .wrapp_slider {
        display: none !important;
    }

    /* ---------- Экран одного свойства («Все») ---------- */
    .nd-filter.nd-fm-sub .nd-fm-chips,
    .nd-filter.nd-fm-sub .bx_filter_parameters_box:not(.nd-fm-open) {
        display: none !important;
    }

    .nd-filter.nd-fm-sub .bx_filter_parameters_box.nd-fm-open {
        border-bottom: 0 !important;
    }

    /* на этом экране значения — список с чекбоксами, как в макете */
    .nd-filter.nd-fm-sub .nd-fm-open .bx_filter_parameters_box_title {
        display: none;
    }

    .nd-filter.nd-fm-sub .nd-fm-open .bx_filter_parameters_box_container,
    .nd-filter.nd-fm-sub .nd-fm-open .hidden_values {
        display: block !important;
    }

    .nd-filter.nd-fm-sub .nd-fm-open .bx_filter_param_label {
        display: flex !important;
        width: 100%;
        padding: 10px 0 !important;
        border: 0;
        background: none;
    }

    .nd-filter.nd-fm-sub .nd-fm-open .bx_filter_input_checkbox {
        gap: 12px;
    }

    .nd-filter.nd-fm-sub .nd-fm-open .bx_filter_input_checkbox:before {
        content: "" !important;
        flex: 0 0 20px;
        width: 20px;
        height: 20px;
        border: 1.5px solid rgba(82, 82, 100, .35);
        border-radius: 4px;
        background: #fff;
    }

    .nd-filter.nd-fm-sub .nd-fm-open input:checked + .bx_filter_param_label .bx_filter_input_checkbox:before {
        border-color: #c60000;
        background: #c60000 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='10' viewBox='0 0 12 10'%3E%3Cpath d='M1 5l3.2 3.2L11 1.4' fill='none' stroke='%23fff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center no-repeat;
    }

    /* ---------- Нижняя панель ---------- */
    .nd-fm-bar {
        display: flex !important;
        flex-direction: column;
        gap: 8px;
        position: absolute !important;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 3;
        height: 128px;
        width: 100%;
        margin: 0;
        padding: 12px 6px;
        border-top: 1px solid rgba(82, 82, 100, .25);
        background: #fff;
    }

    .nd-fm-bar__reset,
    .nd-fm-bar__apply {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 100%;
        height: 48px;
        border-radius: 4px;
        cursor: pointer;
    }

    .nd-fm-bar__reset {
        border: 2px solid rgba(82, 82, 100, .25);
        background: #fff;
        color: #101014;
        font-size: 12px;
        line-height: 16px;
        font-weight: 700;
    }

    .nd-fm-bar__apply {
        border: 0;
        background: #c60000;
        color: #fff;
        font-size: 16px;
        line-height: 24px;
        font-weight: 700;
    }

    /* штатные кнопки формы на мобильном не показываем — их роль у нижней панели */
    body .nd-filter .bx_filter_button_box {
        display: none !important;
    }

    /* Плашку «Выбрано N — Показать» скрипт темы уносит к изменённой группе;
       в шторке она перекрывала бы список — счётчик и так на нижней панели. */
    body .nd-filter .bx_filter_popup_result#modef,
    body .nd-filter .bx_filter_popup_result#modef[style*="display: inline-block"],
    body .nd-filter .bx_filter_popup_result#modef[style*="display:inline-block"] {
        display: none !important;
    }
}
