/**
 * VIDO Popup - Frontend Styles
 */

/* Overlay che toàn màn hình */
.vido-popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.75);
    z-index: 999999;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

/* Đảm bảo multiple popups vẫn center */
.vido-popup-overlay[data-popup-index] {
    justify-content: center !important;
    align-items: center !important;
}

/* Hiển thị overlay khi active */
.vido-popup-overlay.vido-active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* Ẩn popup (dùng cho sequential) */
.vido-popup-overlay.vido-hidden {
    display: none !important;
}

/* Container popup */
.vido-popup-container {
    position: relative;
    max-width: 90%;
    max-height: 85vh;
    width: auto;
    height: auto;
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    transform: scale(0.7);
    transition: transform 0.3s ease;
    -webkit-tap-highlight-color: transparent;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-left: auto;
    margin-right: auto;
    left: 0;
    right: 0;
}

.vido-popup-overlay.vido-active .vido-popup-container {
    transform: scale(1);
}

/* Content popup */
.vido-popup-content {
    position: relative;
    max-width: 100%;
    max-height: 85vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.vido-popup-content img {
    display: block;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 85vh;
    object-fit: contain;
    margin: 0;
}

.vido-popup-content a {
    display: flex;
    justify-content: center;
    align-items: center;
    text-decoration: none;
    max-width: 100%;
    max-height: 85vh;
}

.vido-popup-content a:hover {
    opacity: 0.95;
}

.vido-popup-content a img {
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 85vh;
    object-fit: contain;
}

/* Close button */
.vido-popup-close {
    position: absolute;
    width: 40px;
    height: 40px;
    background-color: rgba(0, 0, 0, 0.7);
    color: #ffffff;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 28px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    transition: background-color 0.2s ease, transform 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation; /* Improve touch responsiveness */
    user-select: none;
    -webkit-user-select: none;
}

/* Close button positions */
.vido-close-top-right {
    top: 10px;
    right: 10px;
}

.vido-close-top-left {
    top: 10px;
    left: 10px;
}

.vido-close-bottom-right {
    bottom: 10px;
    right: 10px;
}

.vido-close-bottom-left {
    bottom: 10px;
    left: 10px;
}

.vido-popup-close:hover {
    background-color: rgba(0, 0, 0, 0.9);
    transform: rotate(90deg);
}

.vido-popup-close span {
    display: block;
    line-height: 1;
}

/* Custom close icon image */
.vido-close-icon-custom {
    max-width: 100%;
    max-height: 100%;
    display: block;
    object-fit: contain;
}

/* =================
   RESPONSIVE
   ================= */

/* Tablet (768px - 1024px) */
@media screen and (max-width: 1024px) and (min-width: 769px) {
    .vido-popup-container {
        max-width: 90%;
    }
    
    .vido-popup-content img {
        max-width: 100%;
    }
}

/* Mobile Landscape & Small Tablet (481px - 768px) */
@media screen and (max-width: 768px) {
    .vido-popup-overlay {
        padding: 10px;
    }
    
    .vido-popup-container {
        max-width: 95%;
        max-height: 80vh;
        border-radius: 8px;
    }

    .vido-popup-content {
        max-height: 80vh;
    }

    .vido-popup-content img,
    .vido-popup-content a img {
        max-width: 100%;
        max-height: 80vh;
        width: auto;
        height: auto;
    }

    .vido-popup-close {
        width: 44px;
        height: 44px;
        font-size: 26px;
        top: 8px;
        right: 8px;
    }
    
    /* Corner positions adjustment */
    .vido-position-top-left .vido-popup-container,
    .vido-position-top-right .vido-popup-container,
    .vido-position-bottom-left .vido-popup-container,
    .vido-position-bottom-right .vido-popup-container {
        max-width: 320px;
    }
}

/* Mobile Portrait (320px - 480px) */
@media screen and (max-width: 480px) {
    .vido-popup-overlay {
        padding: 5px;
    }
    
    .vido-popup-container {
        max-width: 98%;
        max-height: 85vh;
        border-radius: 6px;
        box-shadow: 0 5px 20px rgba(0, 0, 0, 0.3);
    }

    .vido-popup-content {
        max-height: 85vh;
        overflow: hidden;
    }

    .vido-popup-content img,
    .vido-popup-content a img {
        max-width: 100%;
        max-height: 85vh;
        width: auto;
        height: auto;
        object-fit: contain;
    }

    .vido-popup-close {
        width: 40px;
        height: 40px;
        font-size: 24px;
        top: 5px;
        right: 5px;
    }
    
    /* Force center position on mobile */
    .vido-popup-overlay[class*="vido-position-"] {
        justify-content: center;
        align-items: center;
        padding: 5px;
    }
    
    .vido-position-top-left .vido-popup-container,
    .vido-position-top-right .vido-popup-container,
    .vido-position-bottom-left .vido-popup-container,
    .vido-position-bottom-right .vido-popup-container {
        max-width: 95%;
    }
}

/* =================
   POSITIONS
   ================= */

/* Center (default) */
.vido-position-center {
    justify-content: center !important;
    align-items: center !important;
}

/* Đảm bảo container trong center position KHÔNG bị offset */
.vido-position-center .vido-popup-container {
    margin-left: auto !important;
    margin-right: auto !important;
}

/* Top */
.vido-position-top {
    justify-content: center;
    align-items: flex-start;
    padding-top: 20px;
}

/* Bottom */
.vido-position-bottom {
    justify-content: center;
    align-items: flex-end;
    padding-bottom: 20px;
}

/* Top Left */
.vido-position-top-left {
    justify-content: flex-start;
    align-items: flex-start;
    padding: 20px;
}

/* Top Right */
.vido-position-top-right {
    justify-content: flex-end;
    align-items: flex-start;
    padding: 20px;
}

/* Bottom Left */
.vido-position-bottom-left {
    justify-content: flex-start;
    align-items: flex-end;
    padding: 20px;
}

/* Bottom Right */
.vido-position-bottom-right {
    justify-content: flex-end;
    align-items: flex-end;
    padding: 20px;
}

/* Điều chỉnh container cho corner positions */
.vido-position-top-left .vido-popup-container,
.vido-position-top-right .vido-popup-container,
.vido-position-bottom-left .vido-popup-container,
.vido-position-bottom-right .vido-popup-container {
    max-width: 400px;
}

/* =================
   ANIMATIONS
   ================= */

/* Fade Animation (default) */
.vido-animation-fade .vido-popup-container {
    transform: scale(0.7) translateX(0);
    transition: transform 0.3s ease;
}

.vido-animation-fade.vido-active .vido-popup-container {
    transform: scale(1) translateX(0);
}

/* Slide Down Animation */
.vido-animation-slide-down .vido-popup-container {
    transform: translateY(-100px) translateX(0);
    transition: transform 0.4s ease;
}

.vido-animation-slide-down.vido-active .vido-popup-container {
    transform: translateY(0) translateX(0);
}

/* Fix cho multiple popups - đảm bảo không bị offset ngang */
.vido-animation-slide-down[data-popup-index] .vido-popup-container {
    transform: translateY(-100px) translateX(0) !important;
}

.vido-animation-slide-down.vido-active[data-popup-index] .vido-popup-container {
    transform: translateY(0) translateX(0) !important;
}

/* Slide Up Animation */
.vido-animation-slide-up .vido-popup-container {
    transform: translateY(100px) translateX(0);
    transition: transform 0.4s ease;
}

.vido-animation-slide-up.vido-active .vido-popup-container {
    transform: translateY(0) translateX(0);
}

/* Zoom Animation */
.vido-animation-zoom .vido-popup-container {
    transform: scale(0.3) translateX(0);
    transition: transform 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.vido-animation-zoom.vido-active .vido-popup-container {
    transform: scale(1) translateX(0);
}

/* Bounce Animation */
.vido-animation-bounce .vido-popup-container {
    transform: scale(0.5) translateX(0);
    transition: transform 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.vido-animation-bounce.vido-active .vido-popup-container {
    transform: scale(1) translateX(0);
    animation: vidoBounce 0.5s ease;
}

@keyframes vidoBounce {
    0% { transform: scale(0.5) translateX(0); }
    50% { transform: scale(1.1) translateX(0); }
    70% { transform: scale(0.95) translateX(0); }
    100% { transform: scale(1) translateX(0); }
}

/* Multiple popups - offset slightly for overlay effect */
/* CHỈ offset margin-top để tạo hiệu ứng xếp chồng */
/* KHÔNG dùng margin-left để tránh lệch ngang */

.vido-popup-overlay[data-popup-index="1"]:not(.vido-stacked-item) .vido-popup-container {
    margin-top: 20px !important;
    margin-left: auto !important;
    margin-right: auto !important;
}

.vido-popup-overlay[data-popup-index="2"]:not(.vido-stacked-item) .vido-popup-container {
    margin-top: 40px !important;
    margin-left: auto !important;
    margin-right: auto !important;
}

/* Tăng box-shadow để tạo độ sâu thay vì offset ngang */
.vido-popup-overlay[data-popup-index="1"]:not(.vido-stacked-item) .vido-popup-container {
    box-shadow: 0 15px 45px rgba(0, 0, 0, 0.35);
}

.vido-popup-overlay[data-popup-index="2"]:not(.vido-stacked-item) .vido-popup-container {
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
}

/* Đảm bảo stacked items KHÔNG có offset */
.vido-stacked-item[data-popup-index] .vido-popup-container {
    margin: 0 auto !important;
}

/* =================
   STACKED MODE (Vertical)
   ================= */

/* Wrapper cho stacked popups */
.vido-stacked-wrapper {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.75);
    z-index: 999999;
    overflow-y: auto;
    overflow-x: hidden;
    display: none; /* Ẩn ban đầu, JS sẽ hiển thị */
    flex-direction: column;
    align-items: center;
    justify-content: center; /* Center dọc khi ít popup */
    padding: 20px 10px;
    gap: 20px;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    scroll-behavior: smooth;
    box-sizing: border-box;
}

/* Nếu chỉ có 1 popup, center dọc hoàn toàn */
.vido-stacked-wrapper:has(.vido-stacked-item:only-child),
.vido-stacked-wrapper.vido-has-one {
    justify-content: center !important;
    padding-top: 20px;
    padding-bottom: 20px;
}

/* Nếu có 2 popup, flex-start nhưng padding-top lớn để nhìn thấy popup đầu */
.vido-stacked-wrapper:has(.vido-stacked-item:nth-child(2):last-child),
.vido-stacked-wrapper.vido-has-two {
    justify-content: flex-start !important;
    padding-top: 80px; /* Padding lớn hơn để nhìn thấy popup đầu */
    padding-bottom: 40px;
}

/* Nếu có nhiều popup (3+), đẩy lên trên để có thể scroll */
.vido-stacked-wrapper:has(.vido-stacked-item:nth-child(3)),
.vido-stacked-wrapper.vido-has-many {
    justify-content: flex-start !important;
    padding-top: 40px;
    padding-bottom: 40px;
}

/* Mỗi popup trong stacked mode */
.vido-popup-overlay.vido-stacked-item {
    position: relative;
    width: 100%;
    max-width: 800px;
    height: auto;
    background-color: transparent;
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    margin: 0 auto;
    padding: 0;
}

/* Container trong stacked mode */
.vido-stacked-item .vido-popup-container {
    position: relative !important;
    max-width: 100%;
    max-height: 80vh; /* Tăng từ 70vh lên 80vh cho Desktop */
    width: auto;
    height: auto;
    margin: 0 auto !important;
    left: auto !important;
    right: auto !important;
    top: auto !important;
    bottom: auto !important;
    transform: none !important;
    animation: vidoSlideInDown 0.5s ease both;
    overflow: hidden;
}

/* Content trong stacked mode - canh giữa */
.vido-stacked-item .vido-popup-content {
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    text-align: center;
    max-height: 80vh; /* Tăng từ 70vh lên 80vh */
    overflow: hidden;
    width: 100%;
    margin: 0;
    padding: 0;
}

.vido-stacked-item .vido-popup-content img {
    display: block;
    margin: 0 auto !important;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 80vh; /* Tăng từ 70vh lên 80vh */
    object-fit: contain;
}

.vido-stacked-item .vido-popup-content a {
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    max-width: 100%;
    max-height: 80vh; /* Tăng từ 70vh lên 80vh */
    margin: 0;
    padding: 0;
}

.vido-stacked-item .vido-popup-content a img {
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 80vh; /* Tăng từ 70vh lên 80vh */
    object-fit: contain;
    margin: 0 auto !important;
}

/* Override animation và position classes cho stacked mode */
.vido-stacked-item.vido-animation-fade .vido-popup-container,
.vido-stacked-item.vido-animation-slide-down .vido-popup-container,
.vido-stacked-item.vido-animation-slide-up .vido-popup-container,
.vido-stacked-item.vido-animation-zoom .vido-popup-container,
.vido-stacked-item.vido-animation-bounce .vido-popup-container {
    transform: none !important;
    transition: none !important;
}

/* Override position classes cho stacked mode */
.vido-stacked-item[class*="vido-position-"] {
    justify-content: center !important;
    align-items: center !important;
    padding: 0 !important;
}

/* Animation delay cho từng popup (cascade effect) */
.vido-stacked-item[data-popup-index="0"] .vido-popup-container {
    animation-delay: 0s;
}

.vido-stacked-item[data-popup-index="1"] .vido-popup-container {
    animation-delay: 0.15s;
}

.vido-stacked-item[data-popup-index="2"] .vido-popup-container {
    animation-delay: 0.3s;
}

.vido-stacked-item[data-popup-index="3"] .vido-popup-container {
    animation-delay: 0.45s;
}

.vido-stacked-item[data-popup-index="4"] .vido-popup-container {
    animation-delay: 0.6s;
}

.vido-stacked-item[data-popup-index="5"] .vido-popup-container {
    animation-delay: 0.75s;
}

.vido-stacked-item[data-popup-index="6"] .vido-popup-container {
    animation-delay: 0.9s;
}

.vido-stacked-item[data-popup-index="7"] .vido-popup-container {
    animation-delay: 1.05s;
}

.vido-stacked-item[data-popup-index="8"] .vido-popup-container {
    animation-delay: 1.2s;
}

.vido-stacked-item[data-popup-index="9"] .vido-popup-container {
    animation-delay: 1.35s;
}

/* Animation cho stacked items */
@keyframes vidoSlideInDown {
    from {
        opacity: 0;
        transform: translateY(-30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Reduce animation on mobile for performance */
@media screen and (max-width: 768px) {
    @keyframes vidoSlideInDown {
        from {
            opacity: 0;
            transform: translateY(-15px);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }
    
    .vido-stacked-item .vido-popup-container {
        animation-duration: 0.3s;
    }
}

/* Close button trong stacked mode */
.vido-stacked-item .vido-popup-close {
    position: absolute !important;
    top: 10px;
    right: 10px;
    left: auto !important;
    bottom: auto !important;
}

/* Reset tất cả styles có thể gây lệch */
.vido-stacked-item * {
    box-sizing: border-box;
}

.vido-stacked-item .vido-popup-container {
    float: none !important;
    clear: both;
}

/* Đảm bảo wrapper children đều center */
.vido-stacked-wrapper > .vido-stacked-item {
    align-self: center;
}

/* =================
   STACKED MODE RESPONSIVE
   ================= */

/* Tablet (769px - 1024px) */
@media screen and (max-width: 1024px) and (min-width: 769px) {
    .vido-stacked-wrapper {
        padding: 20px 10px;
        gap: 18px;
    }
    
    /* Tablet: 1 popup → center */
    .vido-stacked-wrapper.vido-has-one {
        justify-content: center !important;
    }
    
    /* Tablet: 2 popup → flex-start với padding */
    .vido-stacked-wrapper.vido-has-two {
        justify-content: flex-start !important;
        padding-top: 50px;
    }
    
    .vido-popup-overlay.vido-stacked-item {
        max-width: 90%;
    }
    
    .vido-stacked-item .vido-popup-container {
        max-height: 75vh;
    }
    
    .vido-stacked-item .vido-popup-content {
        max-height: 75vh;
    }
    
    .vido-stacked-item .vido-popup-content img,
    .vido-stacked-item .vido-popup-content a img {
        max-height: 75vh;
    }
}

/* Desktop (>1024px) - Tăng max-height để ảnh lớn hơn */
@media screen and (min-width: 1025px) {
    .vido-stacked-item .vido-popup-container {
        max-height: 80vh; /* Desktop có max-height lớn hơn */
    }
    
    .vido-stacked-item .vido-popup-content {
        max-height: 80vh;
    }
    
    .vido-stacked-item .vido-popup-content img,
    .vido-stacked-item .vido-popup-content a img {
        max-height: 80vh;
    }
}

/* Fallback cho browser không support :has() */
@supports not selector(:has(*)) {
    .vido-stacked-wrapper {
        justify-content: center; /* Default center cho tất cả */
    }
}

/* Mobile Landscape & Small Tablet (481px - 768px) */
@media screen and (max-width: 768px) {
    .vido-stacked-wrapper {
        padding: 15px 8px;
        gap: 12px;
    }
    
    /* Mobile: 1 popup → center */
    .vido-stacked-wrapper.vido-has-one {
        justify-content: center !important;
    }
    
    /* Mobile: 2 popup → center */
    .vido-stacked-wrapper.vido-has-two {
        justify-content: center !important;
    }
    
    /* Mobile: 3+ popup → flex-start */
    .vido-stacked-wrapper.vido-has-many,
    .vido-stacked-wrapper:has(.vido-stacked-item:nth-child(3)) {
        justify-content: flex-start !important;
        padding-top: 20px;
    }
    
    .vido-popup-overlay.vido-stacked-item {
        max-width: 95%;
    }
    
    .vido-stacked-item .vido-popup-container {
        border-radius: 8px;
        max-height: 65vh;
    }
    
    .vido-stacked-item .vido-popup-content {
        max-height: 65vh;
    }
    
    .vido-stacked-item .vido-popup-content img,
    .vido-stacked-item .vido-popup-content a img {
        max-height: 65vh;
    }
    
    .vido-stacked-item .vido-popup-close {
        width: 44px;
        height: 44px;
        font-size: 26px;
        top: 8px;
        right: 8px;
    }
}

/* Mobile Portrait (320px - 480px) */
@media screen and (max-width: 480px) {
    .vido-stacked-wrapper {
        padding: 10px 5px;
        gap: 10px;
    }
    
    /* Mobile portrait: 1-2 popup → center */
    .vido-stacked-wrapper.vido-has-one,
    .vido-stacked-wrapper.vido-has-two {
        justify-content: center !important;
    }
    
    .vido-popup-overlay.vido-stacked-item {
        max-width: 98%;
    }
    
    .vido-stacked-item .vido-popup-container {
        border-radius: 6px;
        box-shadow: 0 3px 15px rgba(0, 0, 0, 0.2);
        max-height: 60vh; /* Tăng từ 55vh */
    }
    
    .vido-stacked-item .vido-popup-content {
        max-height: 60vh;
    }
    
    .vido-stacked-item .vido-popup-content img,
    .vido-stacked-item .vido-popup-content a img {
        max-height: 60vh;
    }
    
    .vido-stacked-item .vido-popup-close {
        width: 40px;
        height: 40px;
        font-size: 24px;
        top: 5px;
        right: 5px;
    }
}

/* Very Small Mobile (max 360px) */
@media screen and (max-width: 360px) {
    .vido-popup-container {
        max-width: 100%;
        margin: 0 3px;
    }
    
    .vido-stacked-wrapper {
        padding: 5px 3px;
        gap: 8px;
    }
    
    .vido-popup-overlay.vido-stacked-item {
        max-width: 100%;
    }
    
    .vido-popup-close,
    .vido-stacked-item .vido-popup-close {
        width: 36px;
        height: 36px;
        font-size: 22px;
    }
}

/* Landscape Orientation on Mobile */
@media screen and (max-height: 500px) and (orientation: landscape) {
    .vido-popup-container {
        max-height: 85vh;
        max-width: 70%;
    }
    
    .vido-popup-content {
        max-height: 85vh;
    }
    
    .vido-popup-content img,
    .vido-popup-content a img {
        max-height: 85vh;
    }
    
    .vido-stacked-wrapper {
        padding: 10px 15px;
        gap: 8px;
    }
    
    /* Landscape: 1-2 popup → center */
    .vido-stacked-wrapper.vido-has-one,
    .vido-stacked-wrapper.vido-has-two {
        justify-content: center !important;
    }
    
    .vido-popup-overlay.vido-stacked-item {
        max-width: 70%;
    }
    
    .vido-stacked-item .vido-popup-container {
        max-height: 45vh; /* Nhỏ hơn để fit 2 popup */
    }
    
    .vido-stacked-item .vido-popup-content {
        max-height: 45vh;
    }
    
    .vido-stacked-item .vido-popup-content img,
    .vido-stacked-item .vido-popup-content a img {
        max-height: 45vh;
    }
}

/* High DPI screens (Retina) */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .vido-popup-container {
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
    }
}

/* Prevent zoom on double-tap for mobile */
.vido-popup-content a,
.vido-popup-content img {
    touch-action: manipulation;
}

