/* Global UI animations — load, hover, scroll reveal */

:root {
    --anim-duration: 0.45s;
    --anim-ease: cubic-bezier(0.22, 1, 0.36, 1);
    --anim-stagger: 0.05s;
}

/* ── Keyframes ── */
@keyframes uiFadeUp {
    from {
        opacity: 0;
        transform: translateY(14px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes uiFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes uiScaleIn {
    from {
        opacity: 0;
        transform: scale(0.94);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes uiPopIn {
    from {
        opacity: 0;
        transform: scale(0.82);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

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

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

@keyframes uiShimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

/* ── Scroll reveal (JS adds .is-revealed) ── */
.ui-reveal {
    opacity: 0;
    transform: translateY(18px);
    transition: opacity var(--anim-duration) var(--anim-ease),
                transform var(--anim-duration) var(--anim-ease);
}

.ui-reveal.is-revealed {
    opacity: 1;
    transform: translateY(0);
}

/* ── Page load (html.ui-ready set by animations.js) ── */
html.ui-ready .navbar {
    animation: uiSlideDown 0.42s var(--anim-ease) both;
}

html.ui-ready .bottom-nav {
    animation: uiSlideUp 0.45s var(--anim-ease) 0.08s both;
}

html.ui-ready main.container > *,
html.ui-ready main.container-app > * {
    animation: uiFadeUp var(--anim-duration) var(--anim-ease) both;
}

html.ui-ready main.container > *:nth-child(1),
html.ui-ready main.container-app > *:nth-child(1) { animation-delay: 0.04s; }
html.ui-ready main.container > *:nth-child(2),
html.ui-ready main.container-app > *:nth-child(2) { animation-delay: 0.1s; }
html.ui-ready main.container > *:nth-child(3),
html.ui-ready main.container-app > *:nth-child(3) { animation-delay: 0.16s; }

html.ui-ready .page-header:not(.ui-reveal) {
    animation: uiFadeUp 0.5s var(--anim-ease) both;
}

html.ui-ready .alert {
    animation: uiScaleIn 0.38s var(--anim-ease) both;
}

html.ui-ready .stats-top-grid > *:not(.ui-reveal),
html.ui-ready .compare-grid > *:not(.ui-reveal),
html.ui-ready .stats-row > *:not(.ui-reveal),
html.ui-ready .stats-row-3 > *:not(.ui-reveal),
html.ui-ready .admin-stats-grid > *,
html.ui-ready .balance-hero:not(.ui-reveal),
html.ui-ready .balance-wallet-card:not(.ui-reveal),
html.ui-ready .category-missing-prompt,
html.ui-ready .stats-empty-hero:not(.ui-reveal) {
    animation: uiFadeUp 0.46s var(--anim-ease) both;
}

/* Stagger grids */
html.ui-ready .stats-row-3 > *:nth-child(1),
html.ui-ready .stats-row > *:nth-child(1),
html.ui-ready .admin-stats-grid > *:nth-child(1),
html.ui-ready .compare-grid > *:nth-child(1),
html.ui-ready .charts-grid > *:nth-child(1),
html.ui-ready .details-grid > *:nth-child(1) { animation-delay: 0.06s; }

html.ui-ready .stats-row-3 > *:nth-child(2),
html.ui-ready .stats-row > *:nth-child(2),
html.ui-ready .admin-stats-grid > *:nth-child(2),
html.ui-ready .compare-grid > *:nth-child(2),
html.ui-ready .charts-grid > *:nth-child(2),
html.ui-ready .details-grid > *:nth-child(2) { animation-delay: 0.12s; }

html.ui-ready .stats-row-3 > *:nth-child(3),
html.ui-ready .stats-row > *:nth-child(3),
html.ui-ready .admin-stats-grid > *:nth-child(3),
html.ui-ready .compare-grid > *:nth-child(3),
html.ui-ready .charts-grid > *:nth-child(3),
html.ui-ready .details-grid > *:nth-child(3) { animation-delay: 0.18s; }

html.ui-ready .admin-stats-grid > *:nth-child(4) { animation-delay: 0.24s; }
html.ui-ready .admin-stats-grid > *:nth-child(5) { animation-delay: 0.3s; }
html.ui-ready .admin-stats-grid > *:nth-child(6) { animation-delay: 0.36s; }

/* Stagger scroll-revealed siblings */
.ui-reveal.is-revealed:nth-child(1) { transition-delay: 0.02s; }
.ui-reveal.is-revealed:nth-child(2) { transition-delay: 0.06s; }
.ui-reveal.is-revealed:nth-child(3) { transition-delay: 0.1s; }
.ui-reveal.is-revealed:nth-child(4) { transition-delay: 0.14s; }

/* Table rows */
html.ui-ready .table tbody tr {
    animation: uiFadeUp 0.36s var(--anim-ease) both;
}

html.ui-ready .table tbody tr:nth-child(1) { animation-delay: 0.04s; }
html.ui-ready .table tbody tr:nth-child(2) { animation-delay: 0.07s; }
html.ui-ready .table tbody tr:nth-child(3) { animation-delay: 0.1s; }
html.ui-ready .table tbody tr:nth-child(4) { animation-delay: 0.13s; }
html.ui-ready .table tbody tr:nth-child(5) { animation-delay: 0.16s; }
html.ui-ready .table tbody tr:nth-child(6) { animation-delay: 0.19s; }
html.ui-ready .table tbody tr:nth-child(7) { animation-delay: 0.22s; }
html.ui-ready .table tbody tr:nth-child(8) { animation-delay: 0.25s; }
html.ui-ready .table tbody tr:nth-child(n+9) { animation-delay: 0.28s; }

/* FAB */
html.ui-ready .app-fab {
    animation: uiPopIn 0.55s cubic-bezier(0.34, 1.4, 0.64, 1) 0.35s both;
}

/* Tab / form switch */
.entry-form.is-type-switching,
.entry-card.is-type-switching {
    animation: uiFadeIn 0.28s ease;
}

/* ── Micro-interactions ── */
.btn {
    transition: transform 0.18s var(--anim-ease), box-shadow 0.22s ease, background 0.2s ease, border-color 0.2s ease;
}

.btn:active:not(:disabled) {
    transform: scale(0.97);
}

.entry-tab,
.tab-btn {
    transition: transform 0.2s var(--anim-ease), background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}

.entry-tab:active,
.tab-btn:active {
    transform: scale(0.96);
}

.nav-link,
.bottom-nav-item,
.settings-nav-item {
    transition: transform 0.2s var(--anim-ease), background 0.2s ease, color 0.2s ease;
}

.nav-link:active,
.bottom-nav-item:active {
    transform: scale(0.95);
}

.quick-template-btn,
.budget-item,
.goals-mini-item,
.admin-aside-item,
.recurring-item,
.detail-list-item {
    transition: transform 0.22s var(--anim-ease), box-shadow 0.22s ease, background 0.2s ease;
}

.quick-template-btn:hover,
.budget-item:hover,
.goals-mini-item:hover {
    transform: translateY(-2px);
}

.quick-template-btn:active {
    transform: scale(0.96);
}

.panel,
.stat-card,
.admin-stat-card,
.entry-card,
.entry-today,
.chart-panel,
.balance-wallet-card {
    transition: transform 0.25s var(--anim-ease), box-shadow 0.25s ease, border-color 0.25s ease;
}

.stat-card:hover,
.admin-stat-card:hover,
.chart-panel:hover {
    transform: translateY(-3px);
}

.table tbody tr {
    transition: background 0.18s ease, transform 0.18s ease;
}

.table tbody tr:hover {
    transform: translateX(2px);
}

.input-control,
.category-select-trigger,
select.input-control {
    transition: border-color 0.22s ease, box-shadow 0.22s ease, transform 0.18s ease;
}

.input-control:focus,
.category-select-trigger:focus {
    transform: translateY(-1px);
}

.empty-state-icon,
.category-missing-icon {
    animation: uiPopIn 0.55s cubic-bezier(0.34, 1.4, 0.64, 1) 0.15s both;
}

.pagination-nav {
    animation: uiFadeUp 0.4s var(--anim-ease) 0.2s both;
}

.app-advisor:not(.is-dismissed):not(.is-changing) {
    animation: uiFadeUp 0.5s var(--anim-ease) both;
}

/* Icon picker pulse (settings) */
.icon-preview-badge.is-pulse {
    animation: uiPopIn 0.35s ease;
}

/* Nav active indicator smooth */
.nav-link.is-active,
.bottom-nav-item.is-active {
    transition: background 0.25s ease, color 0.25s ease, transform 0.2s ease;
}

/* Category select menu */
.category-select-menu.is-floating {
    animation: uiScaleIn 0.22s var(--anim-ease) both;
    transform-origin: top center;
}

/* Toast — enhance existing */
.app-toast {
    animation: uiSlideUp 0.38s var(--anim-ease) both;
}

/* Modal panels */
.app-modal-panel,
.app-confirm-panel {
    animation: uiScaleIn 0.32s var(--anim-ease) both;
}

.app-modal-backdrop,
.app-confirm-modal .app-modal-backdrop {
    animation: uiFadeIn 0.25s ease both;
}

/* Tour tooltip */
.app-tour-tooltip {
    animation: uiPopIn 0.35s var(--anim-ease) both;
}

/* Balance hero subtle */
.balance-hero-bg {
    transition: opacity 0.4s ease, transform 0.6s ease;
}

/* Progress bars animate width */
.budget-progress-bar,
.goals-mini-bar-fill {
    transition: width 0.45s var(--anim-ease);
}

.app-advisor-progress-bar {
    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;
    }

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

    html.ui-ready .table tbody tr:hover {
        transform: none;
    }
}
