/**
 * 4Supply视频管理器样式
 * 支持封面图模式、图库模式、Hook注入模式
 */

/* ==========================================================================
   通用视频样式
   ========================================================================== */

/* 🔥 修复：只在确实有视频时才应用样式 */
.has-product-video[data-video-url] {
    position: relative;
    display: inline-block;
}

/* 确保没有视频的产品图片正常显示 */
.woocommerce-product-gallery__image img {
    display: block !important;
    width: 100% !important;
    height: auto !important;
}

.video-play-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.3);
    cursor: pointer;
    transition: all 0.3s ease;
    opacity: 0;
    visibility: hidden;
}

.has-product-video:hover .video-play-overlay {
    opacity: 1;
    visibility: visible;
}

.video-play-button {
    transition: transform 0.2s ease;
}

.video-play-button:hover {
    transform: scale(1.1);
}

.video-play-button svg {
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
}

.product-video-player {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    height: 100% !important;
    background: #000;
    border-radius: 8px;
    overflow: hidden;
    z-index: 1000 !important;
}

.product-video-player video {
    width: 100% !important;
    height: 100% !important;
    object-fit: contain;
}

.video-close-button {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    border: none;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    transition: background 0.2s ease;
    z-index: 10;
}

.video-close-button:hover {
    background: rgba(0, 0, 0, 0.9);
}

/* ==========================================================================
   封面图模式样式
   ========================================================================== */

.poster-mode .has-product-video {
    cursor: pointer;
}

.poster-mode .video-play-overlay {
    background: linear-gradient(45deg, rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.1));
}

.poster-mode .video-play-button svg circle {
    fill: rgba(255, 255, 255, 0.9);
}

.poster-mode .video-play-button svg polygon {
    fill: #333;
}

/* ==========================================================================
   图库模式样式
   ========================================================================== */

.video-gallery-enabled {
    position: relative;
}

.gallery-video-item {
    position: relative;
}

.video-placeholder {
    width: 100%;
    height: auto;
}

.gallery-video-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.4);
    cursor: pointer;
    transition: all 0.3s ease;
    opacity: 0;
    visibility: hidden;
}

.gallery-video-item:hover .gallery-video-overlay {
    opacity: 1;
    visibility: visible;
}

.gallery-video-player {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #000;
    z-index: 100;
}

.gallery-video-player video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.gallery-video-close {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(255, 255, 255, 0.9);
    color: #333;
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    cursor: pointer;
    font-size: 20px;
    font-weight: bold;
    line-height: 1;
    transition: all 0.2s ease;
    z-index: 101;
}

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

/* ==========================================================================
   Hook注入模式样式
   ========================================================================== */

.product-video-section {
    margin: 20px 0;
    padding: 20px;
    background: #f9f9f9;
    border-radius: 8px;
    border: 1px solid #e1e1e1;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.product-video-section .video-title {
    margin: 0 0 15px 0;
    color: #333;
    font-size: 1.2em;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.product-video-section .video-container {
    text-align: center;
}

.product-video-section video {
    max-width: 100%;
    height: auto;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* ==========================================================================
   响应式设计
   ========================================================================== */

@media (max-width: 768px) {
    .product-video-section {
        margin: 15px 0;
        padding: 15px;
    }
    
    .product-video-section .video-title {
        font-size: 1.1em;
    }
    
    .video-play-button svg {
        width: 50px;
        height: 50px;
    }
    
    .gallery-video-overlay .video-play-button svg {
        width: 40px;
        height: 40px;
    }
    
    .video-close-button,
    .gallery-video-close {
        width: 28px;
        height: 28px;
        font-size: 16px;
    }
}

@media (max-width: 480px) {
    .product-video-section {
        margin: 10px 0;
        padding: 12px;
    }
    
    .video-play-button svg {
        width: 40px;
        height: 40px;
    }
    
    .gallery-video-overlay .video-play-button svg {
        width: 35px;
        height: 35px;
    }
}

/* ==========================================================================
   主题兼容性
   ========================================================================== */

/* WooCommerce默认主题兼容 */
.woocommerce-product-gallery .has-product-video {
    display: block;
    width: 100%;
}

.woocommerce-product-gallery__image .gallery-video-item {
    position: relative;
    display: block;
}

/* Storefront主题兼容 */
.storefront .product-video-section {
    background: #fff;
    border: 1px solid #e6e6e6;
}

/* Astra主题兼容 */
.ast-woocommerce-container .product-video-section {
    margin: 1.5em 0;
}

/* OceanWP主题兼容 */
.oceanwp-woocommerce .product-video-section {
    margin: 20px 0;
}

/* ==========================================================================
   动画效果
   ========================================================================== */

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.product-video-player,
.gallery-video-player {
    animation: fadeIn 0.3s ease;
}

.video-play-overlay,
.gallery-video-overlay {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ==========================================================================
   可访问性
   ========================================================================== */

.video-play-button:focus,
.video-close-button:focus,
.gallery-video-close:focus {
    outline: 2px solid #0073aa;
    outline-offset: 2px;
}

.video-play-overlay[aria-label],
.gallery-video-overlay[aria-label] {
    cursor: pointer;
}

/* 高对比度模式支持 */
@media (prefers-contrast: high) {
    .video-play-overlay {
        background: rgba(0, 0, 0, 0.8);
    }
    
    .product-video-section {
        border: 2px solid #333;
    }
}

/* 减少动画偏好支持 */
@media (prefers-reduced-motion: reduce) {
    .video-play-button,
    .video-close-button,
    .gallery-video-close,
    .video-play-overlay,
    .gallery-video-overlay {
        transition: none;
    }
    
    .product-video-player,
    .gallery-video-player {
        animation: none;
    }
}
