/**
 * Advanced Animations and Transitions
 * Smooth page transitions, micro-interactions, and loading states
 */

/* === Smooth Scroll Behavior === */
html {
    scroll-behavior: smooth;
}

/* === Page Transitions === */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeOut {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(-10px);
    }
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(30px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateX(-30px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideInDown {
    from {
        opacity: 0;
        transform: translateY(-30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes scaleOut {
    from {
        opacity: 1;
        transform: scale(1);
    }
    to {
        opacity: 0;
        transform: scale(0.9);
    }
}

@keyframes bounce {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-10px);
    }
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

@keyframes shake {
    0%, 100% {
        transform: translateX(0);
    }
    25% {
        transform: translateX(-5px);
    }
    75% {
        transform: translateX(5px);
    }
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

@keyframes shimmer {
    0% {
        background-position: -1000px 0;
    }
    100% {
        background-position: 1000px 0;
    }
}

@keyframes ripple {
    0% {
        transform: scale(0);
        opacity: 1;
    }
    100% {
        transform: scale(4);
        opacity: 0;
    }
}

/* === Animation Classes === */
.fade-in {
    animation: fadeIn 0.3s ease-out forwards;
}

.fade-out {
    animation: fadeOut 0.3s ease-out forwards;
}

.slide-in-right {
    animation: slideInRight 0.4s ease-out forwards;
}

.slide-in-left {
    animation: slideInLeft 0.4s ease-out forwards;
}

.slide-in-up {
    animation: slideInUp 0.4s ease-out forwards;
}

.slide-in-down {
    animation: slideInDown 0.4s ease-out forwards;
}

.scale-in {
    animation: scaleIn 0.3s ease-out forwards;
}

.scale-out {
    animation: scaleOut 0.3s ease-out forwards;
}

.bounce {
    animation: bounce 0.6s ease-in-out;
}

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

.shake {
    animation: shake 0.4s ease-in-out;
}

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

/* === Neo-Brutalist Stagger Animations === */
.stagger-fade-in > * {
    opacity: 0;
    animation: brutalSlideIn 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55) forwards;
}

@keyframes brutalSlideIn {
    0% {
        opacity: 0;
        transform: translateX(-30px) rotate(-3deg);
    }
    60% {
        transform: translateX(5px) rotate(1deg);
    }
    100% {
        opacity: 1;
        transform: translateX(0) rotate(0deg);
    }
}

.stagger-fade-in > *:nth-child(1) { animation-delay: 0.05s; }
.stagger-fade-in > *:nth-child(2) { animation-delay: 0.1s; }
.stagger-fade-in > *:nth-child(3) { animation-delay: 0.15s; }
.stagger-fade-in > *:nth-child(4) { animation-delay: 0.2s; }
.stagger-fade-in > *:nth-child(5) { animation-delay: 0.25s; }
.stagger-fade-in > *:nth-child(6) { animation-delay: 0.3s; }
.stagger-fade-in > *:nth-child(7) { animation-delay: 0.35s; }
.stagger-fade-in > *:nth-child(8) { animation-delay: 0.4s; }
.stagger-fade-in > *:nth-child(9) { animation-delay: 0.45s; }
.stagger-fade-in > *:nth-child(10) { animation-delay: 0.5s; }

/* === Enhanced Modal Animations === */
.modal {
    animation: fadeIn 0.3s ease-out;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.modal.closing {
    animation: fadeOut 0.3s ease-out forwards;
}

.modal-content {
    animation: scaleIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

.modal.closing .modal-content {
    animation: scaleOut 0.3s ease-out forwards;
}

/* === Button Micro-interactions === */
.btn {
    position: relative;
    overflow: hidden;
    transform: translateZ(0);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.btn:active::before {
    width: 300px;
    height: 300px;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px -5px rgba(0, 0, 0, 0.2);
}

.btn:active {
    transform: translateY(0);
    box-shadow: 0 5px 10px -3px rgba(0, 0, 0, 0.15);
}

.btn-icon {
    transition: all 0.2s ease;
}

.btn-icon:hover {
    transform: scale(1.1) rotate(5deg);
}

.btn-icon:active {
    transform: scale(0.95);
}

/* === Neo-Brutalist Card Hover Effects === */
.status-card,
.stat-card,
.card,
.metric-card {
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.status-card:hover,
.card:hover {
    transform: translate(-6px, -6px) rotate(-0.5deg);
    box-shadow: var(--card-shadow-hover);
}

.stat-card:hover,
.metric-card:hover {
    transform: translate(-4px, -4px) rotate(-1deg);
}

/* === Table Row Interactions === */
.table tbody tr {
    transition: background-color 0.15s ease;
}

.table tbody tr:hover {
    /* Subtle background change only, no expansion */
}

.data-table tbody tr {
    transition: background-color 0.15s ease;
    cursor: pointer;
}

.data-table tbody tr:hover {
    /* Subtle background change only, no expansion */
}

/* === Badge Hover Effects === */
.status-badge,
.platform-badge,
.badge,
.tag {
    transition: all 0.2s ease;
}

.status-badge:hover,
.platform-badge:hover,
.badge:hover {
    transform: scale(1.05);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
}

.tag:hover {
    transform: scale(1.05);
    cursor: pointer;
}

/* === Input Focus Animations === */
.form-control {
    transition: all 0.3s ease;
}

.form-control:focus {
    transform: scale(1.01);
}

/* === Loading Spinner === */
.spinner,
.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border-primary);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.spinner-sm {
    width: 20px;
    height: 20px;
    border-width: 3px;
}

.spinner-lg {
    width: 60px;
    height: 60px;
    border-width: 5px;
}

/* === Skeleton Loading States === */
.skeleton {
    background: linear-gradient(
        90deg,
        var(--bg-tertiary) 0%,
        var(--bg-secondary) 50%,
        var(--bg-tertiary) 100%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s ease-in-out infinite;
    border-radius: 4px;
    display: block;
}

.skeleton-text {
    height: 1em;
    margin-bottom: 0.5em;
}

.skeleton-text.short {
    width: 60%;
}

.skeleton-text.medium {
    width: 80%;
}

.skeleton-text.long {
    width: 100%;
}

.skeleton-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
}

.skeleton-avatar-lg {
    width: 60px;
    height: 60px;
    border-radius: 50%;
}

.skeleton-card {
    height: 200px;
    border-radius: 8px;
}

.skeleton-button {
    height: 36px;
    width: 100px;
    border-radius: 6px;
}

/* === HTMX Loading States === */
.htmx-request {
    opacity: 0.6;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.htmx-request.htmx-swapping {
    opacity: 0;
    transition: opacity 0.3s ease;
}

.htmx-settling {
    animation: fadeIn 0.3s ease-out;
}

/* === Search Highlight === */
mark,
.highlight {
    background-color: rgba(255, 235, 59, 0.5);
    color: inherit;
    padding: 0.1em 0.2em;
    border-radius: 2px;
    animation: pulse 1s ease-in-out 2;
}

[data-theme="dark"] mark,
[data-theme="dark"] .highlight {
    background-color: rgba(255, 193, 7, 0.3);
}

/* === Nav Link Active State === */
.nav-menu a {
    position: relative;
    transition: all 0.3s ease;
}

.nav-menu a::after {
    content: '';
    position: absolute;
    bottom: -4px;
    left: 0;
    width: 0;
    height: 2px;
    background: var(--primary-color);
    transition: width 0.3s ease;
}

.nav-menu a:hover::after,
.nav-menu a.active::after {
    width: 100%;
}

/* === Notification Slide In === */
.notification-enter {
    animation: slideInRight 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.notification-exit {
    animation: slideInLeft 0.4s ease-out reverse;
}

/* === Progress Bar Animation === */
@keyframes progressBar {
    from {
        width: 0%;
    }
}

.progress-bar {
    animation: progressBar 1s ease-out forwards;
}

/* === Tooltip Fade In === */
[data-tooltip]:hover::after {
    animation: fadeIn 0.2s ease-out;
}

/* === Empty State Animations === */
.empty-state {
    animation: fadeIn 0.5s ease-out;
}

.empty-state-icon {
    animation: bounce 2s ease-in-out infinite;
}

/* === Form Validation Shake === */
.form-control.error {
    animation: shake 0.4s ease-in-out;
    border-color: var(--danger-color);
}

/* === Success Checkmark Animation === */
@keyframes checkmark {
    0% {
        stroke-dashoffset: 100;
    }
    100% {
        stroke-dashoffset: 0;
    }
}

.checkmark {
    stroke-dasharray: 100;
    animation: checkmark 0.5s ease-out forwards;
}

/* === Number Counter Animation === */
@keyframes countUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.stat-value,
.metric-value {
    animation: countUp 0.6s ease-out;
}

/* === Hover Lift Effect === */
.hover-lift {
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.hover-lift:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 24px -6px rgba(0, 0, 0, 0.2);
}

/* === Glow Effect === */
@keyframes glow {
    0%, 100% {
        box-shadow: 0 0 5px var(--primary-color),
                    0 0 10px var(--primary-color);
    }
    50% {
        box-shadow: 0 0 10px var(--primary-color),
                    0 0 20px var(--primary-color),
                    0 0 30px var(--primary-color);
    }
}

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

/* === Blur Backdrop for Modals === */
.modal-backdrop-blur {
    backdrop-filter: blur(8px) saturate(180%);
    -webkit-backdrop-filter: blur(8px) saturate(180%);
    background-color: rgba(0, 0, 0, 0.6);
}

[data-theme="dark"] .modal-backdrop-blur {
    background-color: rgba(0, 0, 0, 0.8);
}

/* === Focus Ring Animation === */
@keyframes focusRing {
    0% {
        box-shadow: 0 0 0 0 var(--primary-color);
    }
    100% {
        box-shadow: 0 0 0 4px transparent;
    }
}

*:focus-visible {
    animation: focusRing 0.3s ease-out;
}

/* === Reduced Motion Support === */
@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;
    }
}

/* === Page Enter Animation === */
.page-enter {
    animation: fadeIn 0.5s ease-out;
}

/* === Sortable Header Animation === */
.sortable {
    transition: all 0.2s ease;
}

.sortable:hover {
    color: var(--primary-color);
    transform: translateY(-1px);
}

.sortable::after {
    transition: all 0.2s ease;
}

.sorted-asc::after,
.sorted-desc::after {
    animation: bounce 0.4s ease-out;
}

/* === Filter Badge Animation === */
.filter-badge {
    animation: scaleIn 0.2s ease-out;
}

.filter-badge.removing {
    animation: scaleOut 0.2s ease-out forwards;
}

/* === Notification Pulse === */
.notification-badge {
    animation: pulse 2s ease-in-out infinite;
}

/* === Theme Transition === */
html,
body {
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* === Smooth Color Transitions === */
/* Target specific interactive elements instead of global * to avoid perf degradation */
.btn,
.card,
.badge,
.tag,
.nav-menu a,
.form-control,
.theme-toggle,
.sidebar a,
.dropdown-item,
.tab,
.alert-rule-card {
    transition-property: background-color, border-color, color, fill, stroke;
    transition-duration: 0.3s;
    transition-timing-function: ease;
}

/* Exception for specific animations that should not inherit */
.no-transition,
.spinner,
.loading-spinner {
    transition: none !important;
}

/* ==========================================
   NEO-BRUTALIST SPECIAL ANIMATIONS
   ========================================== */

/* Brutal Pop Animation */
@keyframes brutalPop {
    0% {
        transform: scale(0) rotate(-12deg);
        opacity: 0;
    }
    50% {
        transform: scale(1.1) rotate(3deg);
    }
    100% {
        transform: scale(1) rotate(0deg);
        opacity: 1;
    }
}

.brutal-pop {
    animation: brutalPop 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

/* Slide and Tilt */
@keyframes slideTilt {
    0% {
        transform: translateX(-100px) rotate(-5deg);
        opacity: 0;
    }
    100% {
        transform: translateX(0) rotate(0deg);
        opacity: 1;
    }
}

.slide-tilt {
    animation: slideTilt 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

/* Shadow Expand */
@keyframes shadowExpand {
    0% {
        box-shadow: 2px 2px 0px rgba(0, 0, 0, 0.8);
    }
    100% {
        box-shadow: 8px 8px 0px rgba(0, 0, 0, 0.8);
    }
}

.shadow-expand {
    animation: shadowExpand 0.3s ease-out forwards;
}

/* Color Pulse */
@keyframes colorPulse {
    0%, 100% {
        border-color: var(--border-primary);
    }
    50% {
        border-color: var(--primary-color);
    }
}

.color-pulse {
    animation: colorPulse 2s ease-in-out infinite;
}

/* Shake on Error */
@keyframes errorShake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px) rotate(-1deg); }
    20%, 40%, 60%, 80% { transform: translateX(5px) rotate(1deg); }
}

.error-shake {
    animation: errorShake 0.5s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

/* Success Bounce */
@keyframes successBounce {
    0%, 100% {
        transform: translateY(0) scale(1);
    }
    25% {
        transform: translateY(-15px) scale(1.1);
    }
    50% {
        transform: translateY(0) scale(0.95);
    }
    75% {
        transform: translateY(-7px) scale(1.05);
    }
}

.success-bounce {
    animation: successBounce 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

/* Brutal Scale Hover */
.brutal-scale {
    transition: transform 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.brutal-scale:hover {
    transform: scale(1.05) rotate(-2deg);
}

.brutal-scale:active {
    transform: scale(0.95) rotate(1deg);
}
