/* ============================================================
   BS 高级筛选：Apple 风格玻璃抽屉
   - 默认主题与 ?ui=glass 共用
   - 只影响筛选面板，不改变筛选算法和数据层
   ============================================================ */

html body #bsFilterPanel.bs-filter-apple-ready {
    --bs-filter-glass:
        linear-gradient(145deg, rgba(255, 255, 255, .88), rgba(248, 250, 255, .76) 56%, rgba(231, 238, 250, .72)),
        #f1f4f9;
    --bs-filter-glass-strong:
        linear-gradient(180deg, rgba(255, 255, 255, .78), rgba(241, 245, 251, .74)),
        #f5f7fb;
    --bs-filter-content: #ffffff;
    --bs-filter-edge: color-mix(in srgb, var(--text) 18%, transparent);
    --bs-filter-edge-soft: color-mix(in srgb, var(--text) 10%, transparent);
    --bs-filter-specular: rgba(255, 255, 255, .94);
    --bs-filter-blue: #007aff;
    --bs-filter-blue-soft: rgba(0, 122, 255, .11);
    --bs-filter-shadow: 0 30px 82px rgba(24, 32, 53, .24), 0 8px 24px rgba(24, 32, 53, .11);
    position: fixed;
    inset: 0;
    z-index: 1000;
    padding: 0 !important;
    overflow: hidden;
    overscroll-behavior: contain;
    /* 右侧筛选作为检查器使用，左侧产品信息保持原始清晰度。 */
    background: transparent !important;
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
}

html body #bsFilterPanel.bs-filter-apple-ready .bs-filter-drawer {
    position: relative;
    width: min(488px, calc(100vw - 28px)) !important;
    height: calc(100vh - 28px) !important;
    height: calc(100dvh - 28px) !important;
    margin: 14px 14px 14px auto !important;
    padding: 0 18px 16px !important;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
    background: var(--bs-filter-glass) !important;
    border: 1px solid var(--bs-filter-edge) !important;
    border-top-color: rgba(255, 255, 255, .76) !important;
    border-radius: 28px !important;
    box-shadow:
        inset 0 1px 0 var(--bs-filter-specular),
        inset 0 -1px 0 color-mix(in srgb, var(--text) 20%, transparent),
        var(--bs-filter-shadow) !important;
    -webkit-backdrop-filter: saturate(185%) blur(38px) brightness(1.025) !important;
    backdrop-filter: saturate(185%) blur(38px) brightness(1.025) !important;
    transform-origin: right center;
    isolation: isolate;
}

html body #bsFilterPanel.bs-filter-apple-ready .bs-filter-drawer::before {
    content: "";
    position: absolute;
    z-index: 4;
    top: 1px;
    left: 12%;
    width: 52%;
    height: 1px;
    border-radius: 999px;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .96), transparent);
    pointer-events: none;
}

html body #bsFilterPanel.is-apple-open {
    animation: bsAppleBackdropIn .18s ease-out both;
}

html body #bsFilterPanel.is-apple-open .bs-filter-drawer {
    animation: bsAppleDrawerIn .34s cubic-bezier(.22, 1.18, .36, 1) both;
}

html body #bsFilterPanel.is-apple-closing {
    animation: bsAppleBackdropOut .18s ease-in both;
}

html body #bsFilterPanel.is-apple-closing .bs-filter-drawer {
    animation: bsAppleDrawerOut .18s cubic-bezier(.4, 0, 1, 1) both;
}

@keyframes bsAppleBackdropIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes bsAppleBackdropOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

@keyframes bsAppleDrawerIn {
    0% { opacity: .42; transform: translateX(38px) scale(.982); }
    72% { opacity: 1; transform: translateX(-2px) scale(1.002); }
    100% { opacity: 1; transform: translateX(0) scale(1); }
}

@keyframes bsAppleDrawerOut {
    from { opacity: 1; transform: translateX(0) scale(1); }
    to { opacity: 0; transform: translateX(24px) scale(.988); }
}

/* 工具栏本身是筛选面板的堆叠上下文；打开时抬高，避免被页面顶栏遮住。 */
html body .bs-record-toolbar:has(#bsFilterPanel.is-apple-open),
html body .bs-record-toolbar:has(#bsFilterPanel.is-apple-closing) {
    z-index: 1001 !important;
}

body.bs-filter-sheet-open {
    overflow: hidden;
}

body.bs-filter-sheet-open .mobile-hamburger {
    opacity: 0 !important;
    pointer-events: none !important;
}

/* 吸顶标题与滚动边缘 */
html body #bsFilterPanel.bs-filter-apple-ready .bs-filter-drawer-head {
    position: relative !important;
    top: auto !important;
    z-index: 3;
    flex: 0 0 auto;
    min-height: 66px;
    margin: 0 -18px !important;
    padding: 13px 18px 12px !important;
    background: var(--bs-filter-glass-strong) !important;
    border-bottom: 1px solid var(--bs-filter-edge-soft) !important;
    box-shadow: none;
    -webkit-backdrop-filter: saturate(175%) blur(28px) !important;
    backdrop-filter: saturate(175%) blur(28px) !important;
    transition: box-shadow .18s ease, background .18s ease;
}

html body #bsFilterPanel.bs-filter-apple-ready .bs-filter-scroll-body {
    min-height: 0;
    flex: 1 1 auto;
    margin: 0 -2px;
    padding: 14px 2px 12px;
    overflow: hidden auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
}

html body #bsFilterPanel.bs-filter-apple-ready.is-scrolled .bs-filter-drawer-head {
    box-shadow: 0 10px 24px rgba(26, 34, 54, .11), inset 0 -1px 0 var(--bs-filter-edge-soft);
}

html body #bsFilterPanel.bs-filter-apple-ready .bs-filter-drawer-title {
    min-width: 0;
    font-size: 17px;
    font-weight: 700;
    letter-spacing: -.015em;
}

html body #bsFilterPanel.bs-filter-apple-ready .bs-filter-active-count {
    display: inline-flex;
    align-items: center;
    min-height: 22px;
    padding: 2px 8px;
    border: 1px solid var(--bs-filter-edge-soft);
    border-radius: 999px;
    background: color-mix(in srgb, var(--bg-elevated) 62%, transparent);
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 600;
    white-space: nowrap;
}

html body #bsFilterPanel.bs-filter-apple-ready .bs-filter-active-count[data-count]:not([data-count="0"]) {
    border-color: rgba(0, 122, 255, .22);
    background: var(--bs-filter-blue-soft);
    color: var(--bs-filter-blue);
}

html body #bsFilterPanel.bs-filter-apple-ready .bs-filter-drawer-close {
    width: 36px !important;
    height: 36px !important;
    flex: 0 0 36px;
    border: 1px solid var(--bs-filter-edge-soft) !important;
    border-radius: 50% !important;
    background: color-mix(in srgb, var(--bg-elevated) 58%, transparent) !important;
    box-shadow: inset 0 1px 0 var(--bs-filter-specular), 0 4px 12px rgba(27, 35, 55, .08);
    color: var(--text-muted) !important;
    font-size: 21px !important;
    transition: transform .15s ease, background .15s ease, color .15s ease, box-shadow .15s ease;
}

html body #bsFilterPanel.bs-filter-apple-ready .bs-filter-drawer-close:hover {
    background: color-mix(in srgb, var(--bg-elevated) 82%, transparent) !important;
    color: var(--text) !important;
    transform: scale(1.04);
}

html body #bsFilterPanel.bs-filter-apple-ready .bs-filter-drawer-close:active {
    transform: scale(.94);
    box-shadow: inset 0 2px 5px rgba(28, 36, 56, .16);
}

html body #bsFilterPanel.bs-filter-apple-ready :where(button, input, select, textarea):focus-visible {
    outline: 3px solid rgba(0, 122, 255, .22) !important;
    outline-offset: 2px !important;
}

/* 内容层保持清晰实体表面 */
html body #bsFilterPanel.bs-filter-apple-ready .bs-filter-modules,
html body #bsFilterPanel.bs-filter-apple-ready .bs-filter-module-editor {
    border: 1px solid var(--bs-filter-edge-soft) !important;
    border-radius: 16px !important;
    background: color-mix(in srgb, var(--bs-filter-content) 94%, var(--bs-filter-blue) 6%) !important;
    box-shadow: inset 0 1px 0 var(--bs-filter-specular), 0 5px 16px rgba(30, 39, 60, .05);
}

html body #bsFilterPanel.bs-filter-apple-ready :where(input[type="number"], input[type="text"], .bs-filter-module-picker-btn) {
    min-height: 36px !important;
    border: 1px solid var(--bs-filter-edge-soft) !important;
    border-radius: 11px !important;
    background: var(--bs-filter-content) !important;
    box-shadow: inset 0 1px 2px rgba(28, 36, 56, .055) !important;
    color: var(--text) !important;
    transition: border-color .16s ease, box-shadow .16s ease, background .16s ease;
}

html body #bsFilterPanel.bs-filter-apple-ready :where(input[type="number"], input[type="text"]):focus {
    border-color: rgba(0, 122, 255, .56) !important;
    box-shadow: inset 0 1px 2px rgba(28, 36, 56, .035), 0 0 0 4px rgba(0, 122, 255, .16) !important;
    outline: none;
}

html body #bsFilterPanel.bs-filter-apple-ready input[type="checkbox"] {
    width: 16px !important;
    height: 16px !important;
    accent-color: var(--bs-filter-blue);
}

html body #bsFilterPanel.bs-filter-apple-ready .bs-f-col-title {
    margin-top: 2px;
    padding-bottom: 7px;
    border-bottom-color: var(--bs-filter-edge-soft);
    letter-spacing: -.005em;
}

html body #bsFilterPanel.bs-filter-apple-ready .bs-f-row {
    margin-bottom: 8px;
}

/* 多选项转为可识别的胶囊状态，仍保留原生 checkbox。 */
html body #bsFilterPanel.bs-filter-apple-ready .bs-f-cc label,
html body #bsFilterPanel.bs-filter-apple-ready :where(#bsF_sellerCountryWrap, #bsF_buyboxTypeWrap, #bsF_badgeWrap) label {
    min-height: 32px;
    padding: 5px 8px !important;
    border: 1px solid var(--bs-filter-edge-soft);
    border-radius: 999px;
    background: color-mix(in srgb, var(--bg-elevated) 72%, transparent);
    transition: transform .14s ease, border-color .14s ease, background .14s ease, color .14s ease;
}

html body #bsFilterPanel.bs-filter-apple-ready .bs-f-cc label:has(input:checked),
html body #bsFilterPanel.bs-filter-apple-ready :where(#bsF_sellerCountryWrap, #bsF_buyboxTypeWrap, #bsF_badgeWrap) label:has(input:checked) {
    border-color: rgba(0, 122, 255, .28);
    background: var(--bs-filter-blue-soft);
    color: var(--bs-filter-blue);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .52);
}

html body #bsFilterPanel.bs-filter-apple-ready .bs-f-cc label:active,
html body #bsFilterPanel.bs-filter-apple-ready :where(#bsF_sellerCountryWrap, #bsF_buyboxTypeWrap, #bsF_badgeWrap) label:active {
    transform: scale(.97);
}

html body #bsFilterPanel.bs-filter-apple-ready .bs-f-chips button,
html body #bsFilterPanel.bs-filter-apple-ready #bsFilterHistory button {
    min-height: 30px;
    padding: 5px 9px !important;
    border: 1px solid var(--bs-filter-edge-soft) !important;
    border-radius: 999px !important;
    background: color-mix(in srgb, var(--bg-elevated) 78%, transparent) !important;
    color: var(--text-muted) !important;
    box-shadow: inset 0 1px 0 var(--bs-filter-specular), 0 3px 9px rgba(28, 36, 56, .05);
}

html body #bsFilterPanel.bs-filter-apple-ready .bs-f-chips button:hover,
html body #bsFilterPanel.bs-filter-apple-ready #bsFilterHistory button:hover {
    border-color: rgba(0, 122, 255, .28) !important;
    background: var(--bs-filter-blue-soft) !important;
    color: var(--bs-filter-blue) !important;
}

/* 底部操作条：实时应用状态 + 分段控件 + 单一主操作 */
html body #bsFilterPanel.bs-filter-apple-ready .bs-filter-actions {
    position: relative !important;
    bottom: auto !important;
    z-index: 3;
    flex: 0 0 auto;
    margin: 0 -18px -16px !important;
    padding: 11px 18px 14px !important;
    border-top: 1px solid var(--bs-filter-edge-soft) !important;
    background: var(--bs-filter-glass-strong) !important;
    box-shadow: 0 -10px 24px rgba(28, 36, 56, .08);
    -webkit-backdrop-filter: saturate(175%) blur(28px) !important;
    backdrop-filter: saturate(175%) blur(28px) !important;
}

html body #bsFilterPanel.bs-filter-apple-ready.is-scroll-end .bs-filter-actions {
    box-shadow: inset 0 1px 0 var(--bs-filter-edge-soft);
}

html body #bsFilterPanel.bs-filter-apple-ready #bsFilterLiveStatus {
    display: inline-flex;
    align-items: center;
    min-height: 18px;
    color: var(--text-muted) !important;
    font-size: 10px !important;
    transition: color .16s ease, transform .16s ease;
}

html body #bsFilterPanel.bs-filter-apple-ready #bsFilterLiveStatus::before {
    content: "";
    width: 6px;
    height: 6px;
    margin-right: 6px;
    border-radius: 50%;
    background: #34c759;
    box-shadow: 0 0 0 3px rgba(52, 199, 89, .12);
}

html body #bsFilterPanel.bs-filter-apple-ready #bsFilterLiveStatus.is-updated {
    color: #1f9d4c !important;
    transform: translateY(-1px);
}

html body #bsFilterPanel.bs-filter-apple-ready .bs-filter-mode-segment {
    display: inline-flex !important;
    align-items: center;
    gap: 2px !important;
    padding: 2px;
    border: 1px solid var(--bs-filter-edge-soft) !important;
    border-radius: 999px !important;
    background: color-mix(in srgb, var(--bg-elevated) 66%, transparent);
    overflow: visible !important;
}

html body #bsFilterPanel.bs-filter-apple-ready .bs-filter-mode-segment button {
    min-width: 48px;
    min-height: 32px;
    padding: 5px 10px !important;
    border: 0 !important;
    border-radius: 999px !important;
    background: transparent !important;
    color: var(--text-muted) !important;
    box-shadow: none !important;
}

html body #bsFilterPanel.bs-filter-apple-ready .bs-filter-mode-segment button[aria-pressed="true"] {
    background: var(--bs-filter-blue) !important;
    color: #fff !important;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .32), 0 4px 11px rgba(0, 122, 255, .22) !important;
}

html body #bsFilterPanel.bs-filter-apple-ready .bs-filter-navigator-option {
    min-height: 36px;
    padding: 6px 9px !important;
    border-color: var(--bs-filter-edge-soft) !important;
    border-radius: 999px !important;
    background: color-mix(in srgb, var(--bg-elevated) 62%, transparent);
}

html body #bsFilterPanel.bs-filter-apple-ready :where(#bsFilterClearBtn, #bsFilterDoneBtn) {
    min-height: 38px;
    padding: 7px 14px !important;
    border-radius: 999px !important;
    font-weight: 650;
    transition: transform .15s ease, box-shadow .15s ease, filter .15s ease;
}

html body #bsFilterPanel.bs-filter-apple-ready #bsFilterClearBtn {
    border-color: var(--bs-filter-edge-soft) !important;
    background: color-mix(in srgb, var(--bg-elevated) 70%, transparent) !important;
    color: var(--text) !important;
}

html body #bsFilterPanel.bs-filter-apple-ready #bsFilterDoneBtn {
    min-width: 86px;
    border-color: rgba(0, 92, 202, .42) !important;
    background: linear-gradient(180deg, #2c91ff, var(--bs-filter-blue)) !important;
    color: #fff !important;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .35), 0 7px 17px rgba(0, 122, 255, .24) !important;
}

html body #bsFilterPanel.bs-filter-apple-ready :where(#bsFilterClearBtn, #bsFilterDoneBtn):active {
    transform: scale(.96);
    filter: brightness(.97);
}

#bsFilterToggleBtn .bs-filter-trigger-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 17px;
    height: 17px;
    margin-left: 4px;
    padding: 0 5px;
    border-radius: 999px;
    background: var(--blue);
    color: #fff;
    font-size: 9px;
    font-weight: 700;
    line-height: 1;
}

#bsFilterToggleBtn[aria-pressed="true"] .bs-filter-trigger-count {
    background: rgba(255, 255, 255, .26);
}

@media (max-width: 640px) {
    html body #bsFilterPanel.bs-filter-apple-ready .bs-filter-drawer {
        width: calc(100vw - 12px) !important;
        height: calc(100vh - 12px) !important;
        height: calc(100dvh - 12px) !important;
        margin: 6px !important;
        padding-inline: 14px !important;
        border-radius: 24px !important;
        transform-origin: center bottom;
    }

    html body #bsFilterPanel.is-apple-open .bs-filter-drawer {
        animation-name: bsAppleSheetIn;
    }

    html body #bsFilterPanel.is-apple-closing .bs-filter-drawer {
        animation-name: bsAppleSheetOut;
    }

    html body #bsFilterPanel.bs-filter-apple-ready .bs-filter-drawer::after {
        content: "";
        position: absolute;
        z-index: 5;
        top: 7px;
        left: 50%;
        width: 38px;
        height: 5px;
        border-radius: 999px;
        background: color-mix(in srgb, var(--text) 20%, transparent);
        transform: translateX(-50%);
        pointer-events: none;
    }

    html body #bsFilterPanel.bs-filter-apple-ready .bs-filter-drawer-head {
        min-height: 70px;
        margin-inline: -14px !important;
        padding: 18px 14px 11px !important;
    }

    html body #bsFilterPanel.bs-filter-apple-ready .bs-filter-actions {
        margin-inline: -14px !important;
        padding-inline: 14px !important;
    }

    html body #bsFilterPanel.bs-filter-apple-ready .bs-filter-actions > div {
        flex-wrap: wrap;
    }

    html body #bsFilterPanel.bs-filter-apple-ready #bsFilterDoneBtn {
        flex: 1 1 86px;
    }
}

@keyframes bsAppleSheetIn {
    0% { opacity: .40; transform: translateY(34px) scale(.985); }
    72% { opacity: 1; transform: translateY(-2px) scale(1.002); }
    100% { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes bsAppleSheetOut {
    from { opacity: 1; transform: translateY(0) scale(1); }
    to { opacity: 0; transform: translateY(24px) scale(.99); }
}

@media (prefers-reduced-transparency: reduce) {
    html body #bsFilterPanel.bs-filter-apple-ready {
        background: transparent !important;
        -webkit-backdrop-filter: none !important;
        backdrop-filter: none !important;
    }

    html body #bsFilterPanel.bs-filter-apple-ready .bs-filter-drawer,
    html body #bsFilterPanel.bs-filter-apple-ready :where(.bs-filter-drawer-head, .bs-filter-actions) {
        background: var(--bs-filter-content) !important;
        -webkit-backdrop-filter: none !important;
        backdrop-filter: none !important;
    }
}

@media (prefers-contrast: more) {
    html body #bsFilterPanel.bs-filter-apple-ready {
        --bs-filter-edge: color-mix(in srgb, var(--text) 44%, transparent);
        --bs-filter-edge-soft: color-mix(in srgb, var(--text) 28%, transparent);
    }

    html body #bsFilterPanel.bs-filter-apple-ready :where(button, input, label) {
        font-weight: 600;
    }
}

@media (prefers-reduced-motion: reduce) {
    html body #bsFilterPanel.bs-filter-apple-ready,
    html body #bsFilterPanel.bs-filter-apple-ready *,
    html body #bsFilterPanel.bs-filter-apple-ready *::before,
    html body #bsFilterPanel.bs-filter-apple-ready *::after {
        scroll-behavior: auto !important;
        transition-duration: .01ms !important;
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
    }
}
