/* ================================
   MODAL FIXES - ADD TO modals.css
   ================================ */

/* Fix 1: Additional image size class when buttons are present */
.modal-image.has-buttons {
    max-height: 45vh; /* Reduce image size to make room for buttons */
}

/* Combine button + long caption adjustments */
.modal-image.has-buttons.has-long-caption {
    max-height: 40vh;
}

.modal-image.has-buttons.has-very-long-caption {
    max-height: 35vh;
}

/* Fix 2: Ensure buttons stay BEHIND zoomed image */
.modal-info {
    position: relative;
    z-index: 1; /* Lower z-index than modal navigation */
}

.modal-image {
    position: relative;
    z-index: 5; /* Higher z-index so zoomed image appears above buttons */
}

.modal-info-buttons {
    position: relative;
    z-index: 1; /* Behind the image when zoomed */
}

/* Mobile adjustments for buttons */
@media screen and (max-width: 768px) {
    .modal-image.has-buttons {
        max-height: 35vh;
    }
    
    .modal-image.has-buttons.has-long-caption {
        max-height: 30vh;
    }
    
    .modal-image.has-buttons.has-very-long-caption {
        max-height: 25vh;
    }
}

/* ================================
   MODAL BUTTON STYLES
   Add these styles to your modals.css file
   ================================ */

/* Button container in modal */
.modal-info-buttons {
    margin-top: 15px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: auto;
}

.modal-info-buttons .btn {
    width: 100%;
    text-align: center;
    pointer-events: auto;
    cursor: pointer;
}

/* Make sure buttons are clickable (override pointer-events: none from modal-info) */
.modal-info .modal-info-buttons {
    pointer-events: auto;
}

.modal-info .modal-info-buttons a {
    pointer-events: auto;
}

/* ================================
   GALLERY MODAL - FIXED VERSION
   Caption visibility & dynamic sizing
   ================================ */

.gallery-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10000;
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.gallery-modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 1;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(10px);
}

/* ================================
   MAIN MODAL CONTENT CONTAINER
   ================================ */
.modal-content {
    position: relative;
    width: 90%;
    max-width: 1200px;
    max-height: 90vh;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 30px 60px rgba(0, 0, 0, 0.3);
    transform: scale(0.8);
    transition: transform 0.3s ease;
    
    /* CRITICAL: Flex container to stack image area + thumbnails */
    display: flex;
    flex-direction: column;
}

.gallery-modal.active .modal-content {
    transform: scale(1);
}

/* ================================
   CLOSE BUTTON
   ================================ */
.modal-close {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 50px;
    height: 50px;
    background: rgba(139, 69, 19, 0.9);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.5rem;
    z-index: 10;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-close:hover {
    background: rgba(139, 69, 19, 1);
    transform: scale(1.1);
}

/* ================================
   NAVIGATION ARROWS
   ================================ */
.modal-navigation {
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    transform: translateY(-50%);
    display: flex;
    justify-content: space-between;
    padding: 0 20px;
    z-index: 10;
    pointer-events: none;
}

.nav-btn {
    width: 60px;
    height: 60px;
    background: rgba(139, 69, 19, 0.9);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.2rem;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
}

.nav-btn:hover {
    background: rgba(139, 69, 19, 1);
    transform: scale(1.1);
}

.nav-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: scale(1);
}

/* ================================
   IMAGE + CAPTION CONTAINER - FIXED
   ================================ */
.modal-image-container {
    /* CRITICAL: Flex container with flex-grow to fill available space */
    flex: 1;
    min-height: 0; /* CRITICAL: Allows flex item to shrink below content size */
    
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 40px 20px; /* Top padding for close button clearance */
    position: relative;
    overflow: hidden;
    gap: 15px; /* Space between image and caption */
}

/* ================================
   IMAGE SIZING - DYNAMIC
   ================================ */
.modal-image {
    /* CRITICAL: Use flex-shrink so image gives space to caption */
    flex-shrink: 1;
    
    /* Maximum size constraints */
    max-width: 100%;
    max-height: 55vh; /* Default: plenty of space for caption */
    
    object-fit: contain;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    transition: transform 0.3s ease;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    pointer-events: auto;
    cursor: zoom-in;
    transform-origin: center center;
}

/* Shrink image when caption is longer */
.modal-image.has-long-caption {
    max-height: 45vh; /* Give more space to caption */
}

.modal-image.has-very-long-caption {
    max-height: 35vh; /* Even more space for very long captions */
}

/* ================================
   CAPTION AREA - FIXED
   ================================ */
.modal-info {
    /* CRITICAL: No flex-shrink, caption takes space it needs */
    flex-shrink: 0;
    
    text-align: center;
    width: 90%;
    max-width: 700px;
    padding: 15px 20px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 15px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    pointer-events: none;
    
    /* CRITICAL: Max height with scroll for extremely long captions */
    max-height: 25vh;
    overflow-y: auto;
}

/* Scrollbar styling for caption overflow */
.modal-info::-webkit-scrollbar {
    width: 6px;
}

.modal-info::-webkit-scrollbar-track {
    background: rgba(240, 240, 240, 0.5);
    border-radius: 3px;
}

.modal-info::-webkit-scrollbar-thumb {
    background: rgba(139, 69, 19, 0.5);
    border-radius: 3px;
}

.modal-info::-webkit-scrollbar-thumb:hover {
    background: rgba(139, 69, 19, 0.7);
}

.modal-info h3 {
    color: #8b4513;
    margin-bottom: 0.5rem;
    font-size: 1.3rem;
    pointer-events: none;
    line-height: 1.3;
}

.modal-info p {
    color: #666;
    font-style: italic;
    margin: 0;
    line-height: 1.6;
}

/* ================================
   THUMBNAILS CAROUSEL - FIXED
   ================================ */
.modal-thumbnails {
    /* CRITICAL: Fixed height, no flex-grow */
    flex-shrink: 0;
    height: 100px; /* Fixed height */
    
    display: flex;
    gap: 10px;
    padding: 20px;
    background: rgba(248, 246, 240, 0.9);
    border-top: 1px solid rgba(139, 69, 19, 0.1);
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: thin;
    scrollbar-color: #8b4513 #f0f0f0;
}

.modal-thumbnails::-webkit-scrollbar {
    height: 6px;
}

.modal-thumbnails::-webkit-scrollbar-track {
    background: #f0f0f0;
    border-radius: 3px;
}

.modal-thumbnails::-webkit-scrollbar-thumb {
    background: #8b4513;
    border-radius: 3px;
}

.thumbnail {
    width: 80px;
    height: 60px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 2px solid transparent;
    object-fit: cover;
    flex-shrink: 0;
}

.thumbnail:hover {
    transform: scale(1.1);
    border-color: rgba(139, 69, 19, 0.5);
}

.thumbnail.active {
    border-color: #8b4513;
    transform: scale(1.1);
    box-shadow: 0 4px 15px rgba(139, 69, 19, 0.3);
}

/* ================================
   AMAZON-STYLE ZOOM - NO CHANGES
   ================================ */
.modal-image.zooming {
    cursor: crosshair;
    transform: scale(2.5);
    transition: none;
}

/* ================================
   MOBILE RESPONSIVE
   ================================ */
@media screen and (max-width: 768px) {
    .modal-content {
        width: 95%;
        max-height: 95vh;
        border-radius: 15px;
    }
    
    .modal-close {
        width: 40px;
        height: 40px;
        top: 10px;
        right: 10px;
        font-size: 1.2rem;
    }
    
    .modal-navigation {
        padding: 0 10px;
    }
    
    .nav-btn {
        width: 45px;
        height: 45px;
        font-size: 1rem;
    }
    
    .modal-image-container {
        padding: 50px 20px 15px;
    }
    
    .modal-image {
        max-height: 45vh; /* More space for caption on mobile */
    }
    
    .modal-image.has-long-caption {
        max-height: 35vh;
    }
    
    .modal-image.has-very-long-caption {
        max-height: 30vh;
    }
    
    .modal-info {
        width: 95%;
        padding: 10px 15px;
        max-height: 30vh; /* More scroll space on mobile */
    }
    
    .modal-info h3 {
        font-size: 1.1rem;
    }
    
    .modal-thumbnails {
        padding: 15px;
        gap: 8px;
        height: 85px;
    }
    
    .thumbnail {
        width: 60px;
        height: 45px;
    }
}

/* Small Mobile */
@media screen and (max-width: 480px) {
    .modal-image {
        max-height: 40vh;
    }
    
    .modal-info {
        max-height: 35vh;
    }
}