/* ==========================================================================
   StoneSync 360 · motion system (static/core/css/motion.css)
   Every animation uses a --dur-* token, so prefers-reduced-motion AND the
   in-app switch (html[data-motion="reduce"]) collapse them to 0; the hard
   stop at the bottom also kills infinite loops (live dots, shimmer, belts).
   ========================================================================== */

/* ---------- Keyframes ------------------------------------------------------ */
@keyframes ss-rise { from { opacity: 0; transform: translateY(12px) scale(.995); } to { opacity: 1; transform: none; } }
@keyframes ss-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes ss-scale-in { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: none; } }
@keyframes ss-slide-in { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }
@keyframes ss-pop-in { from { opacity: 0; transform: translateY(-6px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes ss-swap-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes ss-row-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@keyframes ss-row-flash { 0% { background-color: var(--c-accent-soft); box-shadow: inset 3px 0 0 var(--c-accent); } 70% { background-color: var(--c-accent-soft); } 100% { background-color: transparent; box-shadow: inset 3px 0 0 transparent; } }
@keyframes ss-flash-text { 0% { color: var(--c-accent-ink); } 100% { color: inherit; } }
@keyframes ss-toast-in { from { opacity: 0; transform: translateY(16px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes ss-toast-out { to { opacity: 0; transform: translateX(24px); } }
@keyframes ss-toast-bar { from { transform: scaleX(1); } to { transform: scaleX(0); } }
@keyframes ss-chat-in { from { opacity: 0; transform: translateY(12px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes ss-pulse { 0% { transform: scale(1); opacity: .7; } 70%, 100% { transform: scale(3); opacity: 0; } }
@keyframes ss-blink { 50% { opacity: .2; } }
@keyframes ss-shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }
@keyframes ss-spin { to { transform: rotate(360deg); } }
@keyframes ss-bump { 0% { transform: scale(1); } 40% { transform: scale(1.35); } 100% { transform: scale(1); } }
@keyframes ss-ring { 0%, 100% { transform: rotate(0); } 15% { transform: rotate(14deg); } 30% { transform: rotate(-12deg); } 45% { transform: rotate(8deg); } 60% { transform: rotate(-5deg); } 75% { transform: rotate(2deg); } }
@keyframes ss-auto-fill { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--c-accent) 55%, transparent); } 100% { box-shadow: 0 0 0 10px color-mix(in srgb, var(--c-accent) 0%, transparent); } }
@keyframes ss-draw { from { stroke-dashoffset: 1; } to { stroke-dashoffset: 0; } }
@keyframes ss-reveal { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }
@keyframes ss-grow-x { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes ss-ripple { to { transform: scale(2.6); opacity: 0; } }
@keyframes ss-typing { 0%, 60%, 100% { transform: translateY(0); opacity: .3; } 30% { transform: translateY(-5px); opacity: 1; } }
@keyframes ss-mic { 0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--c-danger) 35%, transparent); } 50% { box-shadow: 0 0 0 8px transparent; } }
@keyframes ss-hazard-move { from { background-position: 0 0; } to { background-position: 28.28px 0; } }
@keyframes ss-shake { 10%, 90% { transform: translateX(-1px); } 20%, 80% { transform: translateX(2px); } 30%, 50%, 70% { transform: translateX(-4px); } 40%, 60% { transform: translateX(4px); } }
/* login illustration */
@keyframes ss-belt { to { stroke-dashoffset: -12; } }
@keyframes ss-rock { 0% { transform: translate(0, 0); opacity: 0; } 8% { opacity: 1; } 92% { opacity: 1; } 100% { transform: translate(190px, -62px); opacity: 0; } }
@keyframes ss-jaw { from { transform: rotate(-3deg); } to { transform: rotate(3deg); } }
@keyframes ss-truck { 0% { transform: translateX(-160px); } 40%, 55% { transform: translateX(120px); } 100% { transform: translateX(760px); } }
@keyframes ss-dust { 0% { opacity: 0; transform: translate(0, 0) scale(.6); } 30% { opacity: .55; } 100% { opacity: 0; transform: translate(-18px, -26px) scale(1.6); } }

/* ---------- Page enter (legacy classes + [data-animate]) ------------------ */
.animate-fadeInUp, .card-stagger, [data-animate]:not([data-animate="children"]):not([data-animate=""]), [data-animate="children"] > *, [data-animate=""] > * {
  animation: ss-rise var(--dur-slow) var(--ease-emphasized) both;
  animation-delay: calc(var(--i, 0) * var(--stagger));
}
[data-animate="fade"] { animation-name: ss-fade; }
[data-animate="scale"] { animation-name: ss-scale-in; }
[data-animate="slide"] { animation-name: ss-slide-in; }
.page-header { animation: ss-rise var(--dur-slow) var(--ease-emphasized) both; }
.animate-delay-1 { --i: 1; } .animate-delay-2 { --i: 2; } .animate-delay-3 { --i: 3; } .animate-delay-4 { --i: 4; }
.stagger > * { animation: ss-rise var(--dur-slow) var(--ease-emphasized) both; animation-delay: calc(var(--i, 0) * var(--stagger)); }

/* sparkline + gauges draw in */
.spark .line { stroke-dasharray: 1; stroke-dashoffset: 0; animation: ss-draw 1.1s var(--ease-emphasized) .15s both; }
.spark .area { animation: ss-fade var(--dur-slower) var(--ease-standard) .45s both; }
.kpi .spark, .kpi-card .spark { animation: ss-reveal 1.2s var(--ease-emphasized) .25s both; }
.kpi .spark .line { animation: none; }
.grow-x { transform-origin: left; animation: ss-grow-x 1s var(--ease-emphasized) both; }

/* count-up: settle flash on change */
.flash, [data-countup].is-changed { animation: ss-flash-text 700ms var(--ease-standard); }

/* ---------- HTMX: swap fade/slide + new-row highlight ---------------------- */
.ss-swap-in { animation: ss-swap-in var(--dur-slow) var(--ease-emphasized) both; animation-delay: calc(var(--i, 0) * 18ms); }
tr.ss-swap-in { animation-name: ss-row-in; }
.ss-row-new, .row-new, tr.is-new, li.is-new, [data-new] { animation: ss-row-flash 2.4s var(--ease-standard) both; }
tr.ss-row-new > td:first-child, tr.is-new > td:first-child { box-shadow: inset 3px 0 0 var(--c-accent); }
.htmx-request.htmx-indicator, .htmx-request .htmx-indicator { opacity: 1; }
.htmx-indicator { transition: opacity var(--dur-base) var(--ease-standard); }
.htmx-swapping { opacity: .55; transition: opacity var(--dur-fast) var(--ease-standard); }
.htmx-settling { transition: opacity var(--dur-base) var(--ease-standard); }
[hx-target].htmx-request, .htmx-request[aria-busy] { cursor: progress; }
.is-invalid-shake { animation: ss-shake .4s var(--ease-standard); }

/* ---------- Press micro-interactions ---------------------------------------- */
.pressable, .chip, .icon-btn, .btn-header, .seg > button, .palette-item, .menu-item { -webkit-tap-highlight-color: transparent; }
.pressable { transition: transform var(--dur-fast) var(--ease-standard); }
.pressable:active, .is-pressed { transform: scale(.97); }

/* ---------- View Transitions ------------------------------------------------- */
@media (prefers-reduced-motion: no-preference) {
  @view-transition { navigation: auto; }
}
::view-transition-old(root), ::view-transition-new(root) { animation-duration: var(--dur-base); animation-timing-function: var(--ease-standard); }
.sidebar { view-transition-name: ss-sidebar; }
.topbar { view-transition-name: ss-topbar; }
::view-transition-group(ss-sidebar), ::view-transition-group(ss-topbar) { animation: none; }
::view-transition-old(ss-sidebar), ::view-transition-new(ss-sidebar), ::view-transition-old(ss-topbar), ::view-transition-new(ss-topbar) { animation: none; mix-blend-mode: normal; }
html.ss-theme-vt::view-transition-old(root) { animation: none; }
html.ss-theme-vt::view-transition-new(root) { animation: ss-theme-reveal var(--dur-slower) var(--ease-emphasized); }
@keyframes ss-theme-reveal { from { clip-path: circle(0 at var(--vt-x, 90%) var(--vt-y, 0%)); } to { clip-path: circle(150vmax at var(--vt-x, 90%) var(--vt-y, 0%)); } }

/* ---------- Hard stop: reduced motion (OS or in-app switch) --------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0ms !important; animation-delay: 0ms !important; animation-iteration-count: 1 !important; transition-duration: 0ms !important; transition-delay: 0ms !important; scroll-behavior: auto !important; }
  .live-dot::after, .skeleton, .sk, .qa-belt, .qa-rock-move, .qa-jaw, .qa-wheel, .qa-truck, .qa-dust, .qa-light, .hazard-stripe.animated, .pill.live::before { animation: none !important; }
  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
}
html[data-motion="reduce"] *, html[data-motion="reduce"] *::before, html[data-motion="reduce"] *::after {
  animation-duration: 0ms !important; animation-delay: 0ms !important; animation-iteration-count: 1 !important;
  transition-duration: 0ms !important; transition-delay: 0ms !important; scroll-behavior: auto !important;
}
html[data-motion="reduce"] .skeleton, html[data-motion="reduce"] .sk, html[data-motion="reduce"] .qa-belt, html[data-motion="reduce"] .qa-rock-move,
html[data-motion="reduce"] .qa-jaw, html[data-motion="reduce"] .qa-wheel, html[data-motion="reduce"] .qa-truck, html[data-motion="reduce"] .qa-dust,
html[data-motion="reduce"] .qa-light, html[data-motion="reduce"] .hazard-stripe.animated { animation: none !important; }
html[data-motion="reduce"] .live-dot::after, html[data-motion="reduce"] .pill.live::before { animation: none !important; }
html[data-motion="reduce"]::view-transition-group(*), html[data-motion="reduce"]::view-transition-old(*), html[data-motion="reduce"]::view-transition-new(*) { animation: none !important; }

/* Polled HTMX refreshes (not user-triggered) never replay entrance animations */
.ss-quiet.animate-fadeInUp, .ss-quiet .animate-fadeInUp, .ss-quiet.card-stagger, .ss-quiet .card-stagger,
.ss-quiet [data-animate], .ss-quiet[data-animate], .ss-quiet [data-animate] > *, .ss-quiet .page-header,
.ss-quiet .spark, .ss-quiet .spark .line, .ss-quiet .spark .area, .ss-quiet .grow-x, .ss-quiet .stagger > * { animation: none !important; }

/* rings and gauges fill from empty (CSS reads the server-rendered target offset) */
@keyframes ss-dash-in { from { stroke-dashoffset: var(--dash-from); } }
.ring .val, .gauge .g-val { animation: ss-dash-in 1.2s var(--ease-emphasized) .15s both; }
.ss-quiet .ring .val, .ss-quiet .gauge .g-val { animation: none !important; }
