/* In-app image viewer — pairs with js/utlis/image-viewer.js.
 *
 * Deliberately palette-independent: this sits over the page as a full-screen
 * dark surface on every page it is loaded on, teacher-themed or not, so it does
 * not read the dashboard custom properties.
 */

.imgv-overlay {
    position: fixed;
    inset: 0;
    z-index: 12000;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(8, 12, 18, 0.94);
    /* iOS: keep the image clear of the notch and the home indicator. */
    padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
}

.imgv-overlay.is-open {
    display: flex;
    animation: imgvFade 0.18s ease;
}

@keyframes imgvFade {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* Locks the page behind the overlay — without it a touch drag scrolls the
   conversation under the image. */
body.imgv-open {
    overflow: hidden;
}

.imgv-stage {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

.imgv-img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 6px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    animation: imgvZoom 0.18s ease;
}

@keyframes imgvZoom {
    from { transform: scale(0.96); opacity: 0; }
    to   { transform: scale(1); opacity: 1; }
}

.imgv-overlay.is-loading .imgv-img,
.imgv-overlay.is-error .imgv-img {
    visibility: hidden;
}

.imgv-spinner {
    display: none;
    position: absolute;
    width: 42px;
    height: 42px;
    border: 3px solid rgba(255, 255, 255, 0.25);
    border-top-color: #fff;
    border-radius: 50%;
    animation: imgvSpin 0.8s linear infinite;
}

.imgv-overlay.is-loading .imgv-spinner {
    display: block;
}

@keyframes imgvSpin {
    to { transform: rotate(360deg); }
}

.imgv-overlay.is-error .imgv-stage::after {
    content: 'تعذّر تحميل الصورة';
    color: #e2e8f0;
    font-size: 0.95rem;
}

/* Controls */
.imgv-close,
.imgv-nav {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    cursor: pointer;
    color: #fff;
    background: rgba(255, 255, 255, 0.14);
    border-radius: 50%;
    transition: background 0.2s ease;
}

.imgv-close:hover,
.imgv-nav:hover {
    background: rgba(255, 255, 255, 0.28);
}

.imgv-close {
    top: max(14px, env(safe-area-inset-top));
    /* RTL and LTR pages both load this file, so the close button is pinned to a
       physical corner rather than a logical one — it must never land under the
       page's own header controls. */
    left: 14px;
    width: 42px;
    height: 42px;
    font-size: 1.8rem;
    line-height: 1;
}

.imgv-nav {
    top: 50%;
    transform: translateY(-50%);
    width: 44px;
    height: 44px;
    font-size: 1.1rem;
}

.imgv-nav[hidden] {
    display: none;
}

.imgv-prev { right: 14px; }
.imgv-next { left: 14px; }

.imgv-counter {
    position: absolute;
    bottom: max(16px, env(safe-area-inset-bottom));
    color: #e2e8f0;
    font-size: 0.9rem;
    letter-spacing: 0.04em;
    background: rgba(0, 0, 0, 0.45);
    padding: 4px 12px;
    border-radius: 999px;
    /* "1 / 3" is two LTR digit runs around a neutral slash: inside an RTL page
       the bidi algorithm reorders it to read "3 / 1". Isolating it as LTR is
       what keeps the current position on the left of the total. */
    direction: ltr;
    unicode-bidi: isolate;
}

.imgv-counter[hidden] {
    display: none;
}

/* The nav buttons sit over the image on a phone; keep them out of the way of a
   pinch and small enough not to cover the subject. */
@media (max-width: 480px) {
    .imgv-nav {
        width: 38px;
        height: 38px;
    }

    .imgv-close {
        width: 38px;
        height: 38px;
        font-size: 1.6rem;
    }
}

/* A clickable image should look clickable. */
a.msg-image,
a.comment-image,
a.attachment-image-link,
.post-image,
img.c-image {
    cursor: zoom-in;
}
