/**
 * Search & Filter 3D Viewer Fix - CSS Compatibility
 * Version: 1.1.0
 */

/* Ensure proper z-index layering for 3D content */
.bp3d-container,
.threed-viewer-container {
    position: relative;
    z-index: 100;
}

/* Fix potential Search & Filter overlay issues */
.searchandfilter[data-sf-form-id] {
    z-index: 50;
}

/* 3D viewer canvas protection */
canvas[data-engine="three.js"],
.threed-canvas {
    position: relative;
    z-index: 101;
}

/* Hide Search & Filter on 3D pages when conflicts detected */
body.sf3d-conflict-page .searchandfilter {
    display: none !important;
}

/* Ensure smooth transitions */
.bp3d-container * {
    transition: opacity 0.3s ease;
}

/* ==========================================================================
   Search & Filter + 3D Viewer Compatibility
   ========================================================================== */

/* Ensure 3D viewer containers don't interfere with search filter styling */
.searchandfilter + model-viewer,
model-viewer + .searchandfilter {
    display: block;
    clear: both;
    margin: 20px 0;
}

/* Prevent search filter from affecting 3D viewer canvas */
.searchandfilter ~ * model-viewer,
.searchandfilter ~ * canvas[data-engine="three.js webgl"] {
    pointer-events: auto !important;
    position: relative !important;
}

/* Ensure proper stacking context */
model-viewer {
    z-index: 1;
    position: relative;
}

.searchandfilter {
    z-index: 2;
    position: relative;
}

/* Hide any JavaScript error messages from conflicting plugins */
.sf-error-message,
.search-filter-error,
.search-filter-pro-error {
    display: none !important;
}

/* Ensure search filter forms don't break 3D viewer layout */
.searchandfilter form {
    position: relative;
    z-index: 3;
}

/* ==========================================================================
   Avada Theme Specific Fixes
   ========================================================================== */

/* Fix for Avada theme with 3D Viewer and Search Filter */
.avada-container model-viewer {
    max-width: 100%;
    height: auto;
}

/* Ensure Avada's flex containers work properly with model viewer */
.fusion-fullwidth model-viewer,
.fusion-builder-column model-viewer {
    width: 100%;
    min-height: 400px;
}

/* Fix Avada button conflicts with model viewer controls */
.fusion-button-wrapper + model-viewer,
model-viewer + .fusion-button-wrapper {
    margin: 15px 0;
}

/* Prevent Avada's CSS animations from interfering */
model-viewer * {
    animation: none !important;
    transition: none !important;
}

/* ==========================================================================
   Responsive Design Fixes
   ========================================================================== */

/* Mobile responsiveness for search filter + 3D viewer */
@media (max-width: 768px) {
    .searchandfilter {
        margin-bottom: 20px;
    }
    
    model-viewer {
        width: 100%;
        min-height: 300px;
    }
    
    /* Stack elements properly on mobile */
    .searchandfilter + model-viewer {
        margin-top: 20px;
    }
}

/* Tablet adjustments */
@media (min-width: 769px) and (max-width: 1024px) {
    model-viewer {
        min-height: 350px;
    }
}

/* Desktop optimizations */
@media (min-width: 1025px) {
    /* Side-by-side layout if both elements are present */
    .sf3d-container {
        display: flex;
        gap: 20px;
        align-items: flex-start;
    }
    
    .sf3d-container .searchandfilter {
        flex: 0 0 300px;
    }
    
    .sf3d-container model-viewer {
        flex: 1;
        min-height: 400px;
    }
}

/* ==========================================================================
   Loading and Error States
   ========================================================================== */

/* Loading spinner for 3D viewer */
model-viewer:not([loaded]) {
    background: #f5f5f5 url('data:image/svg+xml;charset=utf8,%3Csvg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="0 0 50 50"%3E%3Cpath d="M25.251,6.461c-10.318,0-18.683,8.365-18.683,18.683h4.068c0-8.071,6.543-14.615,14.615-14.615V6.461z" fill="%23ccc"%3E%3CanimateTransform attributeType="xml" attributeName="transform" type="rotate" from="0 25 25" to="360 25 25" dur="0.6s" repeatCount="indefinite"/%3E%3C/path%3E%3C/svg%3E') no-repeat center center;
    background-size: 40px 40px;
}

model-viewer[loaded] {
    background: transparent;
}

/* Error state styling */
model-viewer[error] {
    background: #ffebee;
    border: 2px dashed #f44336;
    display: flex;
    align-items: center;
    justify-content: center;
}

model-viewer[error]:after {
    content: "3D Model failed to load";
    color: #f44336;
    font-size: 14px;
    font-weight: bold;
}

/* Search filter loading states */
.searchandfilter.sf-loading {
    opacity: 0.6;
    pointer-events: none;
}

.searchandfilter.sf-loading:after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.8);
    z-index: 10;
}

/* ==========================================================================
   Performance Optimizations
   ========================================================================== */

/* Optimize rendering performance */
model-viewer {
    contain: layout style paint;
    will-change: transform;
}

/* Reduce repaints during search filter operations */
.searchandfilter {
    contain: layout style;
}

/* Hardware acceleration for smooth interactions */
model-viewer canvas {
    transform: translateZ(0);
    backface-visibility: hidden;
}

/* ==========================================================================
   Accessibility Improvements
   ========================================================================== */

/* Focus styles for keyboard navigation */
model-viewer:focus {
    outline: 2px solid #0073aa;
    outline-offset: 2px;
}

.searchandfilter input:focus,
.searchandfilter select:focus,
.searchandfilter button:focus {
    outline: 2px solid #0073aa;
    outline-offset: 1px;
}

/* Screen reader improvements */
model-viewer[aria-label]:empty:after {
    content: attr(aria-label);
    position: absolute;
    left: -10000px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

/* ==========================================================================
   Print Styles
   ========================================================================== */

@media print {
    model-viewer {
        display: none;
    }
    
    .searchandfilter {
        display: none;
    }
    
    /* Show alternative content for print */
    .print-3d-info {
        display: block !important;
    }
}

/* ==========================================================================
   Debug Styles (Only shown when WP_DEBUG is true)
   ========================================================================== */

body.sf3d-debug .searchandfilter {
    border: 2px solid #4CAF50;
    position: relative;
}

body.sf3d-debug .searchandfilter:before {
    content: "Search & Filter Detected";
    position: absolute;
    top: -20px;
    left: 0;
    background: #4CAF50;
    color: white;
    padding: 2px 8px;
    font-size: 10px;
    z-index: 1000;
}

body.sf3d-debug model-viewer {
    border: 2px solid #FF9800;
    position: relative;
}

body.sf3d-debug model-viewer:before {
    content: "3D Viewer Detected";
    position: absolute;
    top: -20px;
    left: 0;
    background: #FF9800;
    color: white;
    padding: 2px 8px;
    font-size: 10px;
    z-index: 1000;
}

/* ==========================================================================
   Browser-Specific Fixes
   ========================================================================== */

/* Safari-specific fixes */
@supports (-webkit-appearance: none) {
    model-viewer {
        -webkit-transform: translateZ(0);
    }
}

/* Firefox-specific fixes */
@-moz-document url-prefix() {
    model-viewer {
        position: relative;
    }
}

/* Edge-specific fixes */
@supports (-ms-ime-align: auto) {
    model-viewer {
        position: relative;
        z-index: 1;
    }
} 