/* =====================================================
   SERVIDENT - Animaciones CSS OPTIMIZADAS
   Versión: 2.0
   Notas: Optimizado para rendimiento con will-change
          y GPU acceleration donde sea apropiado
   ===================================================== */

/* ===== CONFIGURACIÓN BASE ===== */
:root {
    --animation-duration-fast: 0.3s;
    --animation-duration-normal: 0.6s;
    --animation-duration-slow: 1s;
    --animation-timing: cubic-bezier(0.4, 0, 0.2, 1);
}

/* ===== ANIMACIONES DE ENTRADA ===== */

/* Fade Up */
@keyframes fadeUp {
    from {
        opacity: 0;
        transform: translate3d(0, 30px, 0);
    }
    to {
        opacity: 1;
        transform: translate3d(0, 0, 0);
    }
}

.animate-fade-up {
    opacity: 0;
    animation: fadeUp var(--animation-duration-normal) var(--animation-timing) forwards;
    will-change: opacity, transform;
}

/* Delays escalonados para elementos múltiples */
.animate-fade-up:nth-child(1) { animation-delay: 0.1s; }
.animate-fade-up:nth-child(2) { animation-delay: 0.2s; }
.animate-fade-up:nth-child(3) { animation-delay: 0.3s; }
.animate-fade-up:nth-child(4) { animation-delay: 0.4s; }
.animate-fade-up:nth-child(5) { animation-delay: 0.5s; }

/* Fade In */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.animate-fade-in {
    opacity: 0;
    animation: fadeIn var(--animation-duration-slow) ease-out forwards;
    will-change: opacity;
}

/* Slide In Left */
@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translate3d(-50px, 0, 0);
    }
    to {
        opacity: 1;
        transform: translate3d(0, 0, 0);
    }
}

.animate-slide-left {
    opacity: 0;
    animation: slideInLeft var(--animation-duration-normal) var(--animation-timing) forwards;
    will-change: opacity, transform;
}

/* Slide In Right */
@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translate3d(50px, 0, 0);
    }
    to {
        opacity: 1;
        transform: translate3d(0, 0, 0);
    }
}

.animate-slide-right {
    opacity: 0;
    animation: slideInRight var(--animation-duration-normal) var(--animation-timing) forwards;
    will-change: opacity, transform;
}

/* Scale In */
@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale3d(0.8, 0.8, 1);
    }
    to {
        opacity: 1;
        transform: scale3d(1, 1, 1);
    }
}

.animate-scale-in {
    opacity: 0;
    animation: scaleIn var(--animation-duration-normal) var(--animation-timing) forwards;
    will-change: opacity, transform;
}

/* ===== ANIMACIONES DE SCROLL (Intersection Observer) ===== */

/* Reveal base */
.reveal {
    opacity: 0;
    transform: translate3d(0, 30px, 0);
    transition: all var(--animation-duration-normal) var(--animation-timing);
}

.reveal.active {
    opacity: 1;
    transform: translate3d(0, 0, 0);
}

/* Reveal desde la izquierda */
.reveal-left {
    opacity: 0;
    transform: translate3d(-30px, 0, 0);
    transition: all var(--animation-duration-normal) var(--animation-timing);
}

.reveal-left.active {
    opacity: 1;
    transform: translate3d(0, 0, 0);
}

/* Reveal desde la derecha */
.reveal-right {
    opacity: 0;
    transform: translate3d(30px, 0, 0);
    transition: all var(--animation-duration-normal) var(--animation-timing);
}

.reveal-right.active {
    opacity: 1;
    transform: translate3d(0, 0, 0);
}

/* Reveal con scale */
.reveal-scale {
    opacity: 0;
    transform: scale3d(0.9, 0.9, 1);
    transition: all var(--animation-duration-normal) var(--animation-timing);
}

.reveal-scale.active {
    opacity: 1;
    transform: scale3d(1, 1, 1);
}

/* ===== ANIMACIONES DE HOVER ===== */

/* Float */
@keyframes float {
    0%, 100% {
        transform: translate3d(0, 0, 0);
    }
    50% {
        transform: translate3d(0, -10px, 0);
    }
}

.hover-float {
    transition: transform var(--animation-duration-fast) ease;
}

.hover-float:hover {
    animation: float 2s ease-in-out infinite;
    will-change: transform;
}

/* Grow */
.hover-grow {
    transition: transform var(--animation-duration-fast) ease;
}

.hover-grow:hover {
    transform: scale3d(1.05, 1.05, 1);
}

/* Shake */
@keyframes shake {
    0%, 100% {
        transform: translate3d(0, 0, 0);
    }
    10%, 30%, 50%, 70%, 90% {
        transform: translate3d(-5px, 0, 0);
    }
    20%, 40%, 60%, 80% {
        transform: translate3d(5px, 0, 0);
    }
}

.hover-shake {
    transition: transform var(--animation-duration-fast) ease;
}

.hover-shake:hover {
    animation: shake 0.5s ease;
    will-change: transform;
}

/* ===== ANIMACIONES DE BOTONES ===== */

/* Pulse (definido en styles.css para el botón principal) */

/* Ripple Effect */
.btn-ripple {
    position: relative;
    overflow: hidden;
}

.btn-ripple::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.5);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.btn-ripple:active::before {
    width: 300px;
    height: 300px;
}

/* ===== ANIMACIONES DE CARGA ===== */

/* Skeleton Loading */
@keyframes skeleton {
    0% {
        background-position: -200% 0;
    }
    100% {
        background-position: 200% 0;
    }
}

.skeleton {
    background: linear-gradient(
        90deg,
        #f0f0f0 25%,
        #e0e0e0 50%,
        #f0f0f0 75%
    );
    background-size: 200% 100%;
    animation: skeleton 1.5s ease-in-out infinite;
}

/* Spinner */
@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

.spinner {
    border: 3px solid rgba(0, 180, 216, 0.1);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    will-change: transform;
}

/* Loading Dots */
@keyframes loadingDots {
    0%, 80%, 100% {
        opacity: 0;
        transform: scale(0.8);
    }
    40% {
        opacity: 1;
        transform: scale(1);
    }
}

.loading-dots {
    display: inline-flex;
    gap: 0.25rem;
}

.loading-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--primary-color);
    animation: loadingDots 1.4s ease-in-out infinite;
}

.loading-dots span:nth-child(1) { animation-delay: 0s; }
.loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0.4s; }

/* ===== ANIMACIONES DE TEXTO ===== */

/* Text Fade In Word by Word */
.text-fade-words {
    overflow: hidden;
}

.text-fade-words span {
    display: inline-block;
    opacity: 0;
    transform: translate3d(0, 20px, 0);
    animation: fadeUp 0.6s ease forwards;
}

.text-fade-words span:nth-child(1) { animation-delay: 0.1s; }
.text-fade-words span:nth-child(2) { animation-delay: 0.2s; }
.text-fade-words span:nth-child(3) { animation-delay: 0.3s; }
.text-fade-words span:nth-child(4) { animation-delay: 0.4s; }
.text-fade-words span:nth-child(5) { animation-delay: 0.5s; }

/* Gradient Text Animation */
@keyframes textGradient {
    0% {
        background-position: 0% 50%;
    }
    50% {
        background-position: 100% 50%;
    }
    100% {
        background-position: 0% 50%;
    }
}

.text-gradient-animate {
    background: linear-gradient(
        -45deg,
        var(--primary-color),
        var(--secondary-color),
        var(--accent-color),
        var(--primary-dark)
    );
    background-size: 400% 400%;
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: textGradient 3s ease infinite;
}

/* ===== ANIMACIONES DE CONTADOR ===== */

/* Flip Animation para números */
@keyframes flip {
    0% {
        transform: perspective(400px) rotateX(0deg);
    }
    50% {
        transform: perspective(400px) rotateX(-90deg);
    }
    100% {
        transform: perspective(400px) rotateX(0deg);
    }
}

.countdown-number.flip {
    animation: flip 0.6s ease-in-out;
    will-change: transform;
}

/* Estados de urgencia */
.countdown.urgent {
    animation: urgentPulse 2s ease-in-out infinite;
}

@keyframes urgentPulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

.countdown.critical {
    animation: criticalShake 0.5s ease-in-out infinite;
}

@keyframes criticalShake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

/* ===== ANIMACIONES DE NOTIFICACIÓN ===== */

/* Alert Slide In */
.countdown-alert {
    position: fixed;
    top: 20px;
    right: 20px;
    background: white;
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    padding: 1.5rem;
    max-width: 350px;
    transform: translate3d(400px, 0, 0);
    transition: transform 0.3s ease;
    z-index: 1000;
}

.countdown-alert.show {
    transform: translate3d(0, 0, 0);
}

.countdown-alert h4 {
    margin: 0 0 0.5rem;
    color: var(--warning-color);
}

.countdown-alert p {
    margin: 0;
    color: var(--text-gray);
}

.countdown-alert button {
    position: absolute;
    top: 10px;
    right: 10px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-gray);
    transition: color 0.3s ease;
}

.countdown-alert button:hover {
    color: var(--text-dark);
}

/* ===== ANIMACIONES ESPECIALES ===== */

/* Heartbeat */
@keyframes heartbeat {
    0% {
        transform: scale(1);
    }
    14% {
        transform: scale(1.3);
    }
    28% {
        transform: scale(1);
    }
    42% {
        transform: scale(1.3);
    }
    70% {
        transform: scale(1);
    }
}

.heartbeat {
    animation: heartbeat 1.5s ease-in-out infinite;
    will-change: transform;
}

/* Glow */
@keyframes glow {
    from {
        box-shadow: 0 0 10px var(--primary-color);
    }
    to {
        box-shadow: 0 0 20px var(--primary-color),
                    0 0 30px var(--primary-color);
    }
}

.glow {
    animation: glow 1s ease-in-out infinite alternate;
}

/* Wave */
@keyframes wave {
    0% { transform: rotate(0deg); }
    10% { transform: rotate(14deg); }
    20% { transform: rotate(-8deg); }
    30% { transform: rotate(14deg); }
    40% { transform: rotate(-4deg); }
    50% { transform: rotate(10deg); }
    60% { transform: rotate(0deg); }
    100% { transform: rotate(0deg); }
}

.wave {
    animation: wave 2.5s ease-in-out infinite;
    transform-origin: 70% 70%;
    display: inline-block;
}

/* ===== ANIMACIONES DE FAQ ===== */

/* FAQ Answer Slide */
.faq-answer {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.faq-answer[aria-hidden="false"] {
    max-height: 500px;
    transition: max-height 0.5s ease;
}

/* ===== ANIMACIONES DE FORMULARIO ===== */

/* Form Field Focus */
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    animation: fieldFocus 0.3s ease;
}

@keyframes fieldFocus {
    0% {
        box-shadow: 0 0 0 0 rgba(0, 180, 216, 0);
    }
    100% {
        box-shadow: 0 0 0 3px rgba(0, 180, 216, 0.1);
    }
}

/* Error Shake */
.form-group.error input {
    animation: errorShake 0.5s ease;
}

@keyframes errorShake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
    20%, 40%, 60%, 80% { transform: translateX(5px); }
}

/* Success Check */
.form-success {
    animation: successBounce 0.6s ease;
}

@keyframes successBounce {
    0% { transform: scale(0.8); opacity: 0; }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); opacity: 1; }
}

/* ===== CONTROL DE ANIMACIONES ===== */

/* Desactivar will-change después de la animación */
.animate-fade-up.active,
.animate-fade-in.active,
.animate-slide-left.active,
.animate-slide-right.active,
.animate-scale-in.active {
    will-change: auto;
}

/* Pausar animaciones si el usuario lo prefiere */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
    
    .reveal,
    .reveal-left,
    .reveal-right,
    .reveal-scale {
        opacity: 1 !important;
        transform: none !important;
    }
}

/* ===== OPTIMIZACIÓN MÓVIL ===== */

@media (max-width: 768px) {
    /* Reducir duración de animaciones en móvil */
    :root {
        --animation-duration-fast: 0.2s;
        --animation-duration-normal: 0.4s;
        --animation-duration-slow: 0.8s;
    }
    
    /* Simplificar animaciones complejas */
    .animate-fade-up,
    .animate-slide-left,
    .animate-slide-right {
        animation-duration: var(--animation-duration-fast);
    }
    
    /* Desactivar animaciones pesadas en móvil */
    .hover-float:hover,
    .hover-shake:hover {
        animation: none;
        transform: scale(1.05);
    }
    
    /* Reducir distancia de movimiento */
    @keyframes fadeUp {
        from {
            opacity: 0;
            transform: translate3d(0, 20px, 0); /* Reducido de 30px */
        }
        to {
            opacity: 1;
            transform: translate3d(0, 0, 0);
        }
    }
    
    @keyframes slideInLeft {
        from {
            opacity: 0;
            transform: translate3d(-30px, 0, 0); /* Reducido de 50px */
        }
        to {
            opacity: 1;
            transform: translate3d(0, 0, 0);
        }
    }
    
    @keyframes slideInRight {
        from {
            opacity: 0;
            transform: translate3d(30px, 0, 0); /* Reducido de 50px */
        }
        to {
            opacity: 1;
            transform: translate3d(0, 0, 0);
        }
    }
    
    /* Ajustar notificaciones para móvil */
    .countdown-alert {
        top: 10px;
        right: 10px;
        left: 10px;
        max-width: none;
    }
}

/* ===== UTILIDADES DE ANIMACIÓN ===== */

/* Delays personalizados */
.delay-100 { animation-delay: 0.1s; }
.delay-200 { animation-delay: 0.2s; }
.delay-300 { animation-delay: 0.3s; }
.delay-400 { animation-delay: 0.4s; }
.delay-500 { animation-delay: 0.5s; }
.delay-600 { animation-delay: 0.6s; }
.delay-700 { animation-delay: 0.7s; }
.delay-800 { animation-delay: 0.8s; }

/* Duraciones personalizadas */
.duration-fast { animation-duration: var(--animation-duration-fast); }
.duration-normal { animation-duration: var(--animation-duration-normal); }
.duration-slow { animation-duration: var(--animation-duration-slow); }

/* Timing functions */
.ease-in { animation-timing-function: ease-in; }
.ease-out { animation-timing-function: ease-out; }
.ease-in-out { animation-timing-function: ease-in-out; }
.linear { animation-timing-function: linear; }

/* Infinite animations */
.infinite { animation-iteration-count: infinite; }

/* Pause on hover */
.pause-hover:hover {
    animation-play-state: paused;
}