/**
 * ============================================
 * MOBILE-OPTIMIZED SELECT2 STYLES
 * ============================================
 * 
 * Add this CSS to your stylesheet or include as separate file
 * These styles enhance Select2 for mobile devices
 */

/* ============================================ */
/* BASE SELECT2 IMPROVEMENTS */
/* ============================================ */

.select2-container--default .select2-selection--single {
    border: 1px solid #ddd;
    border-radius: 8px;
    transition: border-color 0.3s ease;
}

.select2-container--default.select2-container--focus .select2-selection--single {
    border-color: #E78585;
    outline: none;
}

.select2-container--default .select2-selection--single .select2-selection__placeholder {
    color: black;
}

/* ============================================ */
/* MOBILE OPTIMIZATIONS (phones & small tablets) */
/* ============================================ */

@media (max-width: 768px) {
    
    /* ===== LARGER TOUCH TARGETS ===== */
    .select2-container--default .select2-selection--single {
        height: 32px !important;
        padding: 0px !important;
        font-size: 16px !important; /* Prevents iOS zoom on focus */
    }
    
    .select2-container--default .select2-selection--single .select2-selection__rendered {
        line-height: 28px !important;
        padding-left: 12px !important;
        font-size: 16px !important;
    }
    
    .select2-container--default .select2-selection--single .select2-selection__arrow {
        height: 30px !important;
        right: 8px !important;
    }
    
    .select2-container--default .select2-selection--single .select2-selection__arrow b {
        border-width: 6px 6px 0 6px !important;
        margin-left: -6px !important;
        margin-top: -3px !important;
    }
    
    /* ===== FULL-SCREEN DROPDOWN ===== */
    .select2-container--open .select2-dropdown {
        position: relative !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        max-height: 100vh !important;
        border: none !important;
        border-radius: 0 !important;
        z-index: 99999 !important;
        background: white;
        box-shadow: none !important;
    }
    
    /* ===== CLOSE BUTTON ===== */
    .select2-dropdown::before {
        content: '✕ Close';
        display: block;
        position: sticky;
        top: 0;
        background: #f8f9fa;
        padding: 15px 20px;
        text-align: center;
        font-weight: 600;
        font-size: 16px;
        border-bottom: 2px solid #ddd;
        cursor: pointer;
        z-index: 11;
        color: #333;
    }
    
    .select2-dropdown::before:active {
        background: #e9ecef;
    }
    
    /* ===== SEARCH BOX ===== */
    .select2-search--dropdown {
        padding: 15px !important;
        position: sticky !important;
        top: 0 !important;
        background: white !important;
        z-index: 10 !important;
        border-bottom: 2px solid #f0f0f0 !important;
    }
    
    .select2-search--dropdown .select2-search__field {
        height: 48px !important;
        font-size: 16px !important;
        padding: 12px 15px !important;
        border: 2px solid #ddd !important;
        border-radius: 8px !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }
    
    .select2-search--dropdown .select2-search__field:focus {
        border-color: #E78585 !important;
        outline: none !important;
    }
    
    /* ===== RESULTS CONTAINER ===== */
    .select2-results {
        max-height: calc(100vh - 130px) !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    }
    
    /* ===== RESULT ITEMS ===== */
    .select2-results__option {
        padding: 16px 20px !important;
        font-size: 16px !important;
        border-bottom: 1px solid #f5f5f5 !important;
        cursor: pointer;
        transition: background-color 0.2s ease;
    }
    
    .select2-results__option:active,
    .select2-results__option--highlighted {
        background-color: #E78585 !important;
        color: white !important;
    }
    
    .select2-results__option--selected {
        background-color: #E78585 !important;
        color: white !important;
        font-weight: 600;
    }
    
    /* ===== NO RESULTS MESSAGE ===== */
    .select2-results__option--highlighted.select2-results__message {
        background-color: transparent !important;
        color: #666 !important;
    }
    
    .select2-results__message {
        padding: 30px 20px !important;
        text-align: center !important;
        color: #999 !important;
        font-size: 16px !important;
    }
    
    /* ===== LOADING INDICATOR ===== */
    .select2-results__option.loading-results {
        text-align: center;
        padding: 20px !important;
        color: #999;
    }
    
    /* ===== BACKDROP ===== */
    .select2-container--open::after {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 99998;
        animation: fadeIn 0.2s ease;
    }
    
    @keyframes fadeIn {
        from { opacity: 0; }
        to { opacity: 1; }
    }
}

/* ============================================ */
/* TABLET STYLES (medium screens) */
/* ============================================ */

@media (min-width: 769px) and (max-width: 1024px) {
    .select2-container--default .select2-selection--single {
        height: 45px !important;
    }
    
    .select2-results__option {
        padding: 12px 15px !important;
    }
}

/* ============================================ */
/* DESKTOP STYLES */
/* ============================================ */

@media (min-width: 1025px) {
    .select2-container--default .select2-selection--single {
        height: 45px !important;
        border-radius: 8px !important;
    }
    
    .select2-container--default .select2-selection--single .select2-selection__rendered {
        line-height: 25px !important;
        padding-top: 10px !important;
    }
    
    .select2-dropdown {
        border-radius: 8px !important;
        border: 1px solid #ddd !important;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1) !important;
    }
    
    .select2-results__option {
        padding: 10px 15px !important;
    }
    
    .select2-results__option--highlighted {
        background-color: #E78585 !important;
    }
    
    .select2-search--dropdown {
        padding: 10px !important;
    }
    
    .select2-search--dropdown .select2-search__field {
        border: 1px solid #ddd !important;
        border-radius: 6px !important;
        padding: 8px 12px !important;
    }
}

/* ============================================ */
/* DISABLED STATE */
/* ============================================ */

.select2-container--default .select2-selection--single.select2-selection--disabled {
    background-color: #f5f5f5;
    cursor: not-allowed;
    opacity: 0.6;
}

/* ============================================ */
/* CUSTOM THEME COLORS (match your site) */
/* ============================================ */

.select2-container--default .select2-results__option--selected {
    background-color: #E78585 !important;
    color: white !important;
}

.select2-container--default.select2-container--focus .select2-selection--single {
    border-color: #E78585 !important;
}

/* ============================================ */
/* LOADING SPINNER */
/* ============================================ */

.select2-results__option.loading-results::after {
    content: '';
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #E78585;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-left: 10px;
}

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

/* ============================================ */
/* ACCESSIBILITY IMPROVEMENTS */
/* ============================================ */

.select2-container--default .select2-selection--single:focus {
    outline: 2px solid #E78585;
    outline-offset: 2px;
}

.select2-results__option[aria-selected="true"] {
    position: relative;
}

.select2-results__option[aria-selected="true"]::after {
    content: '✓';
    position: absolute;
    top: 18px;
    right: 15px;
    font-weight: bold;
}

/* ============================================ */
/* SMOOTH TRANSITIONS */
/* ============================================ */

.select2-dropdown {
    transition: all 0.2s ease;
}

.select2-results__option {
    transition: background-color 0.15s ease, color 0.15s ease;
}

/* ============================================ */
/* FIX FOR YOUR CUSTOM-INPUT CLASS */
/* ============================================ */

.custom-input.select2-hidden-accessible + .select2-container {
    width: 100% !important;
}
