/* ===========================================================================
   Bindex motion — plan/10-motion.md §3 (tokens) + §4 (19-animation inventory)
   ---------------------------------------------------------------------------
   Consumes the motion tokens defined ONCE in web/assets/theme.css §2.4
   (--dur-fast/base/slow/exit, --theme-dur, --ease-out, --ease-in-out,
   --stagger). They are NEVER redefined here; every value is var(...).

   Class A = transform + opacity only. Class B = the four enumerated colour
   swaps (theme crossfade, focus overlay, PAN validation, hover overlay). No
   layout geometry is ever animated (plan/10 §1 prohibited-property list), so
   CLS = 0 by construction; overlays are out of flow and pre-rendered.

   Progressive enhancement: the SSR default is the final visible state. JS
   (motion.js) adds .is-in to [data-reveal] via IntersectionObserver and arms
   load entrances; with no JS nothing is hidden or animated. All 19 animations
   are neutralised under prefers-reduced-motion: reduce (§2, essential = none).
   60fps: CSS keyframes + native WAAPI/rAF only, zero JS animation libraries.
   Token-only colours -> all 5 themes; no fixed text sizing -> ru-RU / zh-CN
   strings never clipped; no transform on PAN validation, colour change only.
   =========================================================================== */

/* ---- §4 keyframes (transform / opacity only) ----------------------------- */
@keyframes m-enter {
  from { opacity: 0; transform: translateY(var(--m-y, 0px)) scale(var(--m-s, 1)); }
  to   { opacity: 1; transform: none; }
}
@keyframes m-scale-in {
  from { opacity: 0; transform: scale(var(--m-s, .96)); }
  to   { opacity: 1; transform: none; }
}
@keyframes m-pop {
  from { opacity: 0; transform: scale(var(--m-s, .9)); }
  to   { opacity: 1; transform: none; }
}
@keyframes m-drawer-in {
  from { transform: translateY(100%); }
  to   { transform: none; }
}
@keyframes m-slide-in {          /* toast in */
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: none; }
}
@keyframes m-slide-out {         /* toast / modal out */
  from { opacity: 1; transform: none; }
  to   { opacity: 0; transform: translateY(12px); }
}
@keyframes m-shimmer {           /* §4 row 4 — the ONLY infinite loop (300ms) */
  0%, 100% { opacity: .55; }
  50%      { opacity: 1; }
}

/* ---- Generic, parameterised entrance trigger (§4.1) --------------------- */
/* JS adds .is-in (IntersectionObserver) / .is-out (dismiss). Any [data-reveal]
   value works with defaults; the 19 rules below customise --m-* variables.
   No .is-in (no JS) => element is already at its SSR-visible final state. */
[data-reveal].is-in {
  animation: var(--m-anim, m-enter) var(--m-dur, var(--dur-base)) var(--m-ease, var(--ease-out)) both;
}
[data-reveal].is-out, [data-animate].is-out {
  animation: m-slide-out var(--dur-exit) var(--ease-in-out) both;
}
/* Hero entrance runs on first paint; JS only manages will-change hygiene. */
[data-animate="hero"], .anim-hero {
  animation: m-enter var(--dur-slow) var(--ease-out) both;
}

/* ---- §4 inventory (19 rules). Each has a .anim-<slug> class AND a data-*
   selector; durations/easings are tokens. ---------------------------------- */
/* 1  hero entrance (translateY 12px) */
.anim-hero, [data-animate="hero"] { --m-y: 12px; --m-dur: var(--dur-slow); }
/* 2  input focus glow — opacity crossfade of a pre-rendered ::after overlay;
      the solid --accent focus ring stays instant (theme.css :focus-visible). */
.anim-focus-glow, [data-animate="focus-glow"] { position: relative; }
.anim-focus-glow::after, [data-animate="focus-glow"]::after {
  content: ""; position: absolute; inset: 0; pointer-events: none; opacity: 0;
  background: var(--accent-soft);
  transition: opacity var(--dur-fast) var(--ease-out);
}
.anim-focus-glow:focus-within::after, [data-animate="focus-glow"]:focus-within::after { opacity: 1; }
/* 3  lookup result reveal */
.anim-result, [data-reveal="result"] { --m-y: 8px; }
/* 4  skeleton shimmer (opacity pulse, 3 bands staggered by --stagger) */
.anim-shimmer > *, .skeleton-shimmer > *, [data-animate="shimmer"] > * {
  animation: m-shimmer 300ms var(--ease-in-out) infinite;
}
.anim-shimmer > :nth-child(2), .skeleton-shimmer > :nth-child(2), [data-animate="shimmer"] > :nth-child(2) { animation-delay: var(--stagger); }
.anim-shimmer > :nth-child(3), .skeleton-shimmer > :nth-child(3), [data-animate="shimmer"] > :nth-child(3) { animation-delay: calc(var(--stagger) * 2); }
/* 5  stat counter count-up — no CSS property animates; tabular numerals hold width */
.anim-count-up, [data-count-up] { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
/* 6  chart bar / donut draw-in */
.anim-chart, [data-reveal="chart"], .chart-bar, .chart-donut {
  --m-anim: m-scale-in; --m-s: .96; transform-origin: 0 50%;
}
/* 7  theme switch crossfade — class B, colour-only (no transform/shadow) */
.anim-theme-crossfade, [data-animate="theme-crossfade"] {
  transition: background-color var(--theme-dur) var(--ease-in-out),
              color var(--theme-dur) var(--ease-in-out),
              border-color var(--theme-dur) var(--ease-in-out);
}
/* 8  dropdown / popover scale-in */
.anim-popover, [data-reveal="popover"], .theme-popover {
  --m-anim: m-scale-in; --m-s: .96; --m-dur: var(--dur-exit); transform-origin: 100% 0;
}
/* 9  mobile filter drawer slide */
.anim-drawer, [data-reveal="drawer"], .theme-sheet { --m-anim: m-drawer-in; --m-dur: var(--dur-slow); }
/* 10 copy success checkmark */
.anim-copy-check, [data-reveal="copy-check"] { --m-anim: m-pop; --m-s: .8; }
/* 11 toast slide-in / out */
.anim-toast, [data-reveal="toast"], .toast { --m-anim: m-slide-in; }
/* 12 table row hover — opacity of a pre-rendered ::before highlight */
.anim-row-hover, [data-animate="row-hover"] { position: relative; }
.anim-row-hover::before, [data-animate="row-hover"]::before {
  content: ""; position: absolute; inset: 0; pointer-events: none; opacity: 0;
  background: var(--accent-soft);
  transition: opacity var(--dur-fast) var(--ease-in-out);
}
.anim-row-hover:hover::before, .anim-row-hover:focus-within::before,
[data-animate="row-hover"]:hover::before, [data-animate="row-hover"]:focus-within::before { opacity: 1; }
/* 13 button press feedback (replaces theme.css:231 filter transition) */
.anim-btn-press, [data-animate="btn-press"] { transition: transform var(--dur-fast) var(--ease-out); }
.anim-btn-press:active, [data-animate="btn-press"]:active { transform: scale(.98); }
/* 14 code tab switch */
.anim-code-tab, [data-reveal="code-tab"] { --m-y: 4px; --m-dur: var(--dur-exit); }
/* 15 modal open / close */
.anim-modal, [data-reveal="modal"], .modal { --m-anim: m-scale-in; --m-s: .97; }
/* 16 billing success state */
.anim-billing-success, [data-reveal="billing-success"] { --m-anim: m-scale-in; --m-s: .96; --m-dur: var(--dur-slow); }
/* 17 directory card hover accent — overlay opacity + 2px lift */
.anim-dir-card-hover, [data-animate="dir-card-hover"] { position: relative; transition: transform var(--dur-exit) var(--ease-in-out); }
.anim-dir-card-hover::after, [data-animate="dir-card-hover"]::after {
  content: ""; position: absolute; inset: 0; pointer-events: none; opacity: 0;
  background: var(--accent-soft);
  transition: opacity var(--dur-exit) var(--ease-in-out);
}
.anim-dir-card-hover:hover, [data-animate="dir-card-hover"]:hover { transform: translateY(-2px); }
.anim-dir-card-hover:hover::after, [data-animate="dir-card-hover"]:hover::after { opacity: 1; }
/* 18 provider result reveal */
.anim-provider, [data-reveal="provider"] { --m-y: 6px; }
/* 19 risk signal badge entrance */
.anim-risk-badge, [data-reveal="risk-badge"] { --m-anim: m-pop; --m-s: .9; --m-dur: var(--dur-exit); }

/* ---- §1.3 / §4.3 PAN-input validation — colour-only, NO transform ------- */
[data-invalid="true"], .anim-invalid { border-color: var(--danger); color: var(--danger); }
@media (prefers-reduced-motion: no-preference) {
  [data-invalid="true"], .anim-invalid {
    transition: border-color var(--dur-fast) var(--ease-in-out),
                color var(--dur-fast) var(--ease-in-out);
  }
  html { scroll-behavior: smooth; }
}

/* ---- §2 reduced motion — essential set = NONE; neutralise ALL 19 -------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0s !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0s !important;
    scroll-behavior: auto !important;
  }
  html { scroll-behavior: auto; }
  .anim-hero, .anim-focus-glow, .anim-result, .anim-shimmer, .anim-count-up,
  .anim-chart, .anim-theme-crossfade, .anim-popover, .anim-drawer,
  .anim-copy-check, .anim-toast, .anim-row-hover, .anim-btn-press,
  .anim-code-tab, .anim-modal, .anim-billing-success, .anim-dir-card-hover,
  .anim-provider, .anim-risk-badge,
  [data-animate], [data-reveal], .skeleton-shimmer > *, .chart-bar,
  .chart-donut, .toast, .theme-popover, .theme-sheet, .modal,
  .result-panel, [data-invalid] {
    animation: none !important;
    transition: none !important;
    transform: none !important;
    opacity: 1 !important;
  }
}
