/**
 * Amazon Zoom for WooCommerce - Styles
 * Version: 1.3.3
 * Mobile fit-to-screen with pinch zoom
 */

/* Main image container */
.azw-zoom-container {
    position: relative !important;
    cursor: crosshair !important;
    /* DO NOT set overflow:visible - it breaks WoodMart gallery carousel */
}

.azw-zoom-container.azw-active {
    z-index: 100;
}

/* Desktop only: Make sure container receives events, not the anchor */
@media (hover: hover) and (pointer: fine) {
    .azw-zoom-container a {
        pointer-events: none !important;
    }
    
    .azw-zoom-container img {
        pointer-events: none !important;
    }
}

/* Mobile/Touch: Allow pointer events for tap to zoom */
@media (hover: none), (pointer: coarse) {
    .azw-zoom-container {
        cursor: zoom-in !important;
    }
    
    .azw-zoom-container a,
    .azw-zoom-container img {
        pointer-events: auto !important;
    }
}

/* Zoom lens needs overflow visible only on its direct container */
/* DO NOT apply overflow:visible to gallery wrappers - it breaks carousel */

/* Zoom lens - follows cursor on main image */
.azw-zoom-lens {
    position: absolute;
    border: 2px solid var(--azw-lens-border, #ff9900);
    background: var(--azw-lens-bg, rgba(255, 153, 0, 0.3));
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--azw-animation, 150ms) ease;
    z-index: 999;
    box-sizing: border-box;
    cursor: crosshair;
}

.azw-zoom-container.azw-active .azw-zoom-lens {
    opacity: 1;
    visibility: visible;
}

/* Debug - make lens always visible for testing */
.azw-zoom-lens.azw-debug {
    opacity: 1 !important;
    visibility: visible !important;
    background: rgba(255, 0, 0, 0.3) !important;
}

/* Zoom panel - appears on the right, fills available space */
#azw-zoom-panel,
.azw-zoom-panel {
    position: fixed !important;
    background: #fff !important;
    border: 1px solid #e0e0e0 !important;
    box-shadow: 0 4px 25px rgba(0, 0, 0, 0.15) !important;
    overflow: hidden !important;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s ease, visibility 0.15s ease;
    z-index: 2147483647 !important; /* Maximum z-index */
    pointer-events: none;
    box-sizing: border-box;
}

#azw-zoom-panel.azw-visible,
.azw-zoom-panel.azw-visible {
    opacity: 1 !important;
    visibility: visible !important;
}

#azw-zoom-panel img,
.azw-zoom-panel img {
    position: absolute !important;
    max-width: none !important;
    max-height: none !important;
    width: auto;
    height: auto;
    display: block !important;
    /* Smooth HD image quality */
    image-rendering: auto;
    -ms-interpolation-mode: bicubic;
}

/* Loading indicator */
.azw-zoom-panel::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #ff9900;
    border-radius: 50%;
    animation: azw-spin 1s linear infinite;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.azw-zoom-panel.azw-loading::before {
    opacity: 1;
}

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

/* Mobile fullscreen zoom */
.azw-mobile-zoom {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    z-index: 99999;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease;
    overflow: hidden;
    touch-action: none;
}

.azw-mobile-zoom.azw-visible {
    opacity: 1;
    visibility: visible;
}

.azw-mobile-zoom-content {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.azw-mobile-zoom-image {
    max-width: 100% !important;
    max-height: 100% !important;
    width: auto !important;
    height: auto !important;
    object-fit: contain;
    cursor: grab;
    transition: transform 0.1s ease-out;
    transform-origin: center center;
}

.azw-mobile-zoom-image.azw-dragging {
    cursor: grabbing;
    transition: none;
}

/* Close button */
.azw-mobile-close {
    position: absolute;
    top: 15px;
    right: -10px;
    width: 44px;
    height: 44px;
    background: rgba(255, 255, 255, 0.9);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    z-index: 100001;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, transform 0.2s ease;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

.azw-mobile-close:hover {
    background: #fff;
    transform: scale(1.1);
}

.azw-mobile-close::before,
.azw-mobile-close::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 2px;
    background: #333;
}

.azw-mobile-close::before {
    transform: rotate(45deg);
}

.azw-mobile-close::after {
    transform: rotate(-45deg);
}

/* Zoom controls for mobile */
.azw-mobile-controls {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 10px;
    z-index: 100001;
}

/* Hint text for mobile zoom */
.azw-mobile-hint {
    position: absolute;
    top: 70px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
    white-space: nowrap;
    z-index: 100001;
    opacity: 1;
    transition: opacity 0.5s ease;
    pointer-events: none;
}

.azw-mobile-zoom.azw-zoomed .azw-mobile-hint {
    opacity: 0;
}

.azw-mobile-control-btn {
    width: 44px;
    height: 44px;
    background: rgba(255, 255, 255, 0.9);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: bold;
    color: #333;
    transition: background 0.2s ease, transform 0.2s ease;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

.azw-mobile-control-btn:hover {
    background: #fff;
    transform: scale(1.1);
}

/* Thumbnail navigation indicator */
.azw-thumbnail-indicator {
    position: absolute;
    bottom: 70px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
    z-index: 100001;
}

.azw-thumbnail-dot {
    width: 10px;
    height: 10px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.2s ease;
}

.azw-thumbnail-dot.azw-active {
    background: #fff;
    transform: scale(1.2);
}

/* Expand icon on image */
.azw-expand-icon {
    position: absolute;
    bottom: 10px;
    right: 10px;
    width: 36px;
    height: 36px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 10;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.azw-zoom-container:hover .azw-expand-icon {
    opacity: 1;
}

.azw-expand-icon svg {
    width: 20px;
    height: 20px;
    fill: #333;
}

/* WoodMart theme compatibility */
.woodmart-product-gallery .azw-zoom-container {
    width: 100%;
}

/* CRITICAL: Hide gallery thumbnails during zoom to prevent overlap */
.woocommerce-product-gallery.azw-enabled.azw-zoom-active .wd-carousel-container.wd-gallery-thumb,
.woocommerce-product-gallery.azw-enabled.azw-zoom-active .wd-gallery-thumb,
.woocommerce-product-gallery.azw-enabled.azw-zoom-active .flex-control-thumbs,
.woocommerce-product-gallery.azw-enabled.azw-zoom-active .woocommerce-product-gallery__thumbnails {
    opacity: 0.3 !important;
    pointer-events: none !important;
    z-index: 1 !important;
    position: relative !important;
}

/* Ensure main image container is isolated */
.azw-zoom-container.azw-active {
    z-index: 100;
    isolation: isolate;
}

/* Force thumbnails to stay below zoom elements */
.wd-carousel-container.wd-gallery-thumb,
.wd-gallery-thumb,
.woocommerce-product-gallery .flex-control-thumbs {
    z-index: 10 !important;
}

/* Fix for gallery image wrapper */
.woocommerce-product-gallery__image.azw-zoom-container img {
    width: 100%;
    height: auto;
}

/* Hide default WooCommerce zoom */
.woocommerce-product-gallery.azw-enabled .woocommerce-product-gallery__trigger {
    display: none !important;
}

/* Hide WoodMart's native zoom */
.woocommerce-product-gallery.azw-enabled .zoomImg,
.azw-zoom-container .zoomImg {
    display: none !important;
    opacity: 0 !important;
    visibility: hidden !important;
}

/* Disable WoodMart zoom hover effects */
.woocommerce-product-gallery.azw-enabled figure.woocommerce-product-gallery__image {
    cursor: crosshair !important;
}

.woocommerce-product-gallery.azw-enabled figure.woocommerce-product-gallery__image a {
    cursor: crosshair !important;
    pointer-events: none;
}

/* WoodMart gallery structure - do not modify overflow on carousel containers */

/* Gallery thumbnails styling when active */
.woocommerce-product-gallery .flex-control-thumbs li {
    cursor: pointer;
    transition: opacity 0.2s ease;
}

.woocommerce-product-gallery .flex-control-thumbs li:hover {
    opacity: 0.8;
}

.woocommerce-product-gallery .flex-control-thumbs li.azw-thumb-active {
    opacity: 1;
}

.woocommerce-product-gallery .flex-control-thumbs li.azw-thumb-active img {
    border: 2px solid var(--azw-lens-border, #ff9900);
    box-sizing: border-box;
}

/* Responsive adjustments - panel uses dynamic sizing */
@media (max-width: 992px) {
    .azw-zoom-panel {
        display: none !important;
    }
    
    .azw-zoom-lens {
        display: none !important;
    }
    
    .azw-zoom-container {
        cursor: zoom-in;
    }
    
    .azw-expand-icon {
        opacity: 1;
    }
}

/* Touch devices indicator */
@media (hover: none) and (pointer: coarse) {
    .azw-expand-icon {
        opacity: 1;
        width: 48px;
        height: 48px;
        pointer-events: auto !important;
    }
    
    .azw-expand-icon svg {
        width: 28px;
        height: 28px;
    }
    
    /* Ensure container is tappable */
    .azw-zoom-container {
        cursor: zoom-in !important;
        -webkit-tap-highlight-color: rgba(0,0,0,0.1);
    }
}

/* RTL support */
[dir="rtl"] .azw-zoom-panel {
    left: auto;
}

[dir="rtl"] .azw-expand-icon {
    right: auto;
    left: 10px;
}

[dir="rtl"] .azw-mobile-close {
    right: auto;
    left: 15px;
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .azw-zoom-panel {
        background: #1a1a1a;
        border-color: #333;
    }
}

/* Accessibility - reduce motion */
@media (prefers-reduced-motion: reduce) {
    .azw-zoom-lens,
    .azw-zoom-panel,
    .azw-mobile-zoom,
    .azw-mobile-close,
    .azw-mobile-control-btn,
    .azw-thumbnail-dot,
    .azw-expand-icon {
        transition: none;
    }
    
    .azw-zoom-panel::before {
        animation: none;
    }
}

/* Print - hide zoom elements */
@media print {
    .azw-zoom-lens,
    .azw-zoom-panel,
    .azw-mobile-zoom,
    .azw-expand-icon {
        display: none !important;
    }
}
