/* Modern Custom Modal Styles - Large Image Support */
:root {
    --modal-bg: rgba(0, 0, 0, 0.8);
    --modal-content-bg: #ffffff;
    --modal-border: #e5e7eb;
    --modal-text: #1f2937;
    --modal-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.3);
    --close-btn-bg: #ffffff;
    --close-btn-hover: #ef4444;
    --close-btn-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    --primary-green: #10b981;
    --primary-green-light: #34d399;
}

/* Modal Overlay */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--modal-bg);
    backdrop-filter: blur(8px);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    padding: 20px;
    /* Prevent edge touching */
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* Modal Container - Larger Size */
.modal-container {
    position: relative;
    max-width: 900px;
    /* Increased from 600px */
    width: 95%;
    max-height: 95vh;
    /* Increased from 90vh */
    background: var(--modal-content-bg);
    border-radius: 20px;
    box-shadow: var(--modal-shadow);
    overflow: hidden;
    transform: scale(0.8) translateY(50px);
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
}

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

/* Modal Close Button */
.modal-close {
    position: absolute;
    top: 15px;
    right: 15px;
    width: 40px;
    height: 40px;
    background: var(--close-btn-bg);
    border: 2px solid var(--modal-border);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 10;
    box-shadow: var(--close-btn-shadow);
    transition: all 0.3s ease;
    color: #6b7280;
    font-size: 24px;
    font-weight: 300;
    line-height: 1;
}

.modal-close::before {
    content: "×";
}

.modal-close:hover {
    background: var(--close-btn-hover);
    color: white;
    border-color: var(--close-btn-hover);
    transform: rotate(90deg) scale(1.1);
}

/* Modal Header */
.modal-header {
    padding: 25px 30px 20px;
    background: linear-gradient(135deg, var(--primary-green) 0%, var(--primary-green-light) 100%);
    color: white;
    flex-shrink: 0;
    /* Prevent shrinking */
}

.modal-title {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 700;
    text-align: center;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Modal Body - Scrollable */
.modal-body {
    flex: 1;
    overflow-y: auto;
    /* Enable vertical scrolling */
    overflow-x: hidden;
    max-height: calc(95vh - 120px);
    /* Account for header height */
    padding: 0;

    /* Custom scrollbar */
    scrollbar-width: thin;
    scrollbar-color: var(--primary-green) #f1f5f9;
}

/* Webkit scrollbar styling */
.modal-body::-webkit-scrollbar {
    width: 8px;
}

.modal-body::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 4px;
}

.modal-body::-webkit-scrollbar-thumb {
    background: var(--primary-green);
    border-radius: 4px;
}

.modal-body::-webkit-scrollbar-thumb:hover {
    background: var(--primary-green-light);
}

/* Popup Image - Responsive */
.popup-image {
    width: 100%;
    height: auto;
    max-width: 100%;
    display: block;
    object-fit: contain;
    /* Maintain aspect ratio */
    border-bottom: 1px solid var(--modal-border);
}

/* Large image handling */
.popup-image.large {
    max-height: 60vh;
    /* Limit height for very tall images */
    object-fit: cover;
}

/* Popup Content */
.popup-content {
    padding: 30px;
    color: var(--modal-text);
    line-height: 1.7;
    font-size: 1.1rem;
}

.popup-content h1,
.popup-content h2,
.popup-content h3,
.popup-content h4 {
    color: var(--primary-green);
    margin-top: 0;
    margin-bottom: 1rem;
}

.popup-content p {
    margin-bottom: 1.2rem;
}

.popup-content ul,
.popup-content ol {
    margin-bottom: 1.2rem;
    padding-left: 1.5rem;
}

.popup-content li {
    margin-bottom: 0.5rem;
}

/* Image + Content Layout */
.modal-body.has-both {
    display: flex;
    flex-direction: column;
}

.modal-body.has-both .popup-image {
    flex-shrink: 0;
    max-height: 50vh;
    /* Limit image height when there's also text */
}

.modal-body.has-both .popup-content {
    flex: 1;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .modal-overlay {
        padding: 10px;
    }

    .modal-container {
        max-width: 100%;
        width: 100%;
        max-height: 100vh;
        border-radius: 0;
    }

    .modal-header {
        padding: 20px 20px 15px;
    }

    .modal-title {
        font-size: 1.25rem;
    }

    .popup-content {
        padding: 20px;
        font-size: 1rem;
    }

    .popup-image.large {
        max-height: 50vh;
    }

    .modal-body.has-both .popup-image {
        max-height: 40vh;
    }
}

@media (max-width: 480px) {
    .modal-header {
        padding: 15px;
    }

    .modal-title {
        font-size: 1.1rem;
    }

    .popup-content {
        padding: 15px;
        font-size: 0.95rem;
    }

    .modal-close {
        width: 35px;
        height: 35px;
        top: 10px;
        right: 10px;
        font-size: 20px;
    }
}

/* Landscape orientation on mobile */
@media (max-height: 500px) and (orientation: landscape) {
    .modal-container {
        max-height: 100vh;
    }

    .popup-image.large,
    .modal-body.has-both .popup-image {
        max-height: 30vh;
    }
}

/* Loading state */
.modal-body.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
}

.modal-body.loading::before {
    content: '';
    width: 40px;
    height: 40px;
    border: 4px solid #f3f4f6;
    border-top: 4px solid var(--primary-green);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

    100% {
        transform: rotate(360deg);
    }
}

/* Animation enhancements */
.modal-container {
    animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
    0% {
        opacity: 0;
        transform: scale(0.8) translateY(50px);
    }

    100% {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* Focus trap for accessibility */
.modal-overlay {
    outline: none;
}

.modal-container:focus {
    outline: 2px solid var(--primary-green);
    outline-offset: 2px;
}