/**
 * Glopzi WebGL3D Styles
 * 
 * Main stylesheet for WebGL3D plugin
 * 
 * @package GlopziWebGL3D
 * @since 1.0.0
 */

/* WebGL3D Container */
.webgl3d-container {
    position: relative;
    display: block;
    width: 100%;
    height: 100%;
    overflow: hidden;
    box-sizing: border-box;
}

.webgl3d-canvas {
    display: block;
    width: 100%;
    height: 100%;
    border: none;
    outline: none;
    cursor: grab;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.webgl3d-canvas:active {
    cursor: grabbing;
}

.webgl3d-canvas:focus {
    outline: none;
}

/* Fallback for non-WebGL browsers */
.webgl3d-fallback {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    padding: 20px;
    text-align: center;
    color: #6c757d;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
}

.webgl3d-fallback p {
    margin: 0;
    padding: 0;
}

/* Loading states */
.webgl3d-loading {
    position: relative;
}

.webgl3d-loading::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 40px;
    height: 40px;
    margin: -20px 0 0 -20px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #3498db;
    border-radius: 50%;
    animation: webgl3d-spin 1s linear infinite;
    z-index: 10;
}

.webgl3d-loading::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.8);
    z-index: 5;
}

@keyframes webgl3d-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Error states */
.webgl3d-error {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    background: #fff5f5;
    border: 1px solid #feb2b2;
    border-radius: 4px;
    padding: 20px;
    text-align: center;
    color: #c53030;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
}

.webgl3d-error p {
    margin: 0;
    padding: 0;
}

/* Performance monitor */
.webgl3d-performance {
    position: fixed;
    top: 10px;
    right: 10px;
    background: rgba(0, 0, 0, 0.8);
    color: #00ff00;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    padding: 10px;
    border-radius: 4px;
    z-index: 999999;
    min-width: 200px;
}

.webgl3d-performance h4 {
    margin: 0 0 10px 0;
    padding: 0;
    font-size: 14px;
    color: #ffffff;
    border-bottom: 1px solid #333;
    padding-bottom: 5px;
}

.webgl3d-performance-item {
    display: flex;
    justify-content: space-between;
    margin: 5px 0;
}

.webgl3d-performance-label {
    color: #cccccc;
}

.webgl3d-performance-value {
    color: #00ff00;
    font-weight: bold;
}

.webgl3d-performance-value.warning {
    color: #ffff00;
}

.webgl3d-performance-value.error {
    color: #ff0000;
}

/* Responsive design */
@media (max-width: 768px) {
    .webgl3d-container {
        max-width: 100%;
        overflow-x: auto;
    }
    
    .webgl3d-canvas {
        max-width: 100%;
        height: auto;
    }
    
    .webgl3d-performance {
        top: 5px;
        right: 5px;
        font-size: 10px;
        padding: 5px;
        min-width: 150px;
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    .webgl3d-canvas {
        cursor: default;
        touch-action: manipulation;
    }
    
    .webgl3d-canvas:active {
        cursor: default;
    }
}

/* High DPI display optimizations */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .webgl3d-canvas {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* Animation classes */
.webgl3d-fade-in {
    animation: webgl3d-fade-in 0.5s ease-in-out;
}

@keyframes webgl3d-fade-in {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.webgl3d-fade-out {
    animation: webgl3d-fade-out 0.5s ease-in-out;
}

@keyframes webgl3d-fade-out {
    from {
        opacity: 1;
        transform: scale(1);
    }
    to {
        opacity: 0;
        transform: scale(0.95);
    }
}

.webgl3d-slide-up {
    animation: webgl3d-slide-up 0.5s ease-out;
}

@keyframes webgl3d-slide-up {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.webgl3d-slide-down {
    animation: webgl3d-slide-down 0.5s ease-out;
}

@keyframes webgl3d-slide-down {
    from {
        opacity: 0;
        transform: translateY(-30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.webgl3d-scale-in {
    animation: webgl3d-scale-in 0.5s ease-out;
}

@keyframes webgl3d-scale-in {
    from {
        opacity: 0;
        transform: scale(0.5);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Elementor integration */
.elementor-widget-webgl3d-canvas .webgl3d-container,
.elementor-widget-webgl3d-object .webgl3d-container,
.elementor-widget-webgl3d-particles .webgl3d-container,
.elementor-widget-webgl3d-text .webgl3d-container,
.elementor-widget-webgl3d-interactive .webgl3d-container {
    min-height: 300px;
}

.elementor-editor-active .webgl3d-canvas {
    pointer-events: none;
}

.electric-border {
    --electric-light-color: oklch(from var(--electric-border-color) l c h);
    --eb-border-width: 2px;
    position: relative;
    border-radius: inherit;
    overflow: visible;
    isolation: isolate;
}

.eb-svg {
    position: fixed;
    left: -10000px;
    top: -10000px;
    width: 10px;
    height: 10px;
    opacity: 0.001;
    pointer-events: none;
}

.eb-content {
    position: relative;
    border-radius: inherit;
    z-index: 1;
}

.eb-layers {
    position: absolute;
    inset: 0;
    border-radius: inherit;
    pointer-events: none;
    z-index: 2;
}

.eb-stroke,
.eb-glow-1,
.eb-glow-2,
.eb-overlay-1,
.eb-overlay-2,
.eb-background-glow {
    position: absolute;
    inset: 0;
    border-radius: inherit;
    pointer-events: none;
    box-sizing: border-box;
}

.eb-stroke {
    border: var(--eb-border-width) solid var(--electric-border-color);
}

.eb-glow-1 {
    border: var(--eb-border-width) solid oklch(from var(--electric-border-color) l c h / 0.6);
    opacity: 0.5;
    filter: blur(calc(0.5px + (var(--eb-border-width) * 0.25)));
}

.eb-glow-2 {
    border: var(--eb-border-width) solid var(--electric-light-color);
    opacity: 0.5;
    filter: blur(calc(2px + (var(--eb-border-width) * 0.5)));
}

.eb-background-glow {
    z-index: -1;
    transform: scale(1.08);
    filter: blur(32px);
    opacity: 0.3;
    background: linear-gradient(-30deg, var(--electric-light-color), transparent, var(--electric-border-color));
}

.elementor-editor-active .webgl3d-container::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1;
    background: rgba(0, 0, 0, 0.05);
    border: 1px dashed rgba(0, 0, 0, 0.2);
    pointer-events: none;
}

/* Gutenberg block styles */
.wp-block-glopzi-webgl3d-canvas,
.wp-block-glopzi-webgl3d-object,
.wp-block-glopzi-webgl3d-particles,
.wp-block-glopzi-webgl3d-text,
.wp-block-glopzi-webgl3d-interactive {
    margin: 0 0 20px 0;
}

.wp-block-glopzi-webgl3d-canvas .webgl3d-container,
.wp-block-glopzi-webgl3d-object .webgl3d-container,
.wp-block-glopzi-webgl3d-particles .webgl3d-container,
.wp-block-glopzi-webgl3d-text .webgl3d-container,
.wp-block-glopzi-webgl3d-interactive .webgl3d-container {
    min-height: 300px;
}

/* Admin styles */
.webgl3d-admin-container {
    background: #fff;
    border: 1px solid #ccd0d4;
    border-radius: 4px;
    padding: 20px;
    margin: 20px 0;
}

.webgl3d-admin-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 1px solid #ccd0d4;
}

.webgl3d-admin-title {
    font-size: 18px;
    font-weight: 600;
    color: #23282d;
    margin: 0;
}

.webgl3d-admin-actions {
    display: flex;
    gap: 10px;
}

.webgl3d-admin-button {
    display: inline-flex;
    align-items: center;
    padding: 8px 12px;
    background: #007cba;
    color: #fff;
    text-decoration: none;
    border-radius: 3px;
    font-size: 13px;
    font-weight: 400;
    line-height: 1.4;
    border: 1px solid #007cba;
    cursor: pointer;
    transition: all 0.2s ease;
}

.webgl3d-admin-button:hover {
    background: #0071a1;
    border-color: #0071a1;
}

.webgl3d-admin-button-secondary {
    background: #f3f5f6;
    color: #555;
    border-color: #cccccc;
}

.webgl3d-admin-button-secondary:hover {
    background: #f1f1f1;
    border-color: #999;
}

.webgl3d-admin-settings {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.webgl3d-admin-setting {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.webgl3d-admin-setting label {
    font-weight: 600;
    color: #23282d;
}

.webgl3d-admin-setting input,
.webgl3d-admin-setting select,
.webgl3d-admin-setting textarea {
    width: 100%;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 3px;
    font-size: 14px;
}

.webgl3d-admin-setting input:focus,
.webgl3d-admin-setting select:focus,
.webgl3d-admin-setting textarea:focus {
    border-color: #007cba;
    box-shadow: 0 0 0 1px #007cba;
    outline: none;
}

.webgl3d-admin-setting-description {
    font-size: 12px;
    color: #666;
    margin-top: 5px;
}

/* Settings page specific */
.webgl3d-settings-section {
    background: #fff;
    border: 1px solid #ccd0d4;
    border-radius: 4px;
    margin-bottom: 20px;
    overflow: hidden;
}

.webgl3d-settings-section-header {
    background: #f8f9fa;
    padding: 15px 20px;
    border-bottom: 1px solid #ccd0d4;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.webgl3d-settings-section-title {
    font-size: 16px;
    font-weight: 600;
    color: #23282d;
    margin: 0;
}

.webgl3d-settings-section-content {
    padding: 20px;
}

.webgl3d-settings-section.collapsed .webgl3d-settings-section-content {
    display: none;
}

.webgl3d-settings-section.collapsed .webgl3d-settings-section-header::after {
    transform: rotate(-90deg);
}

.webgl3d-settings-section-header::after {
    content: '▼';
    font-size: 12px;
    color: #666;
    transition: transform 0.2s ease;
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .webgl3d-fallback {
        background: #2d3748;
        border-color: #4a5568;
        color: #a0aec0;
    }
    
    .webgl3d-error {
        background: #2d1818;
        border-color: #742a2a;
        color: #fc8181;
    }
    
    .webgl3d-performance {
        background: rgba(0, 0, 0, 0.9);
        color: #00ff00;
    }
}

/* Print styles */
@media print {
    .webgl3d-container {
        display: none !important;
    }
    
    .webgl3d-performance {
        display: none !important;
    }
}

/* --- Universal Glopzi FOUC Protection --- */
/* Prevent Flash of Unstyled Content by hiding elements until JS is ready */

/* Image Effects: Hide original image until WebGL replaces it */
.glopzi-image-effects-wrapper img {
    opacity: 0;
    transition: opacity 0.2s;
}

/* Text Effects: Hide source text immediately */
.glopzi-text-effects-content {
    opacity: 0;
}

/* GSAP Animations: Hide elements waiting for animation */
[data-gsap] {
    opacity: 0;
    visibility: hidden;
}

/* Universal Cloak Class for manual use */
.glopzi-cloak {
    opacity: 0 !important;
    visibility: hidden !important;
}
.glopzi-3d-model-container {
    width: 100%;
    position: relative;
    overflow: visible; /* Changed from hidden to prevent clipping when model scales up */
    min-height: 50px; /* Fallback to ensure container exists before canvas loads */
    z-index: 1; /* Ensure it stays above standard Elementor backgrounds */
    margin: 0 auto; /* Center the canvas if width is less than 100% */
}
.glopzi-3d-model-container canvas {
    display: block;
    width: 100%;
    height: 100%;
    outline: none;
}
.glopzi-error {
    color: red;
    padding: 20px;
    border: 1px solid red;
    background: #ffe6e6;
}

/* 3D Model Preloader */
.glopzi-3d-preloader {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex; /* Se asegura de que esté visible desde el inicio */
    justify-content: center;
    align-items: center;
    background-color: transparent;
    z-index: 10; /* Aumentado para asegurar que esté sobre el canvas */
    transition: opacity 0.5s ease;
    pointer-events: none;
    opacity: 1; /* Forzar opacidad inicial */
}

.glopzi-spinner {
    animation: glopzi-rotate 2s linear infinite;
    width: 30px;
    height: 30px;
}

.glopzi-spinner .path {
    stroke: rgba(150, 150, 150, 0.5); /* Color gris discreto */
    stroke-linecap: round;
    animation: glopzi-dash 1.5s ease-in-out infinite;
}

@keyframes glopzi-rotate {
    100% { transform: rotate(360deg); }
}

@keyframes glopzi-dash {
    0% { stroke-dasharray: 1, 150; stroke-dashoffset: 0; }
    50% { stroke-dasharray: 90, 150; stroke-dashoffset: -35; }
    100% { stroke-dasharray: 90, 150; stroke-dashoffset: -124; }
}

/* ── Container Scroll: Sticky Proxy Stabilization ──
 * When GSAP animates content inside a sticky element, the proxy wrapper
 * must maintain strict dimensional stability to prevent horizontal shifts
 * caused by containing-block changes during sticky activation.
 */
.glopzi-sticky-proxy {
    box-sizing: border-box !important;
    max-width: 100% !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    overflow: visible;
}

/* Prevent GSAP transforms from leaking into Elementor's sticky spacer clone.
 * When Elementor activates sticky, it clones the element to create a layout spacer.
 * If the proxy inside the clone inherits GSAP transforms, it causes visual
 * duplication and incorrect layout height calculations.
 */
.elementor-sticky__spacer .glopzi-sticky-proxy {
    transform: none !important;
    opacity: 1 !important;
    filter: none !important;
}


/* ── Container Scroll: Sticky Position Corruption Fix ──
 * CRITICAL BUG FIX: Elementor Pro's sticky handler (elementor-sticky.js) calls
 * getBoundingClientRect() on every scroll frame to keep the fixed-position element
 * visually in place. However, when GSAP applies scale/rotate/translate transforms
 * to the SAME element, getBoundingClientRect() returns the TRANSFORMED bounding box.
 * Elementor then sets inset-inline-start to the transformed left edge, which is
 * completely wrong — causing elements to fly off-screen (e.g. -2380px at scale 5x).
 *
 * Fix: At init time (before GSAP transforms), JS captures the element's correct
 * viewport-relative left position into --glopzi-sticky-left. This CSS !important
 * rule overrides Elementor's corrupted inline inset-inline-start with the correct value.
 * Works for any width: full-width (0px), centered (98px), or offset containers.
 *
 * NOTE: Runs unconditionally — Elementor Pro may activate sticky AFTER Glopzi inits.
 */
[data-glopzi-scroll-target].elementor-sticky--active {
    inset-inline-start: var(--glopzi-sticky-left, 0px) !important;
}
