/**
 * 🔧 FIX URGENTE - MODALES CON SCROLL
 * Soluciona el problema de modales que no permiten desplazamiento
 * Versión: 1.0.0 - 2025-01-14
 */

/* ========================================
   MODAL CONTAINER - Forzar comportamiento correcto
   ======================================== */

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    padding: 20px;
    overflow-y: auto !important; /* Permitir scroll en el overlay */
}

.modal.active,
.modal.show {
    display: flex !important;
}

/* ========================================
   MODAL CONTENT - Scroll interno
   ======================================== */

.modal-content {
    background: white;
    border-radius: 12px;
    width: 100%;
    max-width: 700px; /* Aumentado de 600px */
    max-height: 85vh; /* Altura máxima para permitir scroll */
    overflow-y: auto !important; /* Scroll vertical SIEMPRE */
    box-shadow: 0 10px 15px rgba(0, 0, 0, 0.1);
    margin: auto; /* Centrar verticalmente */
    position: relative;
}

/* Asegurar que el contenido interno pueda scrollear */
.modal-content > * {
    position: relative;
    z-index: 1;
}

/* ========================================
   MODAL HEADER - Fijo arriba
   ======================================== */

.modal-header {
    padding: 20px 25px;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: white;
    position: sticky; /* Se mantiene visible al scrollear */
    top: 0;
    z-index: 10;
    border-radius: 12px 12px 0 0;
}

.modal-header h2 {
    font-size: 20px;
    font-weight: 600;
    margin: 0;
    color: #111827;
}

/* ========================================
   MODAL BODY - Área scrolleable
   ======================================== */

.modal-content form {
    padding: 25px;
    overflow-y: visible; /* Permitir que el contenido fluya */
}

/* ========================================
   FORM ACTIONS - Fijos abajo
   ======================================== */

.form-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 25px;
    padding: 20px 25px;
    border-top: 1px solid #e5e7eb;
    background: white;
    position: sticky; /* Se mantiene visible al scrollear */
    bottom: 0;
    z-index: 10;
    border-radius: 0 0 12px 12px;
}

/* ========================================
   MODALES GRANDES - Para formularios extensos
   ======================================== */

/* Modal de inscripción (tiene muchos campos) */
#modalNuevaInscripcion .modal-content,
#modalInscripcion .modal-content {
    max-width: 800px;
    max-height: 90vh;
}

/* Modal de nuevo curso */
#modalCurso .modal-content {
    max-width: 750px;
    max-height: 90vh;
}

/* Modal de nuevo estudiante */
#modalEstudiante .modal-content {
    max-width: 750px;
    max-height: 90vh;
}

/* Modal de campus virtual (puede tener mucho contenido) */
#modalCampusVirtual .modal-content {
    max-width: 900px;
    max-height: 95vh;
}

/* ========================================
   SCROLLBAR PERSONALIZADO
   ======================================== */

.modal-content::-webkit-scrollbar {
    width: 8px;
}

.modal-content::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

.modal-content::-webkit-scrollbar-thumb {
    background: #D4AF37;
    border-radius: 10px;
}

.modal-content::-webkit-scrollbar-thumb:hover {
    background: #B8941F;
}

/* ========================================
   RESPONSIVE - Móviles y tablets
   ======================================== */

@media (max-height: 800px) {
    .modal-content {
        max-height: 90vh; /* Más espacio en pantallas pequeñas */
    }
    
    .modal-header {
        padding: 15px 20px;
    }
    
    .modal-content form {
        padding: 20px;
    }
    
    .form-actions {
        padding: 15px 20px;
    }
}

@media (max-width: 768px) {
    .modal {
        padding: 10px;
    }
    
    .modal-content {
        max-width: 100%;
        max-height: 95vh;
        border-radius: 8px;
    }
    
    .modal-header {
        padding: 15px;
    }
    
    .modal-header h2 {
        font-size: 18px;
    }
    
    .modal-content form {
        padding: 15px;
    }
    
    .form-actions {
        padding: 15px;
        flex-direction: column;
    }
    
    .form-actions .btn {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .modal {
        padding: 5px;
    }
    
    .modal-content {
        max-height: 98vh;
        border-radius: 6px;
    }
    
    .modal-header {
        padding: 12px;
    }
    
    .modal-header h2 {
        font-size: 16px;
    }
    
    .modal-content form {
        padding: 12px;
    }
    
    .form-actions {
        padding: 12px;
        margin-top: 15px;
    }
}

/* ========================================
   FIX: Select2 dentro de modales
   ======================================== */

/* Asegurar que Select2 no interfiera con el scroll */
.select2-container--open {
    z-index: 2100 !important;
}

.select2-dropdown {
    z-index: 2100 !important;
}

/* ========================================
   FIX: Campos de formulario largos
   ======================================== */

/* Áreas de texto deben poder scrollear internamente */
.modal-content textarea {
    max-height: 200px;
    resize: vertical;
}

/* Contenedores de checkbox/radio deben poder scrollear */
.checkbox-container,
.curso-checkbox-item,
#cursosCheckboxContainer {
    max-height: 300px;
    overflow-y: auto;
}

.checkbox-container::-webkit-scrollbar,
#cursosCheckboxContainer::-webkit-scrollbar {
    width: 6px;
}

.checkbox-container::-webkit-scrollbar-track,
#cursosCheckboxContainer::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.checkbox-container::-webkit-scrollbar-thumb,
#cursosCheckboxContainer::-webkit-scrollbar-thumb {
    background: #D4AF37;
    border-radius: 3px;
}

/* ========================================
   ANIMACIONES SUAVES
   ======================================== */

.modal-content {
    animation: modalSlideIn 0.3s ease;
}

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

/* ========================================
   INDICADOR DE SCROLL
   ======================================== */

/* Sombra superior cuando hay contenido arriba */
.modal-content::before {
    content: '';
    position: sticky;
    top: 0;
    left: 0;
    right: 0;
    height: 10px;
    background: linear-gradient(to bottom, rgba(0,0,0,0.1), transparent);
    display: block;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
    z-index: 9;
}

.modal-content.has-scroll::before {
    opacity: 1;
}

/* Sombra inferior cuando hay contenido abajo */
.modal-content::after {
    content: '';
    position: sticky;
    bottom: 0;
    left: 0;
    right: 0;
    height: 10px;
    background: linear-gradient(to top, rgba(0,0,0,0.1), transparent);
    display: block;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
    z-index: 9;
}

.modal-content.has-scroll::after {
    opacity: 1;
}

/* ========================================
   ACCESIBILIDAD
   ======================================== */

/* Mejorar foco para navegación por teclado */
.modal-content:focus {
    outline: none;
}

.modal-content *:focus {
    outline: 2px solid #D4AF37;
    outline-offset: 2px;
}

/* ========================================
   COMPATIBILIDAD CON NAVEGADORES
   ======================================== */

/* Firefox */
.modal-content {
    scrollbar-width: thin;
    scrollbar-color: #D4AF37 #f1f1f1;
}

/* Edge legacy */
.modal-content {
    -ms-overflow-style: -ms-autohiding-scrollbar;
}

/* ========================================
   PRINT - Ocultar modales al imprimir
   ======================================== */

@media print {
    .modal {
        display: none !important;
    }
}
