/**
 * Lazy Loading Styles for Contextual Ads
 * 
 * Стили для различных состояний lazy-загружаемых рекламных блоков
 * с плавными анимациями и оптимизацией производительности.
 * 
 * @author AI Assistant
 * @version 1.0.0
 */

/* ===== БАЗОВЫЕ СТИЛИ ===== */

.inct-lazy {
    /* Базовые стили для всех lazy-элементов */
    position: relative;
    min-height: 50px; /* Минимальная высота для предотвращения layout shift */
    transition: opacity 0.3s ease-in-out, transform 0.3s ease-in-out;
    will-change: opacity, transform; /* Оптимизация для анимаций */
}

/* ===== СОСТОЯНИЕ PLACEHOLDER ===== */

.inct-lazy.inct-placeholder {
    opacity: 0.7;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 4px;
    overflow: hidden;
}

.inct-lazy.inct-placeholder::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 24px;
    height: 24px;
    border: 2px solid #ccc;
    border-top-color: #666;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    z-index: 1;
}

.inct-lazy.inct-placeholder::after {
    content: 'Загрузка рекламы...';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, calc(-50% + 20px));
    font-size: 12px;
    color: #666;
    text-align: center;
    white-space: nowrap;
    z-index: 1;
}

/* ===== СОСТОЯНИЕ ЗАГРУЗКИ ===== */

.inct-lazy.inct-loading {
    opacity: 0.8;
    transform: scale(0.98);
    pointer-events: none; /* Предотвращаем взаимодействие во время загрузки */
}

.inct-lazy.inct-loading::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.8);
    z-index: 10;
    border-radius: inherit;
}

.inct-lazy.inct-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 20px;
    height: 20px;
    border: 2px solid #007bff;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    z-index: 11;
}

/* ===== СОСТОЯНИЕ ЗАГРУЖЕНО ===== */

.inct-lazy.inct-loaded {
    opacity: 1;
    transform: scale(1);
    animation: fadeInUp 0.4s ease-out;
}

/* ===== СОСТОЯНИЕ ОШИБКИ ===== */

.inct-lazy.inct-error {
    opacity: 0.6;
    background: #fff5f5;
    border: 1px dashed #e53e3e;
    border-radius: 4px;
    min-height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.inct-lazy.inct-error::before {
    content: '⚠️';
    font-size: 20px;
    margin-right: 8px;
}

.inct-lazy.inct-error::after {
    content: 'Ошибка загрузки рекламы';
    color: #e53e3e;
    font-size: 14px;
    font-weight: 500;
}

/* ===== АНИМАЦИИ ===== */

@keyframes shimmer {
    0% {
        background-position: -200% 0;
    }
    100% {
        background-position: 200% 0;
    }
}

@keyframes spin {
    0% {
        transform: translate(-50%, -50%) rotate(0deg);
    }
    100% {
        transform: translate(-50%, -50%) rotate(360deg);
    }
}

@keyframes fadeInUp {
    0% {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes pulse {
    0%, 100% {
        opacity: 0.7;
    }
    50% {
        opacity: 1;
    }
}

/* ===== АДАПТИВНОСТЬ ===== */

@media (max-width: 768px) {
    .inct-lazy {
        min-height: 40px;
    }
    
    .inct-lazy.inct-placeholder::after {
        font-size: 11px;
    }
    
    .inct-lazy.inct-error::after {
        font-size: 12px;
    }
}

@media (max-width: 480px) {
    .inct-lazy {
        min-height: 35px;
    }
    
    .inct-lazy.inct-placeholder::before {
        width: 20px;
        height: 20px;
    }
    
    .inct-lazy.inct-loading::after {
        width: 16px;
        height: 16px;
    }
}

/* ===== ОПТИМИЗАЦИИ ПРОИЗВОДИТЕЛЬНОСТИ ===== */

/* Отключение анимаций через JavaScript конфигурацию */
.inct-lazy.inct-no-animations,
.inct-lazy.inct-no-animations::before,
.inct-lazy.inct-no-animations::after {
    animation: none !important;
    transition: none !important;
}

.inct-lazy.inct-no-animations.inct-placeholder {
    background: #f0f0f0 !important;
    background-size: auto !important;
}

.inct-lazy.inct-no-animations.inct-placeholder::before {
    display: none !important;
}

.inct-lazy.inct-no-animations.inct-placeholder::after {
    content: 'Загрузка...' !important;
    position: static !important;
    transform: none !important;
    font-size: 12px !important;
    color: #666 !important;
    text-align: center !important;
    display: block !important;
    padding: 10px !important;
}

/* Отключаем анимации для пользователей с настройкой reduced motion */
@media (prefers-reduced-motion: reduce) {
    .inct-lazy,
    .inct-lazy::before,
    .inct-lazy::after {
        animation: none !important;
        transition: none !important;
    }
    
    .inct-lazy.inct-placeholder {
        background: #f0f0f0;
    }
}

/* Оптимизация для высоких DPI экранов */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .inct-lazy.inct-placeholder::before,
    .inct-lazy.inct-loading::after {
        border-width: 1px;
    }
}

/* ===== ТЕМНАЯ ТЕМА ===== */

@media (prefers-color-scheme: dark) {
    .inct-lazy.inct-placeholder {
        background: linear-gradient(90deg, #2a2a2a 25%, #3a3a3a 50%, #2a2a2a 75%);
    }
    
    .inct-lazy.inct-placeholder::before {
        border-color: #555;
        border-top-color: #999;
    }
    
    .inct-lazy.inct-placeholder::after {
        color: #999;
    }
    
    .inct-lazy.inct-error {
        background: #2d1b1b;
        border-color: #e53e3e;
    }
    
    .inct-lazy.inct-error::after {
        color: #ff6b6b;
    }
}

/* ===== ДОПОЛНИТЕЛЬНЫЕ УТИЛИТЫ ===== */

/* Скрытие контента до загрузки */
.inct-lazy.inct-placeholder > * {
    opacity: 0;
    pointer-events: none;
}

.inct-lazy.inct-loaded > * {
    opacity: 1;
    pointer-events: auto;
    transition: opacity 0.3s ease-in-out;
}

/* Принудительное скрытие для критических элементов */
.inct-lazy[data-critical="true"].inct-placeholder {
    min-height: 100px;
    background: #f8f9fa;
}

/* Компактный режим для мобильных устройств */
.inct-lazy[data-compact="true"] {
    min-height: 30px;
}

.inct-lazy[data-compact="true"].inct-placeholder::after {
    content: 'Загрузка...';
    font-size: 10px;
}

/* Высокоприоритетные элементы */
.inct-lazy[data-priority="high"] {
    will-change: auto; /* Убираем will-change для экономии памяти */
}

/* Низкоприоритетные элементы */
.inct-lazy[data-priority="low"].inct-placeholder {
    animation-duration: 2s; /* Замедляем анимацию */
}

/* ===== ACCESSIBILITY ===== */

/* Поддержка screen readers */
.inct-lazy[aria-label]::after {
    content: attr(aria-label);
}

/* Фокус для keyboard navigation */
.inct-lazy:focus {
    outline: 2px solid #007bff;
    outline-offset: 2px;
}

/* Высокий контраст */
@media (prefers-contrast: high) {
    .inct-lazy.inct-placeholder {
        background: #000;
        color: #fff;
    }
    
    .inct-lazy.inct-error {
        border-width: 2px;
        background: #fff;
    }
}