/**
 * Оптимизированные стили для рекламных блоков
 * Минимальные стили для производительности
 * Версия 2.0 - Добавлена поддержка десктопных блоков 970x250
 */

/* Базовый слот */
.ad-slot {
    display: block;
    margin: 20px auto;
    overflow: hidden;
    position: relative;
    text-align: center;
}

/* Специфичные размеры с aspect-ratio */
.ad-infinite-after-lead.mobile-infinite-after-lead {
    width: 100%;
    max-width: 300px;
    aspect-ratio: 1/1; /* 300x300 */
    height: 300px;
}

.ad-infinite-after-lead.desktop-infinite-after-lead {
    width: 100%;
    max-width: 970px;
    aspect-ratio: 970/250; /* 970x250 */
    height: 250px;
}

.ad-infinite-pretags {
    width: 100%;
    max-width: 300px;
    aspect-ratio: 300/250; /* 300x250 */
    height: 250px;
}

/* Контейнер рекламы */
.ad-container {
    width: 100%;
    height: 100%;
    position: relative;
}

/* Плейсхолдер загрузки */
.ad-placeholder {
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: adLoading 1.5s infinite;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #999;
    font-size: 12px;
}

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

/* Скрываем плейсхолдер после загрузки */
.ad-slot[data-ad-loaded="true"] .ad-placeholder {
    display: none;
}

/* Контейнер для десктопной рекламы */
.desktop-infinite-after-lead .ad-container {
    width: 100%;
    height: 100%;
    position: relative;
}

/* ===================================
   МЕДИА-ЗАПРОСЫ
   =================================== */

/* Десктоп - показываем десктопные блоки */
@media (min-width: 769px) {
    /* Показываем десктопные блоки */
    .ad-infinite-after-lead.desktop-infinite-after-lead {
        display: block !important;
        margin: 20px auto;
    }
    
    /* Скрываем мобильные блоки */
    .ad-infinite-after-lead.mobile-infinite-after-lead,
    .ad-infinite-pretags {
        display: none !important;
    }
    
    /* Адаптация для средних экранов */
    @media (max-width: 1023px) {
        .ad-infinite-after-lead.desktop-infinite-after-lead {
            max-width: calc(100vw - 40px);
        }
        
        .ad-infinite-after-lead.desktop-infinite-after-lead .ad-container {
            width: 100%;
            max-width: 970px;
            height: auto;
            min-height: 200px;
            max-height: 250px;
        }
    }
}

/* Мобильная оптимизация */
@media (max-width: 768px) {
    /* Показываем мобильные блоки */
    .ad-infinite-after-lead.mobile-infinite-after-lead,
    .ad-infinite-pretags {
        display: block !important;
    }
    
    /* Скрываем десктопные блоки */
    .ad-infinite-after-lead.desktop-infinite-after-lead {
        display: none !important;
    }
    
    .ad-slot {
        margin: 15px auto;
        /* Убираем тяжелые эффекты на мобильных */
        box-shadow: none !important;
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
    }
    
    .ad-placeholder {
        /* Упрощенная анимация для мобильных */
        animation-duration: 2s;
        border-radius: 4px;
    }
    
    /* Адаптация размеров под экран */
    .ad-slot {
        max-width: calc(100vw - 30px);
    }
    
    /* Специфичные мобильные размеры */
    .ad-infinite-after-lead.mobile-infinite-after-lead {
        height: 300px;
        max-width: 300px;
    }
    
    .ad-infinite-pretags {
        height: 250px;
        max-width: 300px;
    }
    
    /* Центрирование мобильных блоков в бесконечной ленте - УПРОЩЕНО как в бэкапе */
    .ad-slot.ad-infinite-after-lead.mobile-infinite-after-lead,
    .ad-slot.ad-infinite-pretags {
        display: block !important;
        margin: 15px auto !important; /* Простое центрирование через margin auto */
        position: relative !important;
        left: auto !important; /* Убираем left */
        transform: none !important; /* Убираем transform */
        text-align: center !important;
    }
    
    /* Убедимся что контейнер тоже центрирован */
    .ad-container {
        margin: 0 auto;
        text-align: center;
        display: block;
    }
}

/* Очень маленькие экраны */
@media (max-width: 480px) {
    .ad-slot {
        margin: 10px auto;
    }
    
    .ad-infinite-after-lead.mobile-infinite-after-lead,
    .ad-infinite-pretags {
        max-width: calc(100vw - 20px);
    }
    
    /* Адаптация высоты для очень узких экранов */
    .ad-infinite-after-lead.mobile-infinite-after-lead {
        height: auto;
        max-height: 300px;
        aspect-ratio: 1/1;
    }
    
    .ad-infinite-pretags {
        height: auto;
        max-height: 250px;
        aspect-ratio: 300/250;
    }
}

/* ===================================
   ТЕМНАЯ ТЕМА
   =================================== */

body.dark-theme .ad-placeholder {
    background: linear-gradient(90deg, #2a2a2a 25%, #1a1a1a 50%, #2a2a2a 75%);
    color: #666;
}

body.dark-theme .ad-slot {
    background: transparent;
}

/* ===================================
   СПЕЦИАЛЬНЫЕ КЛАССЫ ДЛЯ ПОЗИЦИЙ
   =================================== */

/* Реклама после лида */
.ad-slot.ad-infinite-after-lead {
    margin-top: 20px;
    margin-bottom: 20px;
}

/* Реклама перед тегами */
.ad-slot.ad-infinite-pretags {
    margin-top: 30px;
    margin-bottom: 20px;
}

/* ===================================
   ОПТИМИЗАЦИЯ ПРОИЗВОДИТЕЛЬНОСТИ
   =================================== */

/* Используем will-change только для анимируемых элементов */
.ad-placeholder {
    will-change: background-position;
}

/* Убираем will-change после загрузки */
.ad-slot[data-ad-loaded="true"] .ad-placeholder {
    will-change: auto;
}

/* GPU ускорение для анимации */
@supports (transform: translateZ(0)) {
    .ad-placeholder {
        transform: translateZ(0);
    }
}

/* ===================================
   FALLBACK ДЛЯ СТАРЫХ БРАУЗЕРОВ
   =================================== */

/* Для браузеров без поддержки aspect-ratio */
@supports not (aspect-ratio: 1/1) {
    .ad-infinite-after-lead.mobile-infinite-after-lead {
        height: 300px !important;
    }
    
    .ad-infinite-after-lead.desktop-infinite-after-lead {
        height: 250px !important;
    }
    
    .ad-infinite-pretags {
        height: 250px !important;
    }
}

/* ===================================
   ДОПОЛНИТЕЛЬНЫЕ УТИЛИТЫ
   =================================== */

/* Класс для скрытия рекламы при необходимости */
.ad-slot.ad-hidden {
    display: none !important;
}

/* Класс для отладки */
.ad-slot.ad-debug {
    border: 2px dashed red;
    background: rgba(255, 0, 0, 0.1);
}

/* Плавное появление после загрузки */
.ad-slot[data-ad-loaded="true"] {
    animation: fadeIn 0.3s ease-in;
}

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

/* ===================================
   ИНТЕГРАЦИЯ С ЯНДЕКС РСЯ
   =================================== */

/* Убеждаемся что контейнеры Яндекса видимы */
.ad-slot div[id^="yandex_rtb_"] {
    visibility: visible !important;
    opacity: 1 !important;
    display: block !important;
}

/* Размеры для десктопного блока 970x250 */
.ad-slot.desktop-infinite-after-lead div[id^="yandex_rtb_"] {
    width: 970px !important;
    height: 250px !important;
    max-width: 100%;
}

/* Размеры для мобильного блока 300x300 */
.ad-slot.mobile-infinite-after-lead div[id^="yandex_rtb_"] {
    width: 300px !important;
    height: 300px !important;
    max-width: 100%;
}

/* Размеры для блока перед тегами 300x250 */
.ad-slot.ad-infinite-pretags div[id^="yandex_rtb_"] {
    width: 300px !important;
    height: 250px !important;
    max-width: 100%;
}

/* ===================================
   АДАПТИВНОСТЬ ДЛЯ КОНТЕЙНЕРОВ
   =================================== */

/* Центрирование на всех размерах экрана */
.ad-slot {
    margin-left: auto;
    margin-right: auto;
}

/* Респонсивные отступы */
@media (min-width: 1200px) {
    .ad-slot.ad-infinite-after-lead {
        margin-top: 30px;
        margin-bottom: 30px;
    }
}

@media (min-width: 769px) and (max-width: 1199px) {
    .ad-slot.ad-infinite-after-lead {
        margin-top: 25px;
        margin-bottom: 25px;
    }
}

/* ===================================
   Z-INDEX УПРАВЛЕНИЕ
   =================================== */

/* Реклама всегда под модальными окнами и меню */
.ad-slot {
    position: relative;
    z-index: 1;
}

/* Но над обычным контентом */
.ad-slot .ad-container {
    position: relative;
    z-index: 2;
}