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

/* ─── Keyframes ─── */

@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}
@keyframes fadeOut {
    from { opacity: 1; }
    to   { opacity: 0; }
}
/* Per-route page entrance — gentle fade + upward glide. */
@keyframes pageContentIn {
    from { opacity: 0; transform: translate3d(0, 12px, 0); }
    to   { opacity: 1; transform: translate3d(0, 0, 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); }
    to   { opacity: 1; transform: scale(1)    translateY(0); }
}
@keyframes blurOut {
    from { opacity: 1; transform: scale(1); }
    to   { opacity: 0; transform: scale(1.02); }
}

/* ── 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 — kept subtle by design: flat/minimal UI, no neon breathing ── */
@keyframes glowPulse {
    0%, 100% { box-shadow: 0 0 8px rgba(79, 70, 229, 0.16); }
    50%       { box-shadow: 0 0 12px rgba(79, 70, 229, 0.24); }
}
@keyframes glowAccent {
    0%, 100% { box-shadow: 0 0 8px rgba(79, 70, 229, 0.16); }
    50%       { box-shadow: 0 0 12px rgba(79, 70, 229, 0.24); }
}

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

/* ── Float — gentle vertical drift only, no rotate/scale wobble (flat, not 3D) ── */
@keyframes float {
    0%, 100% { transform: translateY(0); }
    50%       { transform: translateY(-6px); }
}
@keyframes floatSlow {
    0%, 100% { transform: translate(0, 0); }
    50%       { transform: translate(8px, -10px); }
}
@keyframes floatShadow {
    0%, 100% { box-shadow: var(--pos-shadow-sm); }
    50%       { box-shadow: var(--pos-shadow-md); }
}

/* ── 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; }
    to   { opacity: 1; }
}
@keyframes modalSlideIn {
    from { opacity: 0; transform: translateY(28px) scale(0.95); }
    to   { opacity: 1; transform: translateY(0)    scale(1); }
}
@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);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ── Gradient background — flat by design: no ambient shimmer/breathing.
   Kept as a keyframe (rather than deleting ~30 call sites) so gradient fills
   render as a single static tone instead of an animated sheen. ── */
@keyframes gradientShift {
    0%, 100% { background-position: 0% 50%; }
}

/* ── Border gradient animation — unused; flattened for consistency ── */
@keyframes borderGlow {
    0%, 100% { box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.18); }
}

/* ── 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); }
}

/* ── Accent border breathe — toned down further for a flat, calm look ── */
@keyframes iridescent {
    0%, 100% { border-color: rgba(79, 70, 229, 0.24); box-shadow: 0 0 10px rgba(79,70,229,0.10); }
    50%      { border-color: rgba(79, 70, 229, 0.34); box-shadow: 0 0 14px rgba(79,70,229,0.14); }
}

/* ── Liquid wave (hero orbs) — subtle drift only, no scale/rotate "3D" wobble ── */
@keyframes liquidWave {
    0%, 100% { transform: translate(0, 0); }
    50%      { transform: translate(10px, -8px); }
}

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

/* ── Orbit glow ring (single-hue breathe; currently unused but kept token-consistent) ── */
@keyframes orbitGlow {
    0%, 100% {
        box-shadow: 0 0 20px rgba(79,70,229,0.30), 0 0 40px rgba(67,56,202,0.14);
    }
    50% {
        box-shadow: 0 0 28px rgba(79,70,229,0.36), 0 0 50px rgba(67,56,202,0.20);
    }
}

/* ── 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: fadeIn var(--pos-duration-slow) var(--pos-ease-out) both;
}
.page-header-enter {
    animation: slideInFromTop var(--pos-duration-slow) var(--pos-ease-decelerate) both;
}
.page-content-enter {
    animation: pageContentIn var(--pos-duration-slow) var(--pos-ease-out) both;
    will-change: transform, opacity;
}

/* ─── 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-layer {
    position: fixed;
    inset: 0;
    z-index: 1060;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--pos-space-4);
    pointer-events: none;
}
.modal-backdrop-enter {
    position: absolute;
    inset: 0;
    pointer-events: auto;
    background: rgba(10, 14, 24, 0.35);
    backdrop-filter: blur(8px) saturate(1.2);
    -webkit-backdrop-filter: blur(8px) saturate(1.2);
    animation: backdropFadeIn var(--pos-duration-base) var(--pos-ease-out) both;
}
.modal-layer > .app-modal,
.modal-layer > .app-modal--sheet {
    position: relative;
    z-index: 1;
    pointer-events: auto;
}
.modal-layer:has(.app-modal--sheet) {
    align-items: flex-end;
    padding-bottom: 0;
}
.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(79, 70, 229, 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;
    }
}
