/* =====================================================================
   FELS E-Loan v2 — motion
   Small, fast, GPU-friendly animations (opacity + transform only).
   Everything is switched off for people who prefer reduced motion.
   ===================================================================== */

@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: scale(.92); } 60% { transform: scale(1.03); } to { opacity: 1; transform: none; } }
@keyframes grow-y { from { transform: scaleY(0); } to { transform: scaleY(1); } }
@keyframes grow-x { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shine { 0% { transform: translateX(-130%) skewX(-18deg); } 100% { transform: translateX(230%) skewX(-18deg); } }
@keyframes drift { 0% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } 100% { background-position: 0% 50%; } }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
@keyframes tab-pop { 0% { transform: scale(1); } 40% { transform: scale(1.25) translateY(-2px); } 100% { transform: scale(1); } }
@keyframes pulse-ring { 0% { box-shadow: 0 0 0 0 rgba(239, 77, 85, .5); } 100% { box-shadow: 0 0 0 8px rgba(239, 77, 85, 0); } }
@keyframes slide-in-right { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }

/* ---------- Page enter: sections rise in one after another ---------- */
.portal-main > *, .content > *, .auth-card > * { animation: rise .5s cubic-bezier(.2, .7, .2, 1) both; }
.portal-main > :nth-child(1), .content > :nth-child(1), .auth-card > :nth-child(1) { animation-delay: .02s; }
.portal-main > :nth-child(2), .content > :nth-child(2), .auth-card > :nth-child(2) { animation-delay: .08s; }
.portal-main > :nth-child(3), .content > :nth-child(3), .auth-card > :nth-child(3) { animation-delay: .14s; }
.portal-main > :nth-child(4), .content > :nth-child(4), .auth-card > :nth-child(4) { animation-delay: .20s; }
.portal-main > :nth-child(5), .content > :nth-child(5), .auth-card > :nth-child(5) { animation-delay: .26s; }
.portal-main > :nth-child(6), .content > :nth-child(6), .auth-card > :nth-child(6) { animation-delay: .32s; }
.portal-main > :nth-child(n+7), .content > :nth-child(n+7), .auth-card > :nth-child(n+7) { animation-delay: .38s; }

/* Stats, tiles and table rows stagger in */
.stats > *, .quick-grid > *, .record-grid > *, .how > li, .feature-grid > *, .card-list > li { animation: pop .45s cubic-bezier(.2, .7, .2, 1) both; }
.stats > :nth-child(1), .quick-grid > :nth-child(1), .record-grid > :nth-child(1), .how > :nth-child(1), .feature-grid > :nth-child(1), .card-list > :nth-child(1) { animation-delay: .10s; }
.stats > :nth-child(2), .quick-grid > :nth-child(2), .record-grid > :nth-child(2), .how > :nth-child(2), .feature-grid > :nth-child(2), .card-list > :nth-child(2) { animation-delay: .17s; }
.stats > :nth-child(3), .quick-grid > :nth-child(3), .record-grid > :nth-child(3), .how > :nth-child(3), .feature-grid > :nth-child(3), .card-list > :nth-child(3) { animation-delay: .24s; }
.stats > :nth-child(4), .quick-grid > :nth-child(4), .record-grid > :nth-child(4), .how > :nth-child(4), .feature-grid > :nth-child(4), .card-list > :nth-child(4) { animation-delay: .31s; }
.stats > :nth-child(n+5), .quick-grid > :nth-child(n+5), .record-grid > :nth-child(n+5), .how > :nth-child(n+5), .feature-grid > :nth-child(n+5), .card-list > :nth-child(n+5) { animation-delay: .38s; }

.table tbody tr { animation: fade .4s ease both; }
.table tbody tr:nth-child(1) { animation-delay: .05s; } .table tbody tr:nth-child(2) { animation-delay: .09s; }
.table tbody tr:nth-child(3) { animation-delay: .13s; } .table tbody tr:nth-child(4) { animation-delay: .17s; }
.table tbody tr:nth-child(5) { animation-delay: .21s; } .table tbody tr:nth-child(6) { animation-delay: .25s; }
.table tbody tr:nth-child(7) { animation-delay: .29s; } .table tbody tr:nth-child(8) { animation-delay: .33s; }
.table tbody tr:nth-child(n+9) { animation-delay: .37s; }

/* Elements revealed on scroll: <section class="reveal"> gets .in from app.js */
.reveal { opacity: 0; transform: translateY(16px); transition: opacity .5s ease, transform .5s cubic-bezier(.2, .7, .2, 1); }
.reveal.in { opacity: 1; transform: none; }

/* ---------- Interactive feedback ---------- */
.btn { transition: background .15s, border-color .15s, color .15s, transform .12s cubic-bezier(.2, .7, .2, 1), box-shadow .15s, filter .15s; }
.btn-primary:hover, .btn-success:hover, .btn-danger:hover { transform: translateY(-1px); box-shadow: 0 8px 18px -8px rgba(15, 23, 42, .45); }
.btn:active { transform: scale(.97); box-shadow: none; }
.btn.is-loading { pointer-events: none; color: transparent !important; position: relative; }
.btn.is-loading::after {
  content: ""; position: absolute; width: 18px; height: 18px; border-radius: 50%; border: 2.5px solid rgba(255, 255, 255, .35);
  border-top-color: #fff; animation: spin .7s linear infinite; left: calc(50% - 9px); top: calc(50% - 9px);
}
.btn-outline.is-loading::after, .btn-ghost.is-loading::after, .btn-soft.is-loading::after { border-color: var(--border-strong); border-top-color: var(--primary); }

.card, .quick, .panel, .record { transition: transform .18s cubic-bezier(.2, .7, .2, 1), box-shadow .18s, border-color .18s; }
a.stat:hover, .quick:hover, a.record:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.quick:active, a.stat:active { transform: scale(.98); }

.input, .select, .textarea { transition: border-color .15s, box-shadow .2s, background .15s, transform .15s; }
.input:focus, .select:focus, .textarea:focus { transform: translateY(-1px); }
.has-error .input, .has-error .textarea { animation: shake .4s ease; }
@keyframes shake { 0%, 100% { transform: none; } 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }

.nav-item, .tab, .bottom-nav a, .portal-nav a { transition: background .15s, color .15s, transform .12s; }
.nav-item:active, .tab:active { transform: scale(.97); }
.bottom-nav a .bi { transition: transform .2s; }
.bottom-nav a.active .bi { animation: tab-pop .4s cubic-bezier(.2, .7, .2, 1); }
.nav-count { animation: pulse-ring 1.6s ease-out 3; }
[data-theme-toggle] .bi { transition: transform .35s cubic-bezier(.2, .7, .2, 1); }
[data-theme-toggle]:hover .bi { transform: rotate(-20deg) scale(1.1); }
[data-theme-toggle]:active .bi { transform: rotate(180deg); }
.checkbox { transition: transform .1s; }
.checkbox:active { transform: scale(.85); }

/* ---------- Content animations ---------- */
.balance-card { position: relative; overflow: hidden; background-size: 200% 200%; animation: rise .5s cubic-bezier(.2, .7, .2, 1) both, drift 10s ease-in-out infinite; }
.balance-card::after {
  content: ""; position: absolute; top: -20%; bottom: -20%; width: 35%; left: 0; pointer-events: none;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .16), transparent); animation: shine 4.5s ease-in-out 1.2s infinite;
}
.app-hero h1 span, .hero h1 span { background-size: 200% 100%; animation: drift 6s ease-in-out infinite; }

.bar { transform-origin: bottom; animation: grow-y .8s cubic-bezier(.2, .7, .2, 1) both; }
.bar-col:nth-child(1) .bar { animation-delay: .15s; } .bar-col:nth-child(2) .bar { animation-delay: .22s; }
.bar-col:nth-child(3) .bar { animation-delay: .29s; } .bar-col:nth-child(4) .bar { animation-delay: .36s; }
.bar-col:nth-child(5) .bar { animation-delay: .43s; } .bar-col:nth-child(6) .bar { animation-delay: .50s; }
.bar-col:nth-child(n+7) .bar { animation-delay: .55s; }
.bar-value { animation: fade .5s .8s both; }

.step::before { animation: pop .4s cubic-bezier(.2, .7, .2, 1) both; }
.step.done::after { transform-origin: left; animation: grow-x .5s ease-out both; }
.step:nth-child(1)::before { animation-delay: .25s; }
.step:nth-child(2)::before { animation-delay: .55s; } .step:nth-child(2)::after { animation-delay: .35s; }
.step:nth-child(3)::before { animation-delay: .85s; } .step:nth-child(3)::after { animation-delay: .65s; }
.step:nth-child(4)::before { animation-delay: 1.15s; } .step:nth-child(4)::after { animation-delay: .95s; }

.bubble { animation: pop .35s cubic-bezier(.2, .7, .2, 1) both; }
.bubble.mine { transform-origin: bottom right; }
.bubble.theirs { transform-origin: bottom left; }
.bubble:nth-last-child(1) { animation-delay: .25s; } .bubble:nth-last-child(2) { animation-delay: .18s; }
.bubble:nth-last-child(3) { animation-delay: .11s; } .bubble:nth-last-child(4) { animation-delay: .05s; }

.empty .bi { animation: float 3s ease-in-out infinite; }
.badge-danger, .badge-warning { transition: transform .15s; }
tr:hover .badge-danger { transform: scale(1.05); }
.install-card:not([hidden]) { animation: slide-in-right .45s cubic-bezier(.2, .7, .2, 1) both; }
.flash-stack .alert { animation: slide-in-right .35s cubic-bezier(.2, .7, .2, 1); }
.avatar img { transition: transform .3s; }
.person:hover .avatar img { transform: scale(1.08); }
.brand-mark { transition: transform .3s cubic-bezier(.2, .7, .2, 1); }
.brand:hover .brand-mark { transform: rotate(-8deg) scale(1.08); }
.stat-icon { transition: transform .2s; }
a.stat:hover .stat-icon, .quick:hover .stat-icon { transform: scale(1.12) rotate(-4deg); }

/* Dialogs */
dialog.modal[open] { animation: pop .22s cubic-bezier(.2, .7, .2, 1); }
dialog.modal::backdrop { animation: fade .2s ease; }

html { scroll-behavior: smooth; }

/* ---------- Respect reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
  .reveal { opacity: 1; transform: none; }
  .balance-card::after { display: none; }
}

/* Dashboard charts */
@keyframes wipe { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }
.chart-reveal { animation: wipe 1.1s cubic-bezier(.2, .7, .2, 1) .2s both; }
.donut { animation: donut-in .8s cubic-bezier(.2, .7, .2, 1) .15s both; }
@keyframes donut-in { from { opacity: 0; transform: rotate(-180deg) scale(.85); } to { opacity: 1; transform: rotate(-90deg) scale(1); } }
.spark rect { transform-origin: bottom; animation: grow-y .7s cubic-bezier(.2, .7, .2, 1) .3s both; }
.progress-bar { animation: grow-x 1s cubic-bezier(.2, .7, .2, 1) .3s both; transform-origin: left; }
.notif[open] .notif-menu { animation: pop .18s cubic-bezier(.2, .7, .2, 1); }
.notif-dot { animation: pulse-ring 1.6s ease-out 3; }

.spark rect, .chart-reveal { transform-box: fill-box; }

/* Safety net: once entry animations have had time to play, pin everything visible
   (app.js adds .anim-settled after 2.5s, covers throttled background tabs). */
.anim-settled .portal-main > *, .anim-settled .content > *, .anim-settled .auth-card > *,
.anim-settled .stats > *, .anim-settled .quick-grid > *, .anim-settled .record-grid > *, .anim-settled .how > li,
.anim-settled .feature-grid > *, .anim-settled .card-list > li, .anim-settled .table tbody tr, .anim-settled .bubble,
.anim-settled .bar, .anim-settled .step::before, .anim-settled .step.done::after, .anim-settled .chart-reveal,
.anim-settled .donut, .anim-settled .spark rect, .anim-settled .progress-bar, .anim-settled .bar-value { animation: none !important; opacity: 1; }
.anim-settled .donut { transform: rotate(-90deg); }
