/* School Modal Mobile Fix - Ensures proper display and centering on all devices */

/* Base modal fixes for school selection - Desktop First */
#schoolModal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    overflow: hidden;
}

/* When modal is shown, use flex for centering */
#schoolModal.show,
#schoolModal[style*="display: flex"] {
    display: flex !important;
    align-items: center;
    justify-content: center;
}

/* Desktop modal content styling */
#schoolModal .modal-content {
    position: relative;
    background: white;
    width: 600px;
    max-width: 90%;
    max-height: 80vh;
    border-radius: 1rem;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    animation: modalSlideIn 0.3s ease-out;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Ensure proper scrolling for content inside modal */
#schoolModal .schools-list {
    overflow-y: auto;
    max-height: 400px;
    -webkit-overflow-scrolling: touch;
}

/* Mobile-specific modal fixes */
@media (max-width: 768px) {
    #schoolModal {
        padding: 20px;
        display: none;
        align-items: flex-start;
        justify-content: center;
    }
    
    #schoolModal.show {
        display: flex !important;
    }
    
    #schoolModal .modal-content {
        position: relative !important;
        transform: none !important;
        margin: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        max-height: calc(100vh - 40px);
        top: auto !important;
        left: auto !important;
    }
    
    /* Ensure close button is accessible */
    #schoolModal .close-btn {
        position: absolute;
        right: 15px;
        top: 15px;
        width: 40px;
        height: 40px;
        font-size: 24px;
        display: flex;
        align-items: center;
        justify-content: center;
        background: rgba(0, 0, 0, 0.05);
        border-radius: 50%;
        border: none;
        cursor: pointer;
        z-index: 10;
        color: #64748b;
    }
    
    /* Modal header adjustments */
    #schoolModal .modal-header {
        padding: 20px;
        padding-right: 60px; /* Space for close button */
        border-bottom: 1px solid #e5e7eb;
    }
    
    #schoolModal .modal-title {
        font-size: 20px;
        font-weight: 700;
        color: #1f2937;
        margin: 0;
    }
    
    #schoolModal .modal-subtitle {
        font-size: 14px;
        color: #6b7280;
        margin-top: 5px;
    }
    
    /* Search container */
    #schoolModal .search-container {
        padding: 15px 20px;
        background: #f9fafb;
        border-bottom: 1px solid #e5e7eb;
        position: relative;
    }
    
    #schoolModal .search-input {
        width: 100%;
        padding: 12px 40px 12px 15px;
        font-size: 16px; /* Prevents zoom on iOS */
        border: 1px solid #d1d5db;
        border-radius: 8px;
        background: white;
    }
    
    #schoolModal .search-icon {
        position: absolute;
        right: 30px;
        top: 50%;
        transform: translateY(-50%);
        color: #9ca3af;
        pointer-events: none;
    }
    
    /* Schools list */
    #schoolModal .schools-list {
        padding: 10px;
        max-height: calc(100vh - 300px);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    #schoolModal .school-option {
        display: flex;
        align-items: center;
        padding: 15px;
        margin-bottom: 10px;
        background: white;
        border: 1px solid #e5e7eb;
        border-radius: 8px;
        cursor: pointer;
        transition: all 0.2s ease;
    }
    
    #schoolModal .school-option:active {
        transform: scale(0.98);
        background: #f3f4f6;
    }
    
    /* Loading state */
    #schoolModal .schools-loading {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        padding: 60px 20px;
        text-align: center;
    }
    
    #schoolModal .loading-spinner {
        width: 40px;
        height: 40px;
        border: 3px solid #f3f4f6;
        border-left: 3px solid #3b82f6;
        border-radius: 50%;
        animation: spin 1s linear infinite;
        margin-bottom: 15px;
    }
    
    /* Error state */
    #schoolModal .schools-error {
        text-align: center;
        padding: 40px 20px;
    }
    
    #schoolModal .error-icon {
        font-size: 48px;
        margin-bottom: 15px;
    }
    
    #schoolModal .schools-error h3 {
        font-size: 18px;
        color: #1f2937;
        margin-bottom: 10px;
    }
    
    #schoolModal .schools-error p {
        font-size: 14px;
        color: #6b7280;
        margin-bottom: 20px;
    }
    
    /* No schools found */
    #schoolModal .no-schools {
        text-align: center;
        padding: 40px 20px;
    }
    
    #schoolModal .no-schools-icon {
        font-size: 48px;
        margin-bottom: 15px;
    }
    
    #schoolModal .no-schools h3 {
        font-size: 18px;
        color: #1f2937;
        margin-bottom: 10px;
    }
    
    #schoolModal .no-schools p {
        font-size: 14px;
        color: #6b7280;
    }
}

/* Small mobile devices */
@media (max-width: 480px) {
    #schoolModal {
        padding: 10px;
    }
    
    #schoolModal .modal-header {
        padding: 15px;
        padding-right: 50px;
    }
    
    #schoolModal .modal-title {
        font-size: 18px;
    }
    
    #schoolModal .schools-list {
        max-height: calc(100vh - 280px);
    }
    
    #schoolModal .school-option {
        padding: 12px;
        margin-bottom: 8px;
    }
}

/* Animation for modal */
@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Ensure modal works with enhanced mobile menu */
.mobile-menu.active ~ #schoolModal {
    z-index: 999; /* Below mobile menu */
}

/* Desktop-specific fixes to prevent mobile styles from affecting desktop */
@media (min-width: 769px) {
    #schoolModal {
        padding: 0 !important;
    }
    
    #schoolModal .modal-content {
        position: relative !important;
        margin: 0 !important;
        transform: none !important;
        top: auto !important;
        left: auto !important;
        width: 600px !important;
        max-width: 90% !important;
        max-height: 80vh !important;
    }
    
    /* Ensure close button is properly positioned on desktop */
    #schoolModal .close-btn {
        position: absolute;
        right: 20px;
        top: 20px;
        width: 32px;
        height: 32px;
        font-size: 20px;
        display: flex;
        align-items: center;
        justify-content: center;
        background: transparent;
        border: 1px solid #e5e7eb;
        border-radius: 50%;
        cursor: pointer;
        z-index: 10;
        color: #64748b;
        transition: all 0.2s ease;
    }
    
    #schoolModal .close-btn:hover {
        background: #f3f4f6;
        color: #1f2937;
    }
    
    /* Modal header for desktop */
    #schoolModal .modal-header {
        padding: 24px;
        padding-right: 70px;
        border-bottom: 1px solid #e5e7eb;
    }
    
    /* Search container for desktop */
    #schoolModal .search-container {
        padding: 20px 24px;
        background: #f9fafb;
        border-bottom: 1px solid #e5e7eb;
    }
    
    /* Schools list for desktop */
    #schoolModal .schools-list {
        padding: 20px;
        max-height: 400px;
        overflow-y: auto;
    }
    
    /* School option hover effect on desktop */
    #schoolModal .school-option:hover {
        background: #f3f4f6;
        transform: translateX(4px);
    }
}

/* Override any conflicting styles from other CSS files */
#schoolModal[style*="display: block"] {
    display: flex !important;
}

/* Landscape orientation fixes */
@media (max-width: 768px) and (orientation: landscape) {
    #schoolModal .modal-content {
        max-height: calc(100vh - 20px);
    }
    
    #schoolModal .schools-list {
        max-height: calc(100vh - 200px);
    }
}

/* Accessibility improvements */
@media (prefers-reduced-motion: reduce) {
    #schoolModal .modal-content {
        animation: none;
    }
    
    #schoolModal .school-option {
        transition: none;
    }
}

/* Fix for iOS Safari */
@supports (-webkit-touch-callout: none) {
    #schoolModal {
        /* iOS specific fixes */
        height: 100vh;
        height: -webkit-fill-available;
    }
    
    #schoolModal .modal-content {
        max-height: calc(100vh - 100px);
        max-height: calc(-webkit-fill-available - 100px);
    }
}

/* Ensure proper stacking context */
#schoolModal {
    isolation: isolate;
}

/* Debug helper - remove in production */
.debug-modal-visible #schoolModal {
    outline: 2px solid red;
}

.debug-modal-visible #schoolModal .modal-content {
    outline: 2px solid blue;
}