/**
 * Custom Select Styles with Glass-Morphism & Blur Effects
 * Portal-based dropdown that doesn't break backdrop-filter
 */

/* Container */
.custom-select {
    position: relative;
    display: inline-block;
    width: 100%;
}

/* Trigger Button */
.custom-select-trigger {
    width: 100%;
    padding: 12px 16px;
    background: var(--glass-bg, rgba(255, 255, 255, 0.05));
    border: 1px solid var(--glass-border, rgba(255, 255, 255, 0.1));
    border-radius: 12px;
    color: var(--text-primary, #f5f5f4);
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    transition: all 0.2s ease;
}

.custom-select-trigger:hover:not(:disabled) {
    background: var(--glass-hover, rgba(255, 255, 255, 0.08));
    border-color: var(--glass-border, rgba(255, 255, 255, 0.15));
}

.custom-select-trigger:focus-visible {
    outline: none;
    border-color: var(--emerald-light, #34d399);
    box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.1);
}

.custom-select-trigger:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.custom-select-trigger[aria-expanded="true"] {
    background: var(--glass-hover, rgba(255, 255, 255, 0.08));
    border-color: var(--emerald-light, #34d399);
}

.custom-select-trigger[aria-expanded="true"] .custom-select-caret {
    transform: rotate(180deg);
}

/* Label */
.custom-select-label {
    flex: 1;
    text-align: left;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Caret Icon */
.custom-select-caret {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    transition: transform 0.2s ease;
    color: var(--text-muted, rgba(245, 245, 244, 0.4));
}

/* Menu - Portal Style (position: fixed) */
.custom-select-menu {
    position: fixed;
    margin: 0;
    padding: 8px 0;
    background: rgba(255, 255, 255, 0.55);
    backdrop-filter: blur(18px) saturate(160%);
    -webkit-backdrop-filter: blur(18px) saturate(160%);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 16px;
    list-style: none;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1),
                0 4px 16px rgba(0, 0, 0, 0.08);
    max-height: 400px;
    overflow-y: auto;
    z-index: 9999;
    min-width: 100px;
}

/* Dark mode styles */
[data-theme="dark"] .custom-select-menu,
body:not([data-theme="light"]) .custom-select-menu {
    background: rgba(10, 20, 15, 0.82);
    border-color: rgba(52, 211, 153, 0.18);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45),
                0 0 40px rgba(52, 211, 153, 0.06);
}

/* Light mode styles */
[data-theme="light"] .custom-select-menu,
body[data-theme="light"] .custom-select-menu {
    background: rgba(255, 255, 255, 0.65);
    border-color: rgba(0, 0, 0, 0.08);
}

/* Menu Item (Option) */
.custom-select-option {
    padding: 12px 16px;
    cursor: pointer;
    transition: all 0.15s ease;
    color: var(--text-primary, #f5f5f4);
    user-select: none;
}

.custom-select-option:hover {
    background: rgba(52, 211, 153, 0.1);
}

.custom-select-option.focused {
    background: rgba(52, 211, 153, 0.2);
    outline: none;
}

.custom-select-option[aria-selected="true"] {
    background: rgba(52, 211, 153, 0.15);
    font-weight: 600;
    color: #34d399;
}

.custom-select-option.selected {
    background: rgba(52, 211, 153, 0.15);
    font-weight: 600;
    color: var(--emerald-light, #34d399);
}

.custom-select-option.selected::before {
    content: '✓ ';
    margin-right: 4px;
}

/* Scrollbar styling for menu */
.custom-select-menu::-webkit-scrollbar {
    width: 8px;
}

.custom-select-menu::-webkit-scrollbar-track {
    background: transparent;
}

.custom-select-menu::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
}

.custom-select-menu::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

[data-theme="light"] .custom-select-menu::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
}

[data-theme="light"] .custom-select-menu::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.25);
}

/* Light theme adjustments */
[data-theme="light"] .custom-select-option {
    color: #1a1a1a;
}

[data-theme="light"] .custom-select-option:hover {
    background: rgba(5, 150, 105, 0.08);
}

[data-theme="light"] .custom-select-option.focused {
    background: rgba(5, 150, 105, 0.12);
}

[data-theme="light"] .custom-select-option[aria-selected="true"] {
    background: rgba(5, 150, 105, 0.15);
    color: var(--emerald, #059669);
}

[data-theme="light"] .custom-select-option.selected {
    background: rgba(5, 150, 105, 0.15);
    color: var(--emerald, #059669);
}

[data-theme="light"] .custom-select-trigger {
    background: rgba(255, 255, 255, 0.6);
    border-color: rgba(0, 0, 0, 0.1);
    color: #1a1a1a;
}

[data-theme="light"] .custom-select-trigger:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.8);
    border-color: rgba(0, 0, 0, 0.15);
}

[data-theme="light"] .custom-select-caret {
    color: rgba(26, 26, 26, 0.5);
}

/* Responsive Design */
@media (max-width: 768px) {
    .custom-select-menu {
        max-height: 300px;
        min-width: 180px;
    }

    .custom-select-option {
        padding: 10px 14px;
        font-size: 13px;
    }

    .custom-select-trigger {
        padding: 10px 12px;
        font-size: 13px;
    }
}

@media (max-width: 480px) {
    .custom-select-menu {
        max-height: 250px;
        min-width: 160px;
    }

    .custom-select-option {
        padding: 8px 12px;
        font-size: 12px;
    }

    .custom-select-trigger {
        padding: 8px 10px;
        font-size: 12px;
    }
}

/* Fallback for no-JS (native select still visible) */
.custom-select + select {
    display: none;
}

/* Animation for opening */
@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.custom-select-menu {
    animation: slideDown 0.15s ease-out;
}

/* Accessibility: Focus visible for keyboard nav */
.custom-select-option:focus-visible {
    outline: 2px solid var(--emerald-light, #34d399);
    outline-offset: -2px;
}

/* Accessibility: High contrast mode support */
@media (prefers-contrast: more) {
    .custom-select-trigger {
        border-width: 2px;
    }

    .custom-select-menu {
        border-width: 2px;
    }

    .custom-select-option.focused {
        text-decoration: underline;
    }
}

/* Accessibility: Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .custom-select-trigger,
    .custom-select-option,
    .custom-select-caret {
        transition: none;
    }

    .custom-select-menu {
        animation: none;
    }
}
