/**
 * AdFlow Manager - Frontend Styles
 * Critical styles optimized for performance
 * Supports all content types: images, videos, iframes, HTML, and scripts
 */

/* Critical styles first for fastest rendering */
.adflow-area {
    position: relative;
    margin: 0 auto;
    overflow: hidden;
    max-width: 100% !important;
    line-height: 0 !important;
    display: block !important;
    border: 1px solid #F2F2F2; /* Slightly gray border for all areas */
    box-sizing: border-box;
}

/* Make sure single slots and visible slots display properly */
.adflow-space:only-child,
.adflow-space.adflow-visible,
.adflow-ad:not(.adflow-space) {
    position: relative;
    opacity: 1;
    visibility: visible;
    z-index: 2;
}

/* Standalone ad (single slot without rotation) */
.adflow-standalone-ad {
    position: relative !important;
    display: block !important;
    border: 1px solid #F2F2F2; /* Slightly gray border for standalone ads */
    box-sizing: border-box;
}

/* Basic ad space styles */
.adflow-space {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.5s cubic-bezier(0.25, 0.1, 0.25, 1), visibility 0.5s cubic-bezier(0.25, 0.1, 0.25, 1);
    will-change: opacity, visibility;
    z-index: 1;
    overflow: hidden;
    margin: 0 !important;
    padding: 0 !important;
    line-height: 0 !important;
    display: flex;
    justify-content: center;
    align-items: center;
    border: 1px solid #F2F2F2; /* Slightly gray border for all spaces */
    box-sizing: border-box;
}

/* Universal content styles - single rule to handle all image cases */
.adflow-space img {
    max-width: 100% !important;
    max-height: 100%;
    width: 100%;
    height: 100%;
    object-fit: contain !important;
    contain: none !important;
    contain-intrinsic-size: unset !important;
    margin: 0 !important;
    padding: 0 !important;
    display: block;
}

/* Other content types */
.adflow-space video,
.adflow-space iframe,
.adflow-space div,
.adflow-space dl,
.adflow-space p {
    max-width: 100% !important;
    max-height: 100%;
    width: 100%;
    height: 100%;
    object-fit: contain;
    box-sizing: border-box;
    margin: 0 !important;
    padding: 0 !important;
}

/* WordPress caption handling */
.adflow-space .wp-caption {
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    box-sizing: border-box;
    margin: 0 !important;
    padding: 0 !important;
    line-height: 0 !important;
}

/* Hide caption text */
.adflow-space .wp-caption-dd {
    display: none !important;
}

/* Fix TinyMCE wrapper */
.adflow-space .mceTemp {
    margin: 0 !important;
    padding: 0 !important;
    line-height: 0 !important;
}

/* Animations for transitions */
@keyframes adflowFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

.adflow-space.adflow-fade-in {
    animation: adflowFadeIn 0.5s cubic-bezier(0.25, 0.1, 0.25, 1) forwards;
}

.adflow-space.adflow-fade-out {
    animation: adflowFadeOut 0.5s cubic-bezier(0.25, 0.1, 0.25, 1) forwards;
}

/* Responsive iframe container */
.adflow-iframe-container {
    position: relative;
    width: 100%;
    height: 0;
    padding-bottom: 56.25%;
}

.adflow-iframe-container iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 0;
}

/* Video play button */
.adflow-video-play-btn {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    padding: 10px 20px;
    background-color: rgba(0, 0, 0, 0.7);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    z-index: 2;
}

.adflow-video-play-btn:hover {
    background-color: rgba(0, 0, 0, 0.9);
}

/* Enhanced responsive styles */
@media (max-width: 1200px) {
    .adflow-area {
        width: auto !important;
        max-width: 100% !important;
    }
}

/* Tablet styles */
@media (max-width: 768px) {
    .adflow-area {
        height: auto !important;
        width: 100% !important;
    }
    
    .adflow-area img,
    .adflow-area video,
    .adflow-area iframe {
        height: auto !important;
        max-width: 100% !important;
        margin: 0;
    }
    
    /* Maintain rotation behavior - only change needed styles */
    .adflow-area[data-rotation="true"] .adflow-space {
        /* Keep spaces invisible by default */
        opacity: 0;
        visibility: hidden;
    }
    
    /* Only visible space should display */
    .adflow-area[data-rotation="true"] .adflow-space.adflow-visible {
        position: relative !important;
        height: auto !important;
        opacity: 1 !important;
        visibility: visible !important;
    }
    
    /* Single spaces (non-rotation) */
    .adflow-space:only-child {
        position: relative !important;
        height: auto !important;
    }
    
    .adflow-space img {
        object-fit: contain !important;
        height: auto !important;
    }

            .adflow-standalone-ad {
            max-width: 92vw !important;
}
}

/* Mobile styles */
@media (max-width: 480px) {
    .adflow-area {
        min-height: 0 !important;
        padding-bottom: 0 !important;
    }
    
    /* Don't override rotation visibility - removed this rule */
    /* .adflow-space {
        opacity: 1 !important;
        visibility: visible !important;
    } */
}

/* Print styles */
@media print {
    .adflow-area {
        display: none !important;
    }
}