/* ====================================
   VARIATION MEDIA GALLERY - FRONTEND
   ==================================== */

/* 
 * IMPORTANT: All styles are scoped to .single-product to avoid conflicts
 * with other pages and themes. This ensures the plugin only affects
 * WooCommerce single product pages.
 */

/* Scope all styles to single product pages only to avoid conflicts */
.single-product .vmg-variation-gallery-wrapper {
    margin: 15px 0 20px 0;
    opacity: 1;
    transition: all 0.3s ease;
    border: 1px solid #e1e1e1;
    border-radius: 6px;
    padding: 12px;
    background: linear-gradient(135deg, #f8f9fa 0%, #ffffff 100%);
    box-shadow: 0 1px 6px rgba(0,0,0,0.04);
    display: none;
    max-width: 100%;
}

/* Different placement styles */
.vmg-placement-replace {
    margin: 0;
    border: none;
    background: transparent;
    padding: 0;
}

.vmg-placement-after_main_gallery {
    margin-top: 15px;
    border-top: 1px solid #e0e0e0;
    padding-top: 15px;
}

.vmg-placement-before_summary {
    margin-bottom: 30px;
}

.vmg-placement-after_summary {
    margin-top: 30px;
}

/* Main gallery wrapper for replace mode */
.vmg-main-gallery-wrapper {
    width: 100%;
}

.vmg-main-gallery-wrapper .vmg-variation-gallery-wrapper {
    width: 100%;
    max-width: none;
}

.vmg-variation-gallery-wrapper[data-vmg-active="true"] {
    opacity: 1;
}

.vmg-variation-gallery-wrapper h3 {
    margin: 0 0 10px 0;
    color: #333;
    font-size: 16px;
    font-weight: 600;
}

/* Main Media Container */
.vmg-main-media {
    position: relative;
    width: 100%;
    background: transparent;
    border: 1px solid #ddd;
    border-radius: 6px;
    overflow: hidden;
    margin-bottom: 10px;
    min-height: 200px;
}

.vmg-media-container {
    position: relative;
    width: 100%;
    min-height: 200px;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.vmg-media-container.has-media {
    padding-bottom: 50%;
}

.vmg-media-container.has-media > * {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.vmg-media-container > p {
    position: static;
    margin: 0;
}

/* Placeholder message styling */
.vmg-placeholder-message {
    text-align: center;
    color: #888;
    padding: 20px 15px;
    background: #ffffff;
    border: 2px dashed #ddd;
    border-radius: 4px;
    transition: all 0.3s ease;
}

.vmg-placeholder-icon {
    margin-bottom: 8px;
    opacity: 0.4;
    color: #999;
}

.vmg-placeholder-message p {
    margin: 0;
    font-size: 12px;
    color: #666;
    font-weight: 500;
}

.vmg-placeholder-message:hover {
    border-color: #bbb;
    background: #fefefe;
}

/* Compact mode - always enabled */
.vmg-variation-gallery-wrapper.vmg-compact {
    max-width: 560px;
    padding: 10px;
    margin: 10px 0 15px 0;
}

.vmg-compact .vmg-main-media {
    min-height: 120px;
    margin-bottom: 8px;
    border-radius: 4px;
    overflow: hidden;
}

.vmg-compact .vmg-media-container.has-media > * {
    object-fit: contain;
}

.vmg-compact .vmg-thumbnail {
    width: 60px;
    height: 60px;
}

.vmg-compact .vmg-thumbnails {
    gap: 6px;
    padding: 8px 0 0 0;
    border-top: 1px solid #e1e1e1;
    margin-top: 8px;
}

/* Media Items */
.vmg-media-item-display {
    opacity: 0;
    transition: opacity 0.4s ease;
}

.vmg-media-item-display.active {
    opacity: 1;
    z-index: 1;
}

.vmg-media-item-display img {
    cursor: zoom-in;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.vmg-media-item-display video {
    cursor: pointer;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Video Preview and Controls */
.vmg-video-preview {
    position: relative;
    width: 100%;
    height: 100%;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.vmg-video-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.vmg-video-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
}

.vmg-video-overlay:hover {
    background: rgba(0,0,0,0.5);
}

.vmg-video-overlay .vmg-play-video-btn {
    background: rgba(255,255,255,0.9);
    border: none;
    border-radius: 50%;
    width: 80px;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
}

.vmg-video-overlay .vmg-play-video-btn:hover {
    background: rgba(255,255,255,1);
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(0,0,0,0.4);
}

.vmg-video-overlay .vmg-play-video-btn svg {
    width: 32px;
    height: 32px;
    fill: #333;
}

.vmg-video-info {
    position: absolute;
    bottom: 10px;
    left: 10px;
    background: rgba(0,0,0,0.7);
    color: white;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
}

/* Video Controls */
.vmg-video-controls {
    position: absolute;
    bottom: 15px;
    left: 15px;
    right: 15px;
    background: rgba(0,0,0,0.7);
    border-radius: 6px;
    padding: 10px;
    display: flex;
    align-items: center;
    gap: 10px;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 10;
}

.vmg-main-media:hover .vmg-video-controls {
    opacity: 1;
}

.vmg-video-play-pause {
    background: transparent;
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 5px;
    display: flex;
    align-items: center;
}

.vmg-video-play-pause svg {
    width: 24px;
    height: 24px;
}

.vmg-video-progress {
    flex: 1;
    height: 4px;
    background: rgba(255,255,255,0.3);
    border-radius: 2px;
    cursor: pointer;
    position: relative;
}

.vmg-video-progress-bar {
    height: 100%;
    background: #fff;
    border-radius: 2px;
    width: 0%;
    transition: width 0.1s ease;
}

.vmg-video-time {
    color: #fff;
    font-size: 12px;
    font-weight: 500;
    min-width: 60px;
    text-align: right;
}

/* AR Button */
.vmg-ar-button {
    position: absolute;
    bottom: 15px;
    right: 15px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    border: none;
    padding: 12px 20px;
    border-radius: 25px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
    transition: all 0.3s ease;
    z-index: 10;
}

.vmg-ar-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
}

.vmg-ar-button svg {
    width: 20px;
    height: 20px;
}

/* 3D Model Viewer */
#vmg-model-viewer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

#vmg-model-viewer canvas {
    width: 100%;
    height: 100%;
    cursor: grab;
}

#vmg-model-viewer canvas:active {
    cursor: grabbing;
}

.vmg-model-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #666;
    font-size: 14px;
    text-align: center;
}

.vmg-model-loading::after {
    content: "";
    display: block;
    width: 40px;
    height: 40px;
    margin: 10px auto;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #667eea;
    border-radius: 50%;
    animation: vmg-spin 1s linear infinite;
}

/* Thumbnails */
.vmg-thumbnails {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 10px 0 0 0;
    scrollbar-width: thin;
    scrollbar-color: #ddd transparent;
    border-top: 1px solid #e0e0e0;
    margin-top: 10px;
}

.vmg-thumbnails::-webkit-scrollbar {
    height: 6px;
}

.vmg-thumbnails::-webkit-scrollbar-track {
    background: transparent;
}

.vmg-thumbnails::-webkit-scrollbar-thumb {
    background: #ddd;
    border-radius: 3px;
}

.vmg-thumbnail {
    position: relative;
    width: 60px;
    height: 60px;
    flex-shrink: 0;
    border: 2px solid #ddd;
    border-radius: 4px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.3s ease;
    background: #f9f9f9;
}

.vmg-thumbnail:hover {
    border-color: #667eea;
    transform: translateY(-2px);
}

.vmg-thumbnail.active {
    border-color: #667eea;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.2);
}

.vmg-thumbnail img,
.vmg-thumbnail video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.vmg-thumbnail-badge {
    position: absolute;
    bottom: 2px;
    left: 2px;
    background: rgba(0,0,0,0.7);
    color: #fff;
    padding: 1px 4px;
    font-size: 8px;
    border-radius: 2px;
    font-weight: 600;
    text-transform: uppercase;
}

.vmg-thumbnail-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 24px;
    height: 24px;
    color: #667eea;
}

/* Lightbox */
.vmg-lightbox {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.95);
    z-index: 999999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.vmg-lightbox.active {
    opacity: 1;
    visibility: visible;
}

.vmg-lightbox-content {
    max-width: 90%;
    max-height: 90%;
    position: relative;
}

.vmg-lightbox-content img,
.vmg-lightbox-content video {
    max-width: 100%;
    max-height: 90vh;
    object-fit: contain;
}

.vmg-lightbox-close {
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(255,255,255,0.2);
    border: none;
    color: #fff;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.3s ease;
}

.vmg-lightbox-close:hover {
    background: rgba(255,255,255,0.3);
}

.vmg-lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255,255,255,0.2);
    border: none;
    color: #fff;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.3s ease;
}

.vmg-lightbox-nav:hover {
    background: rgba(255,255,255,0.3);
}

.vmg-lightbox-prev {
    left: 20px;
}

.vmg-lightbox-next {
    right: 20px;
}

/* Loading Animation */
@keyframes vmg-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.vmg-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 50px;
    height: 50px;
    border: 5px solid #f3f3f3;
    border-top: 5px solid #667eea;
    border-radius: 50%;
    animation: vmg-spin 1s linear infinite;
}

/* Video Table Styles */
.vmg-video-table-container {
    margin: 15px 0;
}

.vmg-video-table {
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    border-radius: 6px;
    overflow: hidden;
}

.vmg-video-table table {
    border-collapse: collapse;
    width: 100%;
}

.vmg-video-table th {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
    background: #f8f9fa;
    border-bottom: 2px solid #dee2e6;
}

.vmg-video-table td {
    vertical-align: middle;
    border-bottom: 1px solid #f0f0f0;
}

.vmg-video-table tr:hover {
    background-color: #f8f9fa;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.vmg-video-table tr {
    transition: all 0.3s ease;
}

/* Add Video Row Styles */
.vmg-add-video-row {
    border: 2px dashed #ddd;
    transition: all 0.3s ease;
}

.vmg-add-video-row:hover {
    border-color: #0073aa;
    background: #f0f8ff;
}

.vmg-add-video-row input[type="url"]:focus {
    border-color: #0073aa;
    box-shadow: 0 0 0 2px rgba(0, 115, 170, 0.2);
}

.vmg-play-video-btn {
    transition: all 0.3s ease;
}

.vmg-play-video-btn:hover {
    background: #005a87 !important;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

/* Remove button hover effect */
.vmg-remove-video-url:hover {
    background: #dc3545 !important;
    color: white !important;
    border-color: #dc3545 !important;
    transform: scale(1.1);
}

/* Video Modal Styles */
.vmg-video-modal {
    animation: vmg-fadeIn 0.3s ease;
}

@keyframes vmg-fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.vmg-modal-close:hover {
    color: #000 !important;
}

/* 3D Model Viewer Styles */
.vmg-model-viewer {
    width: 100%;
    height: 385px;
    background: #f5f5f5;
    border-radius: 0px;
    position: relative;
    overflow: hidden;
}

.vmg-model-viewer canvas {
    width: 100% !important;
    height: 100% !important;
    border-radius: 8px;
}

.vmg-model-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #666;
    font-size: 14px;
    z-index: 10;
}


/* Responsive Design */
@media (max-width: 768px) {
    .vmg-variation-gallery-wrapper {
        margin: 8px 0;
        padding: 8px;
        max-width: 100%;
    }

    .vmg-video-modal-content {
        height: 300px;
    }
    
    .vmg-video-modal-video {
        height: 300px;
    }
    
    .vmg-main-media {
        margin-bottom: 6px;
        min-height: 100px;
    }
    
    .vmg-media-container {
        min-height: 100px;
    }
    
    .vmg-media-container.has-media {
        padding-bottom: 80%;
    }
    
    .vmg-thumbnails {
        gap: 4px;
        padding: 6px 0 0 0;
    }
    
    .vmg-thumbnail {
        width: 45px;
        height: 45px;
        border-radius: 3px;
    }
    
    /* Adjust fade indicators for mobile */
    .vmg-thumbnails::before,
    .vmg-thumbnails::after {
        width: 15px;
    }
    
    .vmg-ar-button {
        padding: 8px 12px;
        font-size: 11px;
        bottom: 8px;
        right: 8px;
    }
    
    .vmg-video-controls {
        padding: 6px;
        bottom: 8px;
        left: 8px;
        right: 8px;
    }
    
    .vmg-video-time {
        font-size: 10px;
        min-width: 45px;
    }
}

@media (max-width: 480px) {
    .vmg-variation-gallery-wrapper {
        margin: 6px 0;
        padding: 6px;
    }
    
    .vmg-main-media {
        min-height: 80px;
    }
    
    .vmg-media-container {
        min-height: 80px;
    }
    
    .vmg-media-container.has-media {
        padding-bottom: 25%;
    }
    
    .vmg-thumbnails {
        gap: 4px;
        padding: 6px 0 0 0;
    }
    
    .vmg-thumbnail {
        width: 30px;
        height: 30px;
    }
    
    .vmg-ar-button {
        padding: 6px 10px;
        font-size: 10px;
    }
    
    .vmg-variation-gallery-wrapper h3 {
        font-size: 14px;
        margin-bottom: 8px;
    }
}

/* Theme Compatibility */
/* Storefront Theme */
.storefront .vmg-variation-gallery-wrapper {
    margin-top: 0;
}

/* Astra Theme */
.astra-theme .vmg-main-media {
    border-radius: 4px;
}

/* Flatsome Theme */
.flatsome-theme .vmg-thumbnails {
    padding: 15px 0;
}

/* Block Themes */
.wp-block-woocommerce-product-image-gallery + .vmg-variation-gallery-wrapper {
    margin-top: 20px;
}
