/* ==========================================================================
   FLUXO DESIGN SYSTEM — ANIMATIONS.CSS
   Coreografia motion stile Apple (cubic-bezier(0.32, 0.72, 0, 1)):
     - Cascata Staggered 4 livelli su cambio vista
     - Micro-interazioni liquide su Matrice, Drawer, Riconciliazione e Hub
     - Theme Switcher Bidirezionale 60fps (`data-theme-transition="to-dark" / "to-light"`):
         Light -> Dark: espansione circolare ::view-transition-new(root)
         Dark -> Light: risucchio circolare ::view-transition-old(root)
     - Rispetto rigoroso prefers-reduced-motion: reduce
   REGOLA: Usa esclusivamente variabili --fx-* definite in tokens.css.
   ========================================================================== */

/* === TRANSIZIONE CAMBIO VISTA & CASCATA SPRING BENTO-GRID (640ms) === */
@keyframes fxViewEnter {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.fx-view-enter {
    animation: fxViewEnter var(--fx-duration-base) var(--fx-ease-apple) both;
}

@keyframes fxBentoBlockSpringEnter {
    from {
        opacity: 0;
        transform: translate3d(0, 24px, 0) scale(0.972);
    }

    to {
        opacity: 1;
        transform: translate3d(0, 0, 0) scale(1);
    }
}

.fx-stagger-item[data-fx-stagger-level] {
    will-change: opacity, transform;
}

/* === LIVE SYNC PULSE & MICRO-INTERAZIONI HEADER === */
@keyframes fxLiveDotPulse {
    0%,
    100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 var(--fx-color-inflow-soft);
    }

    50% {
        transform: scale(1.16);
        box-shadow: 0 0 0 5px transparent;
    }
}

.fx-live-dot {
    animation: fxLiveDotPulse 2.4s var(--fx-ease-in-out) infinite;
}

/* === MATRICE: REVEAL RIGHE FIGLIE & DRAWER STAGGER === */
@keyframes fxMatrixRowReveal {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fx-matrix-row-sub.is-revealing {
    animation: fxMatrixRowReveal 220ms var(--fx-ease-apple) var(--fx-row-delay, 0ms) backwards;
}

.fx-matrix-row-sub.is-collapsing {
    opacity: 0;
    transform: translateY(-4px);
    transition:
        opacity var(--fx-duration-micro) var(--fx-ease-apple),
        transform var(--fx-duration-micro) var(--fx-ease-apple);
}

@keyframes fxDrawerDocEnter {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fx-drawer-doc-item.fx-drawer-doc-stagger {
    animation: fxDrawerDocEnter 280ms var(--fx-ease-apple) var(--fx-doc-delay, 90ms) backwards;
}

/* === RICONCILIAZIONE: CONFERMA SPLIT-CARD & PULSE BADGE SIDEBAR === */
.fx-recon-card {
    transition:
        border-color var(--fx-duration-micro) var(--fx-ease-apple),
        transform 260ms var(--fx-ease-apple),
        opacity 220ms var(--fx-ease-apple),
        box-shadow var(--fx-duration-base) var(--fx-ease-apple);
}

.fx-recon-card.is-confirming {
    border-color: var(--fx-color-inflow);
}

.fx-recon-card.is-exiting {
    border-color: var(--fx-color-inflow);
    transform: translateX(16px);
    opacity: 0;
    pointer-events: none;
}

@keyframes fxBadgePulse {
    0% {
        transform: scale(1);
    }

    45% {
        transform: scale(1.18);
    }

    100% {
        transform: scale(1);
    }
}

.fx-nav-badge.is-badge-pulsing {
    animation: fxBadgePulse 340ms var(--fx-ease-apple) both;
}

/* === HUB COMMERCIALISTA: HIGHLIGHT SUPERFICIE === */
@keyframes fxSurfacePulse {
    0% {
        border-color: var(--fx-border-strong);
        box-shadow: 0 0 0 0 var(--fx-accent-ring);
    }

    35% {
        border-color: var(--fx-accent-primary);
        box-shadow: 0 0 0 3px var(--fx-accent-soft);
    }

    100% {
        border-color: var(--fx-border-subtle);
        box-shadow: 0 0 0 0 transparent;
    }
}

.is-surface-pulsing {
    animation: fxSurfacePulse 680ms var(--fx-ease-apple) both;
}

/* === EVIDENZIAZIONE TARGET DA NAVIGAZIONE DASHBOARD -> RICONCILIAZIONE === */
@keyframes fxTargetHighlightPulse {
    0% {
        box-shadow: 0 0 0 0 var(--fx-highlight-ring);
        background-color: var(--fx-highlight-bg);
    }

    30% {
        box-shadow: 0 0 0 4px var(--fx-highlight-ring);
        background-color: var(--fx-highlight-bg);
    }

    100% {
        box-shadow: 0 0 0 0 transparent;
        background-color: transparent;
    }
}

.is-highlighted-target {
    animation: fxTargetHighlightPulse 1.8s var(--fx-ease-apple) both;
    border-color: var(--fx-color-inflow) !important;
}

/* === AGGIORNAMENTO IN-PLACE TABELLA (CROSSFADE MORBIDO 180ms) === */
@keyframes fxTableCrossfade {
    from {
        opacity: 0.35;
    }

    to {
        opacity: 1;
    }
}

.fx-tbody-updating {
    animation: fxTableCrossfade 180ms var(--fx-ease-apple) both;
}

/* === SHIMMER LOADING SKELETON === */
@keyframes fxSkeletonWave {
    0% {
        background-position: 200% 0;
    }

    100% {
        background-position: -200% 0;
    }
}

.fx-skeleton-line {
    height: 12px;
    border-radius: var(--fx-radius-xs);
    background: linear-gradient(
        90deg,
        var(--fx-bg-elevated) 25%,
        var(--fx-border-subtle) 50%,
        var(--fx-bg-elevated) 75%
    );
    background-size: 200% 100%;
    animation: fxSkeletonWave 1.6s linear infinite;
}

.fx-skeleton-stack {
    display: flex;
    flex-direction: column;
    gap: var(--fx-space-2);
}

.fx-skeleton-lg {
    width: 90%;
}

.fx-skeleton-md {
    width: 74%;
}

.fx-skeleton-sm {
    width: 52%;
}

/* === FLASH CONFERMA RICALCOLO CELLA MATRICE === */
@keyframes fxCellFlash {
    0% {
        background-color: var(--fx-accent-soft);
        box-shadow: inset 0 0 0 1px var(--fx-accent-primary);
    }

    100% {
        background-color: transparent;
        box-shadow: inset 0 0 0 1px transparent;
    }
}

.fx-matrix-td-num.is-flashed {
    animation: fxCellFlash 1.1s var(--fx-ease-apple) both;
}

/* === THEME SWITCHER BIDIREZIONALE 60FPS & VIEW TRANSITIONS API === */
html[data-theme-transition] *,
html[data-theme-transition] *::before,
html[data-theme-transition] *::after {
    transition-duration: 0s !important;
    transition-delay: 0s !important;
}

::view-transition-group(root) {
    animation-duration: 0s;
}

::view-transition-image-pair(root) {
    isolation: isolate;
}

::view-transition-old(root),
::view-transition-new(root) {
    animation: none;
    mix-blend-mode: normal;
    display: block;
    will-change: clip-path, opacity;
}

/* LIGHT -> DARK: Il nuovo tema (Dark) sta SOPRA e si espande dal bottone */
html[data-theme-transition="to-dark"]::view-transition-old(root) {
    z-index: 1;
}

html[data-theme-transition="to-dark"]::view-transition-new(root) {
    z-index: 9999;
}

/* DARK -> LIGHT: Il vecchio tema (Dark) resta SOPRA e viene RISUCCHIATO nel bottone, svelando il Light sotto */
html[data-theme-transition="to-light"]::view-transition-new(root) {
    z-index: 1;
}

html[data-theme-transition="to-light"]::view-transition-old(root) {
    z-index: 9999;
}

/* Transizione cambio vista */
@keyframes fxVtFadeOut {
    from {
        opacity: 1;
    }

    to {
        opacity: 0;
    }
}

html[data-fx-transition="view"]::view-transition-old(root) {
    z-index: 2;
    animation: fxVtFadeOut 130ms var(--fx-ease-apple) both;
}

html[data-fx-transition="view"]::view-transition-new(root) {
    z-index: 1;
    animation: none;
}

/* === ACCESSIBILITÀ: DISABILITA MOVIMENTO SE RICHIESTO DAL SISTEMA === */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-delay: 0ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}
