/* Reset and base styles for images */
.document img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 1em auto;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    cursor: pointer;
}


/* Create figure-like wrapper for images with captions */
.document p:has(img[alt]:not([alt=""])) {
    text-align: center;
    margin: 2em 0;
}

/* Style for captions using adjacent text approach */
.document img[alt]:not([alt=""]) {
    margin-bottom: 0.5em;
}

/* Add captions after images using CSS content */
.document img[alt]:not([alt=""])::after {
    content: attr(alt);
    display: block;
    text-align: center;
    font-style: italic;
    font-size: 0.9em;
    color: #666;
    margin: 0.5em auto 1em auto;
    padding: 0 1em;
    max-width: 90%;
    line-height: 1.4;
    border-top: 1px solid #e0e0e0;
    padding-top: 0.5em;
    background: #f9f9f9;
    border-radius: 0 0 4px 4px;
}

/* Alternative approach - create captions using JavaScript-injected elements */
.document img[alt]:not([alt=""]) {
    position: relative;
}

/* Lightbox functionality */
.document img {
    cursor: zoom-in;
}

.document img.lightbox-active {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(1);
    z-index: 9999;
    max-width: 90vw;
    max-height: 90vh;
    cursor: zoom-out;
    border-radius: 8px;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.8);
}

/* Lightbox overlay */
.lightbox-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 9998;
    cursor: zoom-out;
}

/* Enhanced captions for better visibility */
.image-caption {
    display: block;
    text-align: center;
    font-style: italic;
    font-size: 0.9em;
    color: #555;
    margin: 0.5em auto 1.5em auto;
    padding: 0.5em 1em;
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 4px;
    max-width: 80%;
    line-height: 1.4;
}

/* Mobile responsive */
@media (max-width: 768px) {
    .document img[alt]:not([alt=""])::after,
    .image-caption {
        font-size: 0.8em;
        margin: 0.5em auto 1em auto;
        padding: 0.4em 0.8em;
        max-width: 95%;
    }
    
    .document img.lightbox-active {
        max-width: 95vw;
        max-height: 95vh;
    }
}

/* Print styles */
@media print {
    .document img {
        max-width: 100%;
        page-break-inside: avoid;
        box-shadow: none;
    }
    
    .document img[alt]:not([alt=""])::after,
    .image-caption {
        color: #000;
        background: none;
        border: none;
    }
}