/* Lightbox - Premium Glass Design & Performance Optimized */
:root {
    --lightbox-z-index: 100000;
    --lightbox-transition: 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
    --glass-bg: rgba(255, 255, 255, 0.1);
    --glass-border: rgba(255, 255, 255, 0.2);
    --glass-blur: blur(16px);
    --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
}

/* Cursor for clickable images */
.post-content img {
    cursor: pointer !important;
    /* Force pointer for lightbox */
    transition: transform 0.3s ease;
}

.post-content img:hover {
    transform: scale(1.01);
    /* Subtle zoom hint */
}

.lightbox-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(15, 23, 42, 0.75);
    /* Modern semi-transparent dark glass */
    backdrop-filter: blur(24px) saturate(150%);
    /* Smooth, premium blur */
    -webkit-backdrop-filter: blur(24px) saturate(150%);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: var(--lightbox-z-index);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    will-change: opacity, visibility;
    /* Performance Hint */
}

.lightbox-overlay.active {
    opacity: 1;
    visibility: visible;
}

.lightbox-content {
    position: relative;
    max-width: 100%;
    max-height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    transform: scale(0.96);
    transition: transform var(--lightbox-transition);
    width: 100%;
    height: 100%;
    pointer-events: none;
    will-change: transform;
    /* Performance Hint */
}

.lightbox-overlay.active .lightbox-content {
    transform: scale(1);
}

.lightbox-image {
    max-width: 90%;
    max-height: 85vh;
    object-fit: contain;
    border-radius: 12px;
    box-shadow:
        0 25px 50px -12px rgba(0, 0, 0, 0.5),
        0 0 0 1px rgba(255, 255, 255, 0.1);
    opacity: 0;
    transition: opacity 0.3s ease;
    cursor: default;
    pointer-events: auto;
    will-change: opacity;
    /* Performance Hint */
}

.lightbox-image.loaded {
    opacity: 1;
}

/* Glass Buttons - Unified Style */
.lightbox-btn {
    position: absolute;
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--glass-border);
    color: rgba(255, 255, 255, 0.9);
    cursor: pointer;
    z-index: calc(var(--lightbox-z-index) + 10);
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 50%;
    box-shadow: var(--glass-shadow);
    padding: 0;
    outline: none;
    opacity: 1;
    visibility: visible;
}

/* Focus styles for Accessibility */
.lightbox-btn:focus-visible {
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.5);
    border-color: #3B82F6;
}

/* Hide buttons when idle */
.lightbox-overlay.idle .lightbox-btn {
    opacity: 0;
    visibility: hidden;
    transform: scale(0.9);
    pointer-events: none;
    /* Ensure they are not clickable when hidden */
}

.lightbox-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.5);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
    color: #fff;
    /* Removed transform on container to prevent position jump */
}

/* Scale icon instead of button */
.lightbox-btn:hover svg {
    transform: scale(1.15);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Press effect on icon - Fixes jumping issue */
.lightbox-btn:active svg {
    transform: scale(0.95);
    transition: transform 0.1s ease;
}

/* Close Button */
.lightbox-close {
    top: 24px;
    right: 24px;
    width: 48px;
    height: 48px;
}

/* Navigation Buttons */
.lightbox-nav {
    top: 50%;
    transform: translateY(-50%);
    width: 56px;
    height: 56px;
}

.lightbox-overlay.idle .lightbox-nav {
    transform: translateY(-50%) scale(0.9);
}

.lightbox-prev {
    left: 32px;
}

.lightbox-next {
    right: 32px;
}

/* Counter */
.lightbox-counter {
    position: absolute;
    top: 32px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(15, 23, 42, 0.7);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: rgba(255, 255, 255, 0.9);
    font-size: 14px;
    font-weight: 600;
    padding: 8px 16px;
    border-radius: 20px;
    z-index: calc(var(--lightbox-z-index) + 5);
    transition: opacity 0.3s ease, transform 0.3s ease;
    pointer-events: none;
    letter-spacing: 1px;
}

.lightbox-overlay.idle .lightbox-counter {
    opacity: 0;
    transform: translateX(-50%) translateY(-10px);
}

/* Caption */
.lightbox-caption-container {
    position: absolute;
    bottom: 32px;
    left: 0;
    width: 100%;
    display: flex;
    justify-content: center;
    pointer-events: none;
    z-index: calc(var(--lightbox-z-index) + 5);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.lightbox-overlay.idle .lightbox-caption-container {
    opacity: 0;
    transform: translateY(10px);
}

.lightbox-caption {
    background: rgba(15, 23, 42, 0.7);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: rgba(255, 255, 255, 0.95);
    font-size: 15px;
    font-weight: 500;
    padding: 12px 28px;
    border-radius: 40px;
    text-align: center;
    max-width: 80%;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    pointer-events: auto;
    letter-spacing: 0.3px;
}

.lightbox-caption:empty {
    display: none;
}

/* Loader */
.lightbox-loader {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 48px;
    height: 48px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    border-top-color: #fff;
    animation: lightbox-spin 0.8s ease-in-out infinite;
    z-index: var(--lightbox-z-index);
    margin-left: -24px;
    margin-top: -24px;
    will-change: transform;
}

@keyframes lightbox-spin {
    to {
        transform: rotate(360deg);
    }
}

/* Scroll Lock */
body.lightbox-open {
    overflow: hidden;
    padding-right: 15px;
}

/* Responsive Optimization */
@media (max-width: 1024px) {
    .lightbox-image {
        max-width: 95%;
    }
}

@media (max-width: 768px) {
    .lightbox-close {
        top: 16px;
        right: 16px;
        width: 40px;
        height: 40px;
        background: rgba(0, 0, 0, 0.3);
    }

    .lightbox-nav,
    .lightbox-nav:hover,
    .lightbox-nav:focus,
    .lightbox-nav:active {
        width: 44px;
        height: 44px;
        background: rgba(0, 0, 0, 0.3);
        /* Force center vertically on mobile for ALL states */
        top: 50% !important;
        bottom: auto !important;
        transform: translateY(-50%) !important;
    }

    .lightbox-overlay.idle .lightbox-nav {
        transform: translateY(-50%) scale(0.9) !important;
    }

    .lightbox-prev {
        left: 12px;
    }

    .lightbox-next {
        right: 12px;
    }

    .lightbox-image {
        max-width: 100%;
        max-height: 80vh;
        margin-top: 0;
    }

    .lightbox-counter {
        top: 24px;
        font-size: 13px;
        padding: 6px 14px;
    }

    .lightbox-caption-container {
        bottom: 24px;
    }

    .lightbox-caption {
        font-size: 14px;
        padding: 10px 20px;
        max-width: 85%;
        background: rgba(0, 0, 0, 0.8);
    }
}

@media (max-width: 900px) and (orientation: landscape) {
    .lightbox-image {
        max-height: 85vh;
        margin-top: 0;
    }

    .lightbox-nav {
        top: 50%;
        bottom: auto;
        transform: translateY(-50%);
    }

    .lightbox-caption-container {
        bottom: 16px;
    }
}