/**
 * Animations & Transitions — Carbon Design System
 * Clean, subtle motion for a data-focused dashboard.
 */

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

/* === Core Keyframes === */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

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

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

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

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

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

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

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

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

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

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

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

@keyframes progressBar {
    from { width: 0%; }
}

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

/* === Animation Utility 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.35s ease-out forwards; }
.slide-in-left  { animation: slideInLeft 0.35s ease-out forwards; }
.slide-in-up    { animation: slideInUp 0.35s ease-out forwards; }
.slide-in-down  { animation: slideInDown 0.35s ease-out forwards; }
.scale-in     { animation: scaleIn 0.25s ease-out forwards; }
.scale-out    { animation: scaleOut 0.25s ease-out forwards; }
.spin         { animation: spin 1s linear infinite; }
.pulse        { animation: pulse 2s ease-in-out infinite; }

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

/* === Stagger Children === */
.stagger-fade-in > * {
    opacity: 0;
    animation: slideInUp 0.4s ease-out forwards;
}
.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; }

/* === Modal Animations === */
.modal {
    animation: fadeIn 0.25s ease-out;
}

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

.modal-content {
    animation: scaleIn 0.25s ease-out;
}

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

/* === Metric Value Entry === */
.stat-value,
.metric-value {
    animation: countUp 0.5s ease-out;
}

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

.htmx-request.htmx-swapping {
    opacity: 0;
}

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

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

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

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

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

/* === Hover Lift Effect === */
.hover-lift {
    transition: transform var(--duration-normal) ease, box-shadow var(--duration-normal) ease;
}

.hover-lift:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

/* === Notification Animations === */
.notification-enter {
    animation: slideInRight 0.3s ease-out;
}

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

/* === Progress Bar === */
.progress-bar {
    animation: progressBar 1s ease-out forwards;
}

/* === Search Highlight === */
mark,
.highlight {
    background-color: rgba(20, 184, 166, 0.25);
    color: inherit;
    padding: 0.1em 0.2em;
    border-radius: 2px;
}

[data-theme="light"] mark,
[data-theme="light"] .highlight {
    background-color: rgba(13, 148, 136, 0.2);
}

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

.btn,
.card,
.badge,
.tag,
.nav-menu a,
.form-control,
.theme-toggle,
.tab {
    transition-property: background-color, border-color, color, box-shadow, transform;
    transition-duration: 0.2s;
    transition-timing-function: ease;
}

/* No transition on spinners/loaders */
.no-transition,
.spinner,
.loading-spinner {
    transition: none !important;
}

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