/* ============================================================
   Блок фильтров каталога.
   Токены и классы — те же, что в фирменной дизайн-системе
   (profile.php, profile_settings.php, orders.php, add_review.php):
   :root переменные --brand / --page-bg / --surface / --text / ...,
   поля .profile-field / .profile-input / .profile-field-hint / .is-error,
   кнопки .profile-btn / .profile-btn-secondary / .profile-spinner,
   плашки .profile-msg, чипы .profile-chip.
   Определения .profile-* продублированы внутри .cf-panel, потому что
   блок подключается и на страницы, где эти классы не объявлены
   (shop.php, catalog.php); значения полностью совпадают с системой.
   ============================================================ */
.cf-panel{
    /* Токены дизайн-системы (со страховкой, если страница их не задала) */
    --cf-brand:        var(--brand,        #7e22ce);
    --cf-brand-dark:   var(--brand-dark,   #6f1eb5);
    --cf-brand-darker: var(--brand-darker, #5e1a9a);
    --cf-tint:         var(--brand-tint,   #f5edfb);
    --cf-tint-2:       var(--brand-tint-2, #ecdef8);
    --cf-ring:         var(--brand-ring,   rgba(126,34,206,.20));
    --cf-surface:      var(--surface,      #ffffff);
    --cf-bg:           var(--page-bg,      #f4f4f8);
    --cf-text:         var(--text,         #2f2f2f);
    --cf-muted:        var(--muted,        #666666);
    --cf-faint:        var(--faint,        #aaaaaa);
    --cf-border:       var(--border,       #eeeeee);
    --cf-border-hover: var(--border-hover, #dcdcdf);
    --cf-radius:       var(--radius,       16px);
    --cf-radius-sm:    var(--radius-sm,    12px);
    --cf-shadow:       var(--shadow-card,  0 12px 32px rgba(0,0,0,.06));

    position: relative;
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-width: 0;
    padding: 0 16px 18px;      /* верхний отступ — у «прилипающей» шапки .cf-top */
    background: var(--cf-surface);
    border: 1px solid var(--cf-border);
    border-radius: var(--cf-radius);
    box-shadow: var(--cf-shadow);
    color: var(--cf-text);
    font-family: 'Segoe UI', Arial, sans-serif;
    font-size: 14px;
    line-height: 1.4;
    -webkit-font-smoothing: antialiased;
}

.cf-panel *,
.cf-panel *::before,
.cf-panel *::after{ box-sizing: border-box; }

/* Ссылки — только фирменного цвета, без браузерного синего и visited */
.cf-panel a:link,
.cf-panel a:visited{ color: var(--cf-brand); text-decoration: none; }
.cf-panel a:hover,
.cf-panel a:active{ color: var(--cf-brand-dark); }
.cf-panel a:focus-visible,
.cf-panel button:focus-visible,
.cf-panel summary:focus-visible,
.cf-panel input:focus-visible,
.cf-panel select:focus-visible{
    outline: 2px solid transparent;
    outline-offset: 2px;
    box-shadow: 0 0 0 4px var(--cf-ring);
    border-radius: var(--cf-radius-sm);
}

.cf-panel svg{ display: block; }

/* ===== Шапка блока (счётчик) + строка выбранных фильтров =====
   Разделы фильтров по умолчанию свёрнуты, поэтому применённые условия
   должны быть видны иначе — строкой чипов и счётчиком. Эти две части
   собраны в .cf-top и «прилипают» к верху области прокрутки, чтобы чипы
   не уезжали вверх при листании длинного списка значений и в мобильной
   шторке. Позиционирование включается только там, где прокручивается
   сама панель (широкий экран) или шторка страницы (.max-sidebar.open):
   на узких экранах, где панель стоит в потоке страницы, шапка не
   перекрывает содержимое. */
.cf-top{
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 18px 0 6px;
    background: var(--cf-surface);
}
.cf-head{
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}
.cf-title{
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    font-size: 16px;
    font-weight: 700;
    color: var(--cf-text);
}
.cf-title-ico{ display: inline-flex; width: 18px; height: 18px; color: var(--cf-brand); }
.cf-title-pill{
    padding: 3px 8px;
    border: 1px solid rgba(126,34,206,.14);
    border-radius: 999px;
    background: var(--cf-tint);
    color: var(--cf-brand-darker);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
}
.cf-count{
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 22px;
    padding: 0 7px;
    border-radius: 999px;
    background: var(--cf-brand);
    color: #ffffff;
    font-size: 12px;
    font-weight: 700;
    line-height: 1;
}
.cf-count[hidden]{ display: none; }
.cf-head-actions{ display: inline-flex; align-items: center; gap: 6px; }
.cf-close{
    display: none;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 1px solid var(--cf-border);
    border-radius: var(--cf-radius-sm);
    background: var(--cf-surface);
    color: var(--cf-muted);
    cursor: pointer;
    transition: background-color .15s ease, color .15s ease, border-color .15s ease;
}
.cf-close:hover{ background: var(--cf-tint); border-color: var(--cf-brand); color: var(--cf-brand-darker); }
.cf-close svg{ width: 16px; height: 16px; }

/* ===== Выбранные фильтры ===== */
.cf-active{
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
    border: 1px solid rgba(126,34,206,.14);
    border-radius: var(--cf-radius-sm);
    background: var(--cf-tint);
}
.cf-active[hidden]{ display: none; }
.cf-active-head{
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}
.cf-active-title{
    font-size: 12px;
    font-weight: 700;
    color: var(--cf-brand-darker);
}
.cf-reset-all{
    padding: 2px 4px;
    border: 0;
    border-radius: 8px;
    background: none;
    color: var(--cf-brand);
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}
.cf-reset-all:hover{ color: var(--cf-brand-dark); text-decoration: underline; }
.cf-chips{ display: flex; flex-wrap: wrap; gap: 6px; }
.cf-chip{
    display: inline-flex;
    align-items: center;
    gap: 6px;
    max-width: 100%;
    min-height: 30px;
    padding: 4px 10px;
    border: 1px solid rgba(126,34,206,.18);
    border-radius: 999px;
    background: var(--cf-surface);
    color: var(--cf-brand-darker);
    font-size: 12px;
    font-weight: 600;
    overflow-wrap: anywhere;
    transition: background-color .15s ease, border-color .15s ease;
}
.cf-chip:hover{ background: var(--cf-tint-2); border-color: var(--cf-brand-dark); }
.cf-chip-x{
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 15px;
    height: 15px;
    border-radius: 50%;
    background: var(--cf-tint-2);
    color: var(--cf-brand-darker);
    font-size: 10px;
    line-height: 1;
    flex: 0 0 auto;
}

/* ===== Форма ===== */
.cf-form{ display: flex; flex-direction: column; gap: 12px; margin: 0; }
.cf-section{
    border: 1px solid var(--cf-border);
    border-radius: var(--cf-radius-sm);
    background: var(--cf-surface);
    overflow: hidden;
}
.cf-section[open]{ border-color: rgba(126,34,206,.16); }
.cf-summary{
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 46px;
    padding: 10px 12px;
    list-style: none;
    cursor: pointer;
    background: var(--cf-surface);
    color: var(--cf-text);
    font-size: 14px;
    font-weight: 600;
    user-select: none;
    transition: background-color .15s ease, color .15s ease;
}
.cf-summary::-webkit-details-marker{ display: none; }
.cf-summary:hover{ background: var(--cf-tint); color: var(--cf-brand-darker); }
.cf-summary-text{ flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.cf-summary-meta{ font-size: 12px; font-weight: 400; color: var(--cf-muted); }
.cf-summary-badge{
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 999px;
    background: var(--cf-tint-2);
    color: var(--cf-brand-darker);
    font-size: 11px;
    font-weight: 700;
}
.cf-summary-badge[hidden]{ display: none; }
.cf-summary-chev{
    display: inline-flex;
    width: 16px;
    height: 16px;
    color: var(--cf-brand);
    transition: transform .18s ease;
    flex: 0 0 auto;
}
.cf-section[open] .cf-summary-chev{ transform: rotate(180deg); }
.cf-body{ padding: 12px; border-top: 1px solid var(--cf-border); }

/* ===== Цена ===== */
.cf-price-row{ display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.cf-price-note{ margin-top: 10px; }
.cf-price-error{
    display: none;
    margin-top: 10px;
    padding: 9px 12px;
    border: 1px solid var(--cf-ring);
    border-left: 3px solid var(--cf-brand-darker);
    border-radius: var(--cf-radius-sm);
    background: var(--cf-tint-2);
    color: var(--cf-brand-darker);
    font-size: 12px;
    font-weight: 600;
}
.cf-price-error.is-visible{ display: block; }

/* ===== Поля, подписи, ошибки — как в дизайн-системе ===== */
.cf-panel .profile-field{ display: flex; flex-direction: column; min-width: 0; }
.cf-panel .profile-field-label{
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    font-weight: 600;
    color: var(--cf-text);
}
.cf-panel .profile-input{
    display: block;
    width: 100%;
    padding: 12px 14px;
    background: var(--cf-bg);
    border: 1px solid var(--cf-border);
    border-radius: var(--cf-radius-sm);
    font-family: inherit;
    font-size: 16px;
    line-height: 1.2;
    color: var(--cf-text);
    outline: none;
    transition: border-color .15s ease, box-shadow .15s ease, background-color .15s ease;
}
.cf-panel .profile-input::placeholder{ color: var(--cf-faint); }
.cf-panel .profile-input:hover{ border-color: var(--cf-border-hover); }
.cf-panel .profile-input:focus{
    background: var(--cf-surface);
    border-color: var(--cf-brand);
    box-shadow: 0 0 0 4px var(--cf-ring);
}
.cf-panel .profile-field-hint{ margin-top: 6px; font-size: 12px; color: var(--cf-muted); }
.cf-panel .profile-field-error{
    display: none;
    margin-top: 6px;
    font-size: 12px;
    font-weight: 600;
    color: var(--cf-brand-darker);
}
.cf-panel .profile-field.is-error .profile-input{
    border-color: var(--cf-brand-darker);
    background: var(--cf-tint-2);
}
.cf-panel .profile-field.is-error .profile-field-error{ display: block; }

/* ===== Селект (переиспользуем профильный селект) ===== */
.cf-panel .profile-select{ position: relative; }
.cf-panel select.profile-input{
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    padding-right: 42px;
    cursor: pointer;
}
.cf-panel select.profile-input::-ms-expand{ display: none; }
.cf-panel .profile-select-ico{
    position: absolute;
    top: 50%;
    right: 14px;
    transform: translateY(-50%);
    display: inline-flex;
    color: var(--cf-brand);
    pointer-events: none;
}
.cf-panel .profile-select-ico svg{ display: block; }

/* ===== Чипы-значения фильтра ===== */
.cf-opt-list{ display: flex; flex-wrap: wrap; gap: 8px; }
.cf-opt{ position: relative; display: inline-flex; max-width: 100%; }
.cf-opt-input{
    position: absolute;
    width: 1px;
    height: 1px;
    margin: 0;
    padding: 0;
    opacity: 0;
    pointer-events: none;
}
.cf-opt-chip{
    display: inline-flex;
    align-items: center;
    gap: 7px;
    max-width: 100%;
    min-height: 40px;
    padding: 8px 12px;
    border: 1px solid var(--cf-border);
    border-radius: 999px;
    background: var(--cf-bg);
    color: var(--cf-text);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color .15s ease, border-color .15s ease, color .15s ease;
}
.cf-opt-chip:hover{ background: var(--cf-tint); border-color: var(--cf-border-hover); color: var(--cf-brand-darker); }
.cf-opt-check{
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border: 1px solid var(--cf-border-hover);
    border-radius: 50%;
    background: var(--cf-surface);
    color: transparent;
    flex: 0 0 auto;
    transition: background-color .15s ease, border-color .15s ease, color .15s ease;
}
.cf-opt-check svg{ width: 11px; height: 11px; }
.cf-opt-text{ min-width: 0; overflow-wrap: anywhere; }
.cf-opt-count{ color: var(--cf-muted); font-size: 11px; font-weight: 600; }
.cf-opt-input:checked + .cf-opt-chip{
    background: var(--cf-tint);
    border-color: var(--cf-brand);
    color: var(--cf-brand-darker);
}
.cf-opt-input:checked + .cf-opt-chip .cf-opt-check{
    background: var(--cf-brand);
    border-color: var(--cf-brand);
    color: #ffffff;
}
.cf-opt-input:focus-visible + .cf-opt-chip{
    outline: 2px solid transparent;
    outline-offset: 2px;
    box-shadow: 0 0 0 4px var(--cf-ring);
}
.cf-opt.is-empty .cf-opt-chip{ color: var(--cf-faint); background: var(--cf-surface); }
.cf-opt.is-empty .cf-opt-count{ color: var(--cf-faint); }
/* Выбранное значение с нулевым счётчиком: выбор важнее приглушения, поэтому
   это правило идёт последним — чип остаётся с акцентной рамкой и подложкой,
   приглушённым остаётся только число совпадений («0»). */
.cf-opt.is-empty .cf-opt-input:checked + .cf-opt-chip{
    background: var(--cf-tint);
    border-color: var(--cf-brand);
    color: var(--cf-brand-darker);
}

/* ===== Наличие ===== */
.cf-switch{
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-height: 44px;
    padding: 8px 12px;
    border: 1px solid var(--cf-border);
    border-radius: 999px;
    background: var(--cf-bg);
    color: var(--cf-text);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    user-select: none;
    transition: background-color .15s ease, border-color .15s ease, color .15s ease;
}
.cf-switch:hover{ background: var(--cf-tint); border-color: var(--cf-border-hover); }
.cf-switch-input{
    position: absolute;
    width: 1px;
    height: 1px;
    margin: 0;
    padding: 0;
    opacity: 0;
    pointer-events: none;
}
.cf-switch-box{
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border: 1px solid var(--cf-border-hover);
    border-radius: 6px;
    background: var(--cf-surface);
    color: transparent;
    flex: 0 0 auto;
    transition: background-color .15s ease, border-color .15s ease, color .15s ease;
}
.cf-switch-box svg{ width: 13px; height: 13px; }
.cf-switch-input:checked + .cf-switch-box{
    background: var(--cf-brand);
    border-color: var(--cf-brand);
    color: #ffffff;
}
.cf-switch-input:focus-visible + .cf-switch-box{
    outline: 2px solid transparent;
    outline-offset: 2px;
    box-shadow: 0 0 0 4px var(--cf-ring);
}
.cf-switch-input:checked ~ .cf-switch-text{ color: var(--cf-brand-darker); }

/* ===== Кнопки ===== */
.cf-actions{ display: flex; flex-wrap: wrap; gap: 10px; margin-top: 2px; }
.cf-panel .profile-btn{
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 11px 18px;
    border: 1px solid transparent;
    border-radius: var(--cf-radius-sm);
    background: var(--cf-brand);
    color: #ffffff;
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.2;
    cursor: pointer;
    transition: background-color .15s ease, border-color .15s ease, box-shadow .15s ease, transform .08s ease;
}
.cf-panel .profile-btn:link,
.cf-panel .profile-btn:visited{ color: #ffffff; }
.cf-panel .profile-btn:hover{ background: var(--cf-brand-dark); color: #ffffff; }
.cf-panel .profile-btn:active{ background: var(--cf-brand-darker); transform: translateY(1px); }
.cf-panel .profile-btn-secondary{
    background: var(--cf-surface);
    border-color: var(--cf-border);
    color: var(--cf-muted);
}
.cf-panel .profile-btn-secondary:link,
.cf-panel .profile-btn-secondary:visited{ color: var(--cf-muted); }
.cf-panel .profile-btn-secondary:hover{
    background: var(--cf-bg);
    border-color: var(--cf-border-hover);
    color: var(--cf-text);
}
.cf-panel .profile-btn-secondary:active{
    background: var(--cf-tint);
    border-color: var(--cf-border-hover);
    color: var(--cf-text);
}
.cf-panel .profile-btn.is-loading{ background: var(--cf-brand-dark); cursor: progress; }
.cf-panel .profile-spinner{
    display: none;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,.45);
    border-top-color: #ffffff;
    border-radius: 50%;
    animation: cf-spin .7s linear infinite;
}
.cf-panel .profile-btn.is-loading .profile-spinner{ display: inline-block; }
@keyframes cf-spin{ to{ transform: rotate(360deg); } }
.cf-apply{ flex: 1 1 auto; }

/* ===== Ничего не найдено / нет фильтров ===== */
.cf-note{
    padding: 11px 14px;
    border: 1px solid rgba(126,34,206,.14);
    border-left: 3px solid var(--cf-brand);
    border-radius: var(--cf-radius-sm);
    background: var(--cf-tint);
    color: var(--cf-brand-darker);
    font-size: 13px;
    line-height: 1.45;
}

/* ===== Широкий экран: панель прилипает и скроллится внутри ===== */
@media (min-width: 901px){
    .cf-panel{
        position: sticky;
        top: 88px;
        max-height: calc(100vh - 112px);
        overflow-y: auto;
        overscroll-behavior: contain;
        scrollbar-width: thin;
        scrollbar-color: var(--cf-border-hover) transparent;
    }
    .cf-panel::-webkit-scrollbar{ width: 6px; }
    .cf-panel::-webkit-scrollbar-track{ background: transparent; }
    .cf-panel::-webkit-scrollbar-thumb{ background: var(--cf-border-hover); border-radius: 999px; }
    /* шапка и чипы прилипают к верху своей же прокрутки */
    .cf-top{ position: sticky; top: 0; z-index: 3; }
}

/* Панель внутри мобильной шторки страницы (.max-sidebar.open): прокручивается
   шторка, а не панель, поэтому шапка прилипает к верху шторки — счётчик и чипы
   видны, пока пользователь листает раскрытый раздел. Вне шторки (панель в
   потоке страницы) правило не действует. */
.max-sidebar.open .cf-top{ position: sticky; top: 0; z-index: 3; }

/* ===== 900 px — узкий десктоп/планшет ===== */
@media (max-width: 900px){
    .cf-panel{
        position: static;
        max-height: none;
        overflow: visible;
    }
}

/* ===== 768 px — телефон: крупные тач-зоны, панель-шторка ===== */
@media (max-width: 768px){
    .cf-panel{ gap: 12px; padding: 0 14px 16px; border-radius: 14px; }
    .cf-top{ gap: 8px; padding: 16px 0 6px; }
    .cf-summary{ min-height: 52px; font-size: 15px; padding: 12px; }
    .cf-body{ padding: 12px; }
    .cf-opt-chip{ min-height: 44px; padding: 10px 14px; font-size: 14px; }
    .cf-switch{ min-height: 48px; font-size: 14px; }
    .cf-chip{ min-height: 34px; font-size: 13px; }
    .cf-panel .profile-btn{ min-height: 48px; font-size: 15px; }
    .cf-actions{ gap: 8px; }
    .cf-panel .cf-apply{ flex: 1 1 100%; }
    .cf-panel .profile-btn-secondary{ flex: 1 1 100%; }
}

/* ===== 375 px ===== */
@media (max-width: 380px){
    .cf-panel{ padding: 0 12px 14px; gap: 10px; }
    .cf-top{ padding: 14px 0 6px; }
    .cf-price-row{ grid-template-columns: 1fr; }
    .cf-opt-chip{ padding: 9px 12px; }
}

@media (prefers-reduced-motion: reduce){
    .cf-panel *,
    .cf-panel *::before,
    .cf-panel *::after{ transition: none !important; }
    .cf-panel .profile-spinner{ animation: none; }
}
