/**
 * 全站自定义下拉框 — 替换原生 select 弹层（尤其 Android WebView）
 * 配色与 admin / menu 橙红渐变主题一致
 */

/* 隐藏原生 select，保留 DOM 供现有 JS 读写 */
.custom-select-native {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

.custom-select-wrapper {
    position: relative;
    display: inline-flex;
    min-width: 0;
    max-width: 100%;
    vertical-align: middle;
}

.form-item .custom-select-wrapper {
    width: 100%;
}

.custom-select-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
    min-width: 0;
    padding: 10px 32px 10px 12px;
    border: 1px solid #e0e4e8;
    border-radius: 8px;
    font-size: 1rem;
    font-family: inherit;
    background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23666' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E") no-repeat right 10px center;
    background-size: 14px;
    color: #333;
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s;
    text-align: left;
    line-height: 1.4;
    -webkit-tap-highlight-color: transparent;
}

.custom-select-trigger:hover {
    border-color: #ff9a56;
    box-shadow: 0 2px 8px rgba(255, 107, 107, 0.1);
}

.custom-select-trigger:focus-visible {
    outline: none;
    border-color: #ff6b6b;
    box-shadow: 0 0 0 3px rgba(255, 107, 107, 0.12);
}

.custom-select-trigger.is-open {
    border-color: #ff6b6b;
    box-shadow: 0 0 0 3px rgba(255, 107, 107, 0.12);
}

.custom-select-trigger.is-disabled {
    opacity: 0.55;
    cursor: not-allowed;
    pointer-events: none;
}

.custom-select-trigger-text {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.custom-select-trigger.is-placeholder .custom-select-trigger-text {
    color: #999;
}

/* 筛选栏内紧凑样式 */
.filter-bar .custom-select-wrapper {
    flex-shrink: 0;
}

.filter-bar .custom-select-trigger {
    padding: 8px 28px 8px 12px;
    font-size: 14px;
    min-width: 120px;
}

#page-material .filter-bar-main .custom-select-wrapper,
#materialSelectorModal .filter-bar-main .custom-select-wrapper {
    flex: 0 1 auto;
    width: auto;
    min-width: 0;
    max-width: 38%;
}

#page-material .filter-bar-main .custom-select-trigger,
#materialSelectorModal .filter-bar-main .custom-select-trigger {
    font-size: 0.8571rem;
    padding: 8px 24px 8px 8px;
    min-width: 0;
    max-width: 100%;
    width: 100%;
}

.filter-bar-main .custom-select-wrapper {
    flex: 1 1 120px;
}

/* ===== 选择器弹层 ===== */
.custom-select-picker {
    position: fixed;
    inset: 0;
    z-index: 3000;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 0;
}

.custom-select-picker-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    animation: csFadeIn 0.2s ease;
}

.custom-select-picker-panel {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 480px;
    max-height: min(70vh, 520px);
    background: #fff;
    border-radius: 16px 16px 0 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.15);
    animation: csSlideUp 0.28s cubic-bezier(0.32, 0.72, 0, 1);
}

.custom-select-picker-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px 12px;
    border-bottom: 1px solid #f0f2f5;
    flex-shrink: 0;
}

.custom-select-picker-title {
    font-size: 1.07rem;
    font-weight: 600;
    color: #333;
}

.custom-select-picker-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    line-height: 1;
    color: #999;
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.15s, color 0.15s;
    user-select: none;
}

.custom-select-picker-close:hover {
    background: #f5f7fa;
    color: #666;
}

.custom-select-picker-body {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
}

.custom-select-picker-list {
    list-style: none;
    margin: 0;
    padding: 6px 0;
}

.custom-select-picker-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 18px;
    font-size: 1rem;
    color: #333;
    cursor: pointer;
    transition: background 0.15s;
    border-bottom: 1px solid #f5f7fa;
    -webkit-tap-highlight-color: transparent;
}

.custom-select-picker-item:last-child {
    border-bottom: none;
}

.custom-select-picker-item:hover {
    background: #fff8f5;
}

.custom-select-picker-item.is-active {
    background: linear-gradient(90deg, rgba(255, 154, 86, 0.12) 0%, rgba(255, 107, 107, 0.08) 100%);
    color: #ff6b6b;
    font-weight: 500;
}

.custom-select-picker-item-check {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 2px solid #d0d5dd;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.15s, background 0.15s;
}

.custom-select-picker-item.is-active .custom-select-picker-item-check {
    border-color: #ff6b6b;
    background: linear-gradient(135deg, #ff9a56 0%, #ff6b6b 100%);
}

.custom-select-picker-item.is-active .custom-select-picker-item-check::after {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #fff;
}

/* PC 端居中弹窗样式 */
@media (min-width: 768px) {
    .custom-select-picker {
        align-items: center;
        padding: 20px;
    }

    .custom-select-picker-panel {
        border-radius: 12px;
        max-height: min(60vh, 480px);
        box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
        animation: csScaleIn 0.22s cubic-bezier(0.32, 0.72, 0, 1);
    }
}

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

@keyframes csSlideUp {
    from {
        transform: translateY(100%);
    }
    to {
        transform: translateY(0);
    }
}

@keyframes csScaleIn {
    from {
        opacity: 0;
        transform: scale(0.96) translateY(8px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* 暗色主题 */
body.dark-theme .custom-select-trigger {
    background-color: #242424;
    border-color: #3f3f46;
    color: #e4e4e7;
}

body.dark-theme .custom-select-trigger.is-placeholder .custom-select-trigger-text {
    color: #71717a;
}

body.dark-theme .custom-select-picker-panel {
    background: #1a1a1a;
}

body.dark-theme .custom-select-picker-header {
    border-color: #2a2a2a;
}

body.dark-theme .custom-select-picker-title {
    color: #e4e4e7;
}

body.dark-theme .custom-select-picker-item {
    color: #e4e4e7;
    border-color: #262626;
}

body.dark-theme .custom-select-picker-item:hover {
    background: rgba(255, 107, 107, 0.08);
}

body.dark-theme .custom-select-picker-item.is-active {
    background: rgba(255, 107, 107, 0.12);
}
