/**
 * PowerChat Animation Engine
 *
 * Single source of truth for the floating widget, the admin live preview and
 * the admin animation picker. Layout stays in powerchat-frontend.css /
 * powerchat-admin.css; only the animation contract lives here.
 *
 * Two families share one contract:
 *   - RING effects     -> driven by .powerchat-ring inside .powerchat-pulse-wave
 *   - TARGET effects   -> driven by the .powerchat-animation-target button
 *
 * Every rule inherits --pc-btn-size / --pc-btn-radius / --pc-btn-bg so that the
 * shape picker and the colour picker keep working without extra overrides.
 */

/* ---------------------------------------------------------------
 * RING LAYER BASE
 * ------------------------------------------------------------- */
.powerchat-pulse-wave {
    position: absolute !important;
    top: 50% !important;
    left: 50% !important;
    width: var(--pc-btn-size, 58px) !important;
    height: var(--pc-btn-size, 58px) !important;
    margin-top: calc(var(--pc-btn-size, 58px) / -2) !important;
    margin-left: calc(var(--pc-btn-size, 58px) / -2) !important;
    pointer-events: none !important;
    z-index: 1 !important;
}

.powerchat-pulse-wave .powerchat-ring {
    position: absolute !important;
    inset: 0 !important;
    display: block !important;
    box-sizing: border-box !important;
    border-radius: var(--pc-btn-radius, 50%) !important;
    background: var(--pc-btn-bg, var(--pc-preview-color, #25D366)) !important;
    opacity: 0;
    pointer-events: none !important;
    will-change: transform, opacity !important;
}

/* ===============================================================
 * RING FAMILY
 * =============================================================== */

/* 01 Pulse — soft outward halo rings */
.powerchat-anim-pulse .powerchat-ring {
    background: transparent !important;
    border: 2px solid var(--pc-btn-bg, var(--pc-preview-color, #25D366)) !important;
    animation: pcPulse 2.6s cubic-bezier(0.2, 0.7, 0.3, 1) infinite !important;
}
.powerchat-anim-pulse .powerchat-ring:nth-child(2) {
    animation-delay: 1.3s !important;
}

/* 02 Shockwave — smooth sonar radar (double ring) */
.powerchat-anim-shockwave .powerchat-ring {
    animation: pcShockwave 2.8s cubic-bezier(0.1, 0.4, 0.2, 1) infinite !important;
}
.powerchat-anim-shockwave .powerchat-ring:nth-child(2) {
    animation-delay: 1.4s !important;
}

/* 03 Heartbeat Ring — single thump ring around a pulsing button */
.powerchat-anim-heartbeat-ring .powerchat-ring {
    background: transparent !important;
    border: 2px solid var(--pc-btn-bg, var(--pc-preview-color, #25D366)) !important;
    animation: pcHeartbeatRing 1.7s ease-out infinite !important;
}

/* 06 Ripple — thin water ripple lines */
.powerchat-anim-ripple .powerchat-ring {
    inset: -2px !important;
    background: transparent !important;
    border: 1.5px solid var(--pc-btn-bg, var(--pc-preview-color, #25D366)) !important;
    animation: pcRipple 3.1s ease-out infinite !important;
}
.powerchat-anim-ripple .powerchat-ring:nth-child(2) {
    animation-delay: 1.55s !important;
}

/* 07 Triple Wave — three fast ripple rings */
.powerchat-anim-wave-triple .powerchat-ring {
    animation: pcTripleRipple 1.6s ease-out infinite !important;
}
.powerchat-anim-wave-triple .powerchat-ring:nth-child(2) {
    animation-delay: 0.35s !important;
}
.powerchat-anim-wave-triple .powerchat-ring:nth-child(3) {
    animation-delay: 0.7s !important;
}

/* 09 Echo — blurred light discs washing outward */
.powerchat-anim-echo .powerchat-ring {
    filter: blur(3px) !important;
    animation: pcEcho 2.2s ease-out infinite !important;
}
.powerchat-anim-echo .powerchat-ring:nth-child(2) {
    animation-delay: 1.1s !important;
}

/* 10 Rings — counter rotating dashed orbits */
.powerchat-anim-rings .powerchat-ring {
    background: transparent !important;
    border: 1.5px dashed var(--pc-btn-bg, var(--pc-preview-color, #25D366)) !important;
    opacity: 0.7;
    animation: pcRingsSpin 8s linear infinite !important;
}
.powerchat-anim-rings .powerchat-ring:nth-child(1) {
    inset: -7px !important;
}
.powerchat-anim-rings .powerchat-ring:nth-child(2) {
    inset: -15px !important;
    border-style: dotted !important;
    opacity: 0.45;
    animation-direction: reverse !important;
    animation-duration: 12s !important;
}

/* 27 Spin Ring — rotating gradient rim */
.powerchat-anim-spin-ring .powerchat-ring {
    inset: -7px !important;
    padding: 4px !important;
    background: conic-gradient(
        from 0deg,
        transparent 0deg,
        transparent 190deg,
        var(--pc-btn-bg, var(--pc-preview-color, #25D366)) 300deg,
        #ffffff 360deg
    ) !important;
    -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    -webkit-mask-composite: xor;
    mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    mask-composite: exclude;
    opacity: 1;
    animation: pcSpinRing 2.4s linear infinite !important;
}

/* 29 Swirl — nested counter rotating light arcs */
.powerchat-anim-swirl .powerchat-ring {
    inset: -6px !important;
    padding: 3px !important;
    background: conic-gradient(
        from 0deg,
        transparent 0deg,
        transparent 224deg,
        var(--pc-btn-bg, var(--pc-preview-color, #25D366)) 302deg,
        transparent 360deg
    ) !important;
    -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    -webkit-mask-composite: xor;
    mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    mask-composite: exclude;
    opacity: 1;
    animation: pcSwirl 1.9s linear infinite !important;
}
.powerchat-anim-swirl .powerchat-ring:nth-child(2) {
    inset: -13px !important;
    opacity: 0.55;
    animation-duration: 3.1s !important;
    animation-direction: reverse !important;
}

/* 35 Prism — rotating rainbow rim */
.powerchat-anim-prism .powerchat-ring {
    inset: -4px !important;
    padding: 4px !important;
    background: conic-gradient(#ff5f6d, #ffc371, #8ef7b4, #38bdf8, #a78bfa, #ff5f6d) !important;
    -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    -webkit-mask-composite: xor;
    mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    mask-composite: exclude;
    opacity: 1;
    animation: pcPrism 4s linear infinite !important;
}

/* 54 Confetti — colourful particles bursting out of the centre */
.powerchat-anim-confetti .powerchat-ring {
    inset: auto !important;
    top: 50% !important;
    left: 50% !important;
    width: 5px !important;
    height: 5px !important;
    margin: -2.5px 0 0 -2.5px !important;
    border-radius: 50% !important;
    animation: pcConfetti 3s ease-out infinite !important;
}

/* 49 Gooey — liquid blobs merging inside the capsule */
.powerchat-anim-gooey .powerchat-animation-target {
    overflow: hidden !important;
}
.powerchat-anim-gooey .powerchat-ring {
    inset: auto !important;
    top: 13% !important;
    left: 13% !important;
    width: 74% !important;
    height: 74% !important;
    border-radius: 50% !important;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.55), rgba(255, 255, 255, 0) 70%) !important;
    animation: pcGooeyA 4.2s ease-in-out infinite !important;
}
.powerchat-anim-gooey .powerchat-ring:nth-child(2) {
    background: radial-gradient(circle, rgba(0, 0, 0, 0.28), rgba(0, 0, 0, 0) 70%) !important;
    animation-name: pcGooeyB !important;
    animation-duration: 5.4s !important;
}

/* ===============================================================
 * TARGET FAMILY
 * =============================================================== */

/* 04 Heartbeat — double thump of the button itself */
.powerchat-anim-heartbeat .powerchat-animation-target {
    animation: pcHeartbeat 2.2s ease-in-out infinite !important;
}

/* 14 Bounce */
.powerchat-anim-bounce .powerchat-animation-target {
    animation: pcBounce 2.5s infinite !important;
    transform-origin: center bottom !important;
}

/* 15 Jump — squash then leap */
.powerchat-anim-jump .powerchat-animation-target {
    animation: pcJump 2.6s cubic-bezier(0.34, 1.4, 0.64, 1) infinite !important;
}

/* 16 Jelly — soft elastic wobble */
.powerchat-anim-jelly .powerchat-animation-target {
    animation: pcJelly 2.6s ease-in-out infinite !important;
}

/* 17 Rubber Band */
.powerchat-anim-rubberband .powerchat-animation-target {
    animation: pcRubber 2.6s infinite !important;
}

/* 18 Wiggle — periodic swing from a low pivot */
.powerchat-anim-wiggle .powerchat-animation-target {
    animation: pcWiggle 4.2s ease-in-out infinite !important;
    transform-origin: 50% 85% !important;
}

/* 19 Waggle */
.powerchat-anim-waggle .powerchat-animation-target {
    animation: pcWaggle 2.5s ease-in-out infinite !important;
    transform-origin: center center !important;
}

/* 20 Shake — short attention bursts */
.powerchat-anim-shake .powerchat-animation-target {
    animation: pcShake 4s ease-in-out infinite !important;
}

/* 21 Tada */
.powerchat-anim-tada .powerchat-animation-target {
    animation: pcTada 2.8s infinite !important;
}

/* 34 Flip3d — periodic forward flip */
.powerchat-anim-flip3d .powerchat-animation-target {
    animation: pcFlip3d 4.4s cubic-bezier(0.55, 0.05, 0.35, 1) infinite !important;
}

/* 37 Sheen — light sweep across the surface */
.powerchat-anim-sheen .powerchat-animation-target {
    overflow: hidden !important;
}
.powerchat-anim-sheen .powerchat-animation-target::before {
    content: '' !important;
    position: absolute !important;
    inset: 0 !important;
    display: block !important;
    border-radius: inherit !important;
    background-image: linear-gradient(120deg, rgba(255, 255, 255, 0) 30%, rgba(255, 255, 255, 0.65) 50%, rgba(255, 255, 255, 0) 70%) !important;
    background-repeat: no-repeat !important;
    background-size: 250% 100% !important;
    background-position: 180% 0;
    animation: pcSheen 3s cubic-bezier(0.4, 0, 0.2, 1) infinite !important;
    pointer-events: none !important;
    z-index: 2 !important;
}

/* 39 Glow Breath — calm breathing halo */
.powerchat-anim-glow-breath .powerchat-animation-target {
    animation: pcGlowBreath 3s ease-in-out infinite !important;
}

/* 41 Neon — flashing neon tube on a dark surface */
.powerchat-anim-neon .powerchat-animation-target {
    background-color: #052416 !important;
    border: 1.5px solid var(--pc-btn-bg, var(--pc-preview-color, #25D366)) !important;
    animation: pcNeon 2.4s ease-in-out infinite !important;
}
.powerchat-anim-neon .powerchat-animation-target svg {
    filter: drop-shadow(0 0 6px var(--pc-btn-bg, var(--pc-preview-color, #25D366))) !important;
}

/* 46 Fade */
.powerchat-anim-fade .powerchat-animation-target {
    animation: pcFade 2.4s ease-in-out infinite !important;
}

/* None */
.powerchat-anim-none .powerchat-animation-target {
    animation: none !important;
}
.powerchat-anim-none .powerchat-ring {
    animation: none !important;
    opacity: 0 !important;
}

/* ===============================================================
 * KEYFRAMES
 * =============================================================== */

@keyframes pcPulse {
    0% { transform: scale(1); opacity: 0.85; }
    70%, 100% { transform: scale(1.8); opacity: 0; }
}

@keyframes pcShockwave {
    0% { transform: scale(0.95); opacity: 0; }
    12% { opacity: 0.65; }
    100% { transform: scale(1.85); opacity: 0; }
}

@keyframes pcHeartbeatRing {
    0% { transform: scale(1); opacity: 0.6; }
    45% { transform: scale(1.5); opacity: 0.22; }
    100% { transform: scale(1.8); opacity: 0; }
}

@keyframes pcHeartbeat {
    0%, 100% { transform: scale(1); }
    14% { transform: scale(1.16); }
    28% { transform: scale(1); }
    42% { transform: scale(1.10); }
    70% { transform: scale(1); }
}

@keyframes pcRipple {
    0% { transform: scale(0.92); opacity: 0.95; }
    60% { opacity: 0.35; }
    100% { transform: scale(2.35); opacity: 0; }
}

@keyframes pcTripleRipple {
    0% { transform: scale(0.2); opacity: 0; }
    30% { opacity: 0.45; }
    100% { transform: scale(2.1); opacity: 0; }
}

@keyframes pcEcho {
    0% { transform: scale(1); opacity: 0.85; }
    100% { transform: scale(2.6); opacity: 0; }
}

@keyframes pcRingsSpin {
    to { transform: rotate(360deg); }
}

@keyframes pcSpinRing {
    to { transform: rotate(360deg); }
}

@keyframes pcSwirl {
    to { transform: rotate(360deg); }
}

@keyframes pcPrism {
    to { transform: rotate(360deg); }
}

@keyframes pcConfetti {
    0% {
        opacity: 0;
        transform: translate(0, 0) scale(0.4);
        box-shadow:
            0 0 #ff5f6d, 0 0 #ffc371, 0 0 #8ef7b4, 0 0 #38bdf8,
            0 0 #a78bfa, 0 0 #25d366, 0 0 #ffffff, 0 0 #ff5f6d;
    }
    12% { opacity: 1; }
    65%, 100% {
        opacity: 0;
        transform: translate(0, 0) scale(1);
        box-shadow:
            -40px -32px #ff5f6d, 36px -36px #ffc371, 46px 10px #8ef7b4, 14px 44px #38bdf8,
            -28px 36px #a78bfa, -46px 6px #25d366, 32px -14px #ffffff, -12px -48px #ff5f6d;
    }
}

@keyframes pcGooeyA {
    0%, 100% { transform: translate(-26%, -20%) scale(0.85); }
    50% { transform: translate(30%, 22%) scale(1.15); }
}

@keyframes pcGooeyB {
    0%, 100% { transform: translate(34%, 26%) scale(1.1); }
    50% { transform: translate(-30%, -24%) scale(0.8); }
}

@keyframes pcBounce {
    0%, 20%, 53%, 80%, 100% { transform: translateY(0); }
    40%, 43% { transform: translateY(-16px); }
    70% { transform: translateY(-8px); }
    90% { transform: translateY(-3px); }
}

@keyframes pcJump {
    0%, 100% { transform: translateY(0) scale(1, 1); }
    10% { transform: translateY(3px) scale(1.13, 0.87); }
    32% { transform: translateY(-20px) scale(0.94, 1.08); }
    48% { transform: translateY(0) scale(1.1, 0.9); }
    58% { transform: translateY(0) scale(1, 1); }
}

@keyframes pcJelly {
    0%, 100% { transform: scale(1, 1); }
    18% { transform: scale(1.15, 0.87); }
    34% { transform: scale(0.9, 1.12); }
    50% { transform: scale(1.08, 0.94); }
    66% { transform: scale(0.96, 1.04); }
    82% { transform: scale(1.02, 0.98); }
}

@keyframes pcRubber {
    0%, 100% { transform: scale3d(1, 1, 1); }
    15% { transform: scale3d(1.25, 0.75, 1); }
    20% { transform: scale3d(0.75, 1.25, 1); }
    25% { transform: scale3d(1.15, 0.85, 1); }
    32% { transform: scale3d(0.95, 1.05, 1); }
    40% { transform: scale3d(1, 1, 1); }
}

@keyframes pcWiggle {
    0%, 62%, 100% { transform: rotate(0deg) scale(1); }
    66% { transform: rotate(-13deg) scale(1.04); }
    70% { transform: rotate(11deg) scale(1.04); }
    74% { transform: rotate(-9deg) scale(1.03); }
    78% { transform: rotate(7deg) scale(1.02); }
    82% { transform: rotate(-4deg) scale(1.01); }
    86% { transform: rotate(0deg) scale(1); }
}

@keyframes pcWaggle {
    0%, 100% { transform: rotate(0deg); }
    10% { transform: rotate(-14deg); }
    20% { transform: rotate(12deg); }
    30% { transform: rotate(-10deg); }
    40% { transform: rotate(8deg); }
    50% { transform: rotate(-4deg); }
    60% { transform: rotate(0deg); }
}

@keyframes pcShake {
    0%, 72%, 100% { transform: translateX(0) rotate(0deg); }
    75% { transform: translateX(-6px) rotate(-3deg); }
    78% { transform: translateX(6px) rotate(3deg); }
    81% { transform: translateX(-5px) rotate(-2deg); }
    84% { transform: translateX(5px) rotate(2deg); }
    87% { transform: translateX(-3px) rotate(0deg); }
    91% { transform: translateX(0); }
}

@keyframes pcTada {
    0%, 100% { transform: scale(1) rotate(0deg); }
    5%, 10% { transform: scale(0.92) rotate(-5deg); }
    15%, 25%, 35% { transform: scale(1.12) rotate(6deg); }
    20%, 30% { transform: scale(1.12) rotate(-6deg); }
    40% { transform: scale(1) rotate(0deg); }
}

@keyframes pcFlip3d {
    0%, 54%, 100% { transform: perspective(600px) rotateX(0deg); }
    76% { transform: perspective(600px) rotateX(360deg); }
}

@keyframes pcSheen {
    0% { background-position: 180% 0; }
    45%, 100% { background-position: -80% 0; }
}

@keyframes pcGlowBreath {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18), 0 0 0 0 transparent;
    }
    50% {
        transform: scale(1.04);
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.22), 0 0 26px 6px var(--pc-btn-bg, var(--pc-preview-color, #25D366));
    }
}

@keyframes pcNeon {
    0%, 100% {
        box-shadow:
            0 0 8px 0 var(--pc-btn-bg, var(--pc-preview-color, #25D366)),
            inset 0 0 14px 0 var(--pc-btn-bg, var(--pc-preview-color, #25D366));
    }
    50% {
        box-shadow:
            0 0 18px 4px var(--pc-btn-bg, var(--pc-preview-color, #25D366)),
            inset 0 0 24px 0 var(--pc-btn-bg, var(--pc-preview-color, #25D366));
    }
}

@keyframes pcFade {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.55; transform: scale(0.96); }
}

/* Accessibility (WCAG 2.1): respect users who prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
    .powerchat-pulse-wave,
    .powerchat-pulse-wave .powerchat-ring,
    .powerchat-animation-target,
    .powerchat-animation-target::before {
        animation: none !important;
        transition: none !important;
    }
}
