/**
 * Select2 Dropdowns Custom Styles
 * 
 * Custom styles to ensure consistent appearance and proper integration
 * with the application's design system.
 */

/* Select2 Container Styling */
.select2-container {
    width: 100% !important;
}

.select2-container--default .select2-selection--single {
    height: 48px;
    line-height: 48px;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 0 12px;
}

.select2-container--default .select2-selection--single .select2-selection__rendered {
    padding: 0;
    line-height: 46px;
    color: #333;
}

.select2-container--default .select2-selection--single .select2-selection__arrow {
    height: 46px;
    right: 10px;
}

/* Focus States */
.select2-container--default.select2-container--focus .select2-selection--single {
    border-color: #007bff;
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
}

/* Error States */
.select2-container.is-invalid .select2-selection,
.select2-container.is-invalid .select2-selection--single {
    border-color: #dc3545;
    box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.25);
}

.invalid-feedback {
    width: 100%;
    margin-top: 0.25rem;
    font-size: 0.875rem;
    color: #dc3545;
}

/* Loading States */
.select2-container--default .select2-results__option[aria-disabled=true] {
    color: #6c757d;
    background-color: transparent;
}

.select2-container--default .select2-results__option--highlighted[aria-disabled=true] {
    background-color: #f8f9fa;
}

/* Dropdown Styling */
.select2-container--default .select2-dropdown {
    border: 1px solid #ddd;
    border-radius: 4px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.select2-container--default .select2-search--dropdown {
    padding: 8px;
}

.select2-container--default .select2-search--dropdown .select2-search__field {
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 8px 12px;
    margin: 0;
    width: 100%;
    box-sizing: border-box;
}

.select2-container--default .select2-results__option {
    padding: 8px 12px;
    font-size: 14px;
}

.select2-container--default .select2-results__option--highlighted {
    background-color: #007bff;
    color: white;
}

/* Placeholder Styling */
.select2-container--default .select2-selection--single .select2-selection__placeholder {
    color: #6c757d;
    font-style: italic;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .select2-container--default .select2-selection--single {
        height: 44px;
        line-height: 44px;
    }
    
    .select2-container--default .select2-selection--single .select2-selection__rendered {
        line-height: 42px;
    }
    
    .select2-container--default .select2-selection--single .select2-selection__arrow {
        height: 42px;
    }
    
    .select2-container--default .select2-dropdown {
        margin-top: 2px;
    }
    
    .select2-container--default .select2-results__option {
        padding: 12px;
        font-size: 16px; /* Prevents zoom on iOS */
    }
}

/* Material Design Integration (for Materialize CSS) */
.input-field .select2-container {
    margin-top: 0;
}

.input-field .select2-container--default .select2-selection--single {
    background: transparent;
    border: none;
    border-bottom: 1px solid #9e9e9e;
    border-radius: 0;
    height: 3rem;
    line-height: 3rem;
    padding: 0;
}

.input-field .select2-container--default .select2-selection--single .select2-selection__rendered {
    line-height: 3rem;
    padding-left: 0;
}

.input-field .select2-container--default .select2-selection--single .select2-selection__arrow {
    height: 3rem;
    right: 0;
}

.input-field .select2-container--default.select2-container--focus .select2-selection--single {
    border-bottom: 2px solid #26a69a;
    box-shadow: none;
}

.input-field .select2-container.is-invalid .select2-selection--single {
    border-bottom: 2px solid #f44336;
    box-shadow: none;
}

/* Label Positioning for Material Design - Only for Select2 elements */
.input-field .select2-container + label {
    color: #9e9e9e;
    position: absolute;
    top: 0;
    left: 0;
    font-size: 1rem;
    cursor: text;
    transition: transform 0.2s ease-out, color 0.2s ease-out;
    transform-origin: 0% 100%;
    text-align: initial;
    transform: translateY(12px);
}

.input-field .select2-container + label.active {
    transform: translateY(-14px) scale(0.8);
    transform-origin: 0 0;
}

/* Select2 with active label */
.input-field .select2-container + label.active,
.input-field .select2-container--default .select2-selection--single:not(.select2-selection__placeholder) + label {
    transform: translateY(-14px) scale(0.8);
    transform-origin: 0 0;
    color: #26a69a;
}

/* Loading Animation */
.select2-container--default .select2-results__option[aria-disabled=true]::after {
    content: "";
    display: inline-block;
    width: 16px;
    height: 16px;
    margin-left: 8px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #007bff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    vertical-align: middle;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Accessibility Improvements */
.select2-container--default .select2-selection--single:focus {
    outline: 2px solid #007bff;
    outline-offset: 2px;
}

.select2-container--default .select2-results__option[aria-selected=true] {
    background-color: #e3f2fd;
    color: #1976d2;
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
    .select2-container--default .select2-selection--single {
        border: 2px solid #000;
    }
    
    .select2-container--default .select2-dropdown {
        border: 2px solid #000;
    }
    
    .select2-container--default .select2-results__option--highlighted {
        background-color: #000;
        color: #fff;
    }
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
    .select2-container--default .select2-selection--single,
    .input-field .select2-container + label {
        transition: none;
    }
    
    .select2-container--default .select2-results__option[aria-disabled=true]::after {
        animation: none;
    }
}
