/* Overlay */
#isp-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 2147483647; /* Sit on top of everything */
    background: rgba(0,0,0,0.85); /* Dark transparent background */
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Popup container - Desktop Defaults */
#isp-popup {
    background: #f5e6d8; /* Fallback color */
    box-sizing: border-box;
    position: relative; 
    
    /* Desktop Sizing */
    max-width: 90vw;
    max-height: 90vh;
    
    /* Auto width based on image size + padding */
    width: auto;
    height: auto;
    
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
    border-radius: 4px;
}

/* Slide Wrapper Defaults */
.isp-slide {
    display: none; 
    line-height: 0;
    width: 100%; 
    height: auto;
    transition: opacity 0.3s ease;
    
    /* Crucial: This ensures padding from Admin Dashboard is included in the size */
    box-sizing: border-box; 
}

/* DESKTOP: Display as block */
.isp-slide.active {
    display: block;
}

/* Image styling - Desktop */
.isp-slide img {
    display: block;
    height: auto;
    width: auto;
    max-width: 100%;
    margin: 0 auto; 
    max-height: 85vh; 
    object-fit: contain;
}

/* Close button */
#isp-close {
    position: absolute;
    top: -15px;
    right: -15px;
    background: #00000063;
    color: #fff;
    width: 30px;
    height: 30px;
    line-height: 30px;
    text-align: center;
    font-size: 24px;
    font-weight: bold;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    z-index: 100;
    transition: transform 0.2s;
}

#isp-close:hover {
    transform: scale(1.1);
    color: #cc0000;
}

/* Navigation Arrows */
.isp-prev, .isp-next {
    cursor: pointer;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 40px;
    height: 40px;
    line-height: 40px;
    text-align: center;
    color: white;
    font-weight: bold;
    font-size: 24px;
    transition: 0.3s ease;
    user-select: none;
    background-color: rgba(0,0,0,0.3); /* Dark box on Desktop */
    text-decoration: none;
    z-index: 90;
    border-radius: 4px;
}

.isp-next { right: 0; }
.isp-prev { left: 0; }

.isp-prev:hover, .isp-next:hover {
    background-color: rgba(0,0,0,0.8);
}

/* =========================================
   TABLET RESPONSIVENESS (1024px and below)
   ========================================= */
@media screen and (max-width: 1024px) {
    /* Transparent arrows on Tablet/Mobile */
    .isp-prev, .isp-next {
        background-color: transparent !important;
        text-shadow: 0 0 5px rgba(0,0,0,0.9);
        font-size: 40px;
        padding: 20px;
    }
}

/* =========================================
   MOBILE RESPONSIVENESS (768px and below)
   ========================================= */
@media screen and (max-width: 768px) {
    
    #isp-popup {
        display: flex; 
        
        /* FIX: Revert to auto width/height so it doesn't cover the whole page.
           It will only be as big as the image + padding. */
        width: auto;
        height: auto;
        
        /* Constraints to ensure it fits on screen with a small margin */
        max-width: 95vw; 
        max-height: 90vh;
    }

    /* Fix Close Button inside the box */
    #isp-close {
        top: 10px;
        right: 10px;
        background: #00000063;;
        width: 35px;
        height: 35px;
        line-height: 35px;
        font-size: 20px;
    }

    /* Slide Layout - Flex Centering */
    .isp-slide.active {
        display: flex !important;
        justify-content: center;
        align-items: center;
        
        /* Ensure it fits within the popup container */
        width: 100%;
        height: auto;
        
        /* Padding is handled by the inline style from PHP. 
           Flexbox ensures the image sits inside that padding. */
    }

    .isp-slide img {
        /* Ensure image shrinks if it hits the padding limit */
        max-width: 100% !important; 
        max-height: 80vh !important; 
        width: auto !important;
        height: auto !important;
        object-fit: contain; 
    }
}