﻿/* ===== ~/css/components/preview.css ===== */

/* ===== Full-page preview overlay (single source of truth) ===== */
.sf-preview-overlay {
    position: fixed;
    inset: 0;
    z-index: 2147483000;
    display: none;
}

    .sf-preview-overlay.show {
        display: block;
    }

.sf-preview-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,.65);
    backdrop-filter: blur(2px);
}

.sf-preview-dialog {
    position: relative;
    inset: 0;
    display: flex;
    flex-direction: column;
    width: 100vw;
    height: 100vh;
    background: #0b0b0b;
    color: #eee;
    overflow: hidden;
}

.sf-preview-head {
    position: relative;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    min-height: 48px;
    padding: .6rem .9rem;
    background: rgba(0,0,0,.35);
    border-bottom: 1px solid rgba(255,255,255,.08);
}

.sf-preview-title {
    font-weight: 600;
    font-size: 1rem;
    max-width: calc(100% - 160px);
}

.sf-preview-close {
    appearance: none;
    border: 0;
    background: transparent;
    color: #ddd;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

    .sf-preview-close:hover {
        background: rgba(255,255,255,.12);
        color: #fff;
    }

.sf-preview-body {
    position: relative;
    z-index: 1;
    flex: 1;
    background: #000;
    overflow: hidden;
    display: grid;
}

.sf-preview-frame,
.sf-preview-img,
.sf-preview-video {
    width: 100%;
    height: 100%;
    border: 0;
    background: #111;
    object-fit: contain;
    display: block;
}

.sf-preview-fallback {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ddd;
    background: #0b0b0b;
}

.sf-preview-hidden {
    display: none !important;
}

/* Buttons contrast in header for dark bg */
.sf-preview-head .btn-light {
    color: #111;
}

.sf-preview-head .btn-outline-light {
    color: #f0f0f0;
    border-color: rgba(255,255,255,.6);
}

    .sf-preview-head .btn-outline-light:hover {
        background: rgba(255,255,255,.12);
    }

/* ===== Mobile & safe-area support for preview overlay ===== */

/* Use dynamic viewport if available (prevents jump when mobile URL bar hides) */
@supports (height: 100dvh) {
    .sf-preview-dialog {
        height: 100dvh;
    }
}

/* Respect notches / home indicators */
.sf-preview-head {
    padding-top: calc(.6rem + env(safe-area-inset-top, 0));
}

.sf-preview-body {
    padding-bottom: env(safe-area-inset-bottom, 0);
    overscroll-behavior: contain; /* keep scroll contained inside overlay */
    display: grid; /* let the media surface fill all remaining space */
}

/* Missing rule your JS relies on for PDFs (embed) */
.sf-preview-embed {
    width: 100%;
    height: 100%;
    border: 0;
    background: #111;
    display: block;
}

/* Preview media base sizing (all screens) */
.sf-preview-frame,
.sf-preview-img,
.sf-preview-video,
.sf-preview-embed {
    width: 100%;
    height: 100%;
    object-fit: contain; /* letterbox instead of overflow */
}

/* Dark backdrop for videos (also good on pause) */
.sf-preview-video {
    background: #000;
    display: block;
}

/* Small screens */
@media (max-width: 576px) {
    .sf-preview-head {
        min-height: 44px;
        padding: .5rem .65rem;
    }

    .sf-preview-title {
        font-size: .95rem;
        max-width: 70vw; /* leave room for buttons/close */
    }

    .sf-preview-close {
        width: 34px;
        height: 34px;
    }

    .sf-preview-body {
        /* ensure the media gets all remaining space */
        display: grid;
    }

    .sf-preview-frame,
    .sf-preview-img,
    .sf-preview-video,
    .sf-preview-embed {
        width: 100%;
        height: 100%;
        object-fit: contain;
    }
}

/* Slightly larger phones / phablets */
@media (min-width: 577px) and (max-width: 768px) {
    .sf-preview-title {
        max-width: 75vw;
    }
}


/* === Text preview surface (for .txt, .log, etc.) === */
.sf-preview-text {
    margin: 0;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0));
    width: 100%;
    height: 100%;
    overflow: auto;
    white-space: pre-wrap; /* wrap long lines */
    word-break: break-word;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
    line-height: 1.45;
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    background: #0f0f10 !important; /* force paint (some overlays apply translucency) */
    color: #fff !important; /* hard-contrast for dark overlays */
}

/* Slightly larger font & padding on small screens */
@media (max-width: 576px) {
    .sf-preview-text {
        font-size: 15px;
        padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0));
    }
}

/* Overlay preview body base */
#previewOverlay .sf-preview-body {
    background: #0b0b0c; /* subtle, darker than .sf-preview-text */
    color: #fff;
}

@media (prefers-reduced-motion: reduce) {
    .sf-preview-overlay {
        animation: none !important;
        transition: none !important;
    }
}
