/**
 * Ad Placement Styles
 * Responsive ad containers with proper spacing and alignment
 */

/* General Ad Placement Styles */
.ad-placement {
    margin: 15px 0;
    text-align: center;
    position: relative;
    overflow: hidden;
}

.ad-placement.ad-placement--after_header {
    margin-top: 20px;
    margin-bottom: 25px;
}

.ad-placement.ad-placement--above_player {
    margin-bottom: 20px;
}

/* Ad Size Classes */
.ad-leaderboard {
    max-width: 728px;
    min-height: 90px;
    margin-left: auto;
    margin-right: auto;
}

.ad-medium-rectangle {
    max-width: 300px;
    min-height: 250px;
    margin-left: auto;
    margin-right: auto;
}

.ad-mobile-banner {
    max-width: 320px;
    min-height: 50px;
    margin-left: auto;
    margin-right: auto;
}

/* Sidebar Ad Container */
.ads-sidebar {
    width: 100%;
    max-width: 300px;
}

.ad-sidebar-wrapper {
    position: sticky;
    top: 20px;
}

.ad-spacer {
    background: transparent;
}

/* Native Ads in Grid */
.ad-native-grid {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 250px;
    background: #f8f9fa;
    border-radius: 8px;
    padding: 15px;
}

.ad-native-wrapper {
    width: 100%;
    max-width: 300px;
}

/* Lazy Loading States */
.ad-lazy {
    min-height: 100px;
    background: #f8f9fa;
    position: relative;
    border-radius: 4px;
}

.ad-lazy::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 30px;
    height: 30px;
    border: 3px solid #e0e0e0;
    border-top-color: #666;
    border-radius: 50%;
    animation: ad-spinner 0.8s linear infinite;
}

@keyframes ad-spinner {
    to { transform: translate(-50%, -50%) rotate(360deg); }
}

.ad-loaded {
    background: transparent;
}

.ad-loaded::before {
    display: none;
}

/* Ad Content Wrapper */
.ad-content {
    display: block;
    margin: 0 auto;
}

/* Responsive Layout */
@media (max-width: 768px) {
    /* Hide sidebar ads on mobile */
    .ads-sidebar {
        display: none;
    }

    /* Make leaderboard responsive on mobile */
    .ad-leaderboard {
        max-width: 100%;
        min-height: 50px;
    }

    .ad-placement {
        margin: 10px 0;
    }

    .ad-native-grid {
        min-height: 200px;
        padding: 10px;
    }
}

@media (min-width: 769px) and (max-width: 1024px) {
    /* Tablet adjustments */
    .ad-leaderboard {
        max-width: 100%;
    }

    .ads-sidebar {
        max-width: 250px;
    }

    .ad-medium-rectangle {
        max-width: 250px;
        min-height: 200px;
    }
}

/* Homepage Layout with Sidebar */
.homepage-layout {
    display: flex;
    gap: 20px;
    margin-top: 20px;
}

.homepage-main {
    flex: 1;
    min-width: 0; /* Prevent flex item overflow */
}

.homepage-sidebar {
    width: 300px;
    flex-shrink: 0;
}

@media (max-width: 1200px) {
    .homepage-layout {
        flex-direction: column;
    }

    .homepage-sidebar {
        width: 100%;
        max-width: 300px;
        margin: 0 auto;
    }
}

@media (max-width: 768px) {
    .homepage-sidebar {
        display: none;
    }
}

/* Video Grid Layout Adjustments for Native Ads */
.video-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 15px;
}

.video-grid-item {
    position: relative;
}

/* Ensure native ads span full width on small grids */
@media (max-width: 480px) {
    .ad-native-grid {
        grid-column: 1 / -1;
    }
}

/* Performance Optimization */
.ad-placement img {
    max-width: 100%;
    height: auto;
}

/* Prevent Layout Shift */
.ad-placement[data-priority="10"] {
    min-height: 90px;
}

.ad-placement[data-priority="9"] {
    min-height: 90px;
}

.ad-placement[data-priority="8"] {
    min-height: 250px;
}

/* Ad Label (optional - for transparency) */
.ad-label {
    font-size: 10px;
    color: #999;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 5px;
    display: block;
}

/* Error State */
.ad-error {
    background: #fff3cd;
    border: 1px solid #ffc107;
    padding: 10px;
    border-radius: 4px;
    color: #856404;
    font-size: 12px;
    text-align: center;
}

/* Native ad стилизован под video cards */
.ad-native-grid-item {
    position: relative;
}

.ad-native-wrapper {
    position: relative;
    width: 100%;
    background: #1a1a1a;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: all 0.3s ease;
}

.ad-native-wrapper:hover {
    border-color: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}

/* Метка Sponsored */
.ad-sponsored-label {
    position: absolute;
    top: 8px;
    left: 8px;
    z-index: 10;
    pointer-events: none;
}

.ad-sponsored-label span {
    display: inline-block;
    padding: 4px 10px;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(4px);
    color: #999;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Ad container */
.ad-lazy {
    width: 100%;
    min-height: 180px; /* Aspect ratio примерно 16:9 для 300x250 */
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.02);
}

/* Loading spinner пока баннер загружается */
.ad-lazy:not([data-loaded="true"]):empty::before {
    content: '';
    width: 32px;
    height: 32px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top-color: #e74c3c;
    border-radius: 50%;
    animation: adSpin 1s linear infinite;
}

@keyframes adSpin {
    to { transform: rotate(360deg); }
}

/* Адаптация под размеры экрана */
@media (max-width: 767px) {
    .ad-lazy {
        min-height: 150px;
    }
}

@media (min-width: 768px) and (max-width: 991px) {
    .ad-lazy {
        min-height: 160px;
    }
}

@media (min-width: 992px) {
    .ad-lazy {
        min-height: 180px;
    }
}

/* Если баннер не загрузился - скрываем через 5 секунд */
.ad-lazy.ad-load-failed {
    display: none;
}

/* Native ad wrapper - строгие размеры под video cards */
.ad-native-wrapper {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9; /* ← КРИТИЧНО! Как у video thumbnails */
    background: #1a1a1a;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: all 0.3s ease;
}

.ad-native-wrapper:hover {
    border-color: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}

/* Ad container - заполняет wrapper */
.ad-lazy {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.02);
}

/* ExoClick iframe - принудительно подгоняем под размер */
.ad-lazy iframe,
.ad-lazy > div {
    max-width: 100% !important;
    max-height: 100% !important;
    width: 100% !important;
    height: 100% !important;
    object-fit: cover;
}

/* Если баннер 300x250 не влезает - масштабируем */
.ad-lazy iframe[width="300"][height="250"] {
    transform: scale(0.85);
    transform-origin: center;
}

/* Метка Sponsored */
.ad-sponsored-label {
    position: absolute;
    top: 8px;
    left: 8px;
    z-index: 100; /* ← Поверх iframe */
    pointer-events: none;
}

.ad-sponsored-label span {
    display: inline-block;
    padding: 4px 10px;
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(4px);
    color: #999;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

/* Loading state */
.ad-lazy:not([data-loaded="true"]):empty {
    background: rgba(255, 255, 255, 0.03);
}

.ad-lazy:not([data-loaded="true"]):empty::before {
    content: '';
    width: 32px;
    height: 32px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top-color: #e74c3c;
    border-radius: 50%;
    animation: adSpin 1s linear infinite;
}

@keyframes adSpin {
    to { transform: rotate(360deg); }
}

/* Responsive sizing */
@media (max-width: 575px) {
    /* Mobile - 2 columns */
    .ad-native-wrapper {
        aspect-ratio: 16 / 9;
    }

    .ad-lazy iframe[width="300"][height="250"] {
        transform: scale(0.7);
    }
}

@media (min-width: 576px) and (max-width: 767px) {
    /* Small tablets - 2 columns */
    .ad-native-wrapper {
        aspect-ratio: 16 / 9;
    }

    .ad-lazy iframe[width="300"][height="250"] {
        transform: scale(0.75);
    }
}

@media (min-width: 768px) and (max-width: 991px) {
    /* Tablets - 3 columns */
    .ad-native-wrapper {
        aspect-ratio: 16 / 9;
    }

    .ad-lazy iframe[width="300"][height="250"] {
        transform: scale(0.8);
    }
}

@media (min-width: 992px) and (max-width: 1199px) {
    /* Desktop - 3 columns */
    .ad-native-wrapper {
        aspect-ratio: 16 / 9;
    }

    .ad-lazy iframe[width="300"][height="250"] {
        transform: scale(0.85);
    }
}

@media (min-width: 1200px) {
    /* Large desktop - 4 columns */
    .ad-native-wrapper {
        aspect-ratio: 16 / 9;
    }

    .ad-lazy iframe[width="300"][height="250"] {
        transform: scale(0.9);
    }
}

/* Если баннер всё равно вылезает - обрезаем */
.ad-native-grid-item {
    overflow: hidden;
}

/* Fallback - скрыть если совсем не загрузился */
.ad-lazy.ad-load-failed {
    display: none !important;
}