/* ─────────────────────────────────────────────────────────
   ImageViewer – fullscreen overlay with zoom / pan / gallery
   ───────────────────────────────────────────────────────── */

/* Body lock when viewer is open */
.iv-body-lock,
.iv-body-lock * {
    overflow: hidden !important;
}

/* ── Overlay ─────────────────────────────────────────── */
.iv-overlay {
    position: fixed;
    inset: 0;
    z-index: 999999;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
}

.iv-overlay.iv-visible {
    opacity: 1;
    pointer-events: auto;
}

.iv-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.88);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
}

/* ── Top bar ─────────────────────────────────────────── */
.iv-topbar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: linear-gradient(180deg, rgba(0,0,0,0.65) 0%, transparent 100%);
    z-index: 10;
    gap: 12px;
}

.iv-topbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    flex: 1;
}

.iv-counter {
    font-size: 0.8rem;
    font-weight: 700;
    color: rgba(255,255,255,0.85);
    background: rgba(255,255,255,0.12);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 999px;
    padding: 3px 10px;
    white-space: nowrap;
    flex-shrink: 0;
    letter-spacing: 0.03em;
}

.iv-filename {
    font-size: 0.88rem;
    font-weight: 600;
    color: rgba(255,255,255,0.92);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.iv-topbar-right {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.iv-zoom-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: rgba(255,255,255,0.8);
    min-width: 42px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

/* ── Buttons ─────────────────────────────────────────── */
.iv-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: rgba(255,255,255,0.1);
    color: rgba(255,255,255,0.9);
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.12s ease, color 0.15s ease;
    -webkit-user-select: none;
    user-select: none;
}

.iv-btn:hover {
    background: rgba(255,255,255,0.22);
    color: #fff;
}

.iv-btn:active {
    transform: scale(0.93);
}

.iv-btn-sm {
    width: 34px;
    height: 34px;
    padding: 0;
}

.iv-close-btn:hover {
    background: rgba(220,38,38,0.7);
}

/* ── Navigation arrows ───────────────────────────────── */
.iv-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border: none;
    border-radius: 50%;
    background: rgba(255,255,255,0.08);
    color: rgba(255,255,255,0.85);
    cursor: pointer;
    transition: background 0.15s ease, transform 0.12s ease, opacity 0.15s ease;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255,255,255,0.1);
}

.iv-nav:hover {
    background: rgba(255,255,255,0.2);
    color: #fff;
    transform: translateY(-50%) scale(1.08);
}

.iv-nav:active {
    transform: translateY(-50%) scale(0.94);
}

.iv-nav-left {
    left: 16px;
}

.iv-nav-right {
    right: 16px;
}

.iv-nav-hidden {
    opacity: 0;
    pointer-events: none;
}

/* ── Stage (image container) ─────────────────────────── */
.iv-stage {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5;
    cursor: default;
    overflow: hidden;
    touch-action: none;
}

.iv-image {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    transition: opacity 0.18s ease;
    will-change: transform, opacity;
    transform-origin: center center;
    -webkit-user-drag: none;
    user-select: none;
    position: relative;
    z-index: 1;
}

/* ── Spinner ─────────────────────────────────────────── */
.iv-spinner {
    position: absolute;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.iv-spinner-icon {
    color: rgba(255,255,255,0.6);
    animation: iv-spin 0.7s linear infinite;
    filter: drop-shadow(0 0 6px rgba(255,255,255,0.15));
}

@keyframes iv-spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* ── Gallery strip ───────────────────────────────────── */
.iv-gallery {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 16px;
    background: linear-gradient(0deg, rgba(0,0,0,0.65) 0%, transparent 100%);
    overflow-x: auto;
    overflow-y: hidden;
    z-index: 10;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.25) transparent;
}

.iv-gallery::-webkit-scrollbar {
    height: 4px;
}

.iv-gallery::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.25);
    border-radius: 99px;
}

.iv-gallery::-webkit-scrollbar-track {
    background: transparent;
}

.iv-gallery-thumb {
    flex: 0 0 52px;
    height: 52px;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    border: 2px solid transparent;
    transition: border-color 0.15s ease, transform 0.12s ease, opacity 0.15s ease;
    opacity: 0.55;
}

.iv-gallery-thumb:hover {
    opacity: 0.85;
    transform: scale(1.06);
}

.iv-gallery-active {
    border-color: rgba(255,255,255,0.9);
    opacity: 1;
    transform: scale(1.08);
    box-shadow: 0 0 12px rgba(255,255,255,0.25);
}

.iv-gallery-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* ── Responsive adjustments ──────────────────────────── */
@media (max-width: 640px) {
    .iv-topbar {
        padding: 8px 10px;
    }

    .iv-filename {
        display: none;
    }

    .iv-btn-sm {
        width: 30px;
        height: 30px;
    }

    .iv-nav {
        width: 40px;
        height: 40px;
    }

    .iv-nav-left { left: 8px; }
    .iv-nav-right { right: 8px; }

    .iv-gallery-thumb {
        flex: 0 0 42px;
        height: 42px;
    }

    .iv-zoom-label {
        display: none;
    }
}

@media (max-width: 400px) {
    .iv-topbar-right {
        gap: 2px;
    }

    .iv-counter {
        font-size: 0.72rem;
        padding: 2px 7px;
    }

    .iv-gallery {
        padding: 8px 10px;
        gap: 4px;
    }

    .iv-gallery-thumb {
        flex: 0 0 36px;
        height: 36px;
    }
}

/* ── Dark-theme body for overlay (already dark) ──────── */
/* Ensure elements inside viewer always use light text */
.iv-overlay .iv-topbar,
.iv-overlay .iv-gallery,
.iv-overlay .iv-nav,
.iv-overlay .iv-btn {
    color-scheme: dark;
}
