.viewer-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: none;
    background:
        radial-gradient(circle at top, rgba(94, 167, 255, 0.18), transparent 34%),
        linear-gradient(180deg, var(--bg-deep) 0%, var(--bg-deep-2) 100%);
}

.viewer-modal.visible {
    display: block;
}

.viewer-shell {
    position: relative;
    width: 100%;
    height: 100dvh;
    min-height: 100dvh;
}

.viewer-topbar,
.viewer-bottombar {
    position: absolute;
    left: 0;
    right: 0;
    z-index: 3;
    display: flex;
    align-items: center;
    gap: 8px;
}

.viewer-topbar {
    top: 0;
    padding: calc(env(safe-area-inset-top) + 10px) 12px 10px;
    background: linear-gradient(to bottom, rgba(7, 17, 31, 0.9), rgba(7, 17, 31, 0));
}

.viewer-bottombar {
    bottom: 0;
    justify-content: center;
    padding: 10px 12px calc(env(safe-area-inset-bottom) + 12px);
    background: linear-gradient(to top, rgba(12, 23, 40, 0.92), rgba(12, 23, 40, 0));
}

.viewer-meta {
    flex: 1;
    min-width: 0;
    color: var(--text-muted);
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.viewer-stage {
    position: absolute;
    inset: 0;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: calc(env(safe-area-inset-top) + 60px) 10px calc(env(safe-area-inset-bottom) + 70px);
    touch-action: none;
}

.viewer-stage.is-preview-only::before {
    content: attr(data-preview-message);
    position: absolute;
    bottom: calc(env(safe-area-inset-bottom) + 80px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 4;
    padding: 6px 14px;
    border-radius: 12px;
    background: rgba(11, 20, 35, 0.88);
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.78rem;
    font-weight: 600;
    white-space: nowrap;
    pointer-events: none;
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.24);
}

.viewer-stage.is-loading::after {
    content: "";
    position: absolute;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 3px solid rgba(159, 176, 200, 0.24);
    border-top-color: #8fd2ff;
    box-shadow: 0 0 24px rgba(94, 167, 255, 0.22);
    animation: viewer-spin 0.8s linear infinite;
}

.viewer-image {
    display: block;
    width: auto;
    height: auto;
    max-width: calc(100vw - 20px);
    max-height: calc(100dvh - 150px);
    object-fit: contain;
    transform-origin: center center;
    will-change: transform;
    user-select: none;
    -webkit-user-drag: none;
    touch-action: none;
    transition: opacity 160ms ease;
}

.viewer-image.is-loading {
    opacity: 0.12;
}

.viewer-close,
.viewer-nav,
.viewer-delete {
    min-height: 44px;
    padding: 0 14px;
    border-radius: 14px;
    background: rgba(15, 23, 42, 0.9);
    color: var(--text);
    border: 1px solid var(--border);
    font-weight: 700;
}

.viewer-close {
    min-width: 76px;
}

.viewer-nav {
    min-width: 68px;
}

.viewer-delete {
    background: rgba(127, 29, 29, 0.68);
    color: #fee2e2;
    border-color: rgba(239, 68, 68, 0.35);
}

.viewer-reload {
    min-width: 76px;
    min-height: 44px;
    padding: 0 14px;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--primary), var(--primary-strong));
    color: white;
    border: 1px solid rgba(94, 167, 255, 0.38);
    font-weight: 700;
    box-shadow: 0 8px 18px rgba(45, 127, 249, 0.22);
}

.viewer-nav:disabled {
    opacity: 0.45;
    cursor: default;
}

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

@media (min-width: 700px) {
    .viewer-topbar {
        padding-left: 18px;
        padding-right: 18px;
    }

    .viewer-bottombar {
        padding-left: 18px;
        padding-right: 18px;
    }

    .viewer-stage {
        padding-left: 18px;
        padding-right: 18px;
    }
}

/* ─── Viewer Video ─────────────────────────────────────────────────────────────── */

.video-viewer-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

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

.video-viewer-container {
    position: relative;
    width: 100%;
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.video-viewer-video {
    width: 100%;
    max-height: 90vh;
    background: #000;
    border-radius: 8px;
}

.video-viewer-close {
    position: absolute;
    top: -40px;
    right: 0;
    background: none;
    border: none;
    color: #fff;
    font-size: 28px;
    cursor: pointer;
    padding: 8px 12px;
    line-height: 1;
    opacity: 0.8;
    transition: opacity 0.15s;
}

.video-viewer-close:hover {
    opacity: 1;
}
