/* ══════════════════════════════════════════════════════════
   Custom Select – RonDesignLab Style
   Replaces native <select> with a premium dropdown
   ══════════════════════════════════════════════════════════ */

/* ── Wrapper ── */
.custom-select-wrapper {
    position: relative;
    width: fit-content;
    display: inline-block;
    vertical-align: middle;
}

/* ── Trigger ── */
.custom-select-trigger {
    display: inline-flex;
    align-items: center;
    width: fit-content;
    min-width: 100px;
    max-width: 22ch;
    /* Allows roughly 12-15 characters before "..." */
    height: 38px;
    padding: 0 12px 0 16px;
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 9999px !important;
    font-family: var(--font);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    outline: none;
    user-select: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.custom-select-trigger:focus,
.custom-select-trigger.open {
    box-shadow: 0 0 0 2px var(--accent-soft) !important;
    border-color: var(--accent) !important;
    background: var(--bg-surface);
}

.custom-select-trigger.placeholder {
    color: var(--text-muted);
}

/* Chevron */
.custom-select-chevron {
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    color: var(--text-muted);
    transition: transform 150ms var(--ease);
}

.custom-select-trigger.open .custom-select-chevron {
    transform: rotate(180deg);
}

.custom-select-trigger .custom-select-chevron {
    margin-left: 10px;
    flex-shrink: 0;
    transition: transform 150ms var(--ease);
    color: var(--text-muted);
}

/* ── Dropdown ── */
.custom-select-dropdown {
    position: fixed;
    /* Fixed to escape parent overflow */
    z-index: 9999;
    /* Highest priority visibility */
    background: var(--bg-surface);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-float);
    padding: 6px;
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transform: translateY(-4px);
    pointer-events: none;
    transition: max-height 180ms var(--ease),
        opacity 150ms var(--ease),
        transform 150ms var(--ease);
    border: 1px solid rgba(0, 0, 0, 0.05);
    /* Subtle border for premium feel */
}

.custom-select-dropdown.open {
    max-height: 280px;
    overflow-y: auto;
    opacity: 1;
    transform: translateY(0);
    pointer-events: all;
    min-width: 200px;
}

/* Scrollbar */
.custom-select-dropdown::-webkit-scrollbar {
    width: 4px;
}

.custom-select-dropdown::-webkit-scrollbar-track {
    background: transparent;
}

.custom-select-dropdown::-webkit-scrollbar-thumb {
    background: var(--text-dim);
    border-radius: var(--r-full);
}

/* ── Search (for large lists) ── */
.custom-select-search {
    width: 100%;
    height: 36px;
    padding: 8px 12px;
    padding-left: 36px;
    background: var(--bg-input);
    background-image: 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='%2394A3B8' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.35-4.35'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: 12px center;
    color: var(--text-primary);
    border: none;
    border-radius: var(--r-sm);
    font-family: var(--font);
    font-size: 0.82rem;
    outline: none;
    margin-bottom: 6px;
    transition: var(--transition);
}

.custom-select-search:focus {
    box-shadow: 0 0 0 2px var(--accent-soft);
    background: var(--bg-surface);
}

.custom-select-search::placeholder {
    color: var(--text-muted);
}

/* ── Option ── */
.custom-select-option {
    position: relative;
    display: flex;
    align-items: center;
    padding: 10px 16px;
    border-radius: var(--r-md);
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 150ms var(--ease);
    user-select: none;
    gap: 10px;
    margin-bottom: 2px;
}

.custom-select-option:hover {
    background: var(--bg-hover);
}

.custom-select-option.selected {
    color: var(--accent) !important;
    /* Premium Purple returned */
    font-weight: 600;
}

/* ── Chevron ── */
.collapse-chevron {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 4px;
    color: var(--text-muted);
    transition: transform 150ms var(--ease), background 150ms var(--ease);
    margin-left: auto;
    /* Push to right */
    opacity: 0.8;
}

.collapse-chevron:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--text-primary);
}

[data-theme='dark'] .collapse-chevron:hover {
    background: rgba(255, 255, 255, 0.1);
}

.collapse-chevron.collapsed {
    transform: rotate(-90deg);
}

/* ── Depth-based Indentation & Lines ── */
.custom-select-option[style*="padding-left"] {
    border-left: 1px solid rgba(0, 0, 0, 0.08);
    margin-left: 14px;
    border-radius: 0 6px 6px 0;
}

[data-theme='dark'] .custom-select-option[style*="padding-left"] {
    border-left-color: rgba(255, 255, 255, 0.1);
}

/* Recursive lines for deeper nesting */
.custom-select-option.depth-2 {
    margin-left: 34px;
}

.custom-select-option.depth-3 {
    margin-left: 54px;
}

.custom-select-option.disabled {
    color: var(--text-dim);
    cursor: not-allowed;
    opacity: 0.5;
}

/* ── Group label ── */
.custom-select-group-label {
    padding: 12px 16px 6px;
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: none;
    /* Match mockup style */
    color: var(--text-primary);
    user-select: none;
    opacity: 0.8;
}

/* ── Separator ── */
.custom-select-separator {
    height: 1px;
    background: var(--bg-hover);
    margin: 4px 8px;
}

/* ── No results ── */
.custom-select-empty {
    padding: 16px 12px;
    text-align: center;
    font-size: 0.82rem;
    color: var(--text-muted);
}

/* ── Drop-up Variation ── */
.custom-select-dropdown.drop-up {
    transform: translateY(4px);
}

.custom-select-dropdown.drop-up.open {
    transform: translateY(0);
}