/**
 * Drift Image Magnifier Styles
 * Based on CodePen: https://codepen.io/jesse-waitz/pen/MYwzdbz
 */

/* Debug: Ensure this CSS file is loading */
body.single-product {
    --drift-loaded: true;
}

/* Main drift container styling */
.woocommerce-product-gallery {
    position: relative;
}

/* Product image with drift trigger */
.drift-trigger {
    cursor: crosshair;
    transition: opacity 0.3s ease;
    /* Ensure images are easily touchable */
    touch-action: manipulation;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

.drift-trigger:hover {
    opacity: 0.9;
}

/* Inline zoom pane styling (like in CodePen) */
.drift-zoom-pane.drift-inline {
    width: 250px !important;
    height: 250px !important;
    border-radius: 125px !important;
    border: 3px solid #ffffff;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    background: #ffffff;
    overflow: hidden;
    z-index: 1000;
}

/* Zoom pane image */
.drift-zoom-pane img {
    max-width: none !important;
    border-radius: inherit;
}

/* Bounding box styling (if enabled) */
.drift-bounding-box {
    border: 2px solid #ffffff;
    background: rgba(255, 255, 255, 0.1);
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.2);
}

/* Animation for zoom pane opening/closing */
.drift-zoom-pane.drift-opening {
    animation: driftFadeIn 0.18s ease-out;
}

.drift-zoom-pane.drift-closing {
    animation: driftFadeOut 0.18s ease-out;
}

@keyframes driftFadeIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes driftFadeOut {
    from {
        opacity: 1;
        transform: scale(1);
    }
    to {
        opacity: 0;
        transform: scale(0.9);
    }
}

/* Responsive behavior - optimized for mobile touch */
@media only screen and (max-width: 767px) {
    .drift-trigger {
        cursor: pointer; /* Better for touch devices */
    }
    
    /* Make zoom pane smaller on mobile */
    .drift-zoom-pane.drift-inline {
        width: 180px !important;
        height: 180px !important;
        border-radius: 90px !important;
        border: 2px solid #ffffff;
    }
    
    /* Position zoom pane better for mobile */
    .woocommerce-product-gallery .drift-zoom-pane.drift-inline {
        position: fixed; /* Use fixed positioning for better mobile UX */
        top: 20px;
        right: 20px;
        left: auto;
        margin: 0;
        z-index: 9999;
    }
    
    /* Show bounding box on mobile for better UX */
    .drift-bounding-box {
        border: 2px solid #007cba;
        background: rgba(0, 124, 186, 0.1);
        box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.2);
    }
}

/* Touch-friendly improvements */
.drift-trigger {
    /* Ensure images are easily touchable */
    touch-action: manipulation;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Improve bounding box visibility on touch devices */
.drift-bounding-box {
    border: 2px solid #007cba;
    background: rgba(0, 124, 186, 0.15);
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.3);
    transition: all 0.2s ease;
}

/* Add a subtle pulse animation for the zoom pane on mobile to indicate interactivity */
@media only screen and (max-width: 767px) {
    .drift-zoom-pane.drift-inline.drift-opening {
        animation: driftFadeIn 0.3s ease-out, mobilePulse 0.6s ease-in-out;
    }
}

@keyframes mobilePulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

/* Improve zoom pane appearance on mobile */
@media only screen and (max-width: 767px) {
    .drift-zoom-pane.drift-inline {
        box-shadow: 0 8px 25px rgba(0, 0, 0, 0.25) !important;
        border: 3px solid #ffffff !important;
    }
    
    /* Add a close hint for mobile users */
    .drift-zoom-pane.drift-inline::after {
        content: "👆 Tap anywhere to close";
        position: absolute;
        bottom: -30px;
        left: 50%;
        transform: translateX(-50%);
        background: rgba(0, 0, 0, 0.7);
        color: white;
        padding: 4px 8px;
        border-radius: 4px;
        font-size: 12px;
        white-space: nowrap;
        pointer-events: none;
        animation: fadeInHint 0.5s ease-out 1s both;
    }
}

@keyframes fadeInHint {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

@media only screen and (min-width: 1201px) {
    /* Large desktop - zoom pane to the side */
    .woocommerce-product-gallery .drift-zoom-pane.drift-inline {
        position: absolute;
        top: 50%;
        left: 100%;
        margin-left: 20px;
        margin-top: -125px; /* Half of height to center vertically */
        z-index: 1000;
    }
}

@media only screen and (min-width: 768px) {
    /* Desktop-specific styles */
    .drift-trigger {
        cursor: crosshair;
    }
}

/* Ensure proper positioning within WooCommerce gallery */
.woocommerce-product-gallery__wrapper {
    position: relative;
    overflow: visible;
}

.woocommerce-product-gallery__image {
    position: relative;
    overflow: visible;
}

/* Style adjustments for better integration with WooCommerce */
/* Base positioning will be overridden by media queries */

/* Adjust for tablets and medium screens */
@media only screen and (min-width: 768px) and (max-width: 1200px) {
    .woocommerce-product-gallery .drift-zoom-pane.drift-inline {
        width: 200px !important;
        height: 200px !important;
        border-radius: 100px !important;
        left: 50%;
        top: 100%;
        margin-left: -100px; /* Half of width to center horizontally */
        margin-top: 20px;
    }
}

/* Additional styling for product gallery thumbnails */
.woocommerce-product-gallery__trigger.drift-trigger {
    cursor: crosshair;
}

/* Ensure the zoom pane doesn't interfere with other elements */
.drift-zoom-pane {
    pointer-events: none;
}

/* Loading state */
.drift-zoom-pane.drift-loading {
    background: #f8f8f8;
    display: flex;
    align-items: center;
    justify-content: center;
}

.drift-zoom-pane.drift-loading::after {
    content: "Loading...";
    color: #666;
    font-size: 14px;
}
