/**
 * MM Ads Background Styles
 * Styles for background image display
 * 
 * @package MM_Ads
 * @since 1.0.0
 */

/* ==========================================================================
   Background Container
   ========================================================================== */

#samm-km-ads-background-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    z-index: -1;
    pointer-events: none;
    opacity: 1;
    transition: opacity 0.5s ease-in-out;
}

/* Show background when consent is given */
body.samm-km-ads-has-consent #samm-km-ads-background-container {
    opacity: 1;
}

/* ==========================================================================
   Background Overlay (Image)
   ========================================================================== */

.samm-km-ads-background-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-size: cover;
    background-position: center center;
    background-repeat: no-repeat;
    background-attachment: fixed;
    filter: brightness(0.9) contrast(1.1);
    transition: filter 0.3s ease;
}

/* Hover effect for background */
body.samm-km-ads-has-background:hover .samm-km-ads-background-overlay {
    filter: brightness(0.95) contrast(1.05);
}

/* ==========================================================================
   Clickable Area
   ========================================================================== */

.samm-km-ads-background-clickable {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
    pointer-events: auto;
    z-index: 1;
    transition: background-color 0.3s ease;
    outline: none;
}

.samm-km-ads-background-clickable:hover {
    background-color: rgba(0, 115, 170, 0.05);
}

.samm-km-ads-background-clickable:focus {
    background-color: rgba(0, 115, 170, 0.1);
    box-shadow: inset 0 0 0 3px rgba(0, 115, 170, 0.3);
}

.samm-km-ads-background-clickable:active {
    background-color: rgba(0, 115, 170, 0.15);
}

/* ==========================================================================
   Background Label
   ========================================================================== */

.samm-km-ads-background-label {
    position: absolute;
    bottom: 20px;
    right: 20px;
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    padding: 8px 12px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    z-index: 10;
    pointer-events: none;
    opacity: 0.8;
    transition: opacity 0.3s ease;
}

.samm-km-ads-background-label:hover {
    opacity: 1;
}

.samm-km-ads-background-label small {
    font-size: inherit;
    color: inherit;
}

/* ==========================================================================
   Content Area Adjustments
   ========================================================================== */

/* Main content adjustments when background is active */
body.samm-km-ads-has-background {
    position: relative;
}

body.samm-km-ads-has-background .site-content,
body.samm-km-ads-has-background .main-content,
body.samm-km-ads-has-background #main,
body.samm-km-ads-has-background #content {
    position: relative;
    z-index: 10;
    background: rgba(255, 255, 255);

    margin-top: 20px;
    border-radius: 12px 12px 0 0;
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.12);
    min-height: calc(100vh - 40px);
    overflow: hidden;
}

/* Elementor specific adjustments */
body.samm-km-ads-has-background .elementor-section-wrap {
    position: relative;
    z-index: 10;
}

body.samm-km-ads-has-background .elementor-top-section:first-child {
    margin-top: 20px;
    border-radius: 12px 12px 0 0;
    overflow: hidden;
}

body.samm-km-ads-has-background .elementor-container {
    position: relative;
    z-index: 10;
    background: rgba(255, 255, 255);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
}

/* Additional theme compatibility */
body.samm-km-ads-has-background .entry-content,
body.samm-km-ads-has-background .site-main {
    background: rgba(255, 255, 255, 0.98);
    padding: 30px;
    margin-top: 20px;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

/* Header adjustments */
body.samm-km-ads-has-background .site-header,
body.samm-km-ads-has-background header {
    position: relative;
    z-index: 20;
    background: rgba(255, 255, 255);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    box-shadow: 0 2px 20px rgba(0, 0, 0, 0.1);
}

/* Footer adjustments */
body.samm-km-ads-has-background .site-footer,
body.samm-km-ads-has-background footer {
    position: relative;
    z-index: 10;
    background: rgba(255, 255, 255);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

/* ==========================================================================
   Performance Optimizations
   ========================================================================== */

/* Promote to GPU layer for better performance */
#samm-km-ads-background-container,
.samm-km-ads-background-overlay {
    transform: translateZ(0);
    will-change: transform, opacity;
}

/* ==========================================================================
   Responsive Design
   ========================================================================== */

/* Tablet adjustments */
@media (max-width: 1024px) {
    .samm-km-ads-background-label {
        bottom: 15px;
        right: 15px;
        padding: 6px 10px;
        font-size: 10px;
    }
    
    body.samm-km-ads-has-background .site-content,
    body.samm-km-ads-has-background .main-content,
    body.samm-km-ads-has-background #main,
    body.samm-km-ads-has-background #content {
        margin-top: 15px;
        border-radius: 10px 10px 0 0;
    }
    
    body.samm-km-ads-has-background .entry-content,
    body.samm-km-ads-has-background .site-main {
        padding: 20px;
        margin-top: 15px;
    }
}

/* Hide background on mobile devices */
@media (max-width: 768px) {
    #samm-km-ads-background-container {
        display: none !important;
    }
    
    /* Reset content styles for mobile */
    body.samm-km-ads-has-background .site-content,
    body.samm-km-ads-has-background .main-content,
    body.samm-km-ads-has-background #main,
    body.samm-km-ads-has-background #content,
    body.samm-km-ads-has-background .entry-content,
    body.samm-km-ads-has-background .site-main {
        background: transparent;
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
        margin-top: 0;
        border-radius: 0;
        box-shadow: none;
        min-height: auto;
        padding: initial;
    }
    
    body.samm-km-ads-has-background .elementor-container {
        background: transparent;
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
    }
    
    body.samm-km-ads-has-background .elementor-top-section:first-child {
        margin-top: 0;
        border-radius: 0;
    }
}

/* ==========================================================================
   Dark Mode Support
   ========================================================================== */

@media (prefers-color-scheme: dark) {
    body.samm-km-ads-has-background .site-content,
    body.samm-km-ads-has-background .main-content,
    body.samm-km-ads-has-background #main,
    body.samm-km-ads-has-background #content {
        background: rgba(30, 30, 30, 0.95);
        color: #e0e0e0;
    }
    
    body.samm-km-ads-has-background .elementor-container {
        background: rgba(30, 30, 30, 0.98);
        color: #e0e0e0;
    }
    
    body.samm-km-ads-has-background .entry-content,
    body.samm-km-ads-has-background .site-main {
        background: rgba(30, 30, 30, 0.98);
        color: #e0e0e0;
    }
    
    body.samm-km-ads-has-background .site-header,
    body.samm-km-ads-has-background header {
        background: rgba(30, 30, 30, 0.95);
        color: #e0e0e0;
    }
    
    body.samm-km-ads-has-background .site-footer,
    body.samm-km-ads-has-background footer {
        background: rgba(30, 30, 30, 0.95);
        color: #e0e0e0;
    }
    
    .samm-km-ads-background-label {
        background: rgba(255, 255, 255, 0.9);
        color: #000;
    }
}

/* ==========================================================================
   High Contrast Mode
   ========================================================================== */

@media (prefers-contrast: high) {
    .samm-km-ads-background-overlay {
        filter: contrast(1.5) brightness(0.8);
    }
    
    body.samm-km-ads-has-background .site-content,
    body.samm-km-ads-has-background .main-content,
    body.samm-km-ads-has-background #main,
    body.samm-km-ads-has-background #content {
        background: rgba(255, 255, 255, 1);
        border: 2px solid #000;
    }
    
    .samm-km-ads-background-label {
        background: #000;
        color: #fff;
        border: 2px solid #fff;
    }
    
    .samm-km-ads-background-clickable:focus {
        box-shadow: inset 0 0 0 5px #000, inset 0 0 0 8px #fff;
    }
}

/* ==========================================================================
   Reduced Motion Support
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
    #samm-km-ads-background-container,
    .samm-km-ads-background-overlay,
    .samm-km-ads-background-clickable,
    .samm-km-ads-background-label {
        transition: none;
    }
    
    .samm-km-ads-background-overlay {
        background-attachment: scroll;
    }
    
    body.samm-km-ads-has-background .site-content,
    body.samm-km-ads-has-background .main-content,
    body.samm-km-ads-has-background #main,
    body.samm-km-ads-has-background #content {
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
    }
}

/* ==========================================================================
   Print Styles
   ========================================================================== */

@media print {
    #samm-km-ads-background-container {
        display: none !important;
    }
    
    body.samm-km-ads-has-background .site-content,
    body.samm-km-ads-has-background .main-content,
    body.samm-km-ads-has-background #main,
    body.samm-km-ads-has-background #content,
    body.samm-km-ads-has-background .entry-content,
    body.samm-km-ads-has-background .site-main {
        background: transparent !important;
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
        box-shadow: none !important;
        border-radius: 0 !important;
        margin-top: 0 !important;
    }
}

/* ==========================================================================
   Browser Specific Fixes
   ========================================================================== */

/* Safari specific fixes */
@supports (-webkit-appearance: none) {
    .samm-km-ads-background-overlay {
        -webkit-background-attachment: scroll; /* Fixed attachment can cause issues in Safari */
    }
}

/* Firefox specific fixes */
@-moz-document url-prefix() {
    body.samm-km-ads-has-background .site-content,
    body.samm-km-ads-has-background .main-content,
    body.samm-km-ads-has-background #main,
    body.samm-km-ads-has-background #content {
        backdrop-filter: none; /* Firefox doesn't support backdrop-filter well */
        background: rgba(255, 255, 255);
    }
}

/* Edge specific fixes */
@supports (-ms-ime-align: auto) {
    body.samm-km-ads-has-background .site-content,
    body.samm-km-ads-has-background .main-content,
    body.samm-km-ads-has-background #main,
    body.samm-km-ads-has-background #content {
        backdrop-filter: none; /* Older Edge doesn't support backdrop-filter */
        background: rgba(255, 255, 255);
    }
}

/* ==========================================================================
   Animation Keyframes
   ========================================================================== */

@keyframes samm-km-ads-background-fade-in {
    from {
        opacity: 0;
        transform: scale(1.05);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Apply fade-in animation */
body.samm-km-ads-has-consent #samm-km-ads-background-container {
    animation: samm-km-ads-background-fade-in 0.8s ease-out;
}

/* ==========================================================================
   Debugging Styles (only in WP_DEBUG mode)
   ========================================================================== */

.samm-km-ads-debug #samm-km-ads-background-container {
    border: 2px dashed red;
    z-index: 9999;
}

.samm-km-ads-debug .samm-km-ads-background-clickable {
    background: rgba(255, 0, 0, 0.1);
}

.samm-km-ads-debug .samm-km-ads-background-label::after {
    content: ' [DEBUG]';
    color: red;
    font-weight: bold;
}