/* =========================================================
   S‑A‑4‑Sort：排序组件最终定版（三条线动效 + 悬浮下拉菜单完整合并版）
   说明：
   - 包含 0.26s 黄金比例射线动效
   - 包含绝对定位的下拉菜单，彻底解决挤占位置、光秃秃按钮的问题
========================================================= */

/* =========================================================
   1. 排序大图标外壳与三条线原子动效
========================================================= */
.cw-sort-switcher {
    position: relative;
    width: 44px;
    min-width: 44px;
    height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    background: transparent !important;
    border: 0 !important;
    border-radius: 10px;
    color: #292929;
    box-sizing: border-box;
    transition: background-color 160ms ease, color 160ms ease, transform 140ms ease;
}

.cw-sort-line {
    position: absolute;
    left: 11px;                         /* 视觉居中，呼吸感更佳 */
    height: 2px;                        /* 统一 2px 笔触 */
    background: currentColor;           /* 单色流，自动适配深浅主题 */
    border-radius: 2px;                 /* 统一 2px 圆角 */
    opacity: 0.9;
    transform-origin: left center;      /* 左端锚点，向右射线伸缩 */
    transition: 
        width 0.26s cubic-bezier(.33,1,.68,1), 
        opacity 0.26s ease, 
        transform 0.26s cubic-bezier(.33,1,.68,1);
    will-change: width, transform;
}

/* 常态：基础态长度（黄金比例序列）与垂直节奏 */
.cw-sort-line-1 { width: 12px; top: 13px; }
.cw-sort-line-2 { width: 16px; top: 20px; }
.cw-sort-line-3 { width: 20px; top: 27px; }

/* 激活态：黄金比例反向伸缩与 Stagger 律动 */
.cw-sort-switcher.active .cw-sort-line-1 { width: 15px; transition-delay: 0ms; }
.cw-sort-switcher.active .cw-sort-line-2 { width: 18px; transition-delay: 38ms; }
.cw-sort-switcher.active .cw-sort-line-3 { width: 17px; transition-delay: 60ms; }

/* Settle 阶段：轻微阻尼回弹 */
.cw-sort-switcher.settle .cw-sort-line { transform: scaleX(0.98); }

.cw-sort-switcher:focus-visible {
    outline: 2px solid rgba(75, 175, 159, 0.72) !important;
    outline-offset: 3px;
}

.cw-sort-switcher:active {
    transform: scale(0.97);
}

@media (hover: hover) and (pointer: fine) {
    .cw-sort-switcher:hover {
        background: rgba(17, 17, 17, 0.05) !important;
        color: #111111;
    }
}

/* =========================================================
   2. 下拉菜单展现区（悬浮定位，绝对隐藏）
========================================================= */
.cw-sort-menu {
    position: absolute;
    top: calc(100% + 8px); /* 悬浮在图标正下方 */
    right: 0;          /* 死死贴住右边缘，绝不漂移 */
    width: 168px;
    padding: 6px;
    background: #FFFFFF;
    border-radius: 12px;
    box-shadow: 0 18px 44px rgba(17, 17, 17, 0.12);
    border: 1px solid rgba(17, 17, 17, 0.08);
    z-index: 999;

    /* 🌟 核心：默认完全隐藏，绝不占用文档流空间 */
    opacity: 0;
    transform: translateY(-6px) scale(0.98);
    transform-origin: top right;
    pointer-events: none;
    transition: opacity 180ms ease, transform 220ms cubic-bezier(.16,1,.3,1);
}

/* 当 JS 赋予 open 类名时，优雅浮现下拉菜单 */
.cw-sort-menu.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* =========================================================
   3. 菜单内部排序选项 (消除原生 button 丑陋样式)
========================================================= */
.cw-sort-option {
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    display: flex;
    align-items: center;
    background: none;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    color: #444444;
    line-height: 1.3;
    text-decoration: none;
    transition: background-color 150ms ease, color 150ms ease;
    box-sizing: border-box;
    text-align: left; /* 覆盖原生 button 居中 */
}

/* 原子圆点指示器 */
.cw-sort-option::before {
    content: "";
    display: inline-block;
    width: 5px;
    height: 5px;
    margin-right: 8px;
    border-radius: 50%;
    background: transparent;
    transition: background-color 0.15s ease;
}

.cw-sort-option:focus-visible {
    outline: 2px solid rgba(75, 175, 159, 0.7);
    outline-offset: -2px;
}

@media (hover: hover) and (pointer: fine) {
    .cw-sort-option:hover {
        background: rgba(17, 17, 17, 0.045);
        color: #111111;
    }
}

/* 🌟 激活态颜色统一 (Creawith Green) */
.cw-sort-option.is-selected,
.cw-sort-option.active { 
    background: rgba(75, 175, 159, 0.09);
    color: #317e73;
    font-weight: 600; 
}

.cw-sort-option.is-selected::before,
.cw-sort-option.active::before {
    background-color: #4BAF9F;
}

.cw-sort-mask {
    display: none;
}

/* =========================================================
   4. 移动端 Bottom Sheet 自适应
========================================================= */
@media (max-width: 768px) {
    .cw-sort-menu { 
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        top: auto;
        width: 100%;
        padding: 12px 12px max(14px, env(safe-area-inset-bottom));
        border-radius: 16px 16px 0 0;
        transform: translateY(102%);
        transform-origin: bottom center;
        z-index: 2000;
    }
    .cw-sort-menu.open { transform: translateY(0); }

    .cw-sort-option {
        min-height: 52px;
        padding-inline: 16px;
        font-size: 14px;
    }

    .cw-sort-mask { 
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(17, 17, 17, 0.42);
        opacity: 0;
        pointer-events: none;
        transition: opacity 200ms ease;
        z-index: 1999;
    }
    .cw-sort-mask.open { opacity: 1; pointer-events: auto; }

    body.cw-sort-sheet-open {
        overflow: hidden;
    }
}

@media (prefers-reduced-transparency: reduce) {
    .cw-sort-mask {
        background: rgba(17, 17, 17, 0.72);
    }
}

@media (prefers-reduced-motion: reduce) {
    .cw-sort-switcher,
    .cw-sort-line,
    .cw-sort-menu,
    .cw-sort-option,
    .cw-sort-mask {
        transition-duration: 0.01ms !important;
    }
}
