/* ===== Gallery Lightbox Styles ===== */
.gallery-lightbox {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    /* Use dynamic viewport height where supported, fallback to regular vh */
    height: 100vh;
    height: 100dvh;
    background: rgba(0, 0, 0, 0.95);
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    opacity: 0;
    transition: opacity 300ms cubic-bezier(0.4, 0, 0.2, 1);
    padding: 20px;
    box-sizing: border-box;
    /* Add safe area support */
    padding-top: max(20px, env(safe-area-inset-top));
    padding-bottom: max(20px, env(safe-area-inset-bottom));
    padding-left: max(20px, env(safe-area-inset-left));
    padding-right: max(20px, env(safe-area-inset-right));
}

.gallery-lightbox.active {
    display: flex !important;
    opacity: 1;
}

.lightbox-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
    z-index: 9999;
}

.lightbox-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    transform: scale(0.9);
    transition: transform 300ms cubic-bezier(0.4, 0, 0.2, 1);
    /* Safe area for navigation buttons */
    padding: 0 80px 60px 80px;
    box-sizing: border-box;
}

.gallery-lightbox.active .lightbox-container {
    transform: scale(1);
}

.lightbox-media {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.lightbox-image {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    opacity: 0;
    transition: opacity 200ms ease;
}

.lightbox-image.loaded {
    opacity: 1;
}

.lightbox-video {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    border-radius: 8px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
    outline: none;
}

.lightbox-video:focus {
    box-shadow: 0 0 0 3px rgba(212, 175, 55, 0.5), 0 20px 40px rgba(0, 0, 0, 0.5);
}

/* Navigation Buttons */
.lightbox-close {
    position: fixed;
    /* Use safe-area-inset-top and safe-area-inset-right with fallbacks */
    top: max(20px, calc(20px + env(safe-area-inset-top)));
    right: max(20px, calc(20px + env(safe-area-inset-right)));
    width: 44px;
    height: 44px;
    background: rgba(255, 255, 255, 0.9);
    border: none;
    border-radius: 50%;
    font-size: 24px;
    font-weight: bold;
    color: #000;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 44px;
    z-index: 10001;
    transition: all 200ms cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.lightbox-close:hover {
    background: #fff;
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.lightbox-close:focus {
    outline: 2px solid #d4af37;
    outline-offset: 2px;
}

.lightbox-prev, .lightbox-next {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 50px;
    height: 50px;
    background: rgba(255, 255, 255, 0.9);
    border: none;
    border-radius: 50%;
    font-size: 18px;
    font-weight: bold;
    color: #000;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10001;
    transition: all 200ms cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.lightbox-prev:hover, .lightbox-next:hover {
    background: #fff;
    transform: translateY(-50%) scale(1.1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.lightbox-prev:focus, .lightbox-next:focus {
    outline: 2px solid #d4af37;
    outline-offset: 2px;
}

.lightbox-prev {
    left: 20px;
}

.lightbox-next {
    right: 20px;
}

.lightbox-prev::before {
    margin-top: -2px;
    content: '‹';
    font-size: 24px;
    line-height: 1;
}

.lightbox-next::before {
    margin-top: -2px;
    content: '›';
    font-size: 24px;
    line-height: 1;
}

.lightbox-counter {
    position: fixed;
    /* Use safe-area-inset-bottom with fallback */
    bottom: max(6px, calc(6px + env(safe-area-inset-bottom)));
    left: 50%;
    transform: translateX(-50%);
    color: white;
    background: rgba(0, 0, 0, 0.8);
    padding: 10px 20px;
    border-radius: 25px;
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    z-index: 10001;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* ===== Responsive Adjustments ===== */
@media (max-width: 1024px) {
    .lightbox-container {
        padding: 0 70px 60px 70px;
    }
}

@media (max-width: 768px) {
    .gallery-lightbox {
        padding: 15px;
        padding-top: max(15px, env(safe-area-inset-top));
        padding-bottom: max(15px, env(safe-area-inset-bottom));
        padding-left: max(15px, env(safe-area-inset-left));
        padding-right: max(15px, env(safe-area-inset-right));
    }
    
    .lightbox-container {
        padding: 0 30px 50px 30px;
    }
    
    .lightbox-close {
        top: max(15px, calc(15px + env(safe-area-inset-top)));
        right: max(15px, calc(15px + env(safe-area-inset-right)));
        width: 40px;
        height: 40px;
        font-size: 20px;
    }

    .lightbox-prev, .lightbox-next {
        width: 44px;
        height: 44px;
        font-size: 16px;
    }
    
    .lightbox-prev {
        left: 15px;
    }
    
    .lightbox-next {
        right: 15px;
    }
    
    .lightbox-counter {
        bottom: max(15px, calc(15px + env(safe-area-inset-bottom)));
        padding: 8px 16px;
        font-size: 13px;
    }
}

@media (max-width: 480px) {
    .gallery-lightbox {
        padding: 10px;
        padding-top: max(10px, env(safe-area-inset-top));
        padding-bottom: max(10px, env(safe-area-inset-bottom));
        padding-left: max(10px, env(safe-area-inset-left));
        padding-right: max(10px, env(safe-area-inset-right));
    }
    
    .lightbox-container {
        padding: 0 20px 40px 20px;
    }
    
    .lightbox-close {
        width: 36px;
        height: 36px;
        font-size: 18px;
        top: max(10px, calc(10px + env(safe-area-inset-top)));
        right: max(10px, calc(10px + env(safe-area-inset-right)));
    }
    
    .lightbox-prev, .lightbox-next {
        width: 40px;
        height: 40px;
    }
    
    .lightbox-prev {
        left: 10px;
    }
    
    .lightbox-next {
        right: 10px;
    }
    
    .lightbox-counter {
        bottom: max(10px, calc(10px + env(safe-area-inset-bottom)));
        font-size: 12px;
        padding: 6px 12px;
    }
}

/* Very small screens - stack navigation */
@media (max-width: 380px) {
    .lightbox-container {
        padding: 0 10px 35px 10px;
    }
    
    .lightbox-prev, .lightbox-next {
        width: 36px;
        height: 36px;
        font-size: 14px;
    }
    
    .lightbox-prev {
        left: 5px;
    }
    
    .lightbox-next {
        right: 5px;
    }
}

/* ===== High Contrast Mode Support ===== */
@media (prefers-contrast: high) {
    .lightbox-close,
    .lightbox-prev,
    .lightbox-next {
        background: white;
        border: 2px solid black;
    }
    
    .lightbox-counter {
        background: black;
        border: 2px solid white;
    }
}

/* ===== Reduced Motion Support ===== */
@media (prefers-reduced-motion: reduce) {
    .gallery-lightbox,
    .lightbox-container,
    .lightbox-close,
    .lightbox-prev,
    .lightbox-next,
    .lightbox-image {
        transition: none;
    }
    
    .gallery-lightbox.active .lightbox-container {
        transform: scale(1);
    }
}

/* ===== Keyboard Navigation Indicator ===== */
.gallery-lightbox:focus-within .lightbox-close,
.gallery-lightbox:focus-within .lightbox-prev,
.gallery-lightbox:focus-within .lightbox-next {
    box-shadow: 0 0 0 3px rgba(212, 175, 55, 0.5);
}