/* Khung nền Lightbox */
.s-gallery .media-gallery img {
    cursor: zoom-in;
}

.media-lightbox-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.95);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 99999;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    cursor: pointer;
    box-sizing: border-box;
    padding: 15px; /* Thêm padding tổng để chống tràn trên màn hình nhỏ */
}

.media-lightbox-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* Vùng chứa ảnh */
.media-lightbox-container {
    position: relative;
    width: 100%;
    max-width: 1400px;
    max-height: 90vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
    box-sizing: border-box;
    cursor: default;
    border-radius: 12px; /* Tăng nhẹ radius cho mềm mại */
    overflow: hidden;     /* Bắt buộc có để cắt phần góc thừa của ảnh */
    box-shadow: 0 5px 25px rgba(0, 0, 0, 0.8);
    background: #000;     /* Thêm nền đen lót nếu ảnh có tỷ lệ lạ */
}

.media-lightbox-container img {
    display: block;
    max-width: 100vw;
    max-height: 85vh;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 12px;
}

.media-lightbox-close {
    position: fixed;
    top: 15px;
    right: 15px;
    width: 36px;
    height: 36px;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    font-size: 24px;
    font-weight: 300;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 5px;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.2s ease;
    border: none;
    outline: none;
    z-index: 100000;
}

.media-lightbox-close:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

.media-lightbox-spinner {
    position: absolute;
    width: 25px;
    height: 25px;
    border: 3px solid rgba(255, 255, 255, 0.2);
    border-top-color: #ffffff;
    border-radius: 50%;
    animation: lightbox-spin 0.8s linear infinite;
    display: none;
    z-index: 2;
}

.media-lightbox-overlay.is-loading .media-lightbox-spinner {
    display: block;
}

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

/* Tối ưu riêng cho thiết bị di động */
@media (max-width: 768px) {
    .media-lightbox-overlay {
        padding: 10px;
    }
    .media-lightbox-container {
        max-width: 100%;
        max-height: 80vh;
    }
    .media-lightbox-container img {
        max-width: 100%;
        max-height: 80vh;
    }
    .media-lightbox-close {
        top: 10px;
        right: 10px;
        width: 32px;
        height: 32px;
        font-size: 20px;
    }
}