/*
 * Project-wide image preview.
 *
 * Shared by every page shell (admin, login, share pages, public namecard and
 * organization profile, portal) and driven by assets/js/shared/image_preview.js,
 * which builds the dialog on first use - no view carries any markup for it.
 *
 * The dialog takes half of the viewport, so an image is enlarged without the
 * page disappearing behind it. Zooming happens inside that fixed box: the image
 * scales with a transform and is panned by dragging, so the layout never
 * reflows while the user zooms.
 *
 * Colour comes from the admin token layer when it is present (theme.css) and
 * falls back to the light values otherwise, because the share and public
 * surfaces do not load theme.css.
 */

.image-preview {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 1090; /* above AdminLTE modals (1050) and SweetAlert2 (1060) */
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background-color: rgba(9, 12, 16, 0.78);
}

/* `hidden` is the source of truth for the closed state, so the flex display
   above must not win over it. */
.image-preview[hidden] {
    display: none;
}

.image-preview__dialog {
    position: relative;
    display: flex;
    width: 50vw;
    height: 50vh;
    overflow: hidden;
    border-radius: 0.75rem;
    background-color: var(--color-surface-raised, #ffffff);
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.45);
}

/*
 * Half of a phone screen is too small to read an image in, so the dialog takes
 * most of the width there. This is the one place the half-screen rule is
 * deliberately relaxed.
 */
@media (max-width: 768px) {
    .image-preview {
        padding: 8px;
    }

    .image-preview__dialog {
        width: 92vw;
        height: 62vh;
    }
}

.image-preview__stage {
    position: relative;
    display: flex;
    flex: 1;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    cursor: zoom-in;
    /* The stage owns its gestures: pinch/drag must not scroll the page. */
    touch-action: none;
}

.image-preview__stage--zoomed {
    cursor: grab;
}

.image-preview__stage--panning {
    cursor: grabbing;
}

.image-preview__img {
    display: block;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    transform-origin: center center;
    transition: transform 0.16s ease-out;
    -webkit-user-drag: none;
    user-select: none;
}

@media (prefers-reduced-motion: reduce) {
    .image-preview__img {
        transition: none;
    }
}

/* ---------------------------------------------------------------------------
 * Toolbar
 *
 * Sits over the image, so it keeps its own dark surface and white glyphs
 * rather than the dialog tokens - a photo can be any colour.
 * ------------------------------------------------------------------------ */

.image-preview__toolbar {
    position: absolute;
    top: 10px;
    right: 10px;
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 4px;
    border-radius: 999px;
    background-color: rgba(17, 20, 24, 0.72);
    color: #ffffff;
}

.image-preview__btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background-color: transparent;
    color: inherit;
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
}

@media (pointer: coarse) {
    .image-preview__btn {
        width: 44px;
        height: 44px;
    }
}

.image-preview__btn:hover:not(:disabled) {
    background-color: rgba(255, 255, 255, 0.18);
}

.image-preview__btn:focus-visible {
    outline: 2px solid #ffffff;
    outline-offset: -2px;
}

.image-preview__btn:disabled {
    opacity: 0.4;
    cursor: default;
}

.image-preview__zoom {
    min-width: 52px;
    padding: 0 4px;
    text-align: center;
    font-size: 13px;
    font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------------------------
 * Click targets on the page
 * ------------------------------------------------------------------------ */

.image-preview-target {
    cursor: zoom-in;
}

.image-preview-target:focus-visible {
    outline: 2px solid var(--color-focus, #1148c7);
    outline-offset: 2px;
}

body.image-preview-open {
    overflow: hidden;
}
