/* ===== Animation Library — PropertyOS ===== */

/* ─── Keyframes ─── */

@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}
@keyframes fadeOut {
    from { opacity: 1; }
    to   { opacity: 0; }
}

@keyframes slideInFromLeft {
    from { opacity: 0; transform: translateX(-24px); }
    to   { opacity: 1; transform: translateX(0); }
}
@keyframes slideInFromRight {
    from { opacity: 0; transform: translateX(24px); }
    to   { opacity: 1; transform: translateX(0); }
}
/* alias used by login/auth pages */
@keyframes slideInRight {
    from { opacity: 0; transform: translateX(32px) scale(0.98); }
    to   { opacity: 1; transform: translateX(0)    scale(1); }
}
@keyframes slideInFromTop {
    from { opacity: 0; transform: translateY(-18px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes slideInFromBottom {
    from { opacity: 0; transform: translateY(24px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes scaleIn {
    from { opacity: 0; transform: scale(0.90); }
    to   { opacity: 1; transform: scale(1); }
}
@keyframes scaleOut {
    from { opacity: 1; transform: scale(1); }
    to   { opacity: 0; transform: scale(0.90); }
}
@keyframes scaleSpringIn {
    0%   { opacity: 0; transform: scale(0.82); }
    65%  { transform: scale(1.06); }
    100% { opacity: 1; transform: scale(1); }
}

@keyframes blurIn {
    from { opacity: 0; transform: scale(0.97) translateY(6px); filter: blur(10px); }
    to   { opacity: 1; transform: scale(1)    translateY(0);   filter: blur(0px); }
}
@keyframes blurOut {
    from { opacity: 1; transform: scale(1);    filter: blur(0px); }
    to   { opacity: 0; transform: scale(1.02); filter: blur(10px); }
}

/* ── Shimmer for skeletons ── */
@keyframes shimmer {
    0%   { background-position: -800px 0; }
    100% { background-position:  800px 0; }
}

/* ── Liquid shine sweep (button/card hover) ── */
@keyframes liquidShimmer {
    0%   { transform: translateX(-100%) rotate(8deg); }
    100% { transform: translateX(200%)  rotate(8deg); }
}

/* ── Glow pulse ── */
@keyframes glowPulse {
    0%, 100% { box-shadow: 0 0 12px rgba(13, 110, 253, 0.30); }
    50%       { box-shadow: 0 0 28px rgba(13, 110, 253, 0.55); }
}
@keyframes glowAccent {
    0%, 100% { box-shadow: 0 0 16px rgba(102, 16, 242, 0.30); }
    50%       { box-shadow: 0 0 32px rgba(102, 16, 242, 0.55); }
}

/* ── Pulse / ring ── */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.42; }
}
@keyframes pulseRing {
    0%   { box-shadow: 0 0 0 0   rgba(13, 110, 253, 0.65); }
    70%  { box-shadow: 0 0 0 14px rgba(13, 110, 253, 0); }
    100% { box-shadow: 0 0 0 0   rgba(13, 110, 253, 0); }
}
@keyframes ripple {
    0%   { transform: scale(0); opacity: 0.5; }
    100% { transform: scale(4); opacity: 0; }
}

/* ── Float & orbit ── */
@keyframes float {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    33%       { transform: translateY(-10px) rotate(1deg); }
    66%       { transform: translateY(-5px)  rotate(-1deg); }
}
@keyframes floatSlow {
    0%, 100% { transform: translate(0, 0) scale(1); }
    25%       { transform: translate(20px, -15px) scale(1.03); }
    50%       { transform: translate(10px, -25px) scale(1.01); }
    75%       { transform: translate(-10px, -10px) scale(0.98); }
}
@keyframes floatShadow {
    0%, 100% { box-shadow: var(--pos-shadow-md); }
    50%       { box-shadow: var(--pos-shadow-xl); }
}

/* ── Rotation ── */
@keyframes spin {
    to { transform: rotate(360deg); }
}
@keyframes spinReverse {
    to { transform: rotate(-360deg); }
}

/* ── Bounce / shake ── */
@keyframes bounce {
    0%, 100% { transform: translateY(0); animation-timing-function: var(--pos-ease-out); }
    50%       { transform: translateY(-10px); animation-timing-function: var(--pos-ease-in-out); }
}
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-4px); }
    20%, 40%, 60%, 80%      { transform: translateX(4px); }
}
@keyframes wiggle {
    0%, 100% { transform: rotate(0deg); }
    20%       { transform: rotate(-6deg); }
    40%       { transform: rotate(6deg); }
    60%       { transform: rotate(-3deg); }
    80%       { transform: rotate(3deg); }
}

/* ── Modal/sheet ── */
@keyframes backdropFadeIn {
    from { opacity: 0; backdrop-filter: blur(0); }
    to   { opacity: 1; backdrop-filter: blur(6px); }
}
@keyframes modalSlideIn {
    from { opacity: 0; transform: translateY(28px) scale(0.95); filter: blur(4px); }
    to   { opacity: 1; transform: translateY(0)    scale(1);    filter: blur(0px); }
}
@keyframes bottomSheetSlideIn {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
}

/* ── Stagger / reveal ── */
@keyframes staggerFadeIn {
    from { opacity: 0; transform: translateY(14px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes staggerScaleIn {
    from { opacity: 0; transform: scale(0.88) translateY(8px); }
    to   { opacity: 1; transform: scale(1)    translateY(0); }
}

/* ── Glass reveal ── */
@keyframes glassReveal {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.97);
        backdrop-filter: blur(0px);
        filter: blur(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
        backdrop-filter: var(--pos-blur-md);
        filter: blur(0px);
    }
}

/* ── Gradient background shift ── */
@keyframes gradientShift {
    0%   { background-position: 0% 50%; }
    50%  { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* ── Border gradient animation ── */
@keyframes borderGlow {
    0%, 100% { box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.25); }
    50%       { box-shadow: 0 0 0 3px rgba(102, 16, 242, 0.25); }
}

/* ── Sparkline bar entrance ── */
@keyframes sparklineGrow {
    from { transform: scaleY(0); opacity: 0; }
    to   { transform: scaleY(1); opacity: 1; }
}

/* ── Icon bob / micro-float ── */
@keyframes iconBob {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    30%       { transform: translateY(-3px) rotate(-2deg); }
    60%       { transform: translateY(-1px) rotate(1deg); }
}

/* ── Iridescent border shift ── */
@keyframes iridescent {
    0%   { border-color: rgba(29, 110, 249, 0.45); box-shadow: 0 0 24px rgba(29,110,249,0.25); }
    25%  { border-color: rgba(124, 58, 237, 0.45); box-shadow: 0 0 24px rgba(124,58,237,0.25); }
    50%  { border-color: rgba(236,  72, 153, 0.45); box-shadow: 0 0 24px rgba(236,72,153,0.25); }
    75%  { border-color: rgba( 14, 165, 233, 0.45); box-shadow: 0 0 24px rgba(14,165,233,0.25); }
    100% { border-color: rgba(29, 110, 249, 0.45); box-shadow: 0 0 24px rgba(29,110,249,0.25); }
}

/* ── Liquid wave (hero orbs) ── */
@keyframes liquidWave {
    0%   { transform: translate(0, 0) scale(1) rotate(0deg); }
    25%  { transform: translate(15px, -20px) scale(1.04) rotate(3deg); }
    50%  { transform: translate(25px, -10px) scale(1.02) rotate(-2deg); }
    75%  { transform: translate(8px, -28px) scale(0.98) rotate(2deg); }
    100% { transform: translate(0, 0) scale(1) rotate(0deg); }
}

/* ── Specular sweep (card glass lip) ── */
@keyframes specularSweep {
    0%   { opacity: 0.4; }
    50%  { opacity: 1.0; }
    100% { opacity: 0.4; }
}

/* ── Orbit glow ring ── */
@keyframes orbitGlow {
    0%, 100% {
        box-shadow: 0 0 20px rgba(29,110,249,0.30), 0 0 40px rgba(124,58,237,0.15);
    }
    33% {
        box-shadow: 0 0 28px rgba(124,58,237,0.35), 0 0 50px rgba(236,72,153,0.18);
    }
    66% {
        box-shadow: 0 0 24px rgba(14,165,233,0.32), 0 0 44px rgba(29,110,249,0.18);
    }
}

/* ── Count-up flash ── */
@keyframes valueFlash {
    0%   { opacity: 0.5; transform: scale(0.96); }
    60%  { opacity: 1;   transform: scale(1.03); }
    100% { opacity: 1;   transform: scale(1); }
}

/* ─── Utility classes ─── */

.fade-in  { animation: fadeIn  var(--pos-duration-base) var(--pos-ease-out) both; }
.fade-out { animation: fadeOut var(--pos-duration-base) var(--pos-ease-in-out) both; }

.slide-in-left   { animation: slideInFromLeft   var(--pos-duration-slow) var(--pos-ease-out) both; }
.slide-in-right  { animation: slideInFromRight  var(--pos-duration-slow) var(--pos-ease-out) both; }
.slide-in-top    { animation: slideInFromTop    var(--pos-duration-slow) var(--pos-ease-out) both; }
.slide-in-bottom { animation: slideInFromBottom var(--pos-duration-slow) var(--pos-ease-out) both; }

.scale-in        { animation: scaleIn       var(--pos-duration-base) var(--pos-ease-out)    both; }
.scale-out       { animation: scaleOut      var(--pos-duration-base) var(--pos-ease-in-out) both; }
.scale-spring-in { animation: scaleSpringIn var(--pos-duration-slow) var(--pos-ease-spring) both; }

.blur-in    { animation: blurIn      var(--pos-duration-slow)  var(--pos-ease-out) both; }
.blur-out   { animation: blurOut     var(--pos-duration-base)  var(--pos-ease-in-out) both; }

.glass-reveal { animation: glassReveal var(--pos-duration-slow) var(--pos-ease-out) both; }
.glass-enter  { animation: glassReveal var(--pos-duration-slow) var(--pos-ease-decelerate) both; }

.bounce      { animation: bounce       0.6s  var(--pos-ease-in-out) infinite; }
.pulse       { animation: pulse        2.2s  var(--pos-ease-in-out) infinite; }
.float       { animation: float        3.5s  ease-in-out infinite; }
.float-slow  { animation: floatSlow    7s    ease-in-out infinite; }
.spin        { animation: spin         1s    linear infinite; }
.spin-fast   { animation: spin         0.55s linear infinite; }
.spin-reverse{ animation: spinReverse  1s    linear infinite; }
.shake       { animation: shake        0.5s  var(--pos-ease-in-out) both; }
.wiggle      { animation: wiggle       0.55s var(--pos-ease-spring) both; }

.pulse-ring  { animation: pulseRing    2.2s  infinite; }
.glow-pulse   { animation: glowPulse    2.4s  ease-in-out infinite; }
.glow-accent  { animation: glowAccent  2.8s  ease-in-out infinite; }
.orbit-glow   { animation: orbitGlow   3.2s  ease-in-out infinite; }
.iridescent   { animation: iridescent  4.0s  ease-in-out infinite; }
.icon-bob     { animation: iconBob     3.0s  ease-in-out infinite; }
.liquid-wave  { animation: liquidWave  8.0s  ease-in-out infinite; }
.value-flash  { animation: valueFlash  0.5s  var(--pos-ease-spring) both; }

/* ─── Page transitions ─── */
.page-enter {
    animation: blurIn var(--pos-duration-slow) var(--pos-ease-decelerate) both;
}
.page-header-enter {
    animation: slideInFromTop var(--pos-duration-slow) var(--pos-ease-decelerate) both;
}
.page-content-enter {
    animation: fadeIn var(--pos-duration-slow) var(--pos-ease-out) both;
    animation-delay: 60ms;
}

/* ─── Stagger list animations ─── */
.stagger > * {
    animation: staggerFadeIn var(--pos-duration-slow) var(--pos-ease-decelerate) both;
}
.stagger > *:nth-child(1)   { animation-delay:   0ms; }
.stagger > *:nth-child(2)   { animation-delay:  55ms; }
.stagger > *:nth-child(3)   { animation-delay: 110ms; }
.stagger > *:nth-child(4)   { animation-delay: 165ms; }
.stagger > *:nth-child(5)   { animation-delay: 220ms; }
.stagger > *:nth-child(6)   { animation-delay: 275ms; }
.stagger > *:nth-child(7)   { animation-delay: 330ms; }
.stagger > *:nth-child(8)   { animation-delay: 370ms; }
.stagger > *:nth-child(n+9) { animation-delay: 410ms; }

.stagger-scale > * {
    animation: staggerScaleIn var(--pos-duration-slow) var(--pos-ease-spring) both;
}
.stagger-scale > *:nth-child(1) { animation-delay:  30ms; }
.stagger-scale > *:nth-child(2) { animation-delay:  90ms; }
.stagger-scale > *:nth-child(3) { animation-delay: 150ms; }
.stagger-scale > *:nth-child(4) { animation-delay: 210ms; }
.stagger-scale > *:nth-child(n+5) { animation-delay: 270ms; }

/* ─── Badge pop ─── */
.badge-pop { animation: scaleSpringIn var(--pos-duration-slow) var(--pos-ease-spring) both; }

/* ─── Skeleton shimmer ─── */
.skeleton {
    background: linear-gradient(
        90deg,
        var(--pos-surface) 25%,
        var(--pos-border)  50%,
        var(--pos-surface) 75%
    );
    background-size: 800px 100%;
    animation: shimmer 1.6s ease-in-out infinite;
    border-radius: var(--pos-radius-sm);
}

/* ─── Liquid shine element (for card/button ::after hover sweep) ── */
.liquid-shine {
    position: absolute;
    inset: 0;
    background: linear-gradient(
        105deg,
        transparent 30%,
        rgba(255, 255, 255, 0.22) 50%,
        transparent 70%
    );
    transform: translateX(-100%);
    pointer-events: none;
    border-radius: inherit;
}
:hover > .liquid-shine {
    animation: liquidShimmer 0.6s var(--pos-ease-out) both;
}

/* ─── Modal / dialog ─── */
.modal-backdrop-enter { animation: backdropFadeIn var(--pos-duration-base)  var(--pos-ease-out)    both; }
.modal-enter          { animation: modalSlideIn   var(--pos-duration-slow)  var(--pos-ease-spring) both; }
.bottom-sheet-enter   { animation: bottomSheetSlideIn var(--pos-duration-slow) var(--pos-ease-decelerate) both; }

/* ─── Button micro-interactions ─── */
.btn-lift {
    transition:
        transform   var(--pos-duration-base) var(--pos-ease-out),
        box-shadow  var(--pos-duration-base) var(--pos-ease-out);
}
.btn-lift:hover  { transform: translateY(-2px); box-shadow: var(--pos-shadow-md); }
.btn-lift:active { transform: translateY(0) scale(0.97); box-shadow: var(--pos-shadow-xs); }

.btn-spring {
    transition: transform var(--pos-duration-base) var(--pos-ease-spring);
}
.btn-spring:hover  { transform: scale(1.05); }
.btn-spring:active { transform: scale(0.95); }

/* ─── Card hover ─── */
.card-hover {
    transition:
        transform    var(--pos-duration-base) var(--pos-ease-out),
        box-shadow   var(--pos-duration-base) var(--pos-ease-out),
        border-color var(--pos-duration-base) var(--pos-ease-out);
}
.card-hover:hover {
    transform: translateY(-4px);
    box-shadow: var(--pos-shadow-lg);
    border-color: rgba(13, 110, 253, 0.25);
}

/* ─── Transition utilities ─── */
.transition-fast   { transition: all var(--pos-duration-fast)  var(--pos-ease-in-out); }
.transition-smooth { transition: all var(--pos-duration-base)  var(--pos-ease-in-out); }
.transition-slow   { transition: all var(--pos-duration-slow)  var(--pos-ease-in-out); }

/* ─── Performance hints ─── */
.will-animate           { will-change: transform, opacity; }
.will-animate-transform { will-change: transform; }
.will-animate-opacity   { will-change: opacity; }

/* ─── Respect motion preferences ─── */
@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;
    }
    .skeleton { animation: none; background: var(--pos-border); }
}

@media (prefers-reduced-transparency: reduce) {
    .pos-glass, .pos-glass-card, .pos-glass-heavy, .pos-glass-modal {
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
        background: var(--pos-card-bg) !important;
    }
}
