/**
 * HD Popup Manager - Frontend Styles
 * Handles popup display with animations and responsive design
 */

.spm-popup-overlay {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    background: rgba(0, 0, 0, 0.85) !important;
    backdrop-filter: blur(8px) !important;
    z-index: 2147483640 !important;
    /* Max safe 32-bit z-index minus buffer */
    display: none;
    align-items: center !important;
    justify-content: center !important;
    opacity: 0;
    visibility: visible !important;
}

.spm-popup-overlay.active {
    display: flex !important;
}

.spm-popup-container {
    position: relative !important;
    width: auto !important;
    max-width: 90% !important;
    max-height: 90% !important;
    background: transparent !important;
    border-radius: 16px !important;
    box-shadow: none !important;
    overflow: hidden !important;
    z-index: 2147483641 !important;
    display: flex !important;
    flex-direction: column !important;
    margin: auto !important;
}

/* Portrait orientation - allow taller containers */
.spm-popup-container.spm-portrait {
    max-width: 600px !important;
    max-height: 95vh !important;
}

/* Landscape orientation - wider containers */
.spm-popup-container.spm-landscape {
    max-width: 90vw !important;
    max-height: 85vh !important;
}

/* Close Button */
.spm-close-btn {
    position: absolute !important;
    top: 10px !important;
    right: 10px !important;
    width: 40px !important;
    height: 40px !important;
    border: none !important;
    border-radius: 50% !important;
    font-size: 28px !important;
    line-height: 1 !important;
    cursor: pointer !important;
    z-index: 10000000001 !important;
    transition: all 0.3s ease !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-weight: 300 !important;
}

.spm-close-btn:hover {
    transform: rotate(90deg) scale(1.1) !important;
    opacity: 0.9 !important;
}

/* Popup Content */
.spm-popup-content {
    position: relative !important;
    flex: 1 !important;
    display: flex !important;
    flex-direction: column !important;
    width: 100% !important;
    height: auto !important;
    min-height: 200px !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/* Image Popup */
.spm-image-popup {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    flex: 1 !important;
    width: 100% !important;
    min-height: 300px !important;
    visibility: visible !important;
    opacity: 1 !important;
}

.spm-image-popup img {
    display: block !important;
    max-width: 100% !important;
    max-height: 80vh !important;
    width: auto !important;
    height: auto !important;
    border-radius: 12px !important;
    object-fit: contain !important;
    visibility: visible !important;
    opacity: 1 !important;
}

.spm-image-popup a {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    text-decoration: none !important;
    max-width: 100% !important;
    max-height: 100% !important;
    width: 100% !important;
}

/* Slider Popup */
.spm-slider-popup {
    position: relative !important;
    flex: 1 !important;
    display: flex !important;
    flex-direction: column !important;
    width: 100% !important;
    min-height: 300px !important;
}

.spm-slider-container {
    position: relative !important;
    width: 100% !important;
    height: 100% !important;
    min-height: 300px !important;
    flex: 1 !important;
    overflow: hidden !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

.spm-slide {
    display: none !important;
    width: 100% !important;
    height: 100% !important;
    align-items: center !important;
    justify-content: center !important;
}

.spm-slide.active {
    display: flex !important;
}

.spm-slide img {
    display: block !important;
    max-width: 100% !important;
    max-height: 80vh !important;
    width: auto !important;
    height: auto !important;
    object-fit: contain !important;
    margin: auto !important;
    min-width: 100px !important;
    min-height: 100px !important;
}

.spm-slide a {
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}

/* Portrait slider images */
.spm-popup-container.spm-portrait .spm-slide img {
    max-height: calc(95vh - 150px);
    width: auto;
}

/* Landscape slider images */
.spm-popup-container.spm-landscape .spm-slide img {
    max-width: 100%;
    height: auto;
}

/* Slider Navigation */
.spm-slider-prev,
.spm-slider-next {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(33, 64, 154, 0.8);
    color: #ffffff;
    border: none;
    width: 50px;
    height: 50px;
    font-size: 24px;
    cursor: pointer;
    transition: all 0.3s ease;
    z-index: 5;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.spm-slider-prev:hover,
.spm-slider-next:hover {
    background: rgba(33, 64, 154, 1);
    transform: translateY(-50%) scale(1.1);
}

.spm-slider-prev {
    left: 15px;
}

.spm-slider-next {
    right: 15px;
}

/* Slider Dots */
.spm-slider-dots {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 10px;
    z-index: 5;
}

.spm-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.5);
    cursor: pointer;
    transition: all 0.3s ease;
}

.spm-dot:hover {
    background: rgba(255, 255, 255, 0.8);
    transform: scale(1.2);
}

.spm-dot.active {
    background: #21409a;
    transform: scale(1.3);
}

/* HTML Popup */
.spm-html-popup {
    padding: 40px;
    max-width: 800px;
    max-height: 80vh;
    overflow-y: auto;
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes slideDown {
    from {
        transform: translateY(-100px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        transform: translateY(100px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes slideLeft {
    from {
        transform: translateX(100%);
    }

    to {
        transform: translateX(0);
    }
}

@keyframes slideRight {
    from {
        transform: translateX(-100%);
    }

    to {
        transform: translateX(0);
    }
}

@keyframes slideOutLeft {
    from {
        transform: translateX(0);
    }

    to {
        transform: translateX(-100%);
    }
}

@keyframes slideOutRight {
    from {
        transform: translateX(0);
    }

    to {
        transform: translateX(100%);
    }
}

@keyframes zoom {
    from {
        transform: scale(0.5);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes bounce {
    0% {
        transform: scale(0.3);
        opacity: 0;
    }

    50% {
        transform: scale(1.05);
    }

    70% {
        transform: scale(0.9);
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes flipX {
    from {
        transform: perspective(400px) rotateX(90deg);
        opacity: 0;
    }

    to {
        transform: perspective(400px) rotateX(0);
        opacity: 1;
    }
}

@keyframes flipY {
    from {
        transform: perspective(400px) rotateY(90deg);
        opacity: 0;
    }

    to {
        transform: perspective(400px) rotateY(0);
        opacity: 1;
    }
}

/* Slider Transitions */
.spm-slide.transition-fade {
    animation: fadeIn 0.5s ease;
}

/* Base styles for connected animation */
.spm-slide.spm-animating-in,
.spm-slide.spm-animating-out {
    display: flex !important;
    /* Critical fix: Override display: none */
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
}

.spm-slide.spm-animating-in {
    position: absolute !important;
    z-index: 2 !important;
}

.spm-slide.spm-animating-out {
    position: relative !important;
    /* Keep relative to maintain container height */
    z-index: 1 !important;
}

/* Slide Left (Next) */
.spm-slide.transition-slide.slide-direction-next.spm-animating-in {
    animation: slideLeft 0.5s ease forwards;
}

.spm-slide.transition-slide.slide-direction-next.spm-animating-out {
    animation: slideOutLeft 0.5s ease forwards;
}

/* Slide Right (Prev) */
.spm-slide.transition-slide.slide-direction-prev.spm-animating-in {
    animation: slideRight 0.5s ease forwards;
}

.spm-slide.transition-slide.slide-direction-prev.spm-animating-out {
    animation: slideOutRight 0.5s ease forwards;
}

.spm-slide.transition-zoom {
    animation: zoom 0.5s ease;
}

.spm-slide.transition-flip {
    animation: flipX 0.6s ease;
}

/* Responsive Design */
@media (max-width: 768px) {
    .spm-popup-container {
        max-width: 95%;
        max-height: 90%;
    }

    .spm-popup-container.spm-portrait {
        max-width: 90%;
        max-height: 90vh;
    }

    .spm-popup-container.spm-landscape {
        max-width: 95%;
        max-height: 80vh;
    }

    .spm-popup-container.spm-portrait .spm-image-popup img {
        max-height: calc(90vh - 80px);
    }

    .spm-html-popup {
        padding: 20px;
    }

    .spm-slider-prev,
    .spm-slider-next {
        width: 40px;
        height: 40px;
        font-size: 20px;
    }

    .spm-slider-prev {
        left: 10px;
    }

    .spm-slider-next {
        right: 10px;
    }

    .spm-slider-dots {
        bottom: 10px;
    }

    .spm-close-btn {
        width: 36px;
        height: 36px;
        font-size: 24px;
    }
}

@media (max-width: 480px) {
    .spm-popup-container {
        max-width: 100%;
        max-height: 100%;
        border-radius: 0;
    }

    .spm-popup-container.spm-portrait {
        max-width: 100%;
        max-height: 95vh;
    }

    .spm-popup-container.spm-portrait .spm-image-popup img {
        max-height: calc(95vh - 60px);
    }

    .spm-html-popup {
        padding: 15px;
        font-size: 14px;
    }

    .spm-slider-prev,
    .spm-slider-next {
        width: 35px;
        height: 35px;
        font-size: 18px;
    }

    .spm-dot {
        width: 10px;
        height: 10px;
    }
}

/* Responsive Image Adjustments */
.spm-popup-container.responsive {
    width: auto;
    height: auto;
}

.spm-popup-container.responsive img {
    max-width: 100%;
    height: auto;
}

/* Accessibility */
.spm-popup-overlay:focus {
    outline: 2px solid #21409a;
    outline-offset: 2px;
}

.spm-close-btn:focus {
    outline: 2px solid #ffffff;
    outline-offset: 2px;
}

/* Loading State */
.spm-popup-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
}

.spm-popup-loading::after {
    content: '';
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #21409a;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}