/* =============================================================================
   MOP Select2 Custom Styles
   ============================================================================= */

/* Container principal */
.select2-container,
.mop-select-container {
    width: 100% !important;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* Select2 Selection */
.select2-container--default .select2-selection--single {
    height: 42px !important;
    border: 1px solid #e1e5e9 !important;
    border-radius: 8px !important;
    background-color: #ffffff !important;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05) !important;
    transition: all 0.2s ease-in-out !important;
    padding: 0 !important;
}

.select2-container--default .select2-selection--single:hover {
    border-color: #c3c9d0 !important;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08) !important;
}

.select2-container--default.select2-container--focus .select2-selection--single {
    border-color: #4f80ff !important;
    box-shadow: 0 0 0 3px rgba(79, 128, 255, 0.1) !important;
    outline: none !important;
}

/* Texto de la selección */
.select2-container--default .select2-selection--single .select2-selection__rendered {
    color: #374151 !important;
    line-height: 40px !important;
    padding: 0 15px !important;
    font-size: 14px !important;
    font-weight: 400 !important;
}

/* Placeholder */
.select2-container--default .select2-selection--single .select2-selection__placeholder {
    color: #9ca3af !important;
    font-style: normal !important;
}

/* Flecha del dropdown */
.select2-container--default .select2-selection--single .select2-selection__arrow {
    height: 40px !important;
    right: 8px !important;
    top: 1px !important;
}

.select2-container--default .select2-selection--single .select2-selection__arrow b {
    border-color: #6b7280 transparent transparent transparent !important;
    border-style: solid !important;
    border-width: 6px 5px 0 5px !important;
    height: 0 !important;
    left: 50% !important;
    margin-left: -5px !important;
    margin-top: -3px !important;
    position: absolute !important;
    top: 50% !important;
    width: 0 !important;
    transition: transform 0.2s ease-in-out !important;
}

.select2-container--default.select2-container--open .select2-selection--single .select2-selection__arrow b {
    transform: rotate(180deg) !important;
    border-color: #4f80ff transparent transparent transparent !important;
}

/* Dropdown */
.select2-dropdown,
.mop-select-dropdown {
    border: 1px solid #e1e5e9 !important;
    border-radius: 8px !important;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1) !important;
    background-color: #ffffff !important;
    margin-top: 4px !important;
    z-index: 9999 !important;
}

.select2-dropdown--above {
    margin-top: -4px !important;
    margin-bottom: 4px !important;
}

/* Barra de búsqueda */
.select2-search--dropdown {
    padding: 12px !important;
    background-color: #f9fafb !important;
    border-bottom: 1px solid #e5e7eb !important;
    border-radius: 8px 8px 0 0 !important;
}

.select2-search--dropdown .select2-search__field {
    padding: 8px 12px !important;
    border: 1px solid #d1d5db !important;
    border-radius: 6px !important;
    background-color: #ffffff !important;
    font-size: 14px !important;
    width: 100% !important;
    box-sizing: border-box !important;
    transition: border-color 0.2s ease-in-out !important;
}

.select2-search--dropdown .select2-search__field:focus {
    border-color: #4f80ff !important;
    outline: none !important;
    box-shadow: 0 0 0 3px rgba(79, 128, 255, 0.1) !important;
}

/* Resultados */
.select2-results {
    max-height: 250px !important;
    overflow-y: auto !important;
}

.select2-results__options {
    padding: 4px 0 !important;
}

.select2-results__option {
    padding: 10px 15px !important;
    font-size: 14px !important;
    color: #374151 !important;
    cursor: pointer !important;
    transition: all 0.15s ease-in-out !important;
    border: none !important;
}

.select2-results__option:hover {
    background-color: #f3f4f6 !important;
    color: #1f2937 !important;
}

.select2-results__option--highlighted {
    background-color: #4f80ff !important;
    color: #ffffff !important;
}

.select2-results__option--selected {
    background-color: #e0e7ff !important;
    color: #4338ca !important;
    font-weight: 500 !important;
    position: relative !important;
}

.select2-results__option--selected::after {
    content: '✓' !important;
    position: absolute !important;
    right: 15px !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    font-weight: bold !important;
    color: #4338ca !important;
}

/* Mensaje de "No se encontraron resultados" */
.select2-results__option--selectable {
    cursor: pointer !important;
}

.select2-results__message {
    padding: 15px !important;
    color: #6b7280 !important;
    font-style: italic !important;
    text-align: center !important;
}

/* Select múltiple */
.select2-container--default .select2-selection--multiple {
    border: 1px solid #e1e5e9 !important;
    border-radius: 8px !important;
    background-color: #ffffff !important;
    min-height: 42px !important;
    padding: 4px 8px !important;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05) !important;
    transition: all 0.2s ease-in-out !important;
}

.select2-container--default .select2-selection--multiple:hover {
    border-color: #c3c9d0 !important;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08) !important;
}

.select2-container--default.select2-container--focus .select2-selection--multiple {
    border-color: #4f80ff !important;
    box-shadow: 0 0 0 3px rgba(79, 128, 255, 0.1) !important;
    outline: none !important;
}

/* Tags en select múltiple */
.select2-container--default .select2-selection--multiple .select2-selection__choice {
    background-color: #4f80ff !important;
    border: 1px solid #4f80ff !important;
    border-radius: 20px !important;
    color: #ffffff !important;
    font-size: 13px !important;
    margin: 2px 4px 2px 0 !important;
    padding: 4px 8px 4px 12px !important;
    font-weight: 500 !important;
    display: inline-flex !important;
    align-items: center !important;
    gap: 6px !important;
}

.select2-container--default .select2-selection--multiple .select2-selection__choice__remove {
    border: none !important;
    color: #ffffff !important;
    cursor: pointer !important;
    display: inline-block !important;
    font-weight: bold !important;
    margin-right: 0 !important;
    margin-left: 4px !important;
    padding: 0 !important;
    background: none !important;
    font-size: 16px !important;
    line-height: 1 !important;
    opacity: 0.7 !important;
    transition: opacity 0.2s ease-in-out !important;
}

.select2-container--default .select2-selection--multiple .select2-selection__choice__remove:hover {
    opacity: 1 !important;
    color: #ffffff !important;
}

/* Campo de búsqueda en select múltiple */
.select2-container--default .select2-search--inline .select2-search__field {
    background: transparent !important;
    border: none !important;
    outline: none !important;
    box-shadow: none !important;
    -webkit-appearance: textfield !important;
    appearance: textfield !important;
    font-size: 14px !important;
    color: #374151 !important;
    min-width: 120px !important;
    margin: 4px 0 !important;
    padding: 4px 0 !important;
}

/* Estados de validación */
.select2-container.is-invalid .select2-selection {
    border-color: #dc3545 !important;
    box-shadow: 0 0 0 3px rgba(220, 53, 69, 0.1) !important;
}

.select2-container.is-valid .select2-selection {
    border-color: #28a745 !important;
    box-shadow: 0 0 0 3px rgba(40, 167, 69, 0.1) !important;
}

/* Modo deshabilitado */
.select2-container--default.select2-container--disabled .select2-selection--single,
.select2-container--default.select2-container--disabled .select2-selection--multiple {
    background-color: #f3f4f6 !important;
    color: #9ca3af !important;
    cursor: not-allowed !important;
    border-color: #d1d5db !important;
    box-shadow: none !important;
}

.select2-container--default.select2-container--disabled .select2-selection__arrow b {
    border-color: #9ca3af transparent transparent transparent !important;
}

/* Scrollbar personalizada */
.select2-results::-webkit-scrollbar {
    width: 6px !important;
}

.select2-results::-webkit-scrollbar-track {
    background: #f1f1f1 !important;
    border-radius: 3px !important;
}

.select2-results::-webkit-scrollbar-thumb {
    background: #c1c1c1 !important;
    border-radius: 3px !important;
}

.select2-results::-webkit-scrollbar-thumb:hover {
    background: #a1a1a1 !important;
}

/* Responsive */
@media (max-width: 768px) {
    .select2-container--default .select2-selection--single {
        height: 44px !important;
    }
    
    .select2-container--default .select2-selection--single .select2-selection__rendered {
        line-height: 42px !important;
        font-size: 16px !important; /* Evita zoom en iOS */
    }
    
    .select2-container--default .select2-selection--single .select2-selection__arrow {
        height: 42px !important;
    }
    
    .select2-dropdown {
        box-shadow: 0 5px 15px rgba(0, 0, 0, 0.15) !important;
    }
}

/* Tema oscuro (opcional) */
@media (prefers-color-scheme: dark) {
    .select2-container.dark-theme .select2-selection {
        background-color: #1f2937 !important;
        border-color: #374151 !important;
        color: #f9fafb !important;
    }
    
    .select2-container.dark-theme .select2-dropdown {
        background-color: #1f2937 !important;
        border-color: #374151 !important;
    }
    
    .select2-container.dark-theme .select2-results__option {
        color: #f9fafb !important;
    }
    
    .select2-container.dark-theme .select2-results__option:hover {
        background-color: #374151 !important;
    }
}

/* Animaciones adicionales */
.select2-dropdown {
    animation: select2FadeIn 0.15s ease-out !important;
}

@keyframes select2FadeIn {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Grupos de opciones */
.select2-results__group {
    color: #6b7280 !important;
    display: block !important;
    font-size: 12px !important;
    font-weight: 600 !important;
    line-height: 1.5 !important;
    padding: 8px 15px 4px !important;
    text-transform: uppercase !important;
    letter-spacing: 0.5px !important;
    background-color: #f9fafb !important;
    border-bottom: 1px solid #e5e7eb !important;
}

.select2-results__option[aria-disabled=true] {
    color: #9ca3af !important;
    cursor: not-allowed !important;
    background-color: transparent !important;
}

/* Loading state */
.select2-container--default .select2-selection--single .select2-selection__loading {
    margin-top: -2px !important;
    position: absolute !important;
    right: 30px !important;
    top: 50% !important;
}

.select2-spinner {
    display: inline-block !important;
    width: 16px !important;
    height: 16px !important;
    border: 2px solid #e5e7eb !important;
    border-radius: 50% !important;
    border-top-color: #4f80ff !important;
    animation: spin 1s ease-in-out infinite !important;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}
