

/**
 * Modern Popup System
 * Apple-inspired design with smooth animations and glass morphism
 */

/* CSS Custom Properties for easy theming */
:root {
    /* Colors */
    --popup-backdrop-color: rgba(0, 0, 0, 0.4);
    --popup-backdrop-blur: 12px;
    --popup-bg-color: rgba(255, 255, 255, 0.98);
    --popup-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    --popup-border-radius: 20px;

    /* Close button */
    --close-btn-bg: rgba(255, 255, 255, 0.9);
    --close-btn-hover: rgba(255, 255, 255, 1);
    --close-btn-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);

    /* Animations */
    --popup-transition-duration: 0.4s;
    --popup-spring-easing: cubic-bezier(0.34, 1.56, 0.64, 1);
    --popup-ease-out: cubic-bezier(0.22, 0.61, 0.36, 1);

    /* Responsive */
    --popup-max-width: min(90vw, 700px);
    --popup-max-height: min(90vh, 700px);
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    :root {
        --popup-backdrop-color: rgba(0, 0, 0, 0.75);
        --popup-bg-color: rgba(30, 30, 30, 0.98);
        --close-btn-bg: rgba(50, 50, 50, 0.9);
        --close-btn-hover: rgba(60, 60, 60, 1);
        --popup-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    :root {
        --popup-transition-duration: 0.1s;
        --popup-spring-easing: ease-out;
    }
}

/* Popup Overlay with Backdrop Blur */
#popupOverlay {
    position: fixed;
    inset: 0;
    background-color: var(--popup-backdrop-color);
    backdrop-filter: blur(var(--popup-backdrop-blur));
    -webkit-backdrop-filter: blur(var(--popup-backdrop-blur));
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;

    /* Animation setup */
    visibility: hidden;
    opacity: 0;
    transition: opacity var(--popup-transition-duration) var(--popup-ease-out),
    visibility var(--popup-transition-duration) var(--popup-ease-out),
    backdrop-filter var(--popup-transition-duration) var(--popup-ease-out);
}

#popupOverlay.visible {
    visibility: visible;
    opacity: 1;
}

/* Popup Content Container */
.popup-content {
    position: relative;
    width: auto;  /* Changed from fixed width */
    height: auto; /* Changed from fixed height */
    max-width: min(90vw, 700px);
    max-height: 90vh;
    background: var(--popup-bg-color);
    border-radius: var(--popup-border-radius);
    box-shadow: var(--popup-shadow);
    overflow: hidden;

    /* Animation setup */
    transform: scale(0.9) translateY(20px);
    transition: transform var(--popup-transition-duration) var(--popup-spring-easing),
    box-shadow var(--popup-transition-duration) var(--popup-ease-out);

    /* Prevent content shift */
    will-change: transform;
    contain: layout style;
}

/* Animate in when visible */
#popupOverlay.visible .popup-content {
    transform: scale(1) translateY(0);
}

@media (max-width: 799px) {
    .popup-content {
        max-width: min(400px, 85vw);
        max-height: 85vh;
    }
}


/* Image Handling with Loading State */
.popup-content picture,
.popup-content img {
    display: block;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 90vh;
    object-fit: scale-down; /* Ensures image never exceeds natural size */
    object-position: center;
    
    /* Smooth image loading */
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.close-btn {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 36px;
    height: 36px;
    
    /* Dark semi-transparent background for visibility on all images */
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    transition: all 0.2s ease-out;

    /* Text styling for the X */
    color: rgba(255, 255, 255, 0.9);
    font-size: 18px;
    font-weight: 400;
    line-height: 1;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;

    /* Better click target */
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

/* Close button hover state */
.close-btn:hover {
    background: rgba(0, 0, 0, 0.7);
    border-color: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
    color: white;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

/* Active state */
.close-btn:active {
    transform: scale(0.95);
    background: rgba(0, 0, 0, 0.6);
}

/* Focus state for accessibility */
.close-btn:focus-visible {
    outline: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15),
                0 0 0 3px rgba(255, 255, 255, 0.5);
}


/* Loading skeleton for images */
.popup-content:not(.loaded) img {
    background: linear-gradient(
            90deg,
            rgba(0, 0, 0, 0.05) 25%,
            rgba(0, 0, 0, 0.1) 50%,
            rgba(0, 0, 0, 0.05) 75%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* Performance optimizations */
#popupOverlay * {
    /* Prevent text selection on popup */
    user-select: none;
    -webkit-user-select: none;
}

/* Allow text selection in specific areas if needed */
.popup-content .selectable {
    user-select: text;
    -webkit-user-select: text;
}

/* Optional: Add subtle entrance animation for content */
@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}