/* ==========================================================================
   motion.css — the BFA UI v2 motions on this tool's BFA UI v1 screens (with assets/motion.js).
   Nothing here changes layout or wording: it adds movement only, and every rule sits inside
   prefers-reduced-motion: no-preference — with reduced motion the screens are exactly as before.
     1 segmented pill and tab ink that slide · 2 sidebar mark that slides (from the last screen too)
     3 checkbox pop + tick, radio dot, switch stretch · 4 toasts as a stacked deck that unfolds
     5 numbers that count up · 6 rows that glide when sorted or filtered · 7 click-to-copy ids
     8 screens that rise in, panels that open, things that arrive
   ========================================================================== */
:root {
  --m-dur-2: 180ms;     /* fades, label colours */
  --m-dur-3: 240ms;     /* tick draw, small moves */
  --m-dur-4: 420ms;     /* the pill, the ink, the deck */
  --m-ease: cubic-bezier(.2, .8, .2, 1);
  --m-ease-pop: cubic-bezier(.34, 1.56, .64, 1);   /* the tick and the radio dot only */
}

@media (prefers-reduced-motion: no-preference) {

  /* ---------- 1. Segmented pill and tabs: one indicator glides to the chosen item (motion.js places it) ---------- */
  .m-glide { position: relative; isolation: isolate; }
  /* measured in px by motion.js (offsetLeft / offsetTop), so it is placed physically and moved with transform */
  .m-ind {
    position: absolute; z-index: -1; top: 0; left: 0; pointer-events: none; border-radius: var(--radius-sm);
    transition: transform var(--m-dur-4) var(--m-ease), width var(--m-dur-4) var(--m-ease), height var(--m-dur-4) var(--m-ease), opacity var(--m-dur-2);
  }
  .m-ind.m-still { transition: none; }
  /* segmented: the white card the chosen item sits on */
  .segmented.m-glide .m-ind { background: var(--bg); box-shadow: var(--shadow-xs), 0 0 0 1px var(--line); }
  .segmented.m-glide > .segmented__item { position: relative; transition: color var(--m-dur-3) var(--m-ease); }
  .segmented.m-glide > .segmented__item:is([aria-pressed="true"], [aria-selected="true"], .is-active) { background: transparent; box-shadow: none; }
  .segmented.m-glide > .segmented__item:focus-visible { box-shadow: var(--focus-ring); }
  /* pill tabs: the ink pill */
  .tabs:not(.tabs--underline).m-glide .m-ind { background: var(--bg-inverse); }
  .tabs:not(.tabs--underline).m-glide > .tab:is([aria-selected="true"], .is-active, [aria-current="page"]) { background: transparent; transition: color var(--m-dur-3) var(--m-ease) 60ms; }
  /* underline tabs: the 2px ink line */
  .tabs--underline.m-glide .m-ind { background: var(--text); border-radius: 2px 2px 0 0; }
  .tabs--underline.m-glide > .tab::after { display: none; }

  /* ---------- 2. Sidebar: a 3px ink mark slides to the current screen ---------- */
  .sidebar__scroll, .sidebar__footer { position: relative; }
  .m-nav-ind {
    position: absolute; inset-inline-start: 0; inline-size: 3px; block-size: 18px; border-radius: 0 3px 3px 0;
    background: var(--text); pointer-events: none;
    transition: inset-block-start var(--m-dur-4) var(--m-ease), opacity var(--m-dur-2);
  }
  [dir="rtl"] .m-nav-ind { border-radius: 3px 0 0 3px; }
  .m-nav-ind.m-still { transition: none; }
  .nav-item { transition: background var(--dur-1) var(--ease-out), color var(--dur-1) var(--ease-out), transform var(--dur-1) var(--ease-out); }
  .nav-item:active { transform: scale(.985); }
  .nav.m-opening { animation: m-rise var(--m-dur-3) var(--m-ease); }   /* a sidebar section being opened */

  /* ---------- 3. Checkbox, radio, switch ---------- */
  .check input::after, input.checkbox::after { transition: transform var(--m-dur-3) var(--m-ease-pop); }
  .check input:checked::after, input.checkbox:checked::after { transition-delay: 60ms; }
  .check input.m-pop, input.checkbox.m-pop, .radio input.m-pop, input.radio-input.m-pop { animation: m-pop var(--m-dur-4) var(--m-ease-pop); }
  .radio input, input.radio-input {
    transition: border-width var(--m-dur-3) var(--m-ease-pop), border-color var(--dur-1) var(--ease-out), background var(--dur-1) var(--ease-out);
  }
  .switch input { transition: background var(--m-dur-3) var(--m-ease); }
  .switch input::after { transition: transform var(--m-dur-3) var(--m-ease), inline-size var(--m-dur-2) var(--m-ease); }
  .switch input:not(:disabled):active::after { inline-size: 18px; }
  .switch input:checked:not(:disabled):active::after { transform: translateX(10px); }
  [dir="rtl"] .switch input:checked:not(:disabled):active::after { transform: translateX(-10px); }

  /* ---------- 4. Toasts: newest on top, older ones tucked behind; hover or tap unfolds the deck ---------- */
  .toasts.m-deck { display: grid; align-items: end; }
  .toasts.m-deck > .toast {
    grid-area: 1 / 1; align-self: end; transform-origin: 50% 0;
    transform: translateY(calc(var(--i, 0) * -8px)) scale(calc(1 - var(--i, 0) * .04));
    z-index: calc(10 - var(--i, 0));
    transition: transform var(--m-dur-4) var(--m-ease), opacity var(--m-dur-3);
  }
  .toasts.m-deck > .toast > * { transition: opacity var(--m-dur-2); }
  .toasts.m-deck:not(.m-open) > .toast:not(.m-top) > * { opacity: 0; }
  .toasts.m-deck > .toast.m-far { opacity: 0; pointer-events: none; }
  .toasts.m-deck.m-open > .toast { transform: translateY(var(--y, 0px)); }
  .toasts.m-deck.m-open > .toast.m-far { opacity: 1; pointer-events: auto; }
  .toasts.m-deck > .toast.is-leaving { animation: m-toast-out var(--dur-2) var(--ease-in-out) forwards; }

  /* ---------- 5. Numbers that count up: no layout shift while they run ---------- */
  .m-counting { font-variant-numeric: tabular-nums; }

  /* ---------- 6. Rows: filtered-in rows fade up (the glide itself is motion.js FLIP) ---------- */
  .m-row-in > td { animation: m-fade var(--m-dur-3) var(--m-ease); }

  /* ---------- 7. Click-to-copy ids (the feature itself is outside this block) ---------- */
  .m-copy { transition: background var(--dur-1) var(--ease-out), color var(--dur-1) var(--ease-out); }
  .m-copy.m-copied { animation: m-pop var(--m-dur-4) var(--m-ease-pop); }

  /* ---------- 8. Arrivals: the screen's blocks rise in order; panels and states open instead of popping ---------- */
  .page__inner.m-arrive > * { animation: m-rise var(--m-dur-4) var(--m-ease) both; animation-delay: calc(var(--m-i, 0) * 45ms); }
  [role="tabpanel"]:not([hidden]) { animation: m-fade var(--m-dur-3) var(--m-ease); }
  .alert, .empty { animation: m-rise var(--m-dur-3) var(--m-ease); }
  .stat { transition: border-color var(--dur-1) var(--ease-out); }
  dialog.dialog[open] { animation-duration: var(--m-dur-3); animation-timing-function: var(--m-ease); }
  .qpk-check { transition: background var(--m-dur-2) var(--m-ease), border-color var(--m-dur-2) var(--m-ease), color var(--m-dur-2) var(--m-ease), transform var(--m-dur-3) var(--m-ease-pop); }
  [aria-pressed="true"] > .qpk-check, .qpk-tile[aria-pressed="true"] .qpk-check { transform: scale(1.08); }
}

/* Click-to-copy ids work with reduced motion too */
.m-copy { cursor: copy; border-radius: var(--radius-xs); }
.m-copy:hover, .m-copy:focus-visible { background: var(--bg-hover); color: var(--text); outline: none; }
.m-copy.m-copied { color: var(--success); }

@keyframes m-pop { 0% { transform: scale(.86); } 60% { transform: scale(1.12); } 100% { transform: scale(1); } }
@keyframes m-rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes m-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes m-toast-out { to { opacity: 0; } }
