/* ==========================================================================
   Motion layer. Everything here is decoration: content is visible and usable
   without it, and the reduced-motion block at the bottom switches it all off.
   Animations use `backwards` fill so the resting state is always the normal,
   fully visible style: if an animation never runs, nothing is left hidden.
   ========================================================================== */

@keyframes rise     { from { opacity: 0; transform: translateY(14px); } }
@keyframes fade-in  { from { opacity: 0; } }
@keyframes pop-in   { from { opacity: 0; transform: scale(0.94) translateY(8px); } }
@keyframes slide-in { from { opacity: 0; transform: translateX(24px); } }
@keyframes row-in   { from { opacity: 0; transform: translateY(-8px); max-height: 0; } to { max-height: 140px; } }
@keyframes row-out  { to { opacity: 0; transform: translateX(16px) scale(0.98); } }
@keyframes shake    { 20%, 60% { transform: translateX(-5px); } 40%, 80% { transform: translateX(5px); } }
@keyframes spin     { to { transform: rotate(360deg); } }
@keyframes tick     { 0% { background-color: rgba(174, 203, 6, 0.45); } 100% { background-color: transparent; } }
@keyframes swap     { from { opacity: 0; transform: translateY(-6px) rotateX(70deg); } }
@keyframes pie-draw { from { stroke-dasharray: 0 100; } to { stroke-dasharray: var(--dash) calc(100 - var(--dash)); } }
@keyframes float    { 50% { transform: translateY(-6px); } }
@keyframes pulse    { 50% { box-shadow: 0 0 0 5px rgba(230, 126, 34, 0); } 0% { box-shadow: 0 0 0 0 rgba(230, 126, 34, 0.5); } }
@keyframes toast-bar { to { transform: scaleX(0); } }

/* Page entrance: header, tiles, cards and notices rise in sequence. */
.main > * { animation: rise 0.55s var(--ease-out) backwards; }
.main > :nth-child(1) { animation-delay: 0s; }
.main > :nth-child(2) { animation-delay: 0.06s; }
.main > :nth-child(3) { animation-delay: 0.12s; }
.main > :nth-child(4) { animation-delay: 0.18s; }
.main > :nth-child(5) { animation-delay: 0.24s; }
.main > :nth-child(n+6) { animation-delay: 0.3s; }
.stats > .stat { animation: rise 0.55s var(--ease-out) backwards; }
.stats > .stat:nth-child(1) { animation-delay: 0.1s; }
.stats > .stat:nth-child(2) { animation-delay: 0.17s; }
.stats > .stat:nth-child(3) { animation-delay: 0.24s; }
.stats > .stat:nth-child(4) { animation-delay: 0.31s; }
.table:not(.table--editable) tbody tr:nth-child(-n+12) { animation: fade-in 0.4s ease backwards; }
.table:not(.table--editable) tbody tr:nth-child(1) { animation-delay: 0.20s; }
.table:not(.table--editable) tbody tr:nth-child(2) { animation-delay: 0.25s; }
.table:not(.table--editable) tbody tr:nth-child(3) { animation-delay: 0.30s; }
.table:not(.table--editable) tbody tr:nth-child(4) { animation-delay: 0.35s; }
.table:not(.table--editable) tbody tr:nth-child(5) { animation-delay: 0.40s; }
.table:not(.table--editable) tbody tr:nth-child(6) { animation-delay: 0.45s; }
.table:not(.table--editable) tbody tr:nth-child(n+7) { animation-delay: 0.5s; }
.pie__legend tbody tr { animation-delay: 0.5s; }

/* Pie slices draw in clockwise, one after another. */
.pie__slice circle { animation: pie-draw 0.9s var(--ease-out) backwards; animation-delay: calc(0.25s + var(--k, 0) * 0.14s); }

/* Mark / brand / empty state */
.brand__mark { animation: pop-in 0.6s var(--ease-spring) backwards; }
.letterhead__logo { animation: pop-in 0.7s var(--ease-spring) 0.2s backwards; }
.empty__art { animation: float 4s ease-in-out infinite; }

/* Toasts, dialog, progress */
.toast { animation: slide-in 0.35s var(--ease-out) backwards; }
.toast.is-out { animation: row-out 0.22s ease forwards; }
.toast__bar { animation: toast-bar var(--ms, 5s) linear forwards; }
.toast:hover .toast__bar { animation-play-state: paused; }
.dialog[open] { animation: pop-in 0.26s var(--ease-spring); }
.dialog[open]::backdrop { animation: fade-in 0.2s ease; }
.sheet[open] { animation: pop-in 0.22s var(--ease-out); }
.sheet[open]::backdrop { animation: fade-in 0.2s ease; }
.dialog.is-closing { animation: row-out 0.16s ease forwards; }
.progress.is-done i { width: 100%; opacity: 0; transition: width 0.25s ease, opacity 0.4s ease 0.2s; }

/* Forms and editor rows */
.item-row.row-enter { animation: row-in 0.3s var(--ease-out); }
.item-row.row-leave { animation: row-out 0.2s ease forwards; }
.shake { animation: shake 0.4s ease; }
.tick { animation: tick 0.8s ease; }
.cur.swap { animation: swap 0.3s var(--ease-out); }
.is-dirty .form-bar__dot { animation: pulse 1.6s ease infinite; }
.icon.spin { animation: spin 0.7s linear infinite; }
.field-error { animation: rise 0.25s var(--ease-out); }

/* Cross-page fade (supported browsers only; others navigate normally). */
@view-transition { navigation: auto; }
::view-transition-old(root) { animation: fade-in 0.15s ease reverse both; }
::view-transition-new(root) { animation: fade-in 0.2s ease both; }

/* Reduced motion: no movement, no waiting. State changes still happen. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-delay: 0s !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    transition-delay: 0s !important;
    scroll-behavior: auto !important;
  }
  .empty__art { animation: none; }
  @view-transition { navigation: none; }
}
