/* Half-Width Right-Anchored Modal Styles with 720px Maximum Width */

/* Modal Overlay */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    backdrop-filter: blur(2px);
    transition: opacity 0.3s ease;
    opacity: 0;
}

.modal-overlay.active {
    display: block;
    opacity: 1;
}

/* Modal Container - Updated with maximum width of 720px */
.purpose-map-modal {
    position: fixed;
    top: 0;
    right: -720px; /* Start off-screen at the maximum width */
    bottom: 0;
    width: 50vw; /* Default to 50% of viewport */
    max-width: 720px; /* Maximum width of 720px */
    background-color: white;
    box-shadow: -5px 0 15px rgba(0, 0, 0, 0.1);
    z-index: 1001;
    transition: right 0.4s ease;
    display: flex;
    flex-direction: column;
}

.purpose-map-modal.active {
    right: 0;
}

/* Modal Content */
.purpose-map-modal-content {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

/* Modal Header */
.modal-header {
    margin-top: 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    /*border-bottom: 1px solid #eee;*/
    /*background-color: #f8f8f8;*/
}

.modal-header h3 {
    margin: 0;
    color: #353535;
    font-family: 'Lato', sans-serif;
    font-size: 18px;
    font-weight: 600;
}

.close-modal {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #888;
    transition: color 0.2s ease;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.close-modal:hover {
    color: #353535;
    background-color: #eee;
}

/* Modal Body */
.modal-body {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background-color: #fff;
}

/* Purpose Map Container */
.purpose-map-container {
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* Loading Indicator */
.modal-loading {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 200px;
    width: 100%;
    color: #777;
}

.spinner {
    border: 4px solid rgba(0, 0, 0, 0.1);
    border-radius: 50%;
    border-top: 4px solid #353535;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin-bottom: 15px;
}

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

/* Error Message */
.error-message {
    padding: 20px;
    background-color: #fff8f8;
    border-left: 4px solid #ff6b6b;
    color: #555;
    margin: 20px 0;
}

/* Make the modal body handle WordPress content properly */
.modal-body img {
    max-width: 100%;
    height: auto;
}

.modal-body iframe {
    max-width: 100%;
}

/* WordPress content styling adjustments */
.purpose-map-container h1,
.purpose-map-container h2,
.purpose-map-container h3,
.purpose-map-container h4,
.purpose-map-container h5,
.purpose-map-container h6 {
    color: #353535;
    margin-top: 1em;
    margin-bottom: 0.5em;
}

.purpose-map-container p {
    margin-bottom: 1em;
    line-height: 1.6;
}

.purpose-map-container ul,
.purpose-map-container ol {
    margin-left: 1.5em;
    margin-bottom: 1em;
}

/* Responsive adjustments */
@media (max-width: 1200px) {
    .purpose-map-modal {
        width: 60vw;
        /* max-width remains 720px */
        right: -720px;
    }
}

@media (max-width: 768px) {
    .purpose-map-modal {
        width: 80vw;
        /* max-width still applies */
        right: -720px;
    }
}

/* For mobile devices, adjust the modal width */
@media (max-width: 720px) {
    .purpose-map-modal {
        width: 100vw;
        max-width: 100vw; /* On small screens, allow full width */
        right: -100vw;
    }

    .modal-header {
        padding: 15px;
    }

    .modal-body {
        padding: 15px;
    }
}

/* Handle Gutenberg blocks properly */
.purpose-map-container .wp-block-image {
    margin-bottom: 1em;
}

.purpose-map-container .wp-block-button {
    margin-bottom: 1em;
}

.purpose-map-container .blocks-gallery-grid {
    display: flex;
    flex-wrap: wrap;
    list-style-type: none;
    padding: 0;
}

/* Body class to prevent scrolling when modal is open */
body.modal-open {
    overflow: hidden;
}

/* Modal Page Content Wrapper */
.modal-page-content {
    width: 100%;
    overflow-x: hidden;
}

/* Improve content fitting within the modal */
.modal-page-content > * {
    max-width: 100%;
}

/* Improve spacing for Gutenberg blocks */
.modal-page-content > [class^="wp-block-"] {
    margin-bottom: 1.5em;
}

/* Adjust headings for the narrower space */
.modal-page-content h1 {
    font-size: 1.8em;
}

.modal-page-content h2 {
    font-size: 1.5em;
}

.modal-page-content h3 {
    font-size: 1.3em;
}

/* Adjust table styles to fit */
.modal-page-content table {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    display: block;
}

/* Make sure embeds and iframes are responsive */
.modal-page-content .wp-embed-responsive .wp-block-embed iframe {
    max-width: 100%;
}

/* Ensure images don't overflow */
.modal-page-content img,
.modal-page-content figure,
.modal-page-content .wp-block-image {
    height: auto;
    max-width: 100%;
}

/* Adjust columns to fit better in the modal */
@media (max-width: 1200px) {
    .modal-page-content .wp-block-columns {
        flex-wrap: wrap;
    }

    .modal-page-content .wp-block-column {
        flex-basis: 100% !important;
        margin-left: 0 !important;
    }
}

/* Fix for common plugin content */
.modal-page-content .elementor-section {
    width: 100% !important;
    max-width: 100% !important;
    left: 0 !important;
}

/* Handle popular form plugins */
.modal-page-content .gform_wrapper,
.modal-page-content .wpforms-container,
.modal-page-content .wpcf7 {
    width: 100%;
}

/* Extra spacing at the bottom */
.modal-page-content::after {
    content: "";
    display: block;
    height: 40px;
}