/* 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;
}

.bbf-main-image-wrapper img {
    width: 100%;
    height: auto;
    display: block;
}

/* 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;
}
.bbf-main-slide a {
    display: block;
    width: 100%;
    cursor: zoom-in;
}

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

/* 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-inline {
    position: absolute;
    top: 0;
    left: 0;
    width: 100% !important;
    height: 100% !important;
    overflow: hidden;
    border-radius: 0;
    box-shadow: none;
    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;
    }
}

/* WCAG 2.5.5 — Touch-Targets >= 44x44 auf Pointer:coarse (Touch-Geraete).
   Auf Desktop bleiben die kompakten 30x30 fuer Maus-Bedienung. */
@media (pointer: coarse) {
    .bbf-nav-arrow,
    .bbf-thumbnail,
    .bbf-share-product-btn,
    .bbf-share-close,
    .bbf-share-copy-btn {
        min-width: 44px;
        min-height: 44px;
    }
}

/* 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-pane img {
    max-width: none;
}

/* ──────────────────────────────────────────────────────────────────
   v2.1.2 Fixes
   ────────────────────────────────────────────────────────────────── */

/* Fix 2 — Hauptbild proportional einpassen.
   Vorher: width:100%; height:auto auf .bbf-main-image-wrapper img führte bei
   Hochformat-Bildern dazu, dass die Bildhöhe > Slide-Höhe (1:1 aspect-ratio)
   wurde und der overflow:hidden des Wrappers das Bild unten abschnitt.
   Jetzt: Bild füllt den Slide (100% x 100%) und der Inhalt wird via
   object-fit:contain proportional eingepasst — kein Cropping mehr. */
.bbf-main-image-wrapper img,
.bbf-main-slide a img,
.bbf-main-slide picture img {
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    object-position: center;
    display: block;
}

/* Placeholder-Image soll weiterhin width:100% / height:auto behalten —
   sie hat inline-styles, hier aber explizit absichern. */
.bbf-placeholder-image {
    width: 100% !important;
    height: auto !important;
    object-fit: contain;
}

/* Fix 1 — Bei 0/1 Bild Swipe, Drag und Scroll-Snap deaktivieren.
   data-bbf-image-count wird seit v2.1.0 vom image.tpl gesetzt; touch-action
   sperrt horizontalen Wisch (vertikales Page-Scroll bleibt erlaubt). */
.bbf-gallery-container[data-bbf-image-count="0"] .bbf-main-slider,
.bbf-gallery-container[data-bbf-image-count="1"] .bbf-main-slider {
    overflow-x: hidden;
    overflow-y: hidden;
    scroll-snap-type: none;
    touch-action: pan-y;
    cursor: zoom-in;
}

/* Pfeile/Nav defensiv ausblenden (JS erledigt das schon, hier als Doppelung
   für Render-Phase vor JS-Init — verhindert Layout-Flash). */
.bbf-gallery-container[data-bbf-image-count="0"] .bbf-thumbnails-container,
.bbf-gallery-container[data-bbf-image-count="1"] .bbf-thumbnails-container,
.bbf-gallery-container[data-bbf-image-count="0"] .bbf-nav-arrow,
.bbf-gallery-container[data-bbf-image-count="1"] .bbf-nav-arrow {
    display: none !important;
}

/* Fix 3 — Zoom-Pane und Bounding-Box mit scharfen Ecken.
   Vendor drift-basic.min.css setzt border-radius:75px auf .drift-inline;
   wir killen Radius defensiv auf allen drift-Elementen (auch side-Modus,
   falls Theme/Bootstrap einen Radius vererbt). */
.bbf-zoom-pane,
.drift-zoom-pane,
.drift-zoom-pane.drift-inline,
.drift-zoom-pane img,
.drift-bounding-box {
    border-radius: 0 !important;
}
