/* 24racks Cloud — animations: reveal-on-scroll, status dots, traffic bars, cursor-trail, reduced-motion */

/* ── Base keyframes & reveal-delay utilities ───────────────── */
/* fill-mode `backwards`: mantiene el estado inicial DURANTE el delay (sin   */
/* flash al cargar), y al terminar la animación revierte al estilo normal   */
/* del elemento — `transform: none` real, no la matriz identidad que dejaría */
/* `both`+keyframe `to: none`. Eso permite que cualquier descendiente con    */
/* `position: fixed` (drawers, modals) referencie al viewport y no a un      */
/* containing block residual.                                                 */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: .48; transform: scale(.9); }
}

.reveal-delay-1 { animation: fadeInUp .4s ease backwards .04s; }
.reveal-delay-2 { animation: fadeInUp .4s ease backwards .10s; }
.reveal-delay-3 { animation: fadeInUp .4s ease backwards .16s; }
.reveal-delay-4 { animation: fadeInUp .4s ease backwards .22s; }

/* ── Reveal-on-scroll (IntersectionObserver in app.js) ─────── */
/* Reveal on scroll — applied via IntersectionObserver in app.js.
   Default state hides; .is-visible animates in. */
.reveal-on-scroll {
    opacity: 0;
    transform: translateY(14px);
    transition: opacity .55s cubic-bezier(.22, .61, .36, 1),
                transform .55s cubic-bezier(.22, .61, .36, 1);
    /* `will-change` se omite a propósito: crea un containing block que     */
    /* atrapa drawers `position: fixed` incluso después de animar. El coste  */
    /* en rendimiento es marginal para una transición simple de opacidad.    */
}

.reveal-on-scroll.is-visible {
    opacity: 1;
    transform: none;
}

/* Stagger inside a revealed ancestor: children fire sequentially.
   Uses descendant combinator so it works even when wrapped in containers. */
.reveal-on-scroll.is-visible .reveal-child {
    animation: revealChild .5s cubic-bezier(.22, .61, .36, 1) backwards;
}

.reveal-on-scroll.is-visible .reveal-child:nth-child(1) { animation-delay: .04s; }
.reveal-on-scroll.is-visible .reveal-child:nth-child(2) { animation-delay: .10s; }
.reveal-on-scroll.is-visible .reveal-child:nth-child(3) { animation-delay: .16s; }
.reveal-on-scroll.is-visible .reveal-child:nth-child(4) { animation-delay: .22s; }
.reveal-on-scroll.is-visible .reveal-child:nth-child(5) { animation-delay: .28s; }
.reveal-on-scroll.is-visible .reveal-child:nth-child(6) { animation-delay: .34s; }

@keyframes revealChild {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ── Status dots with calm halo ripple ─────────────────────── */
/* Refined status dot — replaces the old scale-pulse with a calm halo ripple.
   Apply via .status-dot (the existing .pulse-dot/.live-dot still work for back-compat). */
.status-dot,
.pulse-dot,
.live-dot {
    position: relative;
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--green);
    animation: none;
    flex: 0 0 auto;
}

.status-dot::after,
.pulse-dot::after,
.live-dot::after {
    content: "";
    position: absolute;
    inset: -2px;
    border-radius: 50%;
    border: 1px solid var(--green);
    opacity: .55;
    animation: ripple 2.4s ease-out infinite;
    pointer-events: none;
}

.status-dot.is-warn,
.status-dot.is-warning { background: var(--warm); }
.status-dot.is-warn::after,
.status-dot.is-warning::after { border-color: var(--warm); }

.status-dot.is-danger { background: var(--danger); }
.status-dot.is-danger::after { border-color: var(--danger); }

.status-dot.is-info,
.status-dot.is-brand { background: var(--brand); }
.status-dot.is-info::after,
.status-dot.is-brand::after { border-color: var(--brand); }

@keyframes ripple {
    0% { transform: scale(.85); opacity: .55; }
    70% { transform: scale(2.2); opacity: 0; }
    100% { transform: scale(2.2); opacity: 0; }
}

/* ── Traffic-bars wobble ───────────────────────────────────── */
/* Traffic bars animated — subtle, slow, staggered. The inline `height` style
   acts as the floor; we add a vertical scale wobble on top.
   transform-origin: bottom so they grow upward. */
.traffic-chart .traffic-bar {
    transform-origin: bottom;
    animation: trafficWobble 6s ease-in-out infinite;
    transition: background var(--transition-base);
}

.traffic-chart .traffic-bar:nth-child(1) { animation-delay: 0s; animation-duration: 6.4s; }
.traffic-chart .traffic-bar:nth-child(2) { animation-delay: .25s; animation-duration: 5.6s; }
.traffic-chart .traffic-bar:nth-child(3) { animation-delay: .5s;  animation-duration: 7.2s; }
.traffic-chart .traffic-bar:nth-child(4) { animation-delay: .75s; animation-duration: 6.0s; }
.traffic-chart .traffic-bar:nth-child(5) { animation-delay: 1s;   animation-duration: 5.4s; }
.traffic-chart .traffic-bar:nth-child(6) { animation-delay: 1.25s; animation-duration: 6.8s; }
.traffic-chart .traffic-bar:nth-child(7) { animation-delay: 1.5s; animation-duration: 5.8s; }
.traffic-chart .traffic-bar:nth-child(8) { animation-delay: 1.75s; animation-duration: 7.0s; }

@keyframes trafficWobble {
    0%, 100% { transform: scaleY(.86); opacity: .85; }
    50%      { transform: scaleY(1);   opacity: 1; }
}

/* ── Service-chip hover ────────────────────────────────────── */
/* Service-chip hover — subtle feedback, no levitation. */
.service-chip {
    transition: border-color var(--transition-base),
                background var(--transition-base),
                color var(--transition-base);
    cursor: default;
}

.service-chip:hover {
    border-color: var(--blue-border);
    background: var(--brand-soft-2);
    color: var(--text-1);
}

:root[data-theme="dark"] .service-chip:hover {
    background: var(--blue-dim);
    color: var(--text-1);
}

.service-chip::before {
    transition: transform .18s ease, background var(--transition-base);
}

.service-chip:hover::before {
    transform: scale(1.4);
}

/* ── Theme color transitions (smooth swap on theme switch) ─── */
/* Smooth color transitions on theme switch */
body,
.rack-card,
.feature-card,
.service-card,
.site-header,
.site-mobile-panel,
.btn,
.btn-primary,
.btn-secondary,
.alert,
.badge,
.status-badge {
    transition-duration: .25s;
}

/* ── Cursor trail (brand-blue dust following pointer) ──────── */
.cursor-trail-layer {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 9998;
    overflow: hidden;
    contain: strict;
}

.cursor-trail-dot {
    position: absolute;
    top: 0;
    left: 0;
    width: 10px;
    height: 10px;
    margin: -5px 0 0 -5px;
    border-radius: 50%;
    background: radial-gradient(circle at center, rgba(59, 130, 246, .95) 0%, rgba(59, 130, 246, .55) 45%, rgba(59, 130, 246, 0) 75%);
    opacity: 0;
    will-change: transform, opacity;
    transition: opacity .25s ease-out;
}

:root[data-theme="dark"] .cursor-trail-dot {
    background: radial-gradient(circle at center, rgba(147, 197, 253, 1) 0%, rgba(96, 165, 250, .6) 45%, rgba(59, 130, 246, 0) 75%);
}

/* Hide on touch devices (defensive — JS also skips) */
@media (pointer: coarse) {
    .cursor-trail-layer { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    .cursor-trail-layer { display: none; }
}

/* ── Reduced-motion global override ────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: .001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .001ms !important;
        scroll-behavior: auto !important;
    }

    .reveal-on-scroll {
        opacity: 1 !important;
        transform: none !important;
    }
}
