/* ============================================================
   Image Viewer — Visor de imágenes unificado (feed + galería)
   ============================================================ */

:root {
    --image-viewer-scrim: rgba(0, 0, 0, 0.85);
    --image-viewer-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

body.image-viewer-open {
    overflow: hidden !important;
    overscroll-behavior: contain;
}

.image-viewer {
    position: fixed;
    inset: 0;
    background: var(--image-viewer-scrim);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
    touch-action: none;
}

.image-viewer[hidden],
.image-viewer[data-open="false"] {
    display: none;
}

/* Diálogo: en modo single es transparente full-area; en modo galería tiene fondo MD3 */
.image-viewer__dialog {
    position: relative;
    background: transparent;
    border-radius: 28px;
    padding: 0;
    max-width: 100vw;
    max-height: 100dvh;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.image-viewer--with-comments .image-viewer__dialog {
    background: var(--md-sys-color-surface);
    box-shadow: var(--image-viewer-shadow);
    padding: 16px;
    max-width: 92vw;
    max-height: 90dvh;
    height: auto;
}

/* Topbar: cerrar + contador */
.image-viewer__topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    flex-shrink: 0;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 5;
    pointer-events: none;
}

.image-viewer__topbar > * {
    pointer-events: auto;
}

.image-viewer--with-comments .image-viewer__topbar {
    position: static;
    padding: 0 4px 8px;
}

.image-viewer__close {
    background: rgba(0, 0, 0, 0.45);
    border: none;
    color: #ffffff;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    min-width: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s ease;
    padding: 0;
}

.image-viewer__close:hover {
    background: rgba(0, 0, 0, 0.7);
}

.image-viewer--with-comments .image-viewer__close {
    background: transparent;
    color: var(--md-sys-color-on-surface-variant);
    width: 40px;
    height: 40px;
    min-width: 40px;
}

.image-viewer--with-comments .image-viewer__close:hover {
    background: var(--md-sys-color-surface-variant);
}

.image-viewer__counter {
    font-family: 'Inter', sans-serif;
    font-size: 13px;
    color: rgba(255, 255, 255, 0.95);
    background: rgba(0, 0, 0, 0.4);
    padding: 6px 14px;
    border-radius: 16px;
}

.image-viewer--with-comments .image-viewer__counter {
    color: var(--md-sys-color-on-surface-variant);
    background: transparent;
    padding: 0;
}

/* Fila: stage central + flechas a los lados */
.image-viewer__image-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex: 1;
    min-height: 0;
    width: 100%;
}

/* Stage: contenedor con overflow hidden para clipping del transform */
.image-viewer__stage {
    flex: 1;
    min-width: 0;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

.image-viewer__image {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    display: block;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-user-drag: none;
    -webkit-touch-callout: none;
    transform-origin: 0 0;
    transition: transform 0.18s ease;
}

.image-viewer--with-comments .image-viewer__image {
    border-radius: 12px;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.3);
    max-width: calc(88vw - 108px);
    max-height: 52dvh;
}

.image-viewer__image[data-zooming="true"] {
    transition: none;
    will-change: transform;
}

/* Botones de navegación prev/next */
.image-viewer__nav {
    background: rgba(0, 0, 0, 0.45);
    border: 1.5px solid rgba(255, 255, 255, 0.4);
    color: #ffffff;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    min-width: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s ease;
    padding: 0;
    flex-shrink: 0;
    z-index: 2;
}

.image-viewer__nav:hover {
    background: rgba(0, 0, 0, 0.7);
}

.image-viewer__nav[hidden] {
    display: none;
}

.image-viewer--with-comments .image-viewer__nav {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.5);
    color: var(--md-sys-color-on-surface);
}

.image-viewer--with-comments .image-viewer__nav:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* Panel de comentarios (solo modo galería) */
.image-viewer__comments-panel {
    max-height: 280px;
    overflow-y: auto;
    overscroll-behavior: contain;
    border-top: 1px solid var(--md-sys-color-outline-variant);
    margin-top: 12px;
    padding: 8px 4px 0;
    flex-shrink: 0;
    touch-action: pan-y;
    display: none;
}

.image-viewer--with-comments .image-viewer__comments-panel {
    display: block;
}

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

@media (max-width: 600px) {
    .image-viewer--with-comments .image-viewer__image {
        max-width: calc(92vw - 100px);
        max-height: 48dvh;
    }
    .image-viewer__nav {
        width: 40px;
        height: 40px;
        min-width: 40px;
    }
    .image-viewer__comments-panel {
        max-height: 220px;
    }
}

@media (min-width: 900px) {
    .image-viewer--with-comments .image-viewer__dialog {
        flex-direction: row;
        align-items: stretch;
        max-width: 1100px;
        max-height: 88dvh;
        gap: 12px;
    }
    .image-viewer--with-comments .image-viewer__image-row {
        flex: 2;
    }
    .image-viewer--with-comments .image-viewer__image {
        max-height: 80dvh;
    }
    .image-viewer--with-comments .image-viewer__comments-panel {
        flex: 1;
        max-height: none;
        border-top: none;
        border-left: 1px solid var(--md-sys-color-outline-variant);
        margin-top: 0;
        padding: 8px 4px 0 16px;
        min-width: 280px;
    }
    .image-viewer--with-comments .image-viewer__topbar {
        position: absolute;
        top: 12px;
        left: 12px;
        right: 12px;
        padding: 0;
        z-index: 5;
    }
}
