/**
 * CSS Field Systems — motion tokens + progressive enhance
 * Pairs with css-motion.js + vendored anime / auto-animate / animate.css
 */

:root {
  --cm-ease: cubic-bezier(0.16, 1, 0.3, 1);
  --cm-ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --cm-dur: 420ms;
  --cm-dur-fast: 180ms;
  --cm-dist: 14px;
}

/*
 * Progressive enhance ONLY after html.cm-enhanced.
 * Without JS, content stays fully visible (no white bricks / invisible panels).
 */
html.cm-enhanced [data-cm="reveal"]:not(.is-in):not(.cm-done),
html.cm-enhanced [data-cm="fade"]:not(.is-in):not(.cm-done),
html.cm-enhanced .cm-reveal:not(.is-in):not(.cm-done) {
  opacity: 0;
  transform: translateY(var(--cm-dist));
  transition:
    opacity var(--cm-dur) var(--cm-ease),
    transform var(--cm-dur) var(--cm-ease);
  will-change: opacity, transform;
}
[data-cm="reveal"],
[data-cm="fade"],
.cm-reveal,
[data-cm="reveal"].is-in,
[data-cm="fade"].is-in,
.cm-reveal.is-in,
[data-cm="reveal"].cm-done,
[data-cm="fade"].cm-done,
.cm-reveal.cm-done {
  /* default visible; enhanced state above only hides pending nodes */
}
html.cm-enhanced [data-cm="reveal"].is-in,
html.cm-enhanced [data-cm="fade"].is-in,
html.cm-enhanced .cm-reveal.is-in,
html.cm-enhanced [data-cm="reveal"].cm-done,
html.cm-enhanced [data-cm="fade"].cm-done,
html.cm-enhanced .cm-reveal.cm-done {
  opacity: 1;
  transform: none;
  will-change: auto;
}

/* Stagger: only hide children when enhanced and parent not yet revealed */
html.cm-enhanced [data-cm="stagger"]:not(.is-in):not(.cm-done) > * {
  opacity: 0;
  transform: translateY(10px);
  transition:
    opacity 0.4s var(--cm-ease),
    transform 0.4s var(--cm-ease);
}
[data-cm="stagger"].is-in > *,
[data-cm="stagger"].cm-done > * {
  opacity: 1;
  transform: none;
}
[data-cm="stagger"].is-in > *:nth-child(1),
[data-cm="stagger"].cm-done > *:nth-child(1) { transition-delay: 0ms; }
[data-cm="stagger"].is-in > *:nth-child(2),
[data-cm="stagger"].cm-done > *:nth-child(2) { transition-delay: 40ms; }
[data-cm="stagger"].is-in > *:nth-child(3),
[data-cm="stagger"].cm-done > *:nth-child(3) { transition-delay: 80ms; }
[data-cm="stagger"].is-in > *:nth-child(4),
[data-cm="stagger"].cm-done > *:nth-child(4) { transition-delay: 120ms; }
[data-cm="stagger"].is-in > *:nth-child(5),
[data-cm="stagger"].cm-done > *:nth-child(5) { transition-delay: 160ms; }
[data-cm="stagger"].is-in > *:nth-child(6),
[data-cm="stagger"].cm-done > *:nth-child(6) { transition-delay: 200ms; }
[data-cm="stagger"].is-in > *:nth-child(7),
[data-cm="stagger"].cm-done > *:nth-child(7) { transition-delay: 240ms; }
[data-cm="stagger"].is-in > *:nth-child(8),
[data-cm="stagger"].cm-done > *:nth-child(8) { transition-delay: 280ms; }
[data-cm="stagger"].is-in > *:nth-child(n + 9),
[data-cm="stagger"].cm-done > *:nth-child(n + 9) { transition-delay: 300ms; }

/* Micro press */
[data-cm="press"],
.cm-press {
  transition: transform var(--cm-dur-fast) var(--cm-ease);
  touch-action: manipulation;
}
[data-cm="press"]:active,
.cm-press:active {
  transform: scale(0.97);
}

/* KPI / card enter after paint */
.cm-pop-in {
  animation: cm-pop-in 0.35s var(--cm-ease) both;
}
@keyframes cm-pop-in {
  from {
    opacity: 0;
    transform: scale(0.96) translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* Chart panels gentle rise */
.cm-panel-in {
  animation: cm-panel-in 0.45s var(--cm-ease) both;
}
@keyframes cm-panel-in {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* Pulse attention (use sparingly) */
.cm-pulse-once {
  animation: cm-pulse 0.6s var(--cm-ease) 1;
}
@keyframes cm-pulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 transparent;
  }
  40% {
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--bc-brand, #0f766e) 28%, transparent);
  }
}

/* Animate.css namespace helper — already uses animate__ prefix when CSS loaded */
.cm-animate-ready .animate__animated {
  --animate-duration: 0.55s;
}

/* When JS has enhanced, mark root */
html.cm-enhanced {
  /* hook for theming */
}

/* Reduced motion: kill decorative motion */
@media (prefers-reduced-motion: reduce) {
  :root {
    --cm-dur: 1ms;
    --cm-dur-fast: 1ms;
    --cm-dist: 0px;
  }
  [data-cm="reveal"],
  [data-cm="fade"],
  [data-cm="stagger"] > *,
  .cm-reveal {
    opacity: 1 !important;
    transform: none !important;
    transition: none !important;
    animation: none !important;
  }
  .cm-pop-in,
  .cm-panel-in,
  .cm-pulse-once,
  .animate__animated {
    animation: none !important;
    opacity: 1 !important;
    transform: none !important;
  }
  [data-cm="press"]:active,
  .cm-press:active {
    transform: none;
  }
}
