/* Custom Select Component - Matches form-input styling exactly */

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

.custom-select-trigger {
    width: 100%;
    padding: 12px 16px;
    font-size: 1rem;
    font-family: var(--font-sans);
    color: var(--color-black);
    background-color: var(--color-gray-50);
    border: 1px solid var(--color-gray-200);
    border-radius: var(--radius-lg);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    direction: ltr; /* Default LTR */
    transition: all 0.2s ease;
    height: auto;
    min-height: auto;
    box-sizing: border-box;
    position: relative;
}

.custom-select-trigger:hover {
    background-color: var(--color-white);
    border-color: var(--color-black);
}

.custom-select-trigger.active,
.custom-select-trigger.open {
    background-color: var(--color-white);
    border-color: var(--color-black);
    box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.05);
}

.custom-select-trigger .custom-select-value {
    flex: 1;
    text-align: left;
    color: var(--color-black);
    font-weight: 500;
}

.custom-select-trigger .custom-select-value.placeholder {
    color: var(--color-gray-500);
    font-weight: normal;
}

.custom-select-trigger .custom-select-icon {
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    transition: transform 0.2s ease;
    color: var(--color-gray-500);
    font-size: 12px;
    pointer-events: none;
    flex-shrink: 0;
}

.custom-select-trigger.active .custom-select-icon,
.custom-select-trigger.open .custom-select-icon {
    transform: translateY(-50%) rotate(180deg);
}

/* RTL Support - Icon positioning */
[dir="rtl"] .custom-select-trigger {
    padding: 12px 16px 12px 40px !important; /* More padding on left (40px) for icon, less on right (16px) for text */
    justify-content: flex-end !important; /* Push text content to the right */
    direction: rtl; /* Ensure RTL direction */
}

[dir="rtl"] .custom-select-trigger .custom-select-icon {
    position: absolute !important;
    right: auto !important;
    left: 16px !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
}

[dir="rtl"] .custom-select-trigger.active .custom-select-icon,
[dir="rtl"] .custom-select-trigger.open .custom-select-icon {
    transform: translateY(-50%) rotate(180deg) !important;
}

[dir="rtl"] .custom-select-trigger .custom-select-value {
    text-align: right !important;
    direction: rtl !important;
    width: 100% !important;
    display: block !important;
    padding-right: 0 !important;
    margin-right: 0 !important;
    margin-left: auto !important; /* Push to the right */
}

/* RTL Support for small size */
[dir="rtl"] .custom-select-wrapper.sm .custom-select-trigger {
    padding: 8px 12px 8px 32px !important; /* Match LTR padding but reversed */
    height: 36px !important;
    min-height: 36px !important;
}

.custom-select-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--color-white);
    border: 1px solid var(--color-gray-200);
    border-radius: var(--radius-lg);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    z-index: 999999;
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transition: all 0.2s ease;
    transform: translateY(-10px);
    pointer-events: none;
}

.custom-select-dropdown.active,
.custom-select-dropdown.open {
    max-height: 300px;
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.custom-select-options {
    max-height: 300px;
    overflow-y: auto;
}

.custom-select-option {
    padding: 12px 16px;
    cursor: pointer;
    transition: background-color 0.2s ease;
    border-bottom: 1px solid var(--color-gray-100);
    font-size: 1rem;
    color: var(--color-black);
    font-family: var(--font-sans);
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

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

.custom-select-option:hover {
    background-color: var(--color-gray-50);
}

.custom-select-option.selected {
    background-color: var(--color-black);
    color: var(--color-white);
}

/* Hide any check icons in custom-select options (safety measure) */
.custom-select-option .fa-check,
.custom-select-option i.fa-check,
.custom-select-option .fas.fa-check,
.custom-select-option-check,
.custom-select-option-check i {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    width: 0 !important;
    height: 0 !important;
}

.custom-select-option.disabled {
    color: var(--color-gray-500);
    cursor: not-allowed;
    background-color: var(--color-gray-50);
}

.custom-select-option.disabled:hover {
    background-color: var(--color-gray-50);
}

.custom-select-optgroup {
    padding: 8px 16px 4px 16px;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--color-gray-500);
    background-color: var(--color-gray-50);
    border-bottom: 1px solid var(--color-gray-200);
}

.custom-select-optgroup:first-child {
    border-top: none;
}

.custom-select-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: transparent;
    z-index: 999998;
    display: none;
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

.custom-select-backdrop.active,
.custom-select-backdrop.open {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    pointer-events: all !important;
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

/* Size variants - match form-input exactly */
.custom-select-wrapper.sm .custom-select-trigger {
    padding: 8px 32px 8px 12px;
    font-size: 0.875rem;
    height: 36px !important;
    min-height: 36px !important;
    line-height: 1.2 !important;
    display: flex !important;
    align-items: center !important;
}

.custom-select-wrapper.lg .custom-select-trigger {
    padding: 16px 48px 16px 20px;
    font-size: 1.125rem;
    height: auto;
    min-height: auto;
}

/* RTL Support - Additional */
[dir="rtl"] .custom-select-trigger .custom-select-value {
    text-align: right;
}

/* Mobile optimizations */
@media (max-width: 768px) {
    .custom-select-dropdown {
        position: fixed;
        top: 50%;
        left: 20px;
        right: 20px;
        transform: translateY(-50%) scale(0.95);
        max-height: 60vh;
        border-radius: 12px;
        touch-action: pan-y;
        -webkit-overflow-scrolling: touch;
    }
    
    .custom-select-dropdown.active {
        transform: translateY(-50%) scale(1);
    }
    
    .custom-select-backdrop.active,
    .custom-select-backdrop.open {
        background: rgba(0, 0, 0, 0.5) !important;
        backdrop-filter: blur(4px) !important;
        -webkit-backdrop-filter: blur(4px) !important;
    }
    
    .custom-select-options {
        -webkit-overflow-scrolling: touch;
        touch-action: pan-y;
    }
    
    .custom-select-option {
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
        touch-action: manipulation;
    }
}

/* Focus styles for accessibility - matches form-input */
.custom-select-trigger:focus {
    outline: none;
    background-color: var(--color-white);
    border-color: var(--color-black);
    box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.05);
}

.custom-select-option:focus {
    outline: none;
    background-color: var(--color-gray-50);
}

/* Animation improvements */
.custom-select-option {
    transition: all 0.15s ease;
}

.custom-select-dropdown {
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}