/**
 * Gallery View Plugin Styles
 * Version: 1.0.0
 */

/* Gallery View主图片区域 - 左侧 */
.gallery-view-main-image {
    position: relative;
    width: 100%;
    margin-bottom: 2em;
}

.gallery-view-main-image .woocommerce-product-gallery__wrapper {
    position: relative;
    width: 100%;
    min-height: 400px;
    border-radius: 8px;
    overflow: hidden;
}

.gallery-view-main-image-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 500px;
}

.gallery-view-main-img {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    transition: transform 0.3s ease;
}

.gallery-view-main-img:hover {
    transform: scale(1.02);
}

.gallery-view-main-placeholder {
    text-align: center;
    color: #999;
    padding: 40px;
}

/* Gallery View详细图片区域 - 右侧 */
.gallery-view-detailed-pictures {
    margin-top: 20px;
    margin-bottom: 10px;
    margin-left: 0;
    margin-right: 0;
    padding: 15px;
    background: #fff;
    border: 1px solid #e1e1e1;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    width: 100%;
    box-sizing: border-box;
}

/* 标题样式 */
.gallery-view-title {
    margin: 0 0 15px 0;
    padding: 0;
    font-size: 16px;
    font-weight: bold;
    color: #333;
    border-bottom: 2px solid #0073aa;
    padding-bottom: 8px;
}

/* 图片容器样式 */
.gallery-view-gallery-container {
    position: relative;
    overflow: hidden;
    border-radius: 8px;
    background: #f8f8f8;
    border: 1px dashed #ddd;
    min-height: 160px;
}

.gallery-view-gallery {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    scroll-behavior: smooth;
    padding: 10px;
    min-height: 140px;
}

/* 图片项样式 */
.gallery-image-item {
    flex: 0 0 120px;
    width: 120px;
    height: 140px;
    text-decoration: none;
    border-radius: 8px;
    overflow: hidden;
    transition: transform 0.3s ease, box-shadow 0.3s ease, border-color 0.3s ease;
    position: relative;
    display: block;
    background: #f9f9f9;
    border: 2px solid #ddd;
}

.gallery-image-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    border-color: #0073aa;
}

.gallery-view-gallery-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 6px;
    cursor: pointer;
    border: none;
    transition: all 0.3s ease;
    display: block;
    background: transparent;
}

.gallery-image-item.selected,
.gallery-image-item:has(.gallery-view-gallery-img.selected) {
    border-color: #0073aa;
    box-shadow: 0 0 0 2px rgba(0, 115, 170, 0.3);
}

/* 选中状态的勾选标记 */
.gallery-image-item.selected::after {
    content: "✓";
    position: absolute;
    top: 8px;
    right: 8px;
    width: 18px;
    height: 18px;
    background: #007cba;
    color: white;
    border: 2px solid white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: bold;
    z-index: 10;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
    animation: checkmarkPop 0.3s ease-out;
    transform: scale(1);
}

.gallery-image-item:not(.selected)::after {
    display: none;
}

@keyframes checkmarkPop {
    0% {
        transform: scale(0);
        opacity: 0;
    }
    50% {
        transform: scale(1.2);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* AI Gallery特殊样式 */
.ai-gallery-image .gallery-view-gallery-img {
    border-color: #ff6b35;
}

.ai-gallery-image:hover .gallery-view-gallery-img {
    border-color: #e55a2b;
    box-shadow: 0 0 8px rgba(255, 107, 53, 0.4);
}

/* 产品相册特殊样式 */
.product-gallery-image .gallery-view-gallery-img {
    border-color: #28a745;
}

.product-gallery-image:hover .gallery-view-gallery-img {
    border-color: #218838;
    box-shadow: 0 0 8px rgba(40, 167, 69, 0.4);
}

/* 占位符消息样式 */
.gallery-placeholder-message {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #666;
    font-style: italic;
    min-height: 120px;
    width: 100%;
    text-align: center;
    padding: 20px;
    background: #f9f9f9;
    border-radius: 8px;
    border: 2px dashed #ddd;
}

.gallery-placeholder-message div {
    margin-bottom: 10px;
}

/* 滚动条样式 */
.gallery-view-gallery::-webkit-scrollbar {
    height: 8px;
}

.gallery-view-gallery::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.gallery-view-gallery::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

.gallery-view-gallery::-webkit-scrollbar-thumb:hover {
    background: #a1a1a1;
}

/* WooCommerce布局兼容 */
.single-product .gallery-view-main-image {
    float: left;
    width: 58%;
    margin-right: 2%;
}

.single-product .summary {
    float: right;
    width: 40%;
}

.gallery-view-detailed-pictures {
    width: 100%;
    margin-top: 20px;
    margin-bottom: 10px;
    box-sizing: border-box;
}

/* 响应式设计 */
@media (max-width: 1024px) {
    .single-product .gallery-view-main-image {
        width: 55%;
        margin-right: 3%;
    }
    
    .single-product .summary {
        width: 42%;
    }
}

@media (max-width: 768px) {
    .gallery-view-main-image {
        margin-bottom: 1em;
    }
    
    .gallery-view-main-image .woocommerce-product-gallery__wrapper {
        min-height: 300px;
    }
    
    .gallery-view-detailed-pictures {
        padding: 15px;
        margin-top: 15px;
        margin-bottom: 10px;
        margin-left: 0;
        margin-right: 0;
        width: 100%;
        box-sizing: border-box;
    }
    
    .gallery-view-gallery {
        gap: 8px;
        padding: 8px;
    }
    
    .gallery-image-item {
        flex: 0 0 100px;
    }
    
    .gallery-view-gallery-img {
        width: 100px;
        height: 100px;
    }
    
    .gallery-view-title {
        font-size: 14px;
    }
    
    /* 移动端勾选标记调整 */
    .gallery-image-item.selected::after {
        top: 6px;
        right: 6px;
        width: 16px;
        height: 16px;
        font-size: 10px;
        border: 1px solid white;
    }
    
    .single-product .gallery-view-main-image,
    .single-product .summary {
        float: none;
        width: 100%;
        margin-right: 0;
    }
}

/* 强制覆盖主题样式 */
.woocommerce div.product div.images,
.woocommerce div.product .gallery-view-main-image {
    width: 58% !important;
    float: left !important;
}

.woocommerce div.product div.summary {
    width: 40% !important;
    float: right !important;
    margin-left: 0 !important;
}

@media (max-width: 768px) {
    .woocommerce div.product div.images,
    .woocommerce div.product .gallery-view-main-image,
    .woocommerce div.product div.summary {
        width: 100% !important;
        float: none !important;
    }
}

/* ==========================================================================
   Product View / 3D View 切换按钮样式 (参考ani-gallery插件)
   ========================================================================== */

/* 2D/3D切换按钮容器 */
.gallery-view-toggle {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 100;
    display: flex;
    gap: 0;
}

/* 切换按钮基础样式 */
.gallery-view-toggle button {
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid #ddd;
    border-radius: 0;
    padding: 8px 12px;
    font-size: 12px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    margin-left: -1px;
    color: #333;
    text-decoration: none;
    outline: none;
}

/* 第一个按钮（Product View）- 左圆角 */
.gallery-view-toggle button:first-child {
    border-radius: 4px 0 0 4px;
    margin-left: 0;
}

/* 最后一个按钮（3D View）- 右圆角 */
.gallery-view-toggle button:last-child {
    border-radius: 0 4px 4px 0;
}

/* 按钮悬停效果 */
.gallery-view-toggle button:hover {
    background: rgba(255, 255, 255, 1);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
    transform: translateY(-1px);
}

/* 激活状态样式 */
.gallery-view-toggle button.active {
    background: #0073aa;
    color: white;
    border-color: #0073aa;
}

.gallery-view-toggle button.active:hover {
    background: #005a87;
    border-color: #005a87;
    transform: translateY(-1px);
}

/* 按钮禁用状态 */
.gallery-view-toggle button:disabled {
    background: rgba(255, 255, 255, 0.5);
    color: #999;
    cursor: not-allowed;
    border-color: #e1e1e1;
}

.gallery-view-toggle button:disabled:hover {
    transform: none;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* 当3D模型功能未启用时隐藏切换按钮 */
body.gallery-view-3d-disabled .gallery-view-toggle {
    display: none !important;
}

/* 3D视图容器样式 */
.gallery-view-3d-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #000;
    border-radius: 8px;
    overflow: hidden;
    z-index: 10;
}

.gallery-view-3d-iframe-container {
    width: 100%;
    height: 100%;
    border: 1px solid #ddd;
    border-radius: 8px;
    overflow: hidden;
    background: #f8f8f8;
}

.gallery-view-3d-iframe-container iframe {
    width: 100%;
    height: 100%;
    border: none;
    background: #fff;
}

/* 平板端切换按钮优化 */
@media (max-width: 1024px) and (min-width: 769px) {
    .gallery-view-toggle {
        top: 10px !important;
        right: 10px !important;
    }
    
    .gallery-view-toggle button {
        padding: 10px 15px !important;
        font-size: 14px !important;
    }
}

/* 移动端切换按钮优化 */
@media (max-width: 768px) {
    .gallery-view-toggle {
        position: absolute !important;
        top: 10px !important;
        right: 10px !important;
        margin: 0 !important;
        justify-content: flex-start !important;
        width: auto !important;
        z-index: 100 !important;
        display: flex !important;
        gap: 0 !important;
    }
    
    .gallery-view-toggle button {
        padding: 8px 12px !important;
        font-size: 12px !important;
        border-radius: 0 !important;
        margin-left: -1px !important;
        flex: none !important;
        max-width: none !important;
        background: rgba(255, 255, 255, 0.9) !important;
        border: 1px solid #ddd !important;
        font-weight: bold !important;
        cursor: pointer !important;
        transition: all 0.3s ease !important;
        box-shadow: 0 2px 4px rgba(0,0,0,0.1) !important;
        color: #333 !important;
    }
    
    .gallery-view-toggle button:hover {
        background: rgba(255, 255, 255, 1) !important;
        box-shadow: 0 4px 8px rgba(0,0,0,0.15) !important;
    }
    
    .gallery-view-toggle button.active {
        background: #0073aa !important;
        color: white !important;
        border-color: #0073aa !important;
    }
    
    .gallery-view-toggle button.active:hover {
        background: #005a87 !important;
        border-color: #005a87 !important;
    }
    
    .gallery-view-toggle button:first-child {
        border-radius: 4px 0 0 4px !important;
        margin-left: 0 !important;
    }
    
    .gallery-view-toggle button:last-child {
        border-radius: 0 4px 4px 0 !important;
    }
}

/* 加载状态动画 */
.gallery-view-toggle button.loading {
    position: relative;
    color: transparent;
}

.gallery-view-toggle button.loading::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 12px;
    height: 12px;
    margin: -6px 0 0 -6px;
    border: 2px solid currentColor;
    border-radius: 50%;
    border-top-color: transparent;
    animation: buttonSpin 0.8s linear infinite;
}

@keyframes buttonSpin {
    to {
        transform: rotate(360deg);
    }
}

/* 从Gallery页面跳转过来的图片样式 */
.gallery-image-item.selected-from-gallery {
    border: 3px solid #0073aa !important;
    box-shadow: 0 6px 20px rgba(0, 115, 170, 0.4) !important;
    transform: translateY(-3px) !important;
    background: rgba(0, 115, 170, 0.05) !important;
}

.gallery-image-item.selected-from-gallery:hover {
    transform: translateY(-4px) !important;
    box-shadow: 0 8px 25px rgba(0, 115, 170, 0.5) !important;
}

/* Gallery插入模式的主图片样式 */
.gallery-view-main-img.from-gallery {
    box-shadow: 0 6px 20px rgba(0, 115, 170, 0.2) !important;
    border: 2px solid rgba(0, 115, 170, 0.1) !important;
}

/* Gallery插入模式指示器 */
.gallery-view-gallery-insert-indicator {
    position: absolute;
    top: 5px;
    left: 5px;
    background: #0073aa;
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: bold;
    z-index: 10;
    text-transform: uppercase;
}

/* 确保选中状态在插入模式下正确显示 */
body.main-image-loaded .gallery-view-gallery-img {
    opacity: 1 !important;
    visibility: visible !important;
}

/* 动画效果：从gallery插入的图片淡入效果 */
.gallery-view-main-img.gallery-fade-in {
    animation: galleryImageFadeIn 0.5s ease-in-out;
}

@keyframes galleryImageFadeIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}
