/**
 * Purpose:
 *   Next-gen animation system for the AI Workspace platform.
 *   Provides staggered reveals, ripple effects, toast notifications,
 *   sortable table headers, and premium micro-animations.
 *
 * Invariants:
 *   - All animations use cubic-bezier(0.16, 1, 0.3, 1) for "snappy" feel
 *   - Stagger delays increase by 40ms per child (up to 20 items)
 *   - All interactive elements have position: relative for ripple containment
 *   - Animations respect prefers-reduced-motion
 *
 * How to undo:
 *   Revert this file to the previous version via git.
 */

/* ═══════════════════════════════════════════════════════════
 * 1. SKELETON LOADERS
 * ═══════════════════════════════════════════════════════════ */
.skeleton {
    background: linear-gradient(90deg, var(--bg-surface) 25%, var(--bg-elevated) 50%, var(--bg-surface) 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: var(--radius-sm);
    pointer-events: none;
}

@keyframes skeleton-loading {
    0% {
        background-position: 200% 0;
    }

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

/* ═══════════════════════════════════════════════════════════
 * 2. STAGGER REVEAL — Premium entrance animation
 * ═══════════════════════════════════════════════════════════ */
.stagger-reveal {
    opacity: 0;
    animation: revealUp 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes revealUp {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.98);
    }

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

/* Stagger delays — 40ms increments for up to 20 items */
.stagger-reveal:nth-child(1) {
    animation-delay: 0.04s;
}

.stagger-reveal:nth-child(2) {
    animation-delay: 0.08s;
}

.stagger-reveal:nth-child(3) {
    animation-delay: 0.12s;
}

.stagger-reveal:nth-child(4) {
    animation-delay: 0.16s;
}

.stagger-reveal:nth-child(5) {
    animation-delay: 0.20s;
}

.stagger-reveal:nth-child(6) {
    animation-delay: 0.24s;
}

.stagger-reveal:nth-child(7) {
    animation-delay: 0.28s;
}

.stagger-reveal:nth-child(8) {
    animation-delay: 0.32s;
}

.stagger-reveal:nth-child(9) {
    animation-delay: 0.36s;
}

.stagger-reveal:nth-child(10) {
    animation-delay: 0.40s;
}

.stagger-reveal:nth-child(11) {
    animation-delay: 0.44s;
}

.stagger-reveal:nth-child(12) {
    animation-delay: 0.48s;
}

.stagger-reveal:nth-child(13) {
    animation-delay: 0.52s;
}

.stagger-reveal:nth-child(14) {
    animation-delay: 0.56s;
}

.stagger-reveal:nth-child(15) {
    animation-delay: 0.60s;
}

.stagger-reveal:nth-child(16) {
    animation-delay: 0.64s;
}

.stagger-reveal:nth-child(17) {
    animation-delay: 0.68s;
}

.stagger-reveal:nth-child(18) {
    animation-delay: 0.72s;
}

.stagger-reveal:nth-child(19) {
    animation-delay: 0.76s;
}

.stagger-reveal:nth-child(20) {
    animation-delay: 0.80s;
}

/* ═══════════════════════════════════════════════════════════
 * 3. SORTABLE TABLE HEADERS
 * ═══════════════════════════════════════════════════════════ */
th.sortable {
    cursor: pointer;
    user-select: none;
    position: relative;
    padding-right: 24px !important;
    transition: color 0.2s ease;
}

th.sortable:hover {
    color: var(--primary);
}

th.sortable::after {
    content: '↕';
    position: absolute;
    right: 8px;
    opacity: 0.3;
    font-size: 0.7em;
    transition: opacity 0.2s ease;
}

th.sortable.asc::after {
    content: '↑';
    opacity: 1;
    color: var(--primary);
}

th.sortable.desc::after {
    content: '↓';
    opacity: 1;
    color: var(--primary);
}

/* ═══════════════════════════════════════════════════════════
 * 4. RIPPLE EFFECT
 * ═══════════════════════════════════════════════════════════ */
.ripple-effect {
    position: absolute;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    transform: scale(0);
    animation: ripple 0.5s cubic-bezier(0.16, 1, 0.3, 1);
    pointer-events: none;
}

@keyframes ripple {
    to {
        transform: scale(3);
        opacity: 0;
    }
}

/* Ensure relative positioning for ripple containers */
.btn,
.action-btn,
.nav-item,
.editorial-card,
.menu-card,
.btn-ghost,
.primary-btn,
.secondary-btn {
    position: relative;
    overflow: hidden;
}

/* ═══════════════════════════════════════════════════════════
 * 5. TOAST NOTIFICATIONS
 * ═══════════════════════════════════════════════════════════ */
@keyframes toastEnter {
    from {
        opacity: 0;
        transform: translateY(-20px) scale(0.9);
    }

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

@keyframes toastExit {
    from {
        opacity: 1;
        transform: translateY(0) scale(1);
    }

    to {
        opacity: 0;
        transform: translateY(-20px) scale(0.9);
    }
}

.toast-enter {
    animation: toastEnter 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.toast-exit {
    animation: toastExit 0.2s ease forwards;
}

/* ═══════════════════════════════════════════════════════════
 * 6. SPIN ANIMATION
 * ═══════════════════════════════════════════════════════════ */
@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

.spin {
    animation: spin 1s linear infinite;
}

/* ═══════════════════════════════════════════════════════════
 * 7. PREMIUM MICRO-ANIMATIONS
 * ═══════════════════════════════════════════════════════════ */

/* Subtle pulse for active status indicators */
@keyframes subtlePulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.6;
    }
}

.pulse-subtle {
    animation: subtlePulse 2s ease-in-out infinite;
}

/* Glow pulse for active elements */
@keyframes glowPulse {

    0%,
    100% {
        box-shadow: 0 0 8px rgba(var(--primary-rgb), 0.2);
    }

    50% {
        box-shadow: 0 0 16px rgba(var(--primary-rgb), 0.35);
    }
}

.glow-pulse {
    animation: glowPulse 2s ease-in-out infinite;
}

/* Slide-in from right (for drawers/panels) */
@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

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

/* Slide-in from bottom (for mobile sheets) */
@keyframes slideInUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }

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

/* Scale entrance (for modals/dialogs) */
@keyframes scaleIn {
    from {
        transform: scale(0.95);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* ═══════════════════════════════════════════════════════════
 * 8. ACCESSIBILITY — Respect reduced motion
 * ═══════════════════════════════════════════════════════════ */
@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;
    }

    .stagger-reveal {
        opacity: 1;
        transform: none;
    }
}