/* Новый простой слайдер для страницы продукта */

.product-gallery {
    position: relative;
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
}

.gallery-main {
    position: relative;
    width: 100%;
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

/* Ozon-like layout */
.ozon-gallery {
    display: grid !important;
    grid-template-columns: 72px 1fr !important;
    gap: 10px !important;
    align-items: stretch !important;
}

.ozon-thumbs-swiper {
    width: 72px !important;
    height: 420px !important;
}

.ozon-thumbs-swiper .swiper-wrapper {
    flex-direction: column !important;
}

.ozon-thumbs-swiper .swiper-slide {
    width: 64px !important;
    height: 64px !important;
    opacity: .6 !important;
    border-radius: 8px !important;
    overflow: hidden !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    background: #fff !important;
    box-shadow: 0 2px 8px rgba(0,0,0,.08) !important;
}

.ozon-thumbs-swiper .swiper-slide-thumb-active {
    opacity: 1 !important;
    box-shadow: 0 4px 14px rgba(0,123,255,.25) !important;
    border: 2px solid #007bff !important;
}

.ozon-main {
    height: min(75vh, 560px) !important;
    border-radius: 12px !important;
    overflow: hidden !important;
    background: #f8f9fa !important;
}

.ozon-main-swiper {
    width: 100% !important;
    height: 100% !important;
}

.ozon-main-swiper .swiper-wrapper { align-items: center !important; }
.ozon-main-swiper .swiper-slide {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    height: 100% !important;
    background: #0000 !important;
}

/* Медиа внутри основного кадра: видео не обрезаем на десктопе */
.ozon-main-swiper .swiper-slide video.gallery-media {
    max-width: 100% !important;
    max-height: 100% !important;
    width: auto !important;
    height: auto !important;
    object-fit: contain !important;
}

.ozon-main-swiper .swiper-slide img.gallery-media {
    max-width: 100% !important;
    max-height: 100% !important;
    width: auto !important;
    height: auto !important;
    object-fit: contain !important;
}

.ozon-main-swiper .swiper-button-prev,
.ozon-main-swiper .swiper-button-next {
    color: #007bff !important;
}

.ozon-main-swiper .swiper-pagination-bullet-active {
    background: #007bff !important;
}

@media (max-width: 1024px) {
    .ozon-gallery { grid-template-columns: 64px 1fr !important; }
    .ozon-thumbs-swiper { width: 64px !important; height: 380px !important; }
    .ozon-thumbs-swiper .swiper-slide { width: 56px !important; height: 56px !important; }
    .ozon-main { height: min(70vh, 480px) !important; }
}

@media (max-width: 768px) {
    .ozon-gallery { grid-template-columns: 1fr !important; }
    .ozon-thumbs-swiper { order: 2; width: 100% !important; height: 72px !important; }
    .ozon-thumbs-swiper .swiper-wrapper { flex-direction: row !important; }
    .ozon-thumbs-swiper .swiper-slide { width: 56px !important; height: 56px !important; }
    .ozon-main { order: 1; height: auto !important; min-height: 240px !important; }
    .ozon-main-swiper { aspect-ratio: 3/4 !important; } /* кадр маркетплейса */
    .ozon-main-swiper .swiper-slide img,
    .ozon-main-swiper .swiper-slide video { max-width: 100% !important; max-height: 100% !important; width: auto !important; height: auto !important; object-fit: contain !important; }
}

.gallery-slider {
    position: relative;
    width: 100%;
    aspect-ratio: 4/3;
}

.gallery-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #007bff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    z-index: 5;
}

@keyframes spin {
    0% { transform: translate(-50%, -50%) rotate(0deg); }
    100% { transform: translate(-50%, -50%) rotate(360deg); }
}

.gallery-slides {
    position: relative;
    width: 100%;
    height: 100%;
}

.gallery-slide {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    transition: opacity 0.4s ease-in-out, transform 0.4s ease-in-out;
    display: flex;
    align-items: center;
    justify-content: center;
    transform: scale(0.95);
}

.gallery-slide.active {
    opacity: 1;
    z-index: 1;
    transform: scale(1);
}

.gallery-item {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.gallery-media {
    max-width: 100%;
    max-height: 100%;
    object-fit: cover;
    object-position: center;
    border-radius: 8px;
    cursor: pointer;
}

.gallery-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
    border-radius: 8px;
    pointer-events: none;
    z-index: 2;
}

.gallery-overlay .gallery-play-btn {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.gallery-overlay .gallery-fullscreen-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    width: 40px;
    height: 40px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    font-size: 14px;
}

.gallery-item:hover .gallery-overlay {
    opacity: 1;
}

.gallery-zoom-btn,
.gallery-play-btn,
.gallery-fullscreen-btn {
    background: rgba(255, 255, 255, 0.9);
    border: none;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    color: #333;
    font-size: 18px;
    pointer-events: auto;
    z-index: 3;
    text-decoration: none;
}

.gallery-zoom-btn:hover,
.gallery-play-btn:hover,
.gallery-fullscreen-btn:hover {
    background: white;
    transform: scale(1.1);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.gallery-overlay .gallery-fullscreen-btn:hover {
    background: rgba(0, 0, 0, 0.9);
    color: white;
}

.gallery-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.95);
    border: none;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    z-index: 2;
    color: #333;
    font-size: 16px;
    backdrop-filter: blur(10px);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.gallery-nav:hover {
    background: rgba(255, 255, 255, 1);
    transform: translateY(-50%) scale(1.15);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
    color: #007bff;
}

.gallery-nav:active {
    transform: translateY(-50%) scale(0.95);
}

.gallery-prev {
    left: 10px;
}

.gallery-next {
    right: 10px;
}

.gallery-dots {
    position: absolute;
    bottom: 15px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
    z-index: 2;
}

.gallery-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.6);
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.gallery-dot.active,
.gallery-dot:hover {
    background: #007bff;
    transform: scale(1.3);
    box-shadow: 0 4px 8px rgba(0, 123, 255, 0.3);
}

.gallery-controls {
    position: absolute;
    top: 15px;
    left: 15px;
    z-index: 10;
}

.gallery-control-btn {
    background: rgba(0, 0, 0, 0.7);
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    color: white;
    font-size: 14px;
}

.gallery-control-btn:hover {
    background: rgba(0, 0, 0, 0.9);
    transform: scale(1.1);
}

/* Миниатюры галереи */
.gallery-thumbnails {
    width: 100%;
    margin-top: 20px;
    padding: 0 10px;
    box-sizing: border-box;
}

.thumbnail-swiper {
    width: 100%;
    overflow: hidden;
}

.thumbnail-wrapper {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding: 5px 0;
    scrollbar-width: thin;
}

.thumbnail-wrapper::-webkit-scrollbar {
    height: 6px;
}

.thumbnail-wrapper::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.thumbnail-wrapper::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

.thumbnail-wrapper::-webkit-scrollbar-thumb:hover {
    background: #999;
}

.thumbnail-item {
    position: relative;
    flex: 0 0 auto;
    width: 70px;
    height: 70px;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.3s ease;
    background: #f8f9fa;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.thumbnail-item:hover {
    border-color: #007bff;
    transform: scale(1.08);
    box-shadow: 0 4px 15px rgba(0, 123, 255, 0.3);
}

.thumbnail-item.active {
    border-color: #007bff;
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(0, 123, 255, 0.4);
}

.thumbnail-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.thumbnail-video-placeholder {
    width: 100%;
    height: 100%;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

.thumbnail-video-placeholder i {
    font-size: 20px;
}

.thumbnail-play-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 24px;
    height: 24px;
    background: rgba(0, 0, 0, 0.8);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 10px;
    z-index: 5;
}

.thumbnail-type-indicator {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 8px;
    color: white;
    z-index: 6;
}

.thumbnail-type-indicator.video {
    background: #ff4757;
}

.thumbnail-type-indicator.image {
    background: #2ed573;
}

/* Кастомные стрелки для Fancybox */
.fancybox__nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.9);
    border: none;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 9999;
    font-size: 20px;
    color: #333;
    transition: all 0.3s ease;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
}

.fancybox__nav--prev {
    left: 20px;
}

.fancybox__nav--next {
    right: 20px;
}

.fancybox__nav:hover {
    background: rgba(255, 255, 255, 1);
    transform: translateY(-50%) scale(1.1);
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
}

.fancybox__nav--prev:hover {
    transform: translateY(-50%) scale(1.1);
}

.fancybox__nav--next:hover {
    transform: translateY(-50%) scale(1.1);
}

/* Fancybox кнопки */
.gallery-zoom-btn,
.gallery-play-btn {
    background: rgba(255, 255, 255, 0.9);
    border: none;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    color: #333;
    font-size: 18px;
    text-decoration: none;
}

.gallery-zoom-btn:hover,
.gallery-play-btn:hover {
    background: white;
    transform: scale(1.1);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    text-decoration: none;
    color: #333;
}

/* Стили для стрелок навигации Fancybox */
.fancybox__nav {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    pointer-events: none !important;
    z-index: 99999 !important;
}

.fancybox__nav .carousel__button {
    position: absolute !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    width: 60px !important;
    height: 60px !important;
    background: rgba(255, 255, 255, 0.95) !important;
    border: none !important;
    border-radius: 50% !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    cursor: pointer !important;
    pointer-events: auto !important;
    transition: all 0.3s ease !important;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3) !important;
    z-index: 99999 !important;
}

.fancybox__nav .carousel__button:hover {
    background: rgba(255, 255, 255, 1) !important;
    transform: translateY(-50%) scale(1.1) !important;
    box-shadow: 0 6px 20px rgba(0,0,0,0.4) !important;
}

.fancybox__nav .carousel__button.is-prev {
    left: 20px !important;
    right: auto !important;
}

.fancybox__nav .carousel__button.is-next {
    right: 20px !important;
    left: auto !important;
}

.fancybox__nav .carousel__button svg {
    width: 24px !important;
    height: 24px !important;
    fill: #333 !important;
    stroke: #333 !important;
    stroke-width: 2 !important;
}

.fancybox__nav .carousel__button:hover svg {
    fill: #000 !important;
    stroke: #000 !important;
}

/* Скрываем кастомные стрелки, если встроенные работают */
.fancybox__nav:not(:empty) ~ .custom-fancybox-arrow {
    display: none !important;
}

/* Адаптивность */
@media (max-width: 768px) {
    .product-gallery {
        max-width: 100%;
    }
    
    .gallery-nav {
        width: 35px;
        height: 35px;
        font-size: 14px;
    }
    
    .gallery-prev {
        left: 5px;
    }
    
    .gallery-next {
        right: 5px;
    }
    
    .gallery-dots {
        bottom: 10px;
    }
    
    .gallery-dot {
        width: 8px;
        height: 8px;
    }
    
    .thumbnail-item {
        width: 60px;
        height: 60px;
    }
    
    .gallery-thumbnails {
        gap: 8px;
    }
}

@media (max-width: 480px) {
    .gallery-nav {
        width: 30px;
        height: 30px;
        font-size: 12px;
    }
    
    .gallery-zoom-btn,
    .gallery-play-btn {
        width: 40px;
        height: 40px;
        font-size: 16px;
    }
    
    .thumbnail-item {
        width: 50px;
        height: 50px;
    }
    
    .gallery-thumbnails {
        gap: 6px;
    }
    
    .thumbnail-play-icon {
        width: 20px;
        height: 20px;
        font-size: 8px;
    }
    
    .thumbnail-type-indicator {
        width: 14px;
        height: 14px;
        font-size: 7px;
    }
}

/* Новые стили для миниатюр с grid */
.thumbnail-grid {
    display: grid !important;
    grid-template-columns: repeat(auto-fit, minmax(60px, 1fr)) !important;
    gap: 10px !important;
    max-width: 100% !important;
    justify-items: center !important;
}

.thumbnail-grid .thumbnail-item {
    width: 60px !important;
    height: 60px !important;
    margin: 0 !important;
    flex-shrink: 0 !important;
}

@media (max-width: 768px) {
    .thumbnail-grid {
        grid-template-columns: repeat(auto-fit, minmax(50px, 1fr)) !important;
        gap: 8px !important;
    }
    
    .thumbnail-grid .thumbnail-item {
        width: 50px !important;
        height: 50px !important;
    }
}

@media (max-width: 480px) {
    .thumbnail-grid {
        grid-template-columns: repeat(auto-fit, minmax(40px, 1fr)) !important;
        gap: 6px !important;
    }
    
    .thumbnail-grid .thumbnail-item {
        width: 40px !important;
        height: 40px !important;
    }
}

/* Стили для кликабельных изображений */
.gallery-image-link {
    display: block !important;
    width: 100% !important;
    height: 100% !important;
    text-decoration: none !important;
    cursor: pointer !important;
    background: transparent !important;
}

.gallery-image-link:hover {
    text-decoration: none !important;
}

/* Исправление позиционирования стрелок Fancybox */
.fancybox__nav .carousel__button {
    position: absolute !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    z-index: 40 !important;
}

.fancybox__nav .carousel__button.is-prev {
    left: 8px !important;
}

.fancybox__nav .carousel__button.is-next {
    right: 8px !important;
}

@media all and (min-width: 1024px) {
    .fancybox__nav .carousel__button.is-prev {
        left: 40px !important;
    }
    
    .fancybox__nav .carousel__button.is-next {
        right: 40px !important;
    }
}

/* Исправление для видео в полноэкранном режиме */
.fancybox__container:fullscreen .fancybox__content {
    width: 100vw !important;
    height: 100vh !important;
    max-width: none !important;
    max-height: none !important;
}

.fancybox__container:fullscreen .fancybox__slide.has-video .fancybox__content,
.fancybox__container:fullscreen .fancybox__slide.has-html5video .fancybox__content {
    width: 100vw !important;
    height: 100vh !important;
    max-width: none !important;
    max-height: none !important;
}

/* Очистка после закрытия Fancybox */
.fancybox__container[aria-hidden="true"] {
    display: none !important;
}

.fancybox__container[aria-hidden="true"] .fancybox__content {
    display: none !important;
}

/* Дополнительные исправления для Fancybox */
.fancybox__container {
    z-index: 9999 !important;
}

.fancybox__backdrop {
    z-index: 9998 !important;
}

/* Исправление для видео элементов */
.fancybox__slide.has-video .fancybox__content,
.fancybox__slide.has-html5video .fancybox__content {
    background: #000 !important;
}

.fancybox__slide.has-video video,
.fancybox__slide.has-html5video video {
    width: 100% !important;
    height: 100% !important;
    object-fit: contain !important;
}