/**
 * Waverick Gallery Lightbox - PhotoSwipe 5 Custom Styling
 * Clean, minimal - hides all default UI and creates custom buttons
 *
 * @since 2026-02-05
 */

/* ========================================
   1. Z-INDEX & BASE - CRITICAL FOR FIXED POSITIONING
   ======================================== */

/* Prevent body scroll when lightbox is open */
body.pswp-open,
html.pswp-open {
    overflow: hidden !important;
    position: fixed !important;
    width: 100% !important;
    height: 100% !important;
}

/* PhotoSwipe root - MUST be fixed and cover viewport */
.pswp {
    z-index: 99999 !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    overflow: hidden !important;
}

.pswp__bg {
    background: rgba(0, 0, 0, 0.95) !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
}

/* ========================================
   2. HIDE DEFAULT PHOTOSWIPE UI ELEMENTS
   Keep top-bar visible (contains close button)
   ======================================== */

/* Style the top bar - don't hide it, close button is inside */
.pswp__top-bar {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    height: auto !important;
    padding: 0 !important;
    background: transparent !important;
    z-index: 100 !important;
    pointer-events: none; /* Let clicks pass through except on buttons */
}

/* Hide buttons EXCEPT close and arrows (more specific selectors below) */
.pswp__button--zoom,
.pswp__button--fs,
.pswp__button--share {
    display: none !important;
}

/* Hide default icons - we create our own */
.pswp__icn,
.pswp__icn svg {
    display: none !important;
}

/* Hide default counter - we create custom one */
.pswp__counter:not(.pswp__counter) {
    display: none !important;
}

/* Hide captions */
.pswp__caption,
.pswp__dynamic-caption {
    display: none !important;
}

/* ========================================
   3. CUSTOM COUNTER - Top left pill
   ======================================== */

/* Our custom counter element (from JS uiRegister) */
.pswp__counter.pswp__counter {
    display: block !important;
    position: fixed !important;
    left: 20px !important;
    top: 20px !important;
    font-family: -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 14px;
    font-weight: 500;
    color: #fff;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 20px;
    padding: 8px 16px;
    z-index: 100;
}

/* ========================================
   4. CUSTOM CLOSE BUTTON - Top right
   ======================================== */

.pswp__button--close.pswp__button--close {
    display: flex !important;
    align-items: center;
    justify-content: center;
    position: fixed !important;
    right: 20px !important;
    top: 20px !important;
    width: 44px !important;
    height: 44px !important;
    background: rgba(0, 0, 0, 0.5) !important;
    backdrop-filter: blur(10px) !important;
    -webkit-backdrop-filter: blur(10px) !important;
    border-radius: 50% !important;
    border: none !important;
    cursor: pointer !important;
    z-index: 100 !important;
    padding: 0 !important;
    margin: 0 !important;
    pointer-events: auto !important; /* Enable clicks (parent has pointer-events: none) */
    opacity: 1 !important;
    visibility: visible !important;
}

.pswp__button--close:hover {
    background: rgba(255, 80, 80, 0.7) !important;
}

/* Hide default icon inside close */
.pswp__button--close .pswp__icn,
.pswp__button--close svg {
    display: none !important;
}

/* Custom X icon */
.pswp__button--close::before,
.pswp__button--close::after {
    content: '';
    position: absolute;
    width: 18px;
    height: 2px;
    background: #fff;
    border-radius: 1px;
}

.pswp__button--close::before {
    transform: rotate(45deg);
}

.pswp__button--close::after {
    transform: rotate(-45deg);
}

/* ========================================
   5. NAVIGATION ARROWS - Center of sides
   ======================================== */

.pswp__button--arrow.pswp__button--arrow {
    display: flex !important;
    align-items: center;
    justify-content: center;
    position: fixed !important;
    top: 50% !important;
    width: 50px !important;
    height: 50px !important;
    margin-top: -25px !important; /* Center vertically */
    background: rgba(0, 0, 0, 0.5) !important;
    backdrop-filter: blur(10px) !important;
    -webkit-backdrop-filter: blur(10px) !important;
    border-radius: 50% !important;
    border: none !important;
    cursor: pointer !important;
    z-index: 100 !important;
    padding: 0 !important;
}

.pswp__button--arrow:hover {
    background: rgba(255, 140, 0, 0.7) !important;
}

.pswp__button--arrow--prev.pswp__button--arrow--prev {
    left: 20px !important;
    right: auto !important;
}

.pswp__button--arrow--next.pswp__button--arrow--next {
    right: 20px !important;
    left: auto !important;
}

/* Hide default arrow icons */
.pswp__button--arrow .pswp__icn,
.pswp__button--arrow svg {
    display: none !important;
}

/* Custom arrow triangles */
.pswp__button--arrow::before {
    content: '';
    display: block;
    width: 0;
    height: 0;
    border-style: solid;
}

.pswp__button--arrow--prev::before {
    border-width: 8px 12px 8px 0;
    border-color: transparent #fff transparent transparent;
    margin-right: 3px;
}

.pswp__button--arrow--next::before {
    border-width: 8px 0 8px 12px;
    border-color: transparent transparent transparent #fff;
    margin-left: 3px;
}

/* ========================================
   6. IMAGE CONTAINER & STACKING
   ======================================== */

/* DO NOT override .pswp__scroll-wrap or .pswp__container
   PhotoSwipe uses transforms for positioning - flex breaks it */

.pswp__img {
    object-fit: contain !important;
}

/* Allow items to show zoom content - don't hide overflow */
.pswp__item {
    overflow: visible !important;
}

/* When closing, hide all items - prevents "ghost image" on swipe up */
.pswp--closing .pswp__item {
    opacity: 0 !important;
    transition: opacity 0.15s ease-out !important;
}

/* During close animation, fade out background */
.pswp--closing .pswp__bg {
    opacity: 0 !important;
    transition: opacity 0.2s ease-out !important;
}

/* ========================================
   7. PRELOADER
   ======================================== */

.pswp__preloader {
    position: fixed !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    z-index: 50;
}

.pswp__preloader__icn {
    width: 40px !important;
    height: 40px !important;
    border: 3px solid rgba(255, 140, 0, 0.3) !important;
    border-top-color: #FF8C00 !important;
    border-radius: 50% !important;
    animation: pswp-spin 0.8s linear infinite !important;
}

@keyframes pswp-spin {
    to { transform: rotate(360deg); }
}

/* ========================================
   8. KEYBOARD HINTS (Desktop)
   ======================================== */

.pswp__keyboard-hints {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 16px;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 20px;
    padding: 8px 20px;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.7);
    transition: opacity 0.3s ease;
    z-index: 100;
}

.pswp__keyboard-hints--hidden {
    opacity: 0;
    pointer-events: none;
}

/* ========================================
   9. ERROR MESSAGE
   ======================================== */

.pswp__error-msg {
    color: #ff6b6b;
    font-size: 16px;
    text-align: center;
}

/* ========================================
   10. MOBILE RESPONSIVE
   ======================================== */

@media (max-width: 768px) {
    /* CRITICAL: Ensure lightbox covers viewport on mobile */
    .pswp {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        height: 100dvh !important;
    }

    .pswp__bg {
        position: fixed !important;
        width: 100vw !important;
        height: 100vh !important;
        height: 100dvh !important;
    }

    /* Images on mobile - allow zoom to work (no max constraints) */
    .pswp__img {
        /* Don't constrain size - PhotoSwipe handles zoom via transforms */
        object-fit: contain !important;
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
    }

    /* Allow zoom overflow - CRITICAL for pinch-to-zoom */
    .pswp__item {
        overflow: visible !important;
    }

    .pswp__zoom-wrap {
        /* Allow zoom to expand beyond viewport */
        will-change: transform;
    }

    /* NO padding on mobile - images go edge to edge */
    .pswp__container {
        padding: 0 !important;
    }

    /* Counter - top left, semi-transparent over image */
    .pswp__counter.pswp__counter {
        font-size: 12px;
        padding: 6px 12px;
        left: 12px !important;
        top: max(12px, env(safe-area-inset-top)) !important;
        background: rgba(0, 0, 0, 0.4) !important;
    }

    /* Close button - top right, over image */
    .pswp__button--close.pswp__button--close {
        width: 44px !important;
        height: 44px !important;
        right: 12px !important;
        top: max(12px, env(safe-area-inset-top)) !important;
        background: rgba(0, 0, 0, 0.4) !important;
    }

    .pswp__button--close::before,
    .pswp__button--close::after {
        width: 16px;
    }

    /* Arrows OVERLAY on image - semi-transparent */
    .pswp__button--arrow.pswp__button--arrow {
        width: 44px !important;
        height: 44px !important;
        margin-top: -22px !important;
        background: rgba(0, 0, 0, 0.3) !important;
    }

    .pswp__button--arrow--prev.pswp__button--arrow--prev {
        left: 8px !important;
    }

    .pswp__button--arrow--next.pswp__button--arrow--next {
        right: 8px !important;
    }

    .pswp__button--arrow--prev::before {
        border-width: 7px 11px 7px 0;
    }

    .pswp__button--arrow--next::before {
        border-width: 7px 0 7px 11px;
    }

    /* Hide keyboard hints on mobile */
    .pswp__keyboard-hints {
        display: none !important;
    }
}

/* ========================================
   11. TOUCH FEEDBACK
   ======================================== */

.pswp__button--close:active,
.pswp__button--arrow:active {
    transform: scale(0.9);
}

.pswp__button--arrow:active {
    transform: scale(0.9) translateY(0) !important;
    margin-top: -22px !important;
}

/* ========================================
   12. ACCESSIBILITY
   ======================================== */

.pswp__button--close:focus,
.pswp__button--arrow:focus {
    outline: 2px solid #FF8C00;
    outline-offset: 2px;
}

.pswp__button--close:focus:not(:focus-visible),
.pswp__button--arrow:focus:not(:focus-visible) {
    outline: none;
}
