/* ============================================================================
   VOSTEGO MOTION PRIMITIVES — shared vocabulary + reduced-motion contract
   ----------------------------------------------------------------------------
   Load order: AFTER refined-tokens.css (whose --duration and --ease tokens it extends)
   and LAST among motion-bearing sheets, so the reduced-motion contract at the
   bottom of this file can win without needing per-file patches.

   Three things live here:
     1. The motion scale     — one duration/easing vocabulary for the whole app.
     2. Interaction classes  — the four motion "types" the UI actually performs.
     3. The motion contract  — what happens when a user asks for less motion.

   Design rule for (3): reduced motion removes MOVEMENT, not MEANING. Anything
   that communicates system state (loading, busy, progress) must keep a visible
   non-moving signal — an opacity pulse — because a frozen spinner tells the
   user nothing. Vestibular-safety guidance targets translation/rotation/scale,
   not cross-fades, so opacity remains available to us as a state channel.
   ============================================================================ */

:root {
  /* ── Duration scale ────────────────────────────────────────────────────────
     Five steps, named by intent. The raw values in the codebase clustered at
     .15/.16/.2/.25/.3/.4 — these collapse that drift onto a real scale. */
  --motion-instant: 80ms;    /* state flips that must feel un-animated  */
  --motion-quick:   160ms;   /* hover, focus, press — pointer feedback  */
  --motion-base:    240ms;   /* the default: reveals, toggles, tabs     */
  --motion-slow:    400ms;   /* entrances, modals, drawers              */
  --motion-ambient: 1400ms;  /* looping/ambient: spinners, shimmer      */

  /* ── Easing vocabulary ─────────────────────────────────────────────────────
     Four curves, each with a job. Everything else in the codebase was a
     near-duplicate of one of these. */
  --motion-ease-exit:     cubic-bezier(0.4, 0, 1, 1);      /* leaving  */
  --motion-ease-enter:    cubic-bezier(0, 0, 0.2, 1);      /* arriving */
  --motion-ease-standard: cubic-bezier(0.4, 0, 0.2, 1);    /* both ways*/
  --motion-ease-spring:   cubic-bezier(0.34, 1.56, 0.64, 1); /* playful */

  /* Distance tokens keep entrance travel consistent (was 4/8/10/14/16/20px). */
  --motion-travel-sm: 4px;
  --motion-travel-md: 8px;
  --motion-travel-lg: 16px;

  /* Master switch. The reduced-motion contract sets this to 0, which lets any
     rule written as `calc(var(--motion-base) * var(--motion-scale))` collapse
     to zero without needing its own media query. */
  --motion-scale: 1;
}

/* ── Shared keyframes ───────────────────────────────────────────────────────
   The codebase had 7 `spin`, 5 `fadeIn`, and 5 shimmer variants. These are the
   canonical set; prefer them over defining a new one. `vm-` = vostego motion. */

@keyframes vm-fade-in    { from { opacity: 0; } to { opacity: 1; } }
@keyframes vm-fade-out   { from { opacity: 1; } to { opacity: 0; } }

@keyframes vm-rise {
  from { opacity: 0; transform: translateY(var(--motion-travel-lg)); }
  to   { opacity: 1; transform: none; }
}
@keyframes vm-drop {
  from { opacity: 0; transform: translateY(calc(var(--motion-travel-sm) * -1)); }
  to   { opacity: 1; transform: none; }
}
@keyframes vm-scale-in {
  from { opacity: 0; transform: scale(0.97); }
  to   { opacity: 1; transform: none; }
}
@keyframes vm-spin      { to { transform: rotate(360deg); } }
@keyframes vm-shimmer   { from { background-position: -200% 0; } to { background-position: 200% 0; } }

/* The reduced-motion stand-in for every looping indicator. Opacity only. */
@keyframes vm-busy-pulse { 0%, 100% { opacity: 0.35; } 50% { opacity: 1; } }

/* ── Interaction types ──────────────────────────────────────────────────────
   Four classes covering the motion the UI actually needs. Compose, don't
   re-invent. Each names the *interaction*, not the effect, so the meaning
   survives a future restyle. */

/* 1. Pointer feedback — hover/press on an affordance. */
.vm-interactive {
  transition:
    background-color calc(var(--motion-quick) * var(--motion-scale)) var(--motion-ease-standard),
    border-color     calc(var(--motion-quick) * var(--motion-scale)) var(--motion-ease-standard),
    color            calc(var(--motion-quick) * var(--motion-scale)) var(--motion-ease-standard),
    box-shadow       calc(var(--motion-quick) * var(--motion-scale)) var(--motion-ease-standard),
    transform        calc(var(--motion-quick) * var(--motion-scale)) var(--motion-ease-standard);
}
.vm-lift:hover  { transform: translateY(-2px); }
.vm-press:active { transform: translateY(1px); }

/* 2. Entrance — content arriving. */
.vm-enter      { animation: vm-fade-in calc(var(--motion-base) * var(--motion-scale)) var(--motion-ease-enter) both; }
.vm-enter-rise { animation: vm-rise    calc(var(--motion-slow) * var(--motion-scale)) var(--motion-ease-enter) both; }
.vm-enter-drop { animation: vm-drop    calc(var(--motion-base) * var(--motion-scale)) var(--motion-ease-enter) both; }
.vm-enter-scale{ animation: vm-scale-in calc(var(--motion-base) * var(--motion-scale)) var(--motion-ease-enter) both; }

/* Staggered lists. Set --motion-index on children; cap the delay so a long
   list never leaves the last item waiting seconds to appear. */
.vm-stagger > * {
  animation: vm-rise calc(var(--motion-base) * var(--motion-scale)) var(--motion-ease-enter) both;
  animation-delay: calc(min(var(--motion-index, 0), 8) * 40ms * var(--motion-scale));
}

/* 3. Busy / loading — the one category reduced motion must NOT silence. */
.vm-busy { animation: vm-spin var(--motion-ambient) linear infinite; }
.vm-skeleton {
  background: linear-gradient(90deg,
    var(--paper-1, #f4f1ea) 25%,
    var(--paper-2, #ebe6dc) 37%,
    var(--paper-1, #f4f1ea) 63%);
  background-size: 400% 100%;
  animation: vm-shimmer var(--motion-ambient) ease-in-out infinite;
}

/* 4. Attention — something changed and the user should notice. Used sparingly. */
.vm-attention { animation: vm-busy-pulse 2s var(--motion-ease-standard) infinite; }

/* ============================================================================
   THE REDUCED-MOTION CONTRACT
   ----------------------------------------------------------------------------
   Applies when the OS asks for reduced motion OR the user set the in-app
   preference (`<html data-motion="reduce">`, written by motion.js).

   `:where()` keeps these selectors at zero specificity for the properties we
   want overridable, while the blanket duration reset uses !important because
   it must beat ~140 keyframe/transition declarations spread across 29 sheets.
   ============================================================================ */

@media (prefers-reduced-motion: reduce) {
  :root { --motion-scale: 0; }
}
:root[data-motion="reduce"] { --motion-scale: 0; }

/* Escape hatch: a user who explicitly opts INTO motion overrides the OS. */
:root[data-motion="full"] { --motion-scale: 1; }

@media (prefers-reduced-motion: reduce) {
  :root:not([data-motion="full"]) *,
  :root:not([data-motion="full"]) *::before,
  :root:not([data-motion="full"]) *::after {
    animation-duration: 1ms !important;
    animation-delay: 0ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
    transition-delay: 0ms !important;
    scroll-behavior: auto !important;
  }
}
:root[data-motion="reduce"] *,
:root[data-motion="reduce"] *::before,
:root[data-motion="reduce"] *::after {
  animation-duration: 1ms !important;
  animation-delay: 0ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 1ms !important;
  transition-delay: 0ms !important;
  scroll-behavior: auto !important;
}

/* ── Reveal safety ──────────────────────────────────────────────────────────
   Anything that starts hidden and is revealed by script or animation must be
   visible unconditionally — otherwise reduced motion hides content outright. */
@media (prefers-reduced-motion: reduce) {
  :root:not([data-motion="full"]) [data-reveal],
  :root:not([data-motion="full"]) .vm-enter,
  :root:not([data-motion="full"]) .vm-enter-rise,
  :root:not([data-motion="full"]) .vm-enter-drop,
  :root:not([data-motion="full"]) .vm-enter-scale,
  :root:not([data-motion="full"]) .vm-stagger > * {
    opacity: 1 !important;
    transform: none !important;
  }
}
:root[data-motion="reduce"] [data-reveal],
:root[data-motion="reduce"] .vm-enter,
:root[data-motion="reduce"] .vm-enter-rise,
:root[data-motion="reduce"] .vm-enter-drop,
:root[data-motion="reduce"] .vm-enter-scale,
:root[data-motion="reduce"] .vm-stagger > * {
  opacity: 1 !important;
  transform: none !important;
}

/* ── Loading affordance survives ────────────────────────────────────────────
   THIS IS THE POINT. The blanket rule above freezes every spinner into a
   static glyph that reads as a rendering bug. Rotation is replaced with an
   opacity pulse: no movement, but activity is still legible.
   Covers the shared primitives AND the existing brand/legacy spinners so the
   fix lands without touching every call site. */
@media (prefers-reduced-motion: reduce) {
  :root:not([data-motion="full"]) .vm-busy,
  :root:not([data-motion="full"]) .vm-skeleton,
  :root:not([data-motion="full"]) .vs-door,
  :root:not([data-motion="full"]) .vs-ring,
  :root:not([data-motion="full"]) .spinner,
  :root:not([data-motion="full"]) .spinner-sm,
  :root:not([data-motion="full"]) .spinner-lg,
  :root:not([data-motion="full"]) [aria-busy="true"] .vs-spinner {
    animation-name: vm-busy-pulse !important;
    animation-duration: 1.6s !important;
    animation-timing-function: cubic-bezier(0.4, 0, 0.2, 1) !important;
    animation-iteration-count: infinite !important;
    animation-fill-mode: none !important;
    animation-play-state: running !important;
    transform: none !important;
    opacity: 1;
  }
}
:root[data-motion="reduce"] .vm-busy,
:root[data-motion="reduce"] .vm-skeleton,
:root[data-motion="reduce"] .vs-door,
:root[data-motion="reduce"] .vs-ring,
:root[data-motion="reduce"] .spinner,
:root[data-motion="reduce"] .spinner-sm,
:root[data-motion="reduce"] .spinner-lg,
:root[data-motion="reduce"] [aria-busy="true"] .vs-spinner {
  animation-name: vm-busy-pulse !important;
  animation-duration: 1.6s !important;
  animation-timing-function: cubic-bezier(0.4, 0, 0.2, 1) !important;
  animation-iteration-count: infinite !important;
  animation-fill-mode: none !important;
  animation-play-state: running !important;
  transform: none !important;
  opacity: 1;
}

/* Stagger the door pulse so the row reads as one indicator, not three blinks.
   Scoped to reduced-motion only: in full motion the brand spinner relies on a
   NEGATIVE delay to start mid-cycle, which this would otherwise clobber. */
@media (prefers-reduced-motion: reduce) {
  :root:not([data-motion="full"]) .vs-door {
    animation-delay: calc(var(--i, 0) * 0.2s) !important;
  }
}
:root[data-motion="reduce"] .vs-door {
  animation-delay: calc(var(--i, 0) * 0.2s) !important;
}

/* ============================================================================
   CALM TOAST — variants + dismiss affordance
   ----------------------------------------------------------------------------
   The base .calm-toast / .calm-toast-stack styles live in main.css; only the
   variant colouring and the dismiss button were missing alongside the JS.
   ============================================================================ */

.calm-toast {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3, 12px);
  max-width: 380px;
  border-left: 3px solid var(--ink-3, #8a8f9c);
}

.calm-toast--success { border-left-color: var(--sage, #6da8a2); }
.calm-toast--error   { border-left-color: var(--clay, #c47b4a); }
.calm-toast--warning { border-left-color: var(--clay, #c47b4a); }
.calm-toast--info    { border-left-color: var(--brand, #5560d0); }

.calm-toast-text { flex: 1 1 auto; line-height: 1.4; }

.calm-toast-close {
  flex: 0 0 auto;
  background: none;
  border: 0;
  padding-inline: var(--space-1);
  font-size: 18px;
  line-height: 1;
  color: var(--ink-3, #8a8f9c);
  cursor: pointer;
  border-radius: var(--r-sm, 4px);
  transition: color calc(var(--motion-quick) * var(--motion-scale)) var(--motion-ease-standard);
}
.calm-toast-close:hover { color: var(--ink-0, #15171c); }
.calm-toast-close:focus-visible {
  outline: 2px solid var(--brand, #5560d0);
  outline-offset: 2px;
  color: var(--ink-0, #15171c);
}
