/* Verbeterde Custom Product Gallery Styling */
.woocommerce-product-gallery {
    position: relative !important;
    margin-bottom: 2em;
}

.custom-gallery-container {
    display: flex;
    gap: 15px;
    margin-bottom: 30px;
    position: relative;
    align-items: flex-start;
    height: auto;
}
.main-item {
    display: none !important;
}

.main-item.active {
  display: block !important;
}

/* Verbeter layout wanneer thumbnails verborgen zijn */
@media (min-width: 769px) {
    .custom-gallery-container:has(.gallery-thumbnails.single-item-only) {
        justify-content: center;
    }
    
    .custom-gallery-container:has(.gallery-thumbnails[style*="display: none"]) .gallery-main-image {
        width: 100%;
        max-width: 100%;
    }
    .custom-gallery-container {
        max-height: 100vh; /* Voorkom dat de container groter wordt dan viewport */
    }
    
    .gallery-thumbnails {
        max-height: calc(100vh - 200px); /* Geef wat ruimte voor header/footer */
    }
}

.product-gallery-section .woocommerce-product-gallery.woocommerce-product-gallery--with-images.images {
  width: 100% !important;
}

.lightbox-video-container {
  width: 100%;
  height: 100%;
}

/* Verberg navigatieknoppen wanneer er slechts één afbeelding is */
.woocommerce-product-gallery__wrapper.single-image .gallery-nav-prev,
.woocommerce-product-gallery__wrapper.single-image .gallery-nav-next {
    display: none !important;
}

/* Extra controle voor als de thumbnails container maar één item heeft */
.gallery-thumbnails:has(.thumbnail-item:only-child) ~ .gallery-navigation {
    display: none !important;
}

/* Alternatieve methode voor browsers die :has niet ondersteunen */
.gallery-thumbnails.single-item-only ~ .gallery-navigation {
    display: none !important;
}

/* Thumbnail zijbalk - AANGEPAST: dynamische hoogte */
.gallery-thumbnails {
    width: 70px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding-right: 5px;
    overflow-y: auto;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE and Edge */
    /* Geen height of max-height hier - laat JavaScript dit regelen */
}

/* Verberg scrollbars voor Webkit browsers (Chrome, Safari, etc.) */
.gallery-thumbnails::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
}

.zoom-controls button {
  margin: 0px;
}

/* Hoofdafbeelding container */
.gallery-main-image {
    flex: 1;
    position: relative;
    width: 100%; /* Neemt volledige beschikbare breedte */
    max-width: 100%; /* Begrensd tot beschikbare ruimte */
    background-color: #f8f8f8;
    border-radius: 30px;
}

/* Dark theme aanpassingen voor gallery */
[data-theme="dark"] .gallery-main-image {
    background-color: #1e2a2e;
    box-shadow: 0 2px 10px rgba(0,0,0,0.3);
}

/* Thumbnail styling */
.thumbnail-item {
    width: 70px;
    height: 70px;
    min-width: 70px;
    max-width: 70px;
    flex: 0 0 70px;
    cursor: pointer;
    border: 2px solid #f1f1f1;
    border-radius: 15px;
    overflow: hidden;
    position: relative;
    transition: all 0.3s ease;
    aspect-ratio: 1 / 1;
}

/* Dark theme thumbnail border */
[data-theme="dark"] .thumbnail-item {
    border-color: #2e2e2e;
}

.thumbnail-item.active {
    border-color: #005f5f;
}

[data-theme="dark"] .thumbnail-item.active {
    border-color: #00a896;
}

.thumbnail-item img {
    width: 100% !important;
    height: 100% !important;
    display: block;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.thumbnail-item:hover img {
    transform: scale(1.10);
}

/* Video thumbnail styling */
.video-thumb {
    position: relative;
}

.video-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0,0,0,0.6);
    color: #fff;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
    transition: background 0.3s ease;
}

.video-thumb:hover .video-icon {
    background: rgba(255,0,0,0.7);
}

/* Hoofdafbeelding styling */
.main-item {
    display: none; /* Standaard verborgen */
    position: relative;
    height: 100%;
    width: 100%;
    border-radius: 30px;
    overflow: hidden;
    text-align: center;
}

.main-item img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    transition: transform 0.3s ease-out;
    border-radius: 30px;
}

/* Video container styling */
.main-item.video-container {
    display: none;
    align-items: center;
    justify-content: center;
    background: #000;
    position: relative;
    height: 100%;
    width: 100%;
}

[data-theme="dark"] .main-item.video-container {
    background: #0a0a0a;
}

.main-item.video-container.active {
    display: flex;
}

.video-wrapper {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    background: #000;
}

[data-theme="dark"] .video-wrapper {
    background: #0a0a0a;
}

/* Specifieke video styling */
.product-video,
.product-video-iframe {
    position: relative !important;
    width: 100% !important;
    height: 100% !important;
    max-width: 100%;
    max-height: 100%;
    display: block;
}

/* Navigatie knoppen */
.gallery-navigation {
    position: absolute;
    top: 50%;
    width: 100%;
    display: flex;
    justify-content: space-between;
    z-index: 1;
    padding: 0 15px;
    pointer-events: none;
    transform: translateY(-50%);
}

.gallery-nav-button {
    pointer-events: auto;
    width: 40px;
  height: 40px;
  background: white;
  border: none;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 10;
  box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
  transition: all 0.2s ease !important;
  color: var(--tty-primary);
  font-size: 18px;
}

/* Dark theme navigation buttons */
[data-theme="dark"] .gallery-nav-button {
    background: rgba(30, 42, 46, 0.9);
    color: #f0f0f0;
}

.gallery-nav-button:hover {
    background: var(--tty-primary);
    color: white;
    transform: scale(1.1);
    box-shadow: 0 8px 30px rgba(0, 95, 95, 0.3);
}

[data-theme="dark"] .gallery-nav-button:hover {
    background: #00a896;
}

.gallery-nav-button.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.gallery-nav-button i {
    font-size: 15px;
}

/* Zoom controls */
.zoom-controls {
    position: absolute;
    bottom: 15px;
    right: 15px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 25px;
    padding: 6px 6px;
    display: flex;
    gap: 8px;
    z-index: 1;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.zoom-controls button i {
  opacity: .8;
}

[data-theme="dark"] .zoom-controls {
    background: rgba(30, 42, 46, 0.9);
}

.zoom-controls button {
    background: transparent;
    border: none;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--tty-primary);
}

[data-theme="dark"] .zoom-controls button {
    color: #f0f0f0;
}

.zoom-controls button:hover {
    box-shadow: 0 8px 30px rgba(0, 95, 95, 0.3);
    background: var(--tty-primary);
    color: var(--tty-text-light);
}

[data-theme="dark"] .zoom-controls button:hover {
    background: #00a896;
}

.pan-instruction {
    position: absolute;
    bottom: 15px;
    left: 15px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 8px 12px;
    border-radius: 20px;
    font-size: 12px;
    z-index: 10;
    display: none;
}

/* Verbeterde Lightbox styling */
.gallery-lightbox {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.95);
    z-index: 9999;
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.gallery-lightbox.active {
    opacity: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.lightbox-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.lightbox-content {
    max-width: 90%;
    max-height: 70%;
    width: 90%;;
    height: 70%;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto;
}

/* Video in lightbox styling */
.lightbox-video-wrapper {
    width: 100%;
    max-width: 80%;
    height: 0;
    padding-bottom: 56.25%; /* 16:9 aspect ratio */
    position: relative;
    background: #000;
    border-radius: 8px;
    overflow: hidden;
    margin: 0 auto;
}

.lightbox-video-wrapper video,
.lightbox-video-wrapper iframe {
    position: absolute !important;
    top: 0;
    left: 0;
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    max-height: 100% !important;
    display: block;
    border-radius: 8px;
}

/* Styling voor thumbnails in lightbox */
.lightbox-thumbnail .video-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0,0,0,0.6);
    color: #fff;
    border-radius: 50%;
    width: 35px;
    height: 35px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
    transition: background 0.3s ease;
}

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

.lightbox-thumbnail:hover .video-icon {
    background: rgba(255,0,0,0.7);
}

/* Aanpassingen voor de lightbox cursor bij video */
.main-item.video-container {
    cursor: pointer;
}

/* Lightbox navigatie voor video's */
.lightbox-content .video-wrapper {
    position: relative;
    z-index: 10;
}

.woocommerce-product-gallery__wrapper {
  max-width: none !important;
  cursor: zoom-in;
  width: 100%;
}

.lightbox-image-container {
    overflow: hidden;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    max-width: 100%;
    max-height: 100%;
    border-radius: 12px;
}

.lightbox-image {
    max-width: 100%;
    max-height: 70vh;
    object-fit: contain;
    box-shadow: 0 0 20px rgba(0,0,0,0.3);
    transition: transform 0.3s ease;
}

/* Lightbox navigatie */
.lightbox-navigation {
    position: absolute;
    top: 50%;
    width: 100%;
    display: flex;
    justify-content: space-between;
    z-index: 10;
    padding: 0 40px;
    pointer-events: none;
    transform: translateY(-50%);
}

.lightbox-nav-button {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: none;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    pointer-events: auto;
    box-shadow: 0 2px 10px rgba(0,0,0,0.3);
}

.lightbox-nav-button:hover {
    background: rgba(255, 255, 255, 0.4);
    transform: scale(1.1);
}

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

.lightbox-nav-button i {
    font-size: 24px;
}

/* Lightbox thumbnails */
.lightbox-thumbnails {
    display: flex;
    gap: 10px;
    margin-top: 20px;
    max-width: 80%;
    overflow-x: auto;
    padding: 5px;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE and Edge */
}

.lightbox-thumbnails::-webkit-scrollbar {
    display: none;
}

.lightbox-thumbnail {
    width: 60px;
    height: 60px;
    min-width: 60px;
    flex: 0 0 60px;
    cursor: pointer;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 6px;
    overflow: hidden;
    position: relative;
    transition: all 0.3s ease;
}

.lightbox-thumbnail.active {
    border-color: white;
}

.lightbox-thumbnail img {
    width: 100%;
    height: 100% !important;
    object-fit: cover;
}

.lightbox-thumbnail:hover {
    border-color: white;
    transform: scale(1.05);
}

/* Lightbox zoom controls */
.lightbox-zoom-controls {
    position: absolute;
    bottom: 30px;
    right: 30px;
    background: rgb(61, 61, 61);
    border-radius: 25px;
    padding: 8px 8px;
    display: flex;
    gap: 10px;
    z-index: 10;
}

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

.lightbox-zoom-controls button:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

/* Lightbox sluitknop */
#product-gallery-lightbox .lightbox-close {
  position: absolute;
  top: 20px;
  right: 20px;
  color: white;
  background: rgb(61, 61, 61);
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  z-index: 100;
}

#product-gallery-lightbox .lightbox-close:hover {
    background: rgba(255,255,255,0.2);
    transform: scale(1.1);
}

/* Cursor op afbeeldingen aanpassen */
.main-item[data-type="image"] {
    cursor: zoom-in;
}

/* Disable WooCommerce lightbox */
.woocommerce-product-gallery__trigger {
    display: none !important;
}

.gallery-thumbnails .thumbnail-item {
    transition: opacity 0.3s ease;
}

.gallery-main-image .main-item {
    transition: opacity 0.3s ease;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.08);
}

/* Laad animatie */
.gallery-loader {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    border: 4px solid rgba(0,0,0,0.1);
    border-radius: 50%;
    border-top-color: #2271b1;
    animation: spin 1s infinite linear;
    z-index: 5;
    display: none;
}

[data-theme="dark"] .gallery-loader {
    border-color: rgba(255,255,255,0.1);
    border-top-color: #00a896;
}

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

/* Verbeterde video controls */
.main-item.video-container video::-webkit-media-controls {
    background-color: rgba(0, 0, 0, 0.5);
}

.main-item.video-container video::-webkit-media-controls-panel {
    background-color: rgba(0, 0, 0, 0.5);
}

/* Basis stijl: standaard controls verbergen op desktop */
@media screen and (min-width: 769px) {
  .woocommerce-product-gallery__wrapper .gallery-nav-prev,
  .woocommerce-product-gallery__wrapper .gallery-nav-next,
  .woocommerce-product-gallery__wrapper .zoom-controls {
    opacity: 0;
    transition: opacity 0.3s ease;
  }
  
  /* Toon controls bij hover over de gallery wrapper */
  .woocommerce-product-gallery__wrapper:hover .gallery-nav-prev,
  .woocommerce-product-gallery__wrapper:hover .gallery-nav-next,
  .woocommerce-product-gallery__wrapper:hover .zoom-controls {
    opacity: 1;
  }
  
  /* Ook tonen wanneer een class 'controls-visible' wordt toegevoegd via JS */
  .woocommerce-product-gallery__wrapper.controls-visible .gallery-nav-prev,
  .woocommerce-product-gallery__wrapper.controls-visible .gallery-nav-next,
  .woocommerce-product-gallery__wrapper.controls-visible .zoom-controls {
    opacity: 1;
  }
}

/* Responsieve aanpassingen */
@media (max-width: 768px) {
    .custom-gallery-container {
        flex-direction: column-reverse;
        gap: 10px;
    }
    
    .woocommerce-product-gallery__wrapper .gallery-nav-prev,
    .woocommerce-product-gallery__wrapper .gallery-nav-next,
    .woocommerce-product-gallery__wrapper .zoom-controls {
        opacity: 1 !important; /* !important om eventuele andere stijlen te overschrijven */
    }
    
    .gallery-thumbnails {
        width: 100%;
        flex-direction: row;
        height: auto; /* AANGEPAST: geen vaste hoogte op mobiel */
        max-height: none;
        overflow-x: auto;
        overflow-y: hidden;
        padding-right: 0;
        padding-bottom: 5px;
        scrollbar-width: none; /* Firefox */
        -ms-overflow-style: none; /* IE and Edge */
        gap: 0px;
    }
    
    .gallery-thumbnails::-webkit-scrollbar {
        display: none;
        width: 0;
        height: 0;
    }
    
    .thumbnail-item {
        width: 70px;
        height: 70px;
        min-width: 70px;
        max-width: 70px;
        flex: 0 0 70px;
        scroll-snap-align: start;
        margin-right: 10px;
    }
    
    .gallery-main-image {
        max-width: 100%;
        margin: 0 auto;
    }
    
    .zoom-controls {
        bottom: 10px;
        right: 10px;
    }
    
    .gallery-nav-button {
        width: 36px;
        height: 36px;
    }
    
    /* Verberg lightbox functionaliteit op mobiel */
    .main-item[data-type="image"] {
        cursor: default;
    }
    
    .lightbox-nav-button,
    .lightbox-nav-button:hover {
        width: 40px;
        height: 40px;
        font-size: 12px;
        background: #717070;
        transform: none !important;
    }
    
    .lightbox-nav-button i {
        font-size: 16px;
    }
    
    #product-gallery-lightbox .lightbox-zoom-controls {
        display: none !important;
    }
    
    #product-gallery-lightbox .lightbox-navigation {
         top: 45% !important;
    }

}

/* Druk af op zwart-wit printers */
@media print {
    .gallery-thumbnails,
    .gallery-navigation,
    .zoom-controls,
    .pan-instruction,
    .video-container,
    .lightbox-thumbnails,
    .lightbox-navigation,
    .lightbox-zoom-controls,
    .lightbox-close {
        display: none !important;
    }
    
    .main-item.active {
        display: block !important;
        page-break-inside: avoid;
    }
    
    .main-item img {
        max-width: 100% !important;
        height: auto !important;
    }
    
    .custom-gallery-container {
        display: block;
        page-break-inside: avoid;
    }
    
    .gallery-main-image {
        box-shadow: none;
        border: 1px solid #ddd;
    }
}