/**
 * Стили для лайтбокса изображений GS Theme
 * Обеспечивает полное отображение изображений без обрезки
 */

/* ===================================
   ОСНОВНАЯ СТРУКТУРА ЛАЙТБОКСА
   =================================== */

/* Основной контейнер лайтбокса */
.gs-lightbox {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 99999;
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.gs-lightbox.active {
    display: flex;
    opacity: 1;
}

/* Затемнение фона */
.gs-lightbox-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

/* Контейнер для изображения */
.gs-lightbox-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    box-sizing: border-box;
}

/* Обертка изображения */
.gs-lightbox-wrapper {
    position: relative;
    max-width: 100%;
    max-height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ===================================
   ИЗОБРАЖЕНИЕ - КЛЮЧЕВЫЕ СТИЛИ
   =================================== */

/* Основное изображение - ПОЛНОЕ ОТОБРАЖЕНИЕ */
.gs-lightbox-image {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain; /* Ключевое свойство - показывает изображение полностью */
    display: block;
    transition: opacity 0.3s ease, transform 0.3s ease;
    cursor: zoom-in;
    /* Убираем любые обрезки */
    border-radius: 0;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
}

/* Состояние загрузки */
.gs-lightbox-image[src=""] {
    opacity: 0;
}

/* ===================================
   НАВИГАЦИЯ ДЛЯ ГАЛЕРЕЙ
   =================================== */

/* Зоны клика на изображении */
.gs-lightbox-image-zones {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    pointer-events: none;
}

.gs-lightbox-image-zone {
    flex: 1;
    cursor: pointer;
    pointer-events: all;
    position: relative;
}

.gs-lightbox-image-zone.prev {
    cursor: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="white" stroke-width="2"><polyline points="15 18 9 12 15 6"></polyline></svg>') 16 16, pointer;
}

.gs-lightbox-image-zone.next {
    cursor: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="white" stroke-width="2"><polyline points="9 18 15 12 9 6"></polyline></svg>') 16 16, pointer;
}

/* Боковые кнопки навигации */
.gs-lightbox-nav-button {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    border-radius: 50%;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.gs-lightbox-nav-button:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-50%) scale(1.1);
}

.gs-lightbox-nav-button:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.gs-lightbox-nav-button.prev {
    left: 20px;
}

.gs-lightbox-nav-button.next {
    right: 20px;
}

.gs-lightbox-nav-button svg {
    width: 24px;
    height: 24px;
}

/* ===================================
   ПАНЕЛЬ УПРАВЛЕНИЯ
   =================================== */

.gs-lightbox-controls {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 16px;
    background: rgba(0, 0, 0, 0.8);
    padding: 12px 20px;
    border-radius: 30px;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    z-index: 10;
}

.gs-lightbox-controls button {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    border-radius: 50%;
}

.gs-lightbox-controls button:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.1);
}

.gs-lightbox-controls button:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.gs-lightbox-controls svg {
    width: 20px;
    height: 20px;
}

.gs-lightbox-controls .counter {
    color: white;
    font-size: 14px;
    white-space: nowrap;
    user-select: none;
}

.gs-lightbox-controls .divider {
    width: 1px;
    height: 20px;
    background: rgba(255, 255, 255, 0.2);
}

.gs-lightbox-controls .close-text {
    color: white;
    font-size: 14px;
    margin-left: -8px;
    cursor: pointer;
}

/* ===================================
   ТОЧЕЧНАЯ НАВИГАЦИЯ
   =================================== */

.gs-lightbox-dots {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
    max-width: 90%;
    overflow-x: auto;
    padding: 10px;
    -webkit-overflow-scrolling: touch;
}

.gs-lightbox-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    border: none;
    cursor: pointer;
    transition: all 0.3s ease;
    flex-shrink: 0;
    padding: 0;
}

.gs-lightbox-dot:hover {
    background: rgba(255, 255, 255, 0.5);
    transform: scale(1.2);
}

.gs-lightbox-dot.active {
    background: white;
    transform: scale(1.2);
}

/* ===================================
   РЕЖИМ ОДИНОЧНОГО ИЗОБРАЖЕНИЯ
   =================================== */

.gs-lightbox.single-image .gs-lightbox-image-zones,
.gs-lightbox.single-image .gs-lightbox-nav-button,
.gs-lightbox.single-image .gs-lightbox-controls,
.gs-lightbox.single-image .gs-lightbox-dots {
    display: none !important;
}

.gs-lightbox.single-image .gs-lightbox-wrapper {
    cursor: pointer;
}

/* ===================================
   МОБИЛЬНАЯ АДАПТАЦИЯ
   =================================== */

@media (max-width: 768px) {
    /* Уменьшаем отступы на мобильных */
    .gs-lightbox-container {
        padding: 10px;
    }
    
    /* ВАЖНО: Обеспечиваем полное отображение на мобильных */
    .gs-lightbox-image {
        max-width: 100%;
        max-height: 100%;
        width: auto !important;
        height: auto !important;
        object-fit: contain !important; /* Принудительно показываем полностью */
    }
    
    /* Скрываем боковые кнопки на мобильных */
    .gs-lightbox-nav-button {
        display: none;
    }
    
    /* Адаптируем панель управления */
    .gs-lightbox-controls {
        bottom: 10px;
        padding: 10px 16px;
        gap: 12px;
        border-radius: 25px;
    }
    
    .gs-lightbox-controls button {
        padding: 6px;
    }
    
    .gs-lightbox-controls svg {
        width: 18px;
        height: 18px;
    }
    
    .gs-lightbox-controls .counter {
        font-size: 12px;
    }
    
    .gs-lightbox-controls .close-text {
        display: none;
    }
    
    /* Точки ближе к панели управления */
    .gs-lightbox-dots {
        bottom: 60px;
    }
}

@media (max-width: 480px) {
    /* Еще меньше отступы для маленьких экранов */
    .gs-lightbox-container {
        padding: 5px;
    }
    
    /* Компактная панель управления */
    .gs-lightbox-controls {
        gap: 8px;
        padding: 8px 12px;
    }
}

/* ===================================
   АЛЬБОМНАЯ ОРИЕНТАЦИЯ НА МОБИЛЬНЫХ
   =================================== */

@media (max-width: 768px) and (orientation: landscape) {
    .gs-lightbox-container {
        padding: 5px;
    }
    
    .gs-lightbox-image {
        max-height: 85vh; /* Оставляем место для панели управления */
    }
    
    .gs-lightbox-controls {
        bottom: 5px;
    }
    
    .gs-lightbox-dots {
        display: none; /* Скрываем точки в альбомной ориентации */
    }
}

/* ===================================
   АНИМАЦИИ
   =================================== */

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.gs-lightbox.active .gs-lightbox-image {
    animation: fadeIn 0.3s ease forwards;
}

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

body.dark-theme .gs-lightbox-overlay {
    background: rgba(0, 0, 0, 0.98);
}

body.dark-theme .gs-lightbox-nav-button {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.1);
}

body.dark-theme .gs-lightbox-controls {
    background: rgba(0, 0, 0, 0.9);
    border-color: rgba(255, 255, 255, 0.05);
}

/* ===================================
   ПОДДЕРЖКА ВЫСОКИХ DPI ЭКРАНОВ
   =================================== */

@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .gs-lightbox-image {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* ===================================
   ИСПРАВЛЕНИЯ ДЛЯ SAFARI
   =================================== */

@supports (-webkit-touch-callout: none) {
    .gs-lightbox-image {
        -webkit-touch-callout: none;
        -webkit-user-select: none;
    }
    
    .gs-lightbox-container {
        -webkit-transform: translate3d(0, 0, 0);
    }
}

/* ===================================
   ПРИНУДИТЕЛЬНОЕ ОТОБРАЖЕНИЕ ПОЛНЫХ ИЗОБРАЖЕНИЙ
   =================================== */

/* Переопределяем любые другие стили */
.gs-lightbox .gs-lightbox-image {
    object-fit: contain !important;
    max-width: 100% !important;
    max-height: 100% !important;
    width: auto !important;
    height: auto !important;
    position: relative !important;
    transform-origin: center center !important;
}

/* Убеждаемся, что контейнер не обрезает изображение */
.gs-lightbox-wrapper {
    overflow: visible !important;
    width: 100% !important;
    height: 100% !important;
}

/* Для очень высоких изображений на мобильных */
@media (max-width: 768px) and (max-aspect-ratio: 3/4) {
    .gs-lightbox-image {
        max-height: 85vh !important; /* Оставляем место для UI */
    }
}

/* ===================================
   КРИТИЧЕСКИЕ ИСПРАВЛЕНИЯ ДЛЯ МОБИЛЬНЫХ
   =================================== */

/* Принудительное исправление для всех устройств */
.gs-lightbox-wrapper img,
.gs-lightbox .gs-lightbox-wrapper .gs-lightbox-image,
.gs-lightbox.active .gs-lightbox-image {
    position: absolute !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    max-width: calc(100vw - 20px) !important;
    max-height: calc(100vh - 100px) !important;
    width: auto !important;
    height: auto !important;
    object-fit: contain !important;
    margin: 0 !important;
    padding: 0 !important;
}

/* Специальные стили для мобильных */
@media (max-width: 768px) {
    .gs-lightbox-wrapper img,
    .gs-lightbox .gs-lightbox-wrapper .gs-lightbox-image,
    .gs-lightbox.active .gs-lightbox-image {
        max-width: calc(100vw - 10px) !important;
        max-height: calc(100vh - 80px) !important;
    }
    
    /* Убеждаемся что wrapper не обрезает */
    .gs-lightbox-wrapper {
        position: absolute !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100% !important;
        height: 100% !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }
    
    .gs-lightbox-container {
        padding: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
    }
}

/* Ультра-специфичные стили для переопределения любых других */
body .gs-lightbox.active .gs-lightbox-container .gs-lightbox-wrapper img.gs-lightbox-image {
    object-fit: contain !important;
    max-width: 100% !important;
    max-height: 100% !important;
}

/* Для маленьких экранов */
@media (max-width: 480px) {
    .gs-lightbox-image {
        max-width: calc(100vw - 10px) !important;
        max-height: calc(100vh - 60px) !important;
    }
}

/* Альбомная ориентация */
@media (orientation: landscape) and (max-width: 812px) {
    .gs-lightbox-image {
        max-height: calc(100vh - 50px) !important;
    }
}

/* ===================================
   СТИЛИ ДЛЯ ГОРИЗОНТАЛЬНОЙ ГАЛЕРЕИ
   =================================== */

/* Контейнер горизонтальной галереи */
.gs-horizontal-wrapper {
    position: relative;
    width: 100%;
    overflow: hidden;
    -webkit-overflow-scrolling: touch; /* Плавный скролл на iOS */
}

.gs-horizontal-container {
    width: 100%;
    height: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    /* Скрываем скроллбар */
    scrollbar-width: none;
    -ms-overflow-style: none;
    /* Оптимизация для мобильных */
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    will-change: scroll-position;
}

.gs-horizontal-container::-webkit-scrollbar {
    display: none;
}

.gs-horizontal-track {
    display: flex;
    height: 100%;
    transition: transform 0.3s ease;
    /* Оптимизация производительности */
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
}

/* Слайды в галерее */
.gs-slide {
    flex: 0 0 auto;
    height: 100%;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ВАЖНО: Изображения в галерее должны быть полными */
.gs-slide img,
.gs-gallery-horizontal .gs-slide .gs-gallery-image {
    max-width: 100%;
    max-height: 100%;
    width: auto !important;
    height: auto !important;
    object-fit: contain !important; /* Показываем изображение полностью */
    display: block;
}

/* Кнопки навигации галереи */
.gs-gallery-horizontal .gs-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0, 0, 0, 0.5);
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    z-index: 2;
}

.gs-gallery-horizontal .gs-nav:hover:not(:disabled) {
    background: rgba(0, 0, 0, 0.7);
}

.gs-gallery-horizontal .gs-nav:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.gs-gallery-horizontal .gs-nav-prev {
    left: 10px;
}

.gs-gallery-horizontal .gs-nav-next {
    right: 10px;
}

/* Индикаторы */
.gs-gallery-horizontal .gs-indicators {
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 6px;
    z-index: 2;
}

.gs-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.5);
    border: none;
    cursor: pointer;
    transition: all 0.3s ease;
    padding: 0;
}

.gs-indicator:hover {
    background: rgba(255, 255, 255, 0.7);
}

.gs-indicator.active {
    background: white;
    transform: scale(1.2);
}

/* Адаптация для мобильных */
@media (max-width: 768px) {
    .gs-gallery-horizontal .gs-nav {
        display: none; /* Скрываем кнопки на мобильных - используем свайпы */
    }
    
    .gs-slide img,
    .gs-gallery-horizontal .gs-slide .gs-gallery-image {
        max-width: 100vw;
        max-height: 100%;
    }
    
    /* Визуальная подсказка о возможности свайпа */
    .gs-horizontal-wrapper::after {
        content: '';
        position: absolute;
        bottom: 10px;
        left: 50%;
        transform: translateX(-50%);
        width: 40px;
        height: 4px;
        background: rgba(255, 255, 255, 0.3);
        border-radius: 2px;
        pointer-events: none;
        animation: swipeHint 2s ease-in-out infinite;
    }
    
    @keyframes swipeHint {
        0%, 100% { transform: translateX(-50%); }
        25% { transform: translateX(-70%); }
        75% { transform: translateX(-30%); }
    }
    
    /* Убираем подсказку после первого взаимодействия */
    .gs-horizontal-wrapper.interacted::after {
        display: none;
    }
}

/* Для маленьких экранов */
@media (max-width: 480px) {
    .gs-horizontal-wrapper {
        height: 300px !important; /* Фиксированная высота для мобильных */
    }
    
    .gs-slide {
        padding: 0 5px;
    }
}

/* Grid галереи - тоже нужно исправить */
.gs-image-grid .gs-image-card img {
    width: 100%;
    height: 100%;
    object-fit: contain !important; /* Изменяем с cover на contain */
}

/* Для мозаичной галереи */
.gs-image-grid.grid-masonry .gs-image-card img {
    object-fit: cover; /* Для мозаики оставляем cover */
}

/* ===================================
   УЛУЧШЕНИЯ ДЛЯ МОБИЛЬНОЙ НАВИГАЦИИ
   =================================== */

/* Плавные переходы при свайпе */
.gs-lightbox-image {
    transition: opacity 0.15s ease, transform 0.15s ease !important;
}

/* Быстрая анимация для мгновенного отклика */
.gs-lightbox-wrapper {
    will-change: transform;
}

/* Индикация свайпа */
@media (max-width: 768px) {
    /* Зона свайпа на весь экран */
    .gs-lightbox-wrapper {
        width: 100%;
        height: 100%;
    }
    
    /* Визуальные подсказки для свайпа - тоньше и прозрачнее */
    .gs-lightbox.gallery-images .gs-lightbox-wrapper::before,
    .gs-lightbox.gallery-images .gs-lightbox-wrapper::after {
        content: '';
        position: absolute;
        top: 50%;
        transform: translateY(-50%);
        width: 20px;
        height: 20px;
        opacity: 0.2;
        pointer-events: none;
        z-index: 5;
        transition: opacity 0.3s ease;
    }
    
    /* Показываем подсказки ярче при первом открытии */
    .gs-lightbox.gallery-images.active .gs-lightbox-wrapper::before,
    .gs-lightbox.gallery-images.active .gs-lightbox-wrapper::after {
        animation: pulse 2s ease-out;
    }
    
    @keyframes pulse {
        0%, 100% { opacity: 0.2; }
        50% { opacity: 0.5; }
    }
    
    /* Стрелка влево */
    .gs-lightbox.gallery-images .gs-lightbox-wrapper::before {
        left: 10px;
        background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="white" stroke-width="2"><polyline points="15 18 9 12 15 6"></polyline></svg>') no-repeat center;
        background-size: contain;
    }
    
    /* Стрелка вправо */
    .gs-lightbox.gallery-images .gs-lightbox-wrapper::after {
        right: 10px;
        background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="white" stroke-width="2"><polyline points="9 18 15 12 9 6"></polyline></svg>') no-repeat center;
        background-size: contain;
    }
    
    /* Скрываем стрелки на крайних фото */
    .gs-lightbox[data-first="true"] .gs-lightbox-wrapper::before,
    .gs-lightbox[data-last="true"] .gs-lightbox-wrapper::after {
        display: none;
    }
}

/* Улучшенная область для свайпа */
.gs-lightbox-wrapper {
    touch-action: pan-y pinch-zoom;
}

.gs-lightbox.gallery-images .gs-lightbox-wrapper {
    touch-action: none; /* Отключаем стандартные жесты для галереи */
}

/* Убираем выделение при касании */
.gs-lightbox * {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

/* Оптимизация производительности */
.gs-lightbox-image {
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
}