/* ES facets — фасеты-фильтры на странице поиска */

.es-facets {
    margin: 16px 0 20px;
    padding: 14px 16px;
    background: #f7f7f7;
    border: 1px solid #e6e6e6;
    border-radius: 6px;
    font-size: 14px;
    line-height: 1.4;
}

.es-facets__group {
    margin-bottom: 10px;
}
.es-facets__group:last-of-type {
    margin-bottom: 0;
}

.es-facets__label {
    display: inline-block;
    font-weight: 600;
    color: #333;
    margin: 4px 8px 6px 0;
    vertical-align: top;
}
.es-facets__label--brand {
    color: #555;
}

.es-facets__row {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 6px 6px;
    vertical-align: top;
    width: calc(100% - 110px);
}

.es-facets__chip {
    display: inline-flex;
    align-items: center;
    padding: 5px 11px;
    background: #fff;
    border: 1px solid #d9d9d9;
    border-radius: 16px;
    color: #333;
    font-size: 13px;
    line-height: 1.2;
    cursor: pointer;
    user-select: none;
    transition: background .12s, border-color .12s, color .12s;
    text-decoration: none;
}
.es-facets__chip:hover {
    background: #fff;
    border-color: #cf0c23;
    color: #cf0c23;
}

.es-facets__chip .es-facets__cb {
    position: absolute;
    opacity: 0;
    pointer-events: none;
    width: 0;
    height: 0;
}

.es-facets__chip-text {
    margin-right: 4px;
}

.es-facets__count {
    color: #999;
    font-size: 12px;
}
.es-facets__chip:hover .es-facets__count {
    color: inherit;
}

/* Состояние "выбрано" */
.es-facets__chip--checked {
    background: #cf0c23;
    border-color: #cf0c23;
    color: #fff;
}
.es-facets__chip--checked:hover {
    background: #b80a1e;
    border-color: #b80a1e;
    color: #fff;
}
.es-facets__chip--checked .es-facets__count {
    color: #fff;
    opacity: 0.85;
}
.es-facets__chip--checked::before {
    content: '✓';
    margin-right: 5px;
    font-weight: bold;
}

/* In-stock бейдж — без чекбокса */
.es-facets__chip--in-stock {
    background: #e8f6e9;
    border-color: #b5dcb6;
    color: #2e7d32;
    cursor: default;
}
.es-facets__chip--in-stock:hover {
    background: #e8f6e9;
    border-color: #b5dcb6;
    color: #2e7d32;
}

/* Сброс */
.es-facets__active-row {
    margin-top: 10px;
    display: flex;
    align-items: center;
    gap: 12px;
}
.es-facets__badge {
    display: inline-block;
    padding: 3px 11px;
    background: #cf0c23;
    color: #fff;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.4;
}
.es-facets__reset {
    display: inline-block;
    color: #888;
    font-size: 13px;
    text-decoration: none;
    border: none;
    background: none;
    cursor: pointer;
    padding: 0;
}
.es-facets__reset:hover {
    color: #cf0c23;
}

/* Пресеты быстрых фильтров (mockup) */
.es-facets__presets {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 6px;
    margin: 0 0 12px 0;
    padding-bottom: 12px;
    border-bottom: 1px dashed #ddd;
}
.es-facets__presets-label {
    font-weight: 600;
    color: #333;
    margin-right: 6px;
    font-size: 13px;
}
.es-facets__preset {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 12px;
    background: #fff;
    border: 1px solid #d0d0d0;
    border-radius: 18px;
    color: #444;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all .12s;
    line-height: 1;
}
.es-facets__preset:hover {
    background: #fff5e1;
    border-color: #f0a020;
    color: #c07a00;
}
.es-facets__preset.es-facets__preset--active {
    background: #f0a020;
    border-color: #f0a020;
    color: #fff;
}
.es-facets__preset-icon {
    font-size: 14px;
    line-height: 1;
}

/* Кнопка «Применить» — только в <noscript> fallback (без JS) */
.es-facets__apply {
    display: inline-block;
    margin-top: 12px;
    padding: 10px 22px;
    background: #cf0c23;
    color: #fff;
    border: none;
    border-radius: 4px;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    width: 100%;
}
.es-facets__apply:hover {
    background: #b80a1e;
}

/* Лоадинг */
.es-loading {
    transition: opacity .15s;
}

/* === МОБАЙЛ === */
@media (max-width: 768px) {
    .es-facets {
        padding: 12px 12px;
    }

    .es-facets__label {
        display: block;
        margin: 0 0 6px 0;
    }

    .es-facets__row {
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
        width: 100%;
        padding-bottom: 4px;
        gap: 6px;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        -webkit-mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 24px), transparent 100%);
                mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 24px), transparent 100%);
    }
    .es-facets__row::-webkit-scrollbar {
        display: none;
    }
    .es-facets__chip {
        flex: 0 0 auto;
        white-space: nowrap;
    }
}

/* ============================================================== */
/* ============ Desktop sidebar layout (≥ 901px) =============== */
/* ============================================================== */

/* Наш sidebar рендерится в слот sidebar_left темы (aside.sidebar-l).
   Layout делает main.html через content-cols / flex-align-r. */

@media (min-width: 901px) {
    /* Sticky card при скролле. 90px = 70px fixed header + 20px gap.
       margin-top: 76px — выравниваем верх сайдбара с началом грида товаров
       (breadcrumbs ~28px + h1 ~38px + gap). margin-right: 24px — отступ до грида. */
    aside.sidebar-l.es-sidebar {
        position: sticky;
        top: 90px;
        max-height: calc(100vh - 110px);
        align-self: flex-start;
        margin-right: 24px;
        margin-top: 100px;
        /* Скрыт до JS-выравнивания (alignSidebarToGrid добавит .es-aligned).
           Иначе на reload видно flash неправильной позиции и затем скачок. */
        visibility: hidden;
        background: #fff;
        border: 1px solid #e8eaed;
        border-radius: 8px;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
        padding: 6px 4px 6px 18px;
        overflow: hidden;
    }
    aside.sidebar-l.es-sidebar.es-aligned {
        visibility: visible;
    }

    /* Форма — внутренний скролл чтобы padding карточки оставался снаружи.
       Явно обнуляем border/bg/padding — наследуются от горизонтального .es-facets базового стиля. */
    .es-facets--sidebar {
        margin: 0;
        padding: 0 14px 0 0;
        background: transparent;
        border: none;
        border-radius: 0;
        box-shadow: none;
        max-height: calc(100vh - 130px);
        overflow-y: auto;
        scrollbar-width: thin;
        scrollbar-color: #cfcfcf transparent;
    }
    .es-facets--sidebar::-webkit-scrollbar { width: 6px; }
    .es-facets--sidebar::-webkit-scrollbar-track { background: transparent; }
    .es-facets--sidebar::-webkit-scrollbar-thumb { background: #dcdcdc; border-radius: 3px; }
    .es-facets--sidebar::-webkit-scrollbar-thumb:hover { background: #bbb; }

    .es-facets--sidebar .es-facets__presets {
        margin: 10px 0 14px;
        padding-bottom: 14px;
        border-bottom: 1px solid #eef0f2;
    }

    /* Group (accordion) */
    .es-sidebar__group {
        border-bottom: 1px solid #eef0f2;
        padding: 14px 0;
        margin: 0;
    }
    .es-sidebar__group:first-child {
        padding-top: 12px;
    }
    .es-sidebar__group:last-of-type {
        border-bottom: none;
        padding-bottom: 12px;
    }

    .es-sidebar__title {
        margin: 0 0 12px;
        font-size: 14px;
        font-weight: 700;
        color: #1a1a1a;
        cursor: pointer;
        user-select: none;
        display: flex;
        align-items: center;
        gap: 8px;
        line-height: 1.25;
        letter-spacing: 0.01em;
    }
    .es-sidebar__title > span:first-child {
        flex: 1;
        min-width: 0;
    }
    .es-sidebar__title:hover {
        color: #cf0c23;
    }
    .es-sidebar__badge {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-width: 20px;
        height: 18px;
        padding: 0 7px;
        background: #cf0c23;
        color: #fff;
        font-size: 10px;
        font-weight: 700;
        border-radius: 10px;
        letter-spacing: 0.02em;
    }
    .es-sidebar__caret {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 18px;
        height: 18px;
        font-size: 14px;
        line-height: 1;
        color: #9aa0a6;
        transform: rotate(180deg);
        transition: transform 0.2s ease;
        flex-shrink: 0;
    }
    .es-sidebar__group--collapsed .es-sidebar__caret {
        transform: rotate(0);
    }
    .es-sidebar__group--collapsed .es-sidebar__title {
        margin-bottom: 0;
    }
    .es-sidebar__group--collapsed .es-sidebar__items {
        display: none;
    }

    .es-sidebar__items {
        display: flex;
        flex-direction: column;
        gap: 0;
    }
    .es-sidebar__cb {
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 7px 6px 7px 2px;
        margin: 0 -6px 0 -2px;
        border-radius: 4px;
        cursor: pointer;
        color: #444;
        font-size: 13px;
        line-height: 1.35;
        transition: background 0.1s;
    }
    .es-sidebar__cb:hover {
        background: #fafafa;
    }
    .es-sidebar__cb:hover .es-sidebar__cb-text {
        color: #cf0c23;
    }
    .es-sidebar__cb input[type=checkbox] {
        flex-shrink: 0;
        width: 15px;
        height: 15px;
        margin: 0;
        accent-color: #cf0c23;
        cursor: pointer;
    }
    .es-sidebar__cb-text {
        flex: 1;
        min-width: 0;
        word-break: break-word;
    }
    .es-sidebar__cb-count {
        flex-shrink: 0;
        color: #9aa0a6;
        font-size: 11px;
        font-variant-numeric: tabular-nums;
        padding-left: 4px;
    }
    .es-sidebar__cb--checked {
        background: #fff5f6;
    }
    .es-sidebar__cb--checked .es-sidebar__cb-text {
        font-weight: 600;
        color: #1a1a1a;
    }

    /* Скрытые «лишние» пункты (после N=5) — показываем по клику «+ ещё N» */
    .es-sidebar__cb--more {
        display: none;
    }
    .es-sidebar__items--expanded .es-sidebar__cb--more {
        display: flex;
    }

    .es-sidebar__more-btn {
        display: inline-block;
        margin: 8px 0 0 2px;
        padding: 4px 0;
        background: none;
        border: none;
        color: #2a5885;
        font-size: 12px;
        font-weight: 500;
        cursor: pointer;
        text-align: left;
    }
    .es-sidebar__more-btn:hover {
        color: #cf0c23;
        text-decoration: underline;
    }

    .es-sidebar__reset {
        display: block;
        margin-top: 14px;
        padding: 10px 14px;
        color: #cf0c23;
        font-size: 12px;
        font-weight: 600;
        text-decoration: none;
        text-align: center;
        border: 1px solid #f0c9cf;
        border-radius: 6px;
        background: #fff;
        transition: all 0.15s;
    }
    .es-sidebar__reset:hover {
        background: #cf0c23;
        color: #fff;
        border-color: #cf0c23;
    }
    .es-sidebar__reset--disabled {
        color: #b8b8b8 !important;
        border-color: #e6e6e6 !important;
        background: #fafafa !important;
        pointer-events: none;
        cursor: default;
    }

    /* «Найдено: N товаров» — компактная строка над чипами */
    .es-search-head {
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin: 0 0 14px;
        padding: 0 2px;
    }
    .es-search-head__found {
        font-size: 15px;
        color: #444;
    }
    .es-search-head__found b {
        font-weight: 700;
        color: #1a1a1a;
    }

    /* Active chips row над гридом */
    .es-active-chips {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        margin: 0 0 20px;
        align-items: center;
        padding: 12px 14px;
        background: #fafbfc;
        border: 1px solid #eef0f2;
        border-radius: 8px;
    }
    .es-chip-active {
        display: inline-flex;
        align-items: center;
        gap: 8px;
        padding: 6px 8px 6px 14px;
        background: #cf0c23;
        color: #fff;
        border-radius: 16px;
        font-size: 12px;
        font-weight: 600;
        cursor: pointer;
        user-select: none;
        box-shadow: 0 1px 2px rgba(207, 12, 35, 0.2);
        transition: background 0.15s, transform 0.1s;
    }
    .es-chip-active:hover {
        background: #a80819;
        transform: translateY(-1px);
    }
    .es-chip-active__text {
        line-height: 1.3;
    }
    .es-chip-active__x {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 18px;
        height: 18px;
        border-radius: 50%;
        background: rgba(255, 255, 255, 0.28);
        font-size: 13px;
        line-height: 1;
        font-weight: 400;
    }
    .es-chip-reset-all {
        font-size: 12px;
        font-weight: 500;
        color: #6b7280;
        text-decoration: none;
        padding: 6px 10px;
        margin-left: auto;
        transition: color 0.15s;
    }
    .es-chip-reset-all:hover {
        color: #cf0c23;
        text-decoration: underline;
    }

    /* В sidebar-режиме старая горизонтальная форма скрыта */
    .es-facets--sidebar .es-facets__group,
    .es-facets--sidebar .es-facets__active-row {
        display: none;
    }
    .es-sb-grip,
    .es-sb-head,
    .es-sb-footer,
    .es-sb-toggle,
    .es-sb-backdrop {
        display: none !important;
    }
}

/* ============================================================
   Mobile bottom sheet (<= 900px)
   Sidebar превращается в шторку снизу: position:fixed, 88vh,
   slide-up анимация, тёмный backdrop, плавающая кнопка «Фильтры [N]».
   ============================================================ */
@media (max-width: 900px) {
    aside.sidebar-l.es-sidebar {
        position: fixed !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        top: auto !important;
        margin: 0 !important;
        padding: 0 !important;
        max-height: 88vh !important;
        width: 100% !important;
        background: #fff;
        border-radius: 22px 22px 0 0;
        box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.18);
        z-index: 1000;
        display: flex;
        flex-direction: column;
        transform: translateY(100%);
        transition: transform 0.3s cubic-bezier(0.22, 0.61, 0.36, 1);
        overflow: hidden;
        border: none;
    }
    aside.sidebar-l.es-sidebar.es-sheet-open {
        transform: translateY(0);
    }
    /* Mastershop theme скрывает детей .sidebar-l на мобильном правилом
       `.sidebar-l > *{display:none}`. Перебиваем с более высокой специфичностью. */
    aside.sidebar-l.es-sidebar > .es-sb-grip { display: block; }
    aside.sidebar-l.es-sidebar > .es-sb-head { display: flex; }
    aside.sidebar-l.es-sidebar > form.es-facets--sidebar { display: block; }
    aside.sidebar-l.es-sidebar > .es-sb-footer { display: flex; }

    .es-sb-grip {
        display: block;
        width: 40px;
        height: 4px;
        background: #d7d9de;
        border-radius: 2px;
        margin: 10px auto 4px;
        flex-shrink: 0;
    }

    .es-sb-head {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 6px 18px 14px;
        border-bottom: 1px solid #eef0f2;
        flex-shrink: 0;
    }
    .es-sb-head__title {
        margin: 0;
        font-size: 17px;
        font-weight: 700;
        color: #1a1a1a;
    }
    .es-sb-close {
        background: #f3f4f6;
        border: none;
        width: 32px;
        height: 32px;
        border-radius: 50%;
        font-size: 20px;
        line-height: 1;
        cursor: pointer;
        color: #555;
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    .es-sb-close:active { background: #e8e9ec; }

    .es-facets--sidebar {
        flex: 1 1 auto;
        overflow-y: auto;
        margin: 0;
        padding: 4px 18px 16px;
        background: transparent;
        border: none;
        border-radius: 0;
        box-shadow: none;
        max-height: none;
        -webkit-overflow-scrolling: touch;
    }

    .es-sidebar__group {
        border-bottom: 1px solid #eef0f2;
        padding: 14px 0;
    }
    .es-sidebar__group:last-of-type { border-bottom: none; }
    .es-sidebar__title {
        display: flex;
        align-items: center;
        font-size: 15px;
        font-weight: 600;
        cursor: pointer;
        user-select: none;
        margin: 0;
    }
    .es-sidebar__title > span:first-child { flex: 1; order: 1; }
    .es-sidebar__badge {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-width: 22px;
        height: 22px;
        padding: 0 7px;
        background: #cf0c23;
        color: #fff;
        border-radius: 11px;
        font-size: 12px;
        font-weight: 700;
        margin-right: 8px;
        order: 0;
    }
    .es-sidebar__caret {
        font-size: 12px;
        color: #888;
        transition: transform 0.2s;
        order: 2;
    }
    .es-sidebar__group--collapsed .es-sidebar__caret { transform: rotate(180deg); }
    .es-sidebar__group--collapsed .es-sidebar__items { display: none; }

    .es-sidebar__items {
        margin-top: 10px;
        display: flex;
        flex-direction: column;
        gap: 0;
    }
    .es-sidebar__cb {
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 11px 0;
        font-size: 14px;
        cursor: pointer;
    }
    .es-sidebar__cb input[type=checkbox] {
        width: 20px;
        height: 20px;
        accent-color: #cf0c23;
        flex-shrink: 0;
    }
    .es-sidebar__cb-text { flex: 1; color: #1a1a1a; }
    .es-sidebar__cb--checked .es-sidebar__cb-text { font-weight: 600; }
    .es-sidebar__cb-count { color: #9aa0a6; font-size: 12px; }
    .es-sidebar__cb--more { display: none; }
    .es-sidebar__items--expanded .es-sidebar__cb--more { display: flex; }
    .es-sidebar__more-btn {
        background: none;
        border: none;
        color: #2a5885;
        font-size: 13px;
        font-weight: 500;
        padding: 10px 0;
        cursor: pointer;
        text-align: left;
    }

    .es-sidebar__reset { display: none !important; }

    .es-sb-footer {
        display: flex;
        padding: 12px 14px calc(14px + env(safe-area-inset-bottom));
        border-top: 1px solid #eef0f2;
        background: #fff;
        flex-shrink: 0;
        box-sizing: border-box;
    }
    /* Специфичность должна победить override `aside.sidebar-l.es-sidebar > .es-sb-footer{display:flex}` */
    aside.sidebar-l.es-sidebar > .es-sb-footer.es-sb-footer--hidden { display: none; }

    .es-sb-reset-btn {
        flex: 1 1 auto;
        padding: 13px 16px;
        background: #f3f4f6;
        color: #555;
        border: none;
        border-radius: 10px;
        font-size: 14px;
        font-weight: 600;
        cursor: pointer;
        line-height: 1.2;
    }
    .es-sb-reset-btn:active { background: #e8e9ec; }

    .es-sb-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        position: fixed;
        left: 50%;
        transform: translateX(-50%);
        bottom: 0;
        padding: 11px 22px;
        background: #cf0c23;
        color: #fff;
        border: none;
        border-radius: 22px 22px 4px 4px;
        font-size: 14px;
        font-weight: 700;
        box-shadow: 0 -2px 12px rgba(207, 12, 35, 0.25);
        cursor: pointer;
        z-index: 900;
        white-space: nowrap;
        width: auto;
    }
    .es-sb-toggle:active { background: #b00a1e; }
    .es-sb-toggle__icon { font-size: 17px; }
    .es-sb-toggle__badge {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-width: 22px;
        height: 22px;
        padding: 0 7px;
        background: #fff;
        color: #cf0c23;
        border-radius: 11px;
        font-size: 12px;
        font-weight: 800;
    }
    body.es-sheet-open .es-sb-toggle { display: none; }

    .es-sb-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.25s;
    }
    .es-sb-backdrop.es-sheet-open {
        opacity: 1;
        pointer-events: auto;
    }

    body.es-sheet-open { overflow: hidden; }

    /* Прячем Jivo-виджет пока открыта шторка фильтров — иначе кнопка чата
       (z-index ~2147483600) оказывается поверх листа. */
    body.es-sheet-open jdiv,
    body.es-sheet-open jvlabel { display: none !important; }

    .es-active-chips {
        display: none !important;
    }
    .es-chip-active {
        display: inline-flex;
        align-items: center;
        gap: 6px;
        padding: 5px 6px 5px 10px;
        background: #cf0c23;
        color: #fff;
        border-radius: 14px;
        font-size: 12px;
        cursor: pointer;
    }
    .es-chip-active__x {
        display: inline-flex;
        width: 16px;
        height: 16px;
        border-radius: 50%;
        background: rgba(255, 255, 255, 0.25);
        align-items: center;
        justify-content: center;
        font-size: 10px;
    }
    .es-chip-reset-all {
        font-size: 12px;
        color: #888;
        padding: 5px 8px;
        text-decoration: none;
    }
}


/* Auto-extracted chip (из query parser). Визуально отличаем что этот фильтр
   был авто-применён сервером из текста запроса, чтобы user понимал что клик ×
   не просто уберёт checkbox, а модифицирует query-parser behavior. */
.es-chip-active--auto {
    background: #fbe9ec !important;
    color: #cf0c23 !important;
    border: 1px dashed #cf0c23;
}
.es-chip-active--auto .es-chip-active__x {
    opacity: 0.8;
}
