/* 
 * 样式表：Product Grid Structure 
 * 归属：assets/css/product-grid.css
 */

.product-grid-wrap {
    padding: 0;
    margin-bottom: 0;
}

.product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 20px;
}

.product-card {
    text-align: left;
    position: relative;
    outline: none;
    border-radius: 0;
    background: #fff;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* 图片区域 */
.product-figure {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    background: #fbfdfc;
    overflow: hidden;
    display: block;
    border-radius: 0;
    margin: 0;
}

.product-img-link {
    display: block;
    width: 100%;
    height: 100%;
}

.product-figure img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    transform-origin: center center;
    display: block;
    pointer-events: none;
}

.product-figure .img-main { 
    opacity: 1; 
    transform: scale(1); 
    z-index: 1; 
}

.product-figure .img-hover { 
    opacity: 0; 
    transform: scale(1); 
    z-index: 2; 
}

.product-card:hover .product-figure .img-main { 
    opacity: 0; 
}

.product-card:hover .product-figure .img-hover { 
    opacity: 1; 
}

/* 悬浮按钮通用样式 */
.overlay-button {
    pointer-events: auto;
    border: none;
    padding: 0;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    transition-property: all; 
    opacity: 0;
    visibility: hidden;
}

.product-card:hover .overlay-button {
    opacity: 1;
    visibility: visible;
    transform: translate(0, 0) !important;
}

/* 标题容器 */
.product-info-row {
    display: block; 
    position: relative;
}

.product-title {
    display: block;
    font-size: 14px;
    text-decoration: none;
    white-space: nowrap; 
    overflow: hidden;
    text-overflow: ellipsis;
    transition: color 0.3s ease;
    margin: 0;
}

.card-meta { 
    font-size: 13px; 
    margin-top: 4px; 
    margin-bottom: 8px; 
    font-weight: 500; 
}

/* ========== Quick View Modal 弹窗样式 ========== */

.qv-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    z-index: 9999;
    align-items: center;
    justify-content: center;
    padding: 20px;
    box-sizing: border-box;
}

.qv-modal.is-open {
    display: flex;
}

/* 弹窗容器 */
.qv-modal-content {
    background: white;
    border-radius: 8px;
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    display: flex;
    flex-direction: column;
    padding: 0;
}

/* 关闭按钮 */
.qv-close {
    position: absolute;
    top: 15px;
    right: 15px;
    width: 32px;
    height: 32px;
    background: #f0f0f0;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    transition: all 0.3s ease;
}

.qv-close:hover {
    background: #e0e0e0;
    transform: scale(1.1);
}

.qv-close::before {
    content: '✕';
    color: #333;
}

/* ✅ 图片滑块容器 */
.qv-slider-viewport {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    overflow: hidden;
    background: #f9f9f9;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.qv-slider-track {
    display: flex;
    width: 100%;
    height: 100%;
    transition: transform 0.3s ease-out;
    touch-action: pan-y;
    cursor: grab;
}

.qv-slider-track.dragging {
    cursor: grabbing;
}

.qv-slide {
    flex: 0 0 100%;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.qv-slide img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    user-select: none;
}

/* ✅ WhatsApp 询价按钮 */
.qv-whatsapp-btn {
    width: 100%;
    height: 50px;
    padding: 0;
    background-color: #000000;
    color: white;
    border: none;
    border-radius: 0;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-sizing: border-box;
    flex-shrink: 0;
    line-height: 1;  /* ✅ 新增：防止行高影响 */
    overflow: hidden;  /* ✅ 新增：隐藏溢出内容 */
}

.qv-whatsapp-btn:hover {
    background-color: #000000;
    color: #FF9500;
    font-size: 17px;  /* ✅ 改这里：用 font-size 替代 scale */
}

.qv-whatsapp-btn .whatsapp-icon {
    width: 20px;
    height: 20px;
    display: inline-block;
    object-fit: contain;
    transition: all 0.3s ease;
}

.qv-whatsapp-btn svg.whatsapp-icon {
    stroke: currentColor;
    fill: currentColor;
}

.qv-whatsapp-btn:hover svg {
    fill: #FF9500;
    width: 21px;  /* ✅ 新增：SVG 轻微放大 */
}

/* ✅ 缩略图导航容器 */
.qv-thumb-nav {
    display: flex;
    align-items: center;
    gap: 0;
    padding: 15px 10px;
    background: white;
    flex-shrink: 0;
}

.qv-thumb-prev,
.qv-thumb-next {
    width: 32px;
    height: 32px;
    border: 1px solid #ddd;
    background: white;
    cursor: pointer;
    font-size: 16px;
    font-weight: bold;
    color: #333;
    transition: all 0.3s ease;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.qv-thumb-prev:hover,
.qv-thumb-next:hover {
    background: #f0f0f0;
    border-color: #999;
}

/* ✅ 缩略图容器 */
.qv-thumbs {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    flex: 1;
    scroll-behavior: smooth;
    padding: 0 10px;
}

.qv-thumbs::-webkit-scrollbar {
    height: 6px;
}

.qv-thumbs::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.qv-thumbs::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 3px;
}

.qv-thumbs::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* ✅ 缩略图按钮 */
.qv-thumbs button {
    flex: 0 0 80px;
    height: 80px;
    border: 2px solid transparent;
    background: white;
    cursor: pointer;
    overflow: hidden;
    transition: all 0.3s ease;
    padding: 0;
}

.qv-thumbs button img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.qv-thumbs button.active {
    border-color: #333;
    box-shadow: 0 0 8px rgba(0, 0, 0, 0.2);
}

.qv-thumbs button:hover {
    border-color: #999;
}

/* ========== 响应式 ========== */

/* 响应式：平板设备 */
@media (max-width: 1024px) {
    .qv-modal-content {
        max-width: 90%;
    }

    .qv-slider-viewport {
        aspect-ratio: 1 / 1;
    }

    .qv-thumbs button {
        flex: 0 0 70px;
        height: 70px;
    }

    .qv-whatsapp-btn {
        height: 44px;
        font-size: 15px;
    }

    .qv-whatsapp-btn:hover {
        color: #FF9500;
        font-size: 16px;  /* ✅ 改这里 */
    }
}

/* 响应式：手机设备 */
@media (max-width: 768px) {
    .qv-modal {
        padding: 10px;
    }

    .qv-modal-content {
        max-width: 100%;
        max-height: 100vh;
        border-radius: 0;
    }

    .qv-close {
        top: 10px;
        right: 10px;
        width: 28px;
        height: 28px;
        font-size: 18px;
    }

    .qv-slider-viewport {
        aspect-ratio: 1 / 1;
    }

    .qv-thumb-nav {
        padding: 12px 8px;
        gap: 0;
    }

    .qv-thumb-prev,
    .qv-thumb-next {
        width: 28px;
        height: 28px;
        font-size: 14px;
    }

    .qv-thumbs {
        padding: 0 6px;
        gap: 6px;
    }

    .qv-thumbs button {
        flex: 0 0 60px;
        height: 60px;
    }

    .qv-whatsapp-btn {
        height: 40px;
        font-size: 14px;
    }

    .qv-whatsapp-btn:hover {
        color: #FF9500;
        font-size: 15px;  /* ✅ 改这里 */
    }

    /* ✅ 手机隐藏悬浮图标 */
    .overlay-button {
        display: none !important;
    }
}

/* 响应式：超小手机 */
@media (max-width: 480px) {
    .qv-modal {
        padding: 5px;
    }

    .qv-slider-viewport {
        aspect-ratio: 1 / 1;
    }

    .qv-thumb-nav {
        padding: 10px 5px;
    }

    .qv-thumb-prev,
    .qv-thumb-next {
        width: 24px;
        height: 24px;
        font-size: 12px;
    }

    .qv-thumbs button {
        flex: 0 0 50px;
        height: 50px;
    }

    .qv-whatsapp-btn {
        height: 36px;
        font-size: 13px;
    }

    .qv-whatsapp-btn:hover {
        color: #FF9500;
        font-size: 14px;  /* ✅ 改这里 */
    }
}

/* ========== 无限滚动加载器 ========== */

.my-product-grid-loader {
    all: unset;
    display: block !important;
    width: 100% !important;
    margin: 50px auto 0 !important;
    padding: 0 !important;
    
    min-height: 0 !important;
    height: 0 !important;
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
    overflow: hidden !important;
    
    transition: all 0.3s ease !important;
    border: 0 !important;
    background: transparent !important;
}

.my-product-grid-loader.loader-active {
    min-height: 100px !important;
    height: 100px !important;
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
    overflow: visible !important;
    
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

.my-product-grid-loader .loader-text {
    all: unset;
    display: inline-block !important;
    position: relative !important;
    padding-left: 50px !important;
    font-size: 18px !important;
    font-weight: 600 !important;
    color: #333 !important;
}

.my-product-grid-loader .loader-text::before {
    content: '' !important;
    position: absolute !important;
    left: 0 !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    
    width: 32px !important;
    height: 32px !important;
    border: 4px solid #f0f0f0 !important;
    border-top-color: #ff6b00 !important;
    border-right-color: #ff6b00 !important;
    border-radius: 50% !important;
    
    animation: pgLoaderSpin 0.8s linear infinite !important;
}

.my-product-grid-loader.no-more-products {
    height: auto !important;
    min-height: 60px !important;
    opacity: 1 !important;
    visibility: visible !important;
    
    padding: 30px 20px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

.my-product-grid-loader.no-more-products .loader-text {
    font-size: 16px !important;
    color: #999 !important;
    padding-left: 0 !important;
}

.my-product-grid-loader.no-more-products .loader-text::before {
    display: none !important;
}

@keyframes pgLoaderSpin {
    to {
        transform: translateY(-50%) rotate(360deg);
    }
}

/* 
 * JS 交互：Quick View Modal
 * 归属：assets/js/quick-view.js
 */

function openQuickView(galleryArr, productTitle = '') {
            if (!galleryArr || !galleryArr.length) return;
            
            currentProductTitle = productTitle;
            
            // ✅ 清空轨道
            track.innerHTML = '';
            
            // ✅ 只添加图片到 DOM，不显示
            galleryArr.forEach((url, idx) => {
                const slide = document.createElement('div');
                slide.className = 'qv-slide';
                const img = document.createElement('img');
                img.src = url;
                img.draggable = false;
                slide.appendChild(img);
                track.appendChild(slide);
            });

            // ✅ 创建缩略图
            qvThumbs.innerHTML = '';
            galleryArr.forEach((url, idx) => {
                const btn = document.createElement('button');
                btn.type = 'button';
                const timg = document.createElement('img');
                timg.src = url;
                btn.appendChild(timg);
                btn.onclick = () => {
                    currentIndex = idx;
                    track.style.transition = `transform ${slideDuration}ms ease-out`;
                    setPositionByIndex();
                };
                qvThumbs.appendChild(btn);
            });

            totalSlides = galleryArr.length;
            currentIndex = 0;
            modal.classList.add('is-open');
            modal.setAttribute('aria-hidden', 'false');

            // ✅ 重要：先显示弹窗，再设置位置
            setTimeout(() => {
                // ✅ 确保 viewport 有正确的宽度
                const viewportWidth = viewport.offsetWidth;
                
                // ✅ 设置轨道的总宽度
                track.style.width = `${totalSlides * 100}%`;
                
                // ✅ 重置位置：显示第一张图
                track.style.transition = 'none';
                currentTranslate = 0;
                prevTranslate = 0;
                currentIndex = 0;
                setSliderPosition();
                updateThumbs();
            }, 10);
        }
