/**
 * Modal System CSS
 * Styles for modal dialogs and overlays
 * 
 * @package Hampstead_Academy
 * @since 1.0.0
 */

/* ==========================================================================
   Modal System Styles
   ========================================================================== */

/* Modal Overlay */
.ha-modal-overlay {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    background: rgba(0, 0, 0, 0.7);
    z-index: 99999999 !important; /* Increased to 99999999 to ensure it's above everything */
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    overflow: auto;
    /* Ensure modal overlay covers full viewport regardless of body styling */
    transform: translateZ(0);
    will-change: opacity, visibility;
    /* Force new stacking context */
    isolation: isolate;
    /* Ensure it's above WordPress admin bar and any other elements */
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    outline: none !important;
}

.ha-modal-overlay.active,
.ha-modal-overlay.modal-open {
    opacity: 1;
    visibility: visible;
    display: flex !important;
}

/* Ensure modal overlay works correctly with body styling */
body.has-body-styling .ha-modal-overlay {
    /* Override any body styling transforms that might affect modal positioning */
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    z-index: 999999999 !important; /* Even higher z-index for body styling context */
    /* Create new stacking context to ensure modal appears above body styling */
    transform: translateZ(0);
    /* Force isolation from parent stacking contexts */
    isolation: isolate;
}

/* Force all headers and navigation to be below modal when body styling is active */
body.has-body-styling.modal-open .site-header,
body.has-body-styling.modal-open header,
body.has-body-styling.modal-open nav,
body.has-body-styling.modal-open .header,
body.has-body-styling.modal-open .navigation,
body.has-body-styling.modal-open .navbar,
body.has-body-styling.modal-open .top-bar,
body.has-body-styling.modal-open .main-navigation,
body.has-body-styling.modal-open [class*="header"],
body.has-body-styling.modal-open [class*="nav"] {
    z-index: 999999998 !important;
    position: relative !important;
}

/* Specifically target any blue header elements */
body.has-body-styling.modal-open [style*="background"][style*="blue"],
body.has-body-styling.modal-open [style*="background-color"][style*="blue"],
body.has-body-styling.modal-open .bg-blue,
body.has-body-styling.modal-open .blue-header,
body.has-body-styling.modal-open .header-blue {
    z-index: 999999998 !important;
}

/* Prevent body scrolling when modal is open */
body.modal-open {
    overflow: hidden !important;
    position: fixed !important;
    width: 100% !important;
    height: 100% !important;
    /* Ensure body stays at the top when fixed on mobile */
    left: 0 !important;
    right: 0 !important;
}

/* Restore body scrolling when modal is closed */
body:not(.modal-open) {
    overflow: auto !important;
    position: static !important;
    width: auto !important;
    height: auto !important;
    left: auto !important;
    right: auto !important;
    top: auto !important;
}

/* Modal Container */
.ha-modal {
    background: #ffffff;
    border-radius: 12px;
    max-width: 90vw;
    max-height: 90vh;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    transform: scale(0.8) translateY(50px);
    transition: all 0.3s ease;
    position: relative;
}

.ha-modal-overlay.active .ha-modal {
    transform: scale(1) translateY(0);
}

/* Modal Header */
.ha-modal-header {
    padding: 2rem 2rem 1rem;
    border-bottom: 1px solid #e9ecef;
    position: relative;
}

.ha-modal-title {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--wp--preset--color--primary-blue, #07074E);
    margin: 0;
    padding-right: 3rem;
}

.ha-modal-close {
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #666666;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.ha-modal-close:hover {
    background: #f8f9fa;
    color: var(--wp--preset--color--primary-blue, #07074E);
}

.ha-modal-close:focus {
    outline: 2px solid var(--wp--preset--color--primary-accent, #50A684);
    outline-offset: 2px;
}

/* Modal Body */
.ha-modal-body {
    padding: 2rem;
    overflow-y: auto;
    max-height: calc(90vh - 200px);
}

/* Modal Footer */
.ha-modal-footer {
    padding: 1rem 2rem 2rem;
    border-top: 1px solid #e9ecef;
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
}

/* Tour Booking Modal Specific Styles */
.tour-modal {
    width: 100%;
    max-width: 600px;
}

.tour-form-group {
    margin-bottom: 1.5rem;
}

.tour-form-label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--wp--preset--color--primary-blue, #07074E);
}

.tour-form-input,
.tour-form-select,
.tour-form-textarea {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid #e9ecef;
    border-radius: 6px;
    font-size: 1rem;
    transition: border-color 0.3s ease;
}

.tour-form-input:focus,
.tour-form-select:focus,
.tour-form-textarea:focus {
    outline: none;
    border-color: var(--wp--preset--color--primary-accent, #50A684);
    box-shadow: 0 0 0 3px rgba(80, 166, 132, 0.1);
}

.tour-form-textarea {
    resize: vertical;
    min-height: 100px;
}

.tour-form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.tour-form-checkbox {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.tour-form-checkbox input[type="checkbox"] {
    margin-top: 0.25rem;
}

.tour-form-checkbox label {
    font-size: 0.9rem;
    line-height: 1.4;
    color: #666666;
}

.tour-form-error {
    color: #dc3545;
    font-size: 0.875rem;
    margin-top: 0.25rem;
}

.tour-form-success {
    background: #d4edda;
    color: #155724;
    padding: 1rem;
    border-radius: 6px;
    margin-bottom: 1rem;
    border: 1px solid #c3e6cb;
}

/* Available Times Grid */
.available-times {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 0.5rem;
    margin-top: 1rem;
}

.time-slot {
    padding: 0.75rem;
    border: 2px solid #e9ecef;
    border-radius: 6px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background: #ffffff;
}

.time-slot:hover {
    border-color: var(--wp--preset--color--primary-accent, #50A684);
    background: rgba(80, 166, 132, 0.1);
}

.time-slot.selected {
    border-color: var(--wp--preset--color--primary-accent, #50A684);
    background: var(--wp--preset--color--primary-accent, #50A684);
    color: #ffffff;
}

.time-slot.unavailable {
    background: #f8f9fa;
    color: #999999;
    cursor: not-allowed;
    opacity: 0.6;
}

.time-slot.unavailable:hover {
    border-color: #e9ecef;
    background: #f8f9fa;
}

/* Loading State */
.ha-modal-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3rem;
}

.ha-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #e9ecef;
    border-top: 4px solid var(--wp--preset--color--primary-accent, #50A684);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Confirmation Modal */
.confirmation-modal {
    max-width: 500px;
    text-align: center;
}

.confirmation-icon {
    width: 80px;
    height: 80px;
    margin: 0 auto 1.5rem;
    background: var(--wp--preset--color--primary-accent, #50A684);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    font-size: 2rem;
}

.confirmation-message {
    font-size: 1.125rem;
    line-height: 1.6;
    color: #666666;
    margin-bottom: 2rem;
}

/* Responsive Design */
@media (max-width: 768px) {
    .ha-modal {
        max-width: 95vw;
        margin: 1rem;
    }
    
    .ha-modal-header,
    .ha-modal-body,
    .ha-modal-footer {
        padding: 1.5rem;
    }
    
    .ha-modal-title {
        font-size: 1.5rem;
        padding-right: 2.5rem;
    }
    
    .tour-form-row {
        grid-template-columns: 1fr;
    }
    
    .available-times {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .ha-modal-footer {
        flex-direction: column;
    }
    
    .ha-modal-footer .ha-button {
        width: 100%;
        justify-content: center;
    }
}

@media (max-width: 480px) {
    .ha-modal-header,
    .ha-modal-body,
    .ha-modal-footer {
        padding: 1rem;
    }
    
    .available-times {
        grid-template-columns: 1fr;
    }
    
    .time-slot {
        padding: 1rem;
    }
}

/* Accessibility */
.ha-modal-overlay[aria-hidden="true"] {
    display: none;
}

.ha-modal:focus {
    outline: none;
}

.ha-modal-close:focus-visible {
    outline: 2px solid var(--wp--preset--color--primary-accent, #50A684);
    outline-offset: 2px;
}

/* Mobile-specific modal positioning and animation */
@media (max-width: 768px) {
    /* Ensure modal overlay covers full mobile viewport */
    .ha-modal-overlay {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        /* Use 100vh instead of 100% to avoid iOS Safari issues */
        height: 100dvh !important; /* Dynamic viewport height for modern browsers */
        padding: 1rem;
        box-sizing: border-box;
        /* Ensure proper centering on mobile */
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }
    
    /* Mobile modal positioning - start from bottom but center when active */
    .ha-modal {
        transform: translateY(100vh) scale(0.9);
        max-height: calc(100vh - 2rem);
        max-width: calc(100vw - 2rem);
        margin: 0;
        /* Ensure modal is scrollable if content is too tall */
        overflow-y: auto;
    }
    
    .ha-modal-overlay.active .ha-modal {
        transform: translateY(0) scale(1);
    }
    
    /* Ensure body styling doesn't interfere on mobile */
    body.has-body-styling.modal-open {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        overflow: hidden !important;
    }
}

/* Additional mobile fixes for very small screens */
@media (max-width: 480px) {
    .ha-modal-overlay {
        padding: 0.5rem;
    }
    
    .ha-modal {
        max-height: calc(100vh - 1rem);
        max-width: calc(100vw - 1rem);
        border-radius: 8px;
    }
}

/* WordPress Admin Bar Override */
.ha-modal-overlay {
    /* Ensure modal is above WordPress admin bar (z-index: 99999) */
    z-index: 99999999 !important;
}

/* Override any WordPress core styles that might interfere */
body.modal-open #wpadminbar,
body.modal-open .wp-toolbar {
    z-index: 99999998 !important;
}

/* Ensure modal is above any sticky headers or navigation */
.ha-modal-overlay {
    /* Force modal to be above everything */
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    outline: none !important;
    /* Create isolated stacking context */
    isolation: isolate;
    /* Prevent any transforms from affecting positioning */
    transform: none !important;
}

/* Mobile-specific overrides for positioning issues */
@media (max-width: 768px) {
    .ha-modal-overlay {
        /* Force full viewport coverage on mobile */
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        height: 100dvh !important; /* Dynamic viewport height */
        /* Ensure it's not affected by any parent transforms */
        transform: translateZ(0) !important;
        /* Force hardware acceleration */
        will-change: opacity, visibility;
        /* Prevent any margin/padding issues */
        margin: 0 !important;
        padding: 0 !important;
        box-sizing: border-box !important;
    }
    
    /* Ensure modal content is properly centered */
    .ha-modal-overlay.active {
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        padding: 1rem !important;
    }
    
    /* Fix for iOS Safari viewport issues */
    .ha-modal-overlay.active .ha-modal {
        max-height: calc(100vh - 2rem) !important;
        max-height: calc(100dvh - 2rem) !important;
        max-width: calc(100vw - 2rem) !important;
        margin: 0 !important;
        transform: none !important;
    }
}

/* Print styles */
@media print {
    .ha-modal-overlay {
        display: none !important;
    }
}
