/* ============================================ */
/* IMAGE MODAL - FULLSCREEN GALLERY            */
/* Uses main browser scrollbar for native feel */
/* ============================================ */

/* Modal Base - THIS is now the scrollable element */
#imageModal.modal-responsive,
#imageModal.modal,
#imageModal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 99999;
    background: rgba(0, 0, 0, 0.95);
    padding: 0;
    margin: 0;
    /* Main scrollbar on the modal itself */
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

#imageModal.modal-responsive.show,
#imageModal.modal.show,
#imageModal.show {
    display: block !important;
    animation: imageModalFadeIn 0.3s ease-out;
}

@keyframes imageModalFadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* Backdrop - positioned inside for click detection */
#imageModal .modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: transparent;
    z-index: 0;
    pointer-events: none;
}

/* Vertical Thumbnails Container */
#imageModal #verticalThumbnails,
#imageModal .vertical-thumbnails {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 30px;
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    padding: 0;
}

/* Individual Modal Thumbnail */
#imageModal .modal-thumbnail {
    position: relative;
    width: 100%;
    max-width: 100%;
    flex-shrink: 0;
    border-radius: 12px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.02);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

#imageModal .modal-thumbnail:hover {
    transform: scale(1.005);
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
}


/* Image Counter Indicator */
#imageModal .modal-thumbnail[data-index]::after {
    content: attr(data-index);
    position: absolute;
    bottom: 16px;
    right: 16px;
    background: rgba(0, 0, 0, 0.7);
    color: rgba(255, 255, 255, 0.9);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    opacity: 0;
    transition: opacity 0.3s ease;
}

#imageModal .modal-thumbnail:hover::after {
    opacity: 1;
}

/* Close Button - Fixed position, always visible */
#imageModal .close-btn-modal-external {
    position: fixed;
    top: 20px;
    right: 30px; /* Offset to not overlap scrollbar */
    z-index: 100001;
    width: 56px;
    height: 56px;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    color: white;
    font-size: 28px;
    font-weight: 300;
    line-height: 1;
}

#imageModal .close-btn-modal-external:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: rotate(90deg) scale(1.1);
}

#imageModal .close-btn-modal-external:focus {
    outline: 2px solid rgba(255, 255, 255, 0.5);
    outline-offset: 4px;
}

#imageModal .close-btn-modal-external span {
    display: flex;
    align-items: center;
    justify-content: center;
}


/* Scroll Hint Indicator */
#imageModal .scroll-hint {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    color: rgba(255, 255, 255, 0.6);
    font-size: 13px;
    z-index: 100000;
    animation: scrollHintFade 3s ease-in-out forwards;
    pointer-events: none;
}

#imageModal .scroll-hint-icon {
    width: 24px;
    height: 40px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 12px;
    position: relative;
}

#imageModal .scroll-hint-dot {
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 4px;
    height: 8px;
    background: rgba(255, 255, 255, 0.6);
    border-radius: 2px;
    animation: scrollBounce 1.5s ease-in-out infinite;
}

@keyframes scrollHintFade {
    0%, 70% {
        opacity: 1;
    }
    100% {
        opacity: 0;
    }
}

@keyframes scrollBounce {
    0%, 100% {
        transform: translateX(-50%) translateY(0);
    }
    50% {
        transform: translateX(-50%) translateY(10px);
    }
}

/* Body class when image modal is open */
body.modal-open-image {
    /* Hide the main page scrollbar, modal has its own */
    overflow: hidden !important;
}

/* Ensure html doesn't have conflicting overflow */
html.modal-open-image {
    overflow: hidden !important;
}

/* ============================================ */
/* RESPONSIVE ADJUSTMENTS                      */
/* ============================================ */

/* Tablet */
@media (max-width: 1024px) {
    #imageModal .modal-container {
        padding: 70px 15px 30px;
    }
    
    #imageModal #verticalThumbnails,
    #imageModal .vertical-thumbnails {
        max-width: 100%;
        gap: 25px;
    }
    
    #imageModal .modal-thumbnail img {
        max-height: 80vh;
    }
    
    #imageModal .close-btn-modal-external {
        width: 50px;
        height: 50px;
        top: 15px;
        right: 20px;
        font-size: 24px;
    }
}

/* Mobile */
@media (max-width: 768px) {
    #imageModal .modal-container {
        padding: 60px 10px 25px;
    }
    
    #imageModal #verticalThumbnails,
    #imageModal .vertical-thumbnails {
        gap: 20px;
    }
    
    #imageModal .modal-thumbnail {
        border-radius: 8px;
    }
    
    #imageModal .modal-thumbnail img {
        border-radius: 8px;
        max-height: 75vh;
    }
    
    #imageModal .close-btn-modal-external {
        width: 44px;
        height: 44px;
        top: 12px;
        right: 12px;
        font-size: 22px;
    }
    
    #imageModal .modal-thumbnail[data-index]::after {
        bottom: 10px;
        right: 10px;
        padding: 4px 10px;
        font-size: 12px;
    }
    
    #imageModal .scroll-hint {
        bottom: 20px;
        font-size: 12px;
    }
}

/* Small Mobile */
@media (max-width: 480px) {
    #imageModal .modal-container {
        padding: 55px 8px 20px;
    }
    
    #imageModal #verticalThumbnails,
    #imageModal .vertical-thumbnails {
        gap: 15px;
    }
    
    #imageModal .modal-thumbnail {
        border-radius: 6px;
    }
    
    #imageModal .modal-thumbnail img {
        border-radius: 6px;
        max-height: 70vh;
    }
    
    #imageModal .close-btn-modal-external {
        width: 40px;
        height: 40px;
        top: 10px;
        right: 10px;
        font-size: 20px;
    }
}

/* Landscape Mode Adjustments */
@media (max-height: 500px) and (orientation: landscape) {
    #imageModal .modal-container {
        padding: 50px 20px 20px;
    }
    
    #imageModal #verticalThumbnails,
    #imageModal .vertical-thumbnails {
        flex-direction: row;
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        max-width: 100%;
        gap: 20px;
        padding: 0 20px;
    }
    
    #imageModal .modal-thumbnail {
        flex: 0 0 auto;
        width: auto;
        max-width: 90vw;
    }
    
    #imageModal .modal-thumbnail img {
        max-height: calc(100vh - 80px);
        max-width: 90vw;
        width: auto;
        height: auto;
    }
    
    #imageModal .scroll-hint {
        display: none;
    }
}

/* ============================================ */
/* ACCESSIBILITY                               */
/* ============================================ */

/* Focus states */
#imageModal .modal-thumbnail:focus-visible {
    outline: 3px solid rgba(255, 255, 255, 0.5);
    outline-offset: 4px;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    #imageModal.modal-responsive.show,
    #imageModal.modal.show {
        animation: none;
    }
    
    #imageModal .modal-thumbnail {
        transition: none;
    }
    
    #imageModal .close-btn-modal-external {
        transition: none;
    }
    
    #imageModal .close-btn-modal-external:hover {
        transform: none;
    }
    
    #imageModal .scroll-hint,
    #imageModal .scroll-hint-dot {
        animation: none;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    #imageModal .modal-thumbnail img {
        border: 2px solid white;
    }
    
    #imageModal .close-btn-modal-external {
        background: black;
        border: 2px solid white;
    }
}

/* Dark mode - already dark by default, minor adjustments */
body.dark-mode #imageModal .modal-thumbnail[data-index]::after {
    background: rgba(255, 255, 255, 0.15);
    color: white;
}

/* ============================================ */
/* PRINT STYLES                                */
/* ============================================ */

@media print {
    #imageModal {
        display: none !important;
    }
}
