/**
 * QuickPeek vertical view ("reels" overlay).
 *
 * Loaded only by resources/views/quickpeek.blade.php. Everything here is scoped
 * under #qp-vv (the overlay), body.qp-vv-open (page state while open), or the
 * .qp-vv-* affordance classes injected by public/js/quickpeek-vertical.js.
 *
 * The overlay does NOT own the post-card markup — it re-themes the classic
 * .instagram-post-card DOM, which is styled by ~1700 lines of inline CSS in
 * quickpeek.blade.php and the card component. That CSS renders later in the
 * document than this file (body <style> vs head <link>), so ties go to the page.
 * The !important density below is deliberate: this file is a retheme layer and
 * must win those fights.
 */

/* ---------------------------------------------------------------- overlay -- */

#qp-vv {
    position: fixed;
    inset: 0;
    z-index: 1040; /* above header (1030 !important) + mobile menu (999); below Bootstrap modals (1054/1055 !important) */
    background: #000;
}

#qp-vv .qp-vv-scroller {
    height: 100%;
    overflow-y: scroll;
    scroll-snap-type: y mandatory;
    overscroll-behavior: contain;
    scrollbar-width: none;
}
#qp-vv .qp-vv-scroller::-webkit-scrollbar { display: none; }

#qp-vv .qp-vv-slide {
    height: 100%;
    scroll-snap-align: start;
    scroll-snap-stop: always;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

/* Broken-video cards are display:none'd by the card's own error handler;
   collapse their slide so the snap track has no empty viewport-height gap. */
#qp-vv .qp-vv-slide:has(> .instagram-post-card[style*="display: none"]) { display: none; }

/* Lock the page behind the overlay: exactly one scroller. */
body.qp-vv-open { overflow: hidden !important; }

/* ------------------------------------------------------- card as a slide -- */

#qp-vv .instagram-post-card {
    position: relative;
    width: 100%;
    height: 100%;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    border-radius: 0 !important;
    background: #000 !important;
    box-shadow: none !important;
    display: flex;
    flex-direction: column;
    justify-content: center;
    overflow: hidden;
}

/* The card spans the full viewport on every size: media letterboxes into the
   full stage (object-fit: contain), and the bottom user/caption stack and the
   action rail run edge-to-edge. */

/* Media fills the slide, letterboxed on black — never crops, never rescales. */
#qp-vv .instagram-post-image {
    margin: 0 !important;
    max-height: none !important;
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
    overflow: hidden;
}

#qp-vv .instagram-post-image img,
#qp-vv .instagram-post-image video {
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    max-height: 100% !important;
    object-fit: contain !important;
}

/* Multi-media carousel fills the slide too (min-height 400px cap removed). */
#qp-vv .post-media-carousel,
#qp-vv .carousel-container { width: 100%; height: 100% !important; }
#qp-vv .media-slide {
    min-height: 0 !important;
    height: 100% !important;
}

/* Keep the carousel's next-arrow clear of the right-edge action rail. */
#qp-vv .carousel-nav.next-btn { right: 64px !important; }

/* Touch-primary devices: swipe drives the carousel — no arrows in vertical
   mode. (Capability query, not width: desktop windows keep arrows at any
   size since mouse users can't swipe.) */
@media (hover: none) and (pointer: coarse) {
    #qp-vv .carousel-nav { display: none !important; }
}

/* ------------------------------------------------------- overlay anatomy -- */

/* Instagram-reels bottom stack: the card is a flex column where the media
   grows and everything textual flows underneath it in normal flow (no absolute
   overlap to fight) — media, then user info + Follow, then caption, then the
   full-width link bar(s). The top of the slide holds only overlay chrome. */
#qp-vv .instagram-post-image { order: 0; }

#qp-vv .instagram-post-header {
    order: 1;
    position: static !important;
    display: flex !important;
    align-items: center !important;
    margin: 0 !important;
    padding: 10px calc(14px + env(safe-area-inset-right)) 4px calc(14px + env(safe-area-inset-left)) !important;
    border: none !important;
    background: transparent;
}

/* Follow sits at the row's right edge, vertically centered on the user info. */
#qp-vv .instagram-post-header .quickpeek-follow-btn {
    align-self: center !important;
    margin: 0 0 0 auto !important;
}

/* Action row becomes a right-edge vertical rail ending just above the bottom
   (user/caption) stack. Its wrapper div sits at the flex seam between the
   media and the bottom stack, so collapsing the wrapper to a zero-height
   anchor line and hanging the rail from it keeps the rail bottom-aligned to
   that seam whatever height the caption block takes. Same DOM node, same IDs,
   same inline onclick handlers — only presentation changes. */
#qp-vv .instagram-post-card > div:has(> .instagram-post-actions) {
    order: 0;
    position: relative;
    width: 100%;
    height: 0;
    overflow: visible;
}

#qp-vv .instagram-post-actions {
    position: absolute !important;
    right: calc(8px + env(safe-area-inset-right));
    bottom: 10px;
    z-index: 7;
    display: flex !important;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    margin: 0 !important;
    padding: 0 !important;
    background: transparent;
}

#qp-vv .vote-buttons-container {
    display: flex !important;
    flex-direction: column;
    gap: 14px;
    border: none !important;
    border-radius: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    background: transparent !important;
    overflow: visible !important;
}

#qp-vv .instagram-post-actions button {
    display: flex !important;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px !important;
    width: 46px;
    height: 46px;
    margin: 0 !important;
    padding: 4px !important;
    border: none !important;
    border-radius: 50%;
    background: rgba(30, 30, 30, 0.55) !important;
    color: #fff !important;
    font-size: 19px;
}

#qp-vv .instagram-post-actions button i { font-size: 18px !important; }

/* Hide the "Hit"/"Miss" text labels (unlabeled spans); keep the percentage
   spans (which have ids) as the small line under each icon. */
#qp-vv .like-btn > span:not([id]),
#qp-vv .dislike-btn > span:not([id]) { display: none !important; }
#qp-vv .instagram-post-actions button span[id] {
    font-size: 10px !important;
    color: #eee !important;
    line-height: 1;
}

#qp-vv .instagram-post-actions .dropdown { margin: 0 !important; }
#qp-vv .instagram-post-actions .dropdown-menu { z-index: 1080; }

/* Caption right under the user row. Keeps its 2-line clamp and see-more.
   The caption's own mini-avatar duplicates the user row's — hidden here. */
#qp-vv .instagram-post-description {
    order: 2;
    position: static !important;
    margin: 0 !important;
    padding: 0 calc(14px + env(safe-area-inset-right)) 6px calc(14px + env(safe-area-inset-left)) !important;
    background: transparent;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.75);
}
#qp-vv .instagram-post-description .author-profile-pic { display: none !important; }

/* Links go below everything, full width with padding: the "Watch: {title}"
   CTA pill and the async link preview (shown by the page JS when a caption
   URL resolves). */
#qp-vv .instagram-post-card > div:has(> a[href*="video-player"]) {
    order: 3;
    position: static !important;
    width: 100%;
    margin: 0 !important;
    padding: 0 14px 10px !important;
}

#qp-vv .post-link-preview {
    order: 4;
    width: 100%;
    margin: 0 !important;
    padding: 0 14px calc(10px + env(safe-area-inset-bottom)) !important;
}

/* Not part of the vertical grammar: the inline comments preview. */
#qp-vv .instagram-post-comments { display: none !important; }

/* ------------------------------------------------------- overlay chrome -- */

#qp-vv .qp-vv-close,
#qp-vv .qp-vv-mute {
    position: absolute;
    top: calc(14px + env(safe-area-inset-top));
    z-index: 20;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: rgba(30, 30, 30, 0.6);
    color: #fff;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}
#qp-vv .qp-vv-close { left: calc(14px + env(safe-area-inset-left)); }
#qp-vv .qp-vv-mute  { right: calc(14px + env(safe-area-inset-right)); }
#qp-vv .qp-vv-close:hover,
#qp-vv .qp-vv-mute:hover { background: rgba(60, 60, 60, 0.75); }

/* ------------------------------------------- classic-page entry affordances -- */

/* Floating "vertical view" button on the classic feed. */
.qp-vv-fab {
    position: fixed;
    right: 18px;
    bottom: 26px;
    z-index: 1029; /* under the fixed header (1030) and every modal */
    width: 52px;
    height: 52px;
    border: none;
    border-radius: 50%;
    background: #3185fc;
    color: #fff;
    font-size: 19px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}
.qp-vv-fab:hover { background: #2574e3; }
body.qp-vv-open .qp-vv-fab { display: none; }

@media (max-width: 991px) {
    /* Clear the fixed bottom .mobile-menu tab bar. */
    .qp-vv-fab { bottom: calc(84px + env(safe-area-inset-bottom)); }
}

/* Per-video vertical-mode button: center-right of the media box. Fades out
   when idle; a tap/click on the video brings it back (JS toggles --faded). */
.reel-container .instagram-post-image { position: relative; }

.qp-vv-fs {
    position: absolute;
    top: 50%;
    right: 10px;
    transform: translateY(-50%);
    z-index: 5;
    width: 38px;
    height: 38px;
    border: none;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.45);
    color: #fff;
    font-size: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 1;
    transition: opacity 0.4s ease;
}
.qp-vv-fs:hover { background: rgba(0, 0, 0, 0.7); }
.qp-vv-fs.qp-vv-fs--faded { opacity: 0; pointer-events: none; }
#qp-vv .qp-vv-fs { display: none; } /* not while already in vertical view */

/* ------------------------------------- comments modal as mobile bottom sheet -- */

@media (max-width: 991px) {
    body.qp-vv-open #commentsModal .modal-dialog {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        margin: 0;
        max-width: none;
        width: 100%;
    }
    body.qp-vv-open #commentsModal .modal-content {
        border-radius: 16px 16px 0 0;
        max-height: 78vh;
        overflow: hidden;
    }
}
