/* ========================================
   FONDOS DINÁMICOS AVANZADOS - ABRATECNICA
   ======================================== */

/* Base para containers de fondos dinámicos */
.dynamic-background {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    overflow: hidden;
}

.dynamic-background-content {
    position: relative;
    z-index: 3;
}

/* ========================================
   1. PARTICLES.JS INDUSTRIAL MEJORADO
   ======================================== */
#particles-js {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    background: transparent;
}

#particles-js canvas {
    display: block;
    position: absolute;
    top: 0;
    left: 0;
}

/* ========================================
   2. THREE.JS GEOMETRIC BACKGROUND
   ======================================== */
#three-background {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    background: transparent;
}

#three-background canvas {
    display: block !important;
    position: absolute;
    top: 0;
    left: 0;
}

/* ========================================
   3. FLOATING GEOMETRIC SHAPES (CSS + GSAP)
   ======================================== */
.floating-shapes {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    overflow: hidden;
    pointer-events: none;
}

.floating-shape {
    position: absolute;
    opacity: 0.1;
    animation: float 20s infinite ease-in-out;
}

.floating-shape.circle {
    border-radius: 50%;
    background: linear-gradient(45deg, var(--primary-color), var(--accent-color));
}

.floating-shape.triangle {
    width: 0;
    height: 0;
    background: transparent;
    border-style: solid;
}

.floating-shape.square {
    background: linear-gradient(135deg, var(--accent-color), var(--primary-color));
    transform: rotate(45deg);
}

.floating-shape.hexagon {
    background: var(--primary-color);
    width: 60px;
    height: 34.64px;
    position: relative;
}

.floating-shape.hexagon:before,
.floating-shape.hexagon:after {
    content: "";
    position: absolute;
    width: 0;
    border-left: 30px solid transparent;
    border-right: 30px solid transparent;
}

.floating-shape.hexagon:before {
    bottom: 100%;
    border-bottom: 17.32px solid var(--primary-color);
}

.floating-shape.hexagon:after {
    top: 100%;
    border-top: 17.32px solid var(--primary-color);
}

@keyframes float {
    0%, 100% { 
        transform: translateY(0px) rotate(0deg); 
        opacity: 0.1;
    }
    25% { 
        transform: translateY(-20px) rotate(90deg); 
        opacity: 0.3;
    }
    50% { 
        transform: translateY(-10px) rotate(180deg); 
        opacity: 0.2;
    }
    75% { 
        transform: translateY(-30px) rotate(270deg); 
        opacity: 0.4;
    }
}

/* ========================================
   4. ANIMATED GRID PATTERN
   ======================================== */
.animated-grid {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    opacity: 0.1;
    background-image: 
        linear-gradient(var(--primary-color) 1px, transparent 1px),
        linear-gradient(90deg, var(--primary-color) 1px, transparent 1px);
    background-size: 50px 50px;
    animation: grid-move 20s linear infinite;
}

@keyframes grid-move {
    0% { 
        transform: translate(0, 0); 
        opacity: 0.05;
    }
    25% { 
        opacity: 0.15;
    }
    50% { 
        transform: translate(-25px, -25px); 
        opacity: 0.1;
    }
    75% { 
        opacity: 0.2;
    }
    100% { 
        transform: translate(-50px, -50px); 
        opacity: 0.05;
    }
}

/* ========================================
   5. LOTTIE ANIMATIONS CONTAINER
   ======================================== */
.lottie-background {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    opacity: 0.3;
    pointer-events: none;
}

.lottie-gear {
    position: absolute;
    width: 100px;
    height: 100px;
    opacity: 0.2;
}

/* ========================================
   6. WAVE ANIMATION (CSS PURO)
   ======================================== */
.wave-background {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 200px;
    z-index: 1;
    overflow: hidden;
}

.wave {
    position: absolute;
    top: 0;
    left: 0;
    width: 200%;
    height: 100%;
    background: linear-gradient(90deg, 
        transparent, 
        rgba(44, 82, 130, 0.1), 
        transparent);
    animation: wave-move 15s ease-in-out infinite;
}

.wave:nth-child(2) {
    animation-delay: -5s;
    animation-duration: 20s;
    background: linear-gradient(90deg, 
        transparent, 
        rgba(229, 62, 62, 0.1), 
        transparent);
}

.wave:nth-child(3) {
    animation-delay: -10s;
    animation-duration: 25s;
    background: linear-gradient(90deg, 
        transparent, 
        rgba(214, 158, 46, 0.1), 
        transparent);
}

@keyframes wave-move {
    0% { 
        transform: translateX(-50%) rotateZ(0deg); 
    }
    50% { 
        transform: translateX(-25%) rotateZ(180deg); 
    }
    100% { 
        transform: translateX(-50%) rotateZ(360deg); 
    }
}

/* ========================================
   7. MATRIX RAIN EFFECT
   ======================================== */
.matrix-rain {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    overflow: hidden;
    pointer-events: none;
}

.matrix-column {
    position: absolute;
    top: -100%;
    color: var(--primary-color);
    font-family: 'JetBrains Mono', monospace;
    font-size: 14px;
    font-weight: 400;
    opacity: 0.3;
    animation: matrix-fall linear infinite;
    white-space: nowrap;
}

@keyframes matrix-fall {
    0% { 
        transform: translateY(-100vh); 
        opacity: 0;
    }
    10% { 
        opacity: 0.6;
    }
    90% { 
        opacity: 0.6;
    }
    100% { 
        transform: translateY(100vh); 
        opacity: 0;
    }
}

/* ========================================
   8. RESPONSIVE BACKGROUNDS
   ======================================== */
@media (max-width: 768px) {
    .floating-shapes,
    .animated-grid,
    .matrix-rain {
        display: none; /* Economizar batería en móviles */
    }
    
    #particles-js,
    #three-background {
        opacity: 0.3; /* Reducir intensidad */
    }
}

@media (prefers-reduced-motion: reduce) {
    .floating-shape,
    .animated-grid,
    .wave,
    .matrix-column {
        animation: none;
    }
    
    #particles-js,
    #three-background,
    .floating-shapes {
        display: none;
    }
}

/* ========================================
   9. PERFORMANCE OPTIMIZATION
   ======================================== */
.dynamic-background,
.floating-shapes,
.animated-grid {
    will-change: transform;
    backface-visibility: hidden;
    perspective: 1000px;
}

.floating-shape {
    will-change: transform, opacity;
    backface-visibility: hidden;
}

/* ========================================
   10. SECTION-SPECIFIC BACKGROUNDS
   ======================================== */
.hero .dynamic-background {
    background: var(--gradient-primary);
}

.technical-expertise .dynamic-background {
    background: var(--gradient-industrial);
}

.testimonials .dynamic-background {
    background: linear-gradient(135deg, 
        rgba(44, 82, 130, 0.05) 0%, 
        rgba(229, 62, 62, 0.05) 100%);
}

/* ========================================
   11. PERFORMANCE OPTIMIZATIONS
   ======================================== */
.low-performance #three-background,
.low-performance .floating-shapes,
.low-performance .matrix-rain {
    display: none !important;
}

.reduced-motion .floating-shape,
.reduced-motion .wave,
.reduced-motion .matrix-column,
.reduced-motion .animated-grid {
    animation: none !important;
}

.paused-animations * {
    animation-play-state: paused !important;
}

/* ========================================
   12. MOBILE OPTIMIZATIONS
   ======================================== */
@media (max-width: 768px) {
    .floating-shapes,
    .matrix-rain,
    .animated-grid {
        display: none;
    }
    
    #particles-js {
        opacity: 0.2;
    }
    
    .wave-background {
        height: 100px;
    }
}

@media (max-width: 480px) {
    #three-background,
    .lottie-background {
        display: none;
    }
}

/* ========================================
   13. DARK MODE SUPPORT
   ======================================== */
@media (prefers-color-scheme: dark) {
    .floating-shape.circle {
        background: linear-gradient(45deg, 
            rgba(44, 82, 130, 0.3), 
            rgba(229, 62, 62, 0.3));
    }
    
    .animated-grid {
        background-image: 
            linear-gradient(rgba(255,255,255,0.1) 1px, transparent 1px),
            linear-gradient(90deg, rgba(255,255,255,0.1) 1px, transparent 1px);
    }
}