/* Gallery Layout */
.bbf-gallery-container {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
    position: relative;
}

/* Positions */
.bbf-gallery-container.pos-below {
    flex-direction: column;
}

.bbf-gallery-container.pos-above {
    flex-direction: column-reverse;
}

.bbf-gallery-container.pos-left {
    flex-direction: row-reverse;
}

.bbf-gallery-container.pos-right {
    flex-direction: row;
}

/* Main Image */
.bbf-main-image-wrapper {
    flex: 1;
    position: relative;
    background: #fdfdfd;
    border: 1px solid #eee;
    overflow: hidden;
    cursor: zoom-in;
    min-width: 0;
}

/* Nur das Produktbild sizen — NICHT das Drift-Zoom-Bild!
   Selektor ist bewusst eng, damit `.drift-zoom-pane img` nicht getroffen wird. */
.bbf-main-slide > a > img.bbf-main-image,
.bbf-main-slide > a > picture > img.bbf-main-image,
.bbf-main-slide > a > img.img-fluid,
.bbf-main-slide > a > picture > img.img-fluid {
    display: block;
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    margin: 0 auto;
    object-fit: contain;
}

/* Slider Layout */
.bbf-main-slider {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
    /* Firefox */
    -ms-overflow-style: none;
    /* IE 10+ */
    scroll-behavior: smooth;
    cursor: zoom-in;
}

.bbf-main-slider::-webkit-scrollbar {
    display: none;
}

.bbf-main-slide {
    flex: 0 0 100%;
    scroll-snap-align: center;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    min-width: 0;
    height: 100%;
    overflow: hidden;
}
.bbf-main-slide a {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    cursor: zoom-in;
}

.bbf-main-slide a picture {
    display: flex;
    align-items: center;
    justify-content: center;
    max-width: 100%;
    max-height: 100%;
    line-height: 0;
}

.bbf-main-slide a picture img,
.bbf-main-slide a > img {
    cursor: zoom-in;
}

/* ── Single-Image-Modus: kein Slider/Scroll/Snap nötig ──
   touch-action: pan-y → vertikaler Seiten-Scroll bleibt erlaubt,
   horizontales Wischen wird hardwareseitig vom Browser blockiert,
   damit keine Bewegung/Animation mehr passieren kann. */
.bbf-main-slider.bbf-single-image {
    overflow: hidden;
    scroll-snap-type: none;
    cursor: zoom-in;
    touch-action: pan-y pinch-zoom;
    overscroll-behavior: contain;
}
.bbf-main-slider.bbf-single-image .bbf-main-slide {
    scroll-snap-align: none;
    touch-action: pan-y pinch-zoom;
}
.bbf-main-slider.bbf-single-image .bbf-main-slide a {
    touch-action: pan-y pinch-zoom;
}

/* Thumbnails */
.bbf-thumbnails-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    user-select: none;
}

.pos-above .bbf-thumbnails-container,
.pos-below .bbf-thumbnails-container {
    flex-direction: row;
    width: 100%;
}

.bbf-nav-arrow {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    cursor: pointer;
    color: #333;
    font-size: 16px;
    transition: all 0.2s ease;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 50%;
    z-index: 10;
    opacity: 1;
    visibility: visible;
}

.bbf-nav-arrow.disabled {
    opacity: 0.3;
    cursor: default;
    pointer-events: none;
}

.bbf-nav-arrow.hidden {
    display: none !important;
}

.pos-above .bbf-nav-arrow,
.pos-below .bbf-nav-arrow {
    margin: 0 5px;
}

.pos-left .bbf-nav-arrow,
.pos-right .bbf-nav-arrow {
    margin: 5px 0;
    width: 100%;
    height: auto;
    padding: 5px 0;
    border-radius: 4px;
}

.bbf-nav-arrow:hover,
.bbf-nav-arrow:focus {
    background: var(--bbf-accent-color, #007bff);
    color: #fff;
    border-color: var(--bbf-accent-color, #007bff);
    outline: none;
}

.bbf-nav-arrow:focus-visible {
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.5);
}

.bbf-thumbnails-wrapper {
    display: flex;
    overflow: hidden;
    position: relative;
    max-height: 350px;
    /* Exactly 4 thumbnails (80*4 + 10*3) */
    flex: 1;
}

.pos-above .bbf-thumbnails-wrapper {
    display: flex;
    overflow: hidden;
    position: relative;
    max-height: 350px;
    /* Exactly 4 thumbnails (80*4 + 10*3) */
    flex: 1;
}

.pos-below .bbf-thumbnails-wrapper {
    max-height: none;
    max-width: 100%;
}

.bbf-thumbnails-inner {
    display: flex;
    gap: var(--bbf-thumbnail-gap, 10px);
    transition: transform 0.3s ease;
}

.pos-left .bbf-thumbnails-inner,
.pos-right .bbf-thumbnails-inner {
    flex-direction: column;
}

.pos-left .bbf-thumbnails-container,
.pos-right .bbf-thumbnails-container {
    width: var(--bbf-thumbnail-size, 80px);
}

.bbf-thumbnail {
    flex: 0 0 calc((100% / var(--bbf-thumb-count-xs, 4)) - (var(--bbf-thumbnail-gap, 10px) * (var(--bbf-thumb-count-xs, 4) - 1) / var(--bbf-thumb-count-xs, 4)));
    position: relative;
    width: var(--bbf-thumbnail-size, 80px);
    height: var(--bbf-thumbnail-size, 80px);
    aspect-ratio: 1 / 1;
    border: 1px solid #dee2e6;
    cursor: pointer;
    transition: all 0.2s ease;
    background: #fff;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

@media (min-width: 576px) {
    .bbf-thumbnail {
        flex: 0 0 calc((100% / var(--bbf-thumb-count-sm, 4)) - (var(--bbf-thumbnail-gap, 10px) * (var(--bbf-thumb-count-sm, 4) - 1) / var(--bbf-thumb-count-sm, 4)));
    }
}

@media (min-width: 768px) {
    .bbf-thumbnail {
        flex: 0 0 calc((100% / var(--bbf-thumb-count-md, 4)) - (var(--bbf-thumbnail-gap, 10px) * (var(--bbf-thumb-count-md, 4) - 1) / var(--bbf-thumb-count-md, 4)));
    }

    .pos-left .bbf-thumbnail,
    .pos-right .bbf-thumbnail {
        flex: 0 0 var(--bbf-thumbnail-size, 80px);
        width: var(--bbf-thumbnail-size, 80px);
        height: var(--bbf-thumbnail-size, 80px);
    }
}

@media (min-width: 992px) {
    .bbf-thumbnail {
        flex: 0 0 calc((100% / var(--bbf-thumb-count-lg, 4)) - (var(--bbf-thumbnail-gap, 10px) * (var(--bbf-thumb-count-lg, 4) - 1) / var(--bbf-thumb-count-lg, 4)));
    }
}

@media (min-width: 1200px) {
    .bbf-thumbnail {
        flex: 0 0 calc((100% / var(--bbf-thumb-count-xl, 4)) - (var(--bbf-thumbnail-gap, 10px) * (var(--bbf-thumb-count-xl, 4) - 1) / var(--bbf-thumb-count-xl, 4)));
    }
}

.bbf-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 4px;
    transition: transform 0.3s ease;
}

/* Thumbnail Hover-Effekte (konfigurierbar via thumb_hover_effect) */
.bbf-thumbnail.hover-zoom:hover img {
    transform: scale(1.05);
    will-change: transform;
}

.bbf-thumbnail.hover-border:hover {
    border-color: var(--bbf-accent-color, #007bff);
    box-shadow: 0 0 0 1px var(--bbf-accent-color, #007bff);
}

.bbf-thumbnail.hover-opacity:hover {
    opacity: 0.7;
}

.bbf-thumbnail.hover-none:hover img {
    transform: none;
}

/* Thumbnail Aktiver Zustand (konfigurierbar via thumb_active_style) */
.bbf-thumbnail.active.active-border {
    border-color: var(--bbf-accent-color, #007bff);
    box-shadow: 0 0 0 1px var(--bbf-accent-color, #007bff);
}

.bbf-thumbnail.active.active-opacity {
    opacity: 0.6;
}

.bbf-thumbnail.active.active-shadow {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* Fallback: Standard-Hover wenn keine Klasse gesetzt */
.bbf-thumbnail:hover img {
    transform: scale(1.02);
}

/* Performance: contain layout on thumbnail container */
.bbf-thumbnails-inner {
    contain: content;
}

.bbf-thumbnail.active {
    border-color: var(--bbf-accent-color, #007bff);
    box-shadow: 0 0 0 1px var(--bbf-accent-color, #007bff);
}

.bbf-thumbnail:focus {
    outline: none;
}

.bbf-thumbnail:focus-visible {
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.5);
    z-index: 11;
}

.bbf-thumbnail .video-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #fff;
    font-size: 20px;
    text-shadow: 0 0 10px rgba(0, 0, 0, 0.8);
    pointer-events: none;
}

/* Drift Zoom Container — Inline-Modus (über dem Bild) */
.bbf-zoom-pane {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    overflow: hidden;
    pointer-events: none;
}

.bbf-zoom-pane .drift-zoom-pane {
    opacity: 0;
    transition: opacity 0.3s ease;
}

.bbf-zoom-pane .drift-zoom-pane.drift-open {
    opacity: 1;
}

.drift-zoom-pane {
    background: #fff;
    border: none;
    box-shadow: none;
}

.drift-zoom-pane,
.drift-zoom-pane.drift-inline {
    position: absolute;
    top: 0;
    left: 0;
    width: 100% !important;
    height: 100% !important;
    overflow: hidden;
    /* Drift default ist 75px — wir wollen scharfe Kanten */
    border-radius: 0 !important;
    box-shadow: none !important;
    z-index: 1000;
}

/* Responsiveness */
@media (max-width: 768px) {
    .bbf-gallery-container {
        flex-direction: column !important;
    }

    .bbf-thumbnails-container {
        flex-direction: row !important;
        width: 100% !important;
    }

    .bbf-thumbnails-inner {
        flex-direction: row !important;
    }

    .bbf-nav-arrow {
        width: auto !important;
        padding: 0 10px !important;
    }
}

/* CLS prevention: reserve space for main slider before images load */
.bbf-main-slider {
    aspect-ratio: 1 / 1;
    contain: layout style;
}

/* Avoid rendering off-screen thumbnails */
.bbf-thumbnail:nth-child(n+7) {
    content-visibility: auto;
    contain-intrinsic-size: var(--bbf-thumbnail-size, 80px);
}

/* CSS classes for elements that had inline styles */
.bbf-product-actions {
    position: absolute;
    right: 10px;
    top: 10px;
    z-index: 5;
}

.bbf-video-placeholder {
    width: 100%;
    height: 100%;
    background: #f0f0f0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.bbf-video-placeholder i {
    font-size: 2rem;
    color: #999;
}

/* Accessibility: Respect user motion preferences */
@media (prefers-reduced-motion: reduce) {
    .bbf-thumbnails-inner,
    .bbf-thumbnail,
    .bbf-main-slider,
    .bbf-main-slide,
    .bbf-nav-arrow,
    .bbf-play-icon,
    .bbf-zoom-pane {
        transition: none !important;
        animation: none !important;
    }

    .bbf-thumbnail:hover img {
        transform: none !important;
    }
}

/* Print styles: show only first image, hide interactive elements */
@media print {
    .bbf-nav-arrow,
    .bbf-share-product-wrapper,
    .bbf-play-icon,
    .bbf-product-actions,
    .bbf-zoom-pane,
    .bbf-thumbnails-container {
        display: none !important;
    }

    .bbf-main-slider {
        overflow: visible;
    }

    .bbf-main-slide:not(:first-child) {
        display: none;
    }

    .bbf-gallery-container {
        display: block;
    }
}

/* Placeholder Mode */
.bbf-placeholder-mode .bbf-main-image-wrapper {
    cursor: default;
}

.bbf-placeholder-mode .bbf-placeholder-slide {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 300px;
}

.bbf-placeholder-image {
    max-width: 100%;
    height: auto;
    pointer-events: none;
    user-select: none;
}

/* ── Accessibility ── */

.bbf-gallery-container *:focus-visible {
    outline: 2px solid var(--bbf-accent-color, #0891b2);
    outline-offset: 2px;
}

.bbf-nav-arrow:focus-visible,
.bbf-thumbnail:focus-visible {
    outline: 2px solid var(--bbf-accent-color, #0891b2);
    outline-offset: 2px;
    border-radius: 4px;
}

@media (prefers-reduced-motion: reduce) {
    .bbf-gallery-container *,
    .bbf-gallery-container *::before,
    .bbf-gallery-container *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ── Drift Zoom Overflow Protection ── */

.bbf-main-image-wrapper {
    overflow: hidden;
}

.drift-zoom-pane {
    max-width: 100% !important;
    max-height: 100% !important;
    overflow: hidden;
}

/* Drift-Zoom-Bild: Drift setzt width/height/transform inline — wir resetten nur
   die Properties, die versehentlich von Gallery-Image-Regeln gesetzt werden könnten. */
.drift-zoom-pane img,
.bbf-zoom-pane img {
    max-width: none;
    max-height: none;
    margin: 0;
    object-fit: fill;
}
