/*
 * Flux motion primitives, shared by every screen. Works with public/js/fx-motion.js.
 * Durations and easings come from fx-tokens.css. Animate transform and opacity. Motion only on a change: nothing
 * loops on the office or factory screens (the TV board alone keeps a calm belt and live dot, under html.fx-live), and
 * everything stops for people who asked their system for less motion.
 *
 * Classes on <html>
 *   fx-motion   motion is allowed (set before first paint). "Before" states are hidden only under it, so with
 *               no script, or with reduced motion, every element is simply visible.
 *   fx-paused   the tab is hidden: every CSS animation is paused.
 *   fx-live     printed only by the TV layout: its .fx-loop animations (a slow belt, the live dot) keep going.
 *   fx-vt       a page transition is being captured (see the end of this file).
 *
 * State classes written by fx-motion.js all start with "is-fx-" and survive Livewire updates.
 * Never print an is-fx-* class from the server.
 *
 * ---------------------------------------------------------------------------------------------------------
 * ENTER   <section data-fx-reveal>…</section>                    rises 12px and fades in when the page opens
 *         <section data-fx-reveal="fade|scale|left|slats">        other entrances ("slats": opens like louvres)
 *         <ul data-fx-stagger="rise"> <li>…</li> … </ul>          children arrive one after another (50ms apart,
 *                                                                 at most 8 steps); later additions slide in 6px
 *         <section data-fx-reveal data-fx-when="view">            waits until it is scrolled into view
 *         <div data-fx-scene="dashboard"> … </div>                the full entrance once per tab session;
 *                                                                 later visits get a short fade, no count-up
 * NUMBERS <b data-fx-count="1234.5" data-fx-decimals="2" data-fx-suffix=" lei">1.234,50 lei</b>
 *         counts up from 0 on first show; after a Livewire update counts from the old value to the new one
 *         (380ms) and pulses its [data-fx-pulse] host. The server text stays the final value.
 * PULSE   <article data-fx-pulse="{{ $signature }}">               a tint that fades over 700ms whenever the
 *                                                                 attribute's value, or a count inside, changes
 *         data-fx-pulse-tone="ok|warn|bad|remark|brand"           colour of that tint (default: graphite)
 * URGENT  <article class="fx-breathe">                            a red ring breathes 3 times, then holds still
 * DONE    <span class="fx-pop">✓ Casetă</span>                     a done mark pops in once when it appears
 * PRESS   class="fx-press" (scale .97)  class="fx-press-soft" (scale .985, for cards)
 * LIFT    class="fx-lift"                                         rises 2px with a deeper shadow under a mouse
 * GLIDE   <ol data-fx-flip> <li wire:key="o-12">…</li> … </ol>     keyed items glide to their new place after a
 *                                                                 Livewire update, even into another list inside
 *                                                                 the same [data-fx-flip] root
 * BELT    <span class="fx-flow"></span>                           moving slats; FX.run(el) runs them twice (when
 *                                                                 work moves); class="fx-flow fx-loop" runs only
 *                                                                 under html.fx-live (the TV board)
 * GROW    <i class="fx-grow-x" style="--fx-v:.42"></i>             a bar scaled from its start edge (0..1), grows
 *         <i class="fx-grow-y" style="--fx-v:.8"></i>              in on first show, glides on change
 * DRAW    <path class="fx-draw" pathLength="1" …/>                 an SVG line that draws itself on first show
 * WAIT    <div class="fx-skeleton is-line"></div>                  a quiet shimmer placeholder (stops after ~7s)
 *         <span class="fx-spinner"></span> + class="fx-delay-in" on its wrapper (appears only after 200ms)
 * ALPINE  x-transition:enter="fx-t-in" x-transition:enter-start="fx-t-pop-0" x-transition:enter-end="fx-t-1"
 *         x-transition:leave="fx-t-out" x-transition:leave-start="fx-t-1" x-transition:leave-end="fx-t-pop-0"
 *         states: fx-t-fade-0, fx-t-pop-0, fx-t-up-0, fx-t-toast-0, fx-t-sheet-0, fx-t-drawer-0, fx-t-drawer-r-0;
 *         slow pair for sheets and drawers: fx-t-in-slow / fx-t-out-slow
 * PAGES   whole-page changes cross-fade; [data-fx-vt="nav-pill|dock-pill|main"] are captured on their own,
 *         so the current-place pill slides to the new place and the page body rises in
 * ---------------------------------------------------------------------------------------------------------
 */

/* ---------- Keyframes ---------- */
@keyframes fx-rise { from { opacity: 0; transform: translateY(12px) scale(0.985); } }
@keyframes fx-fade-in { from { opacity: 0; } }
@keyframes fx-fade-up { from { opacity: 0; transform: translateY(8px); } }
@keyframes fx-scale-in { from { opacity: 0; transform: scale(0.96); } }
@keyframes fx-left-in { from { opacity: 0; transform: translateX(-16px); } }
@keyframes fx-row-in { from { opacity: 0; transform: translateY(-6px); } }
@keyframes fx-pop { 0% { transform: scale(0.6); } 60% { transform: scale(1.1); } 100% { transform: none; } }
@keyframes fx-spin { to { transform: rotate(360deg); } }
@keyframes fx-shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }
@keyframes fx-belt { to { transform: translateX(calc(-1 * var(--fx-flow-period, 8px))); } }
@keyframes fx-grow-x { from { transform: scaleX(0); } }
@keyframes fx-grow-y { from { transform: scaleY(0); } }
@keyframes fx-draw { from { stroke-dashoffset: 1; } }
@keyframes fx-reveal-failsafe { to { opacity: 1; visibility: visible; } }
@keyframes fx-breathe {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.25; transform: scale(1.025); }
}

/* The louvre entrance: the element appears through horizontal slats that open, as a shutter does. */
@property --fx-slat-open {
    syntax: '<length>';
    inherits: false;
    initial-value: 24px;
}
@keyframes fx-slats-open { from { --fx-slat-open: 0px; opacity: 0.2; } to { --fx-slat-open: 24px; opacity: 1; } }

/* ---------- ENTER ---------- */
/* A stagger's children rise by default, even inside a "slats" reveal (whose timing would otherwise be inherited). */
[data-fx-stagger] > * { --fx-reveal-anim: fx-rise; --fx-reveal-dur: var(--fx-dur-4); --fx-reveal-ease: var(--fx-ease-enter); }
[data-fx-reveal="fade"], [data-fx-stagger="fade"] > * { --fx-reveal-anim: fx-fade-in; }
[data-fx-reveal="scale"], [data-fx-stagger="scale"] > * { --fx-reveal-anim: fx-scale-in; }
[data-fx-reveal="left"], [data-fx-stagger="left"] > * { --fx-reveal-anim: fx-left-in; }
[data-fx-reveal="slats"] { --fx-reveal-anim: fx-slats-open; --fx-reveal-dur: 900ms; --fx-reveal-ease: var(--fx-ease-move); }

html.fx-motion [data-fx-reveal]:not(.is-fx-in),
html.fx-motion [data-fx-stagger] > :not(.is-fx-in) {
    opacity: 0;
    animation: fx-reveal-failsafe 1ms linear 2.5s forwards;   /* if the script never runs, show it anyway */
}
/* Waiting to be scrolled into view: hidden, no failsafe (the script is clearly running). */
html.fx-motion [data-fx-reveal].is-fx-wait,
html.fx-motion [data-fx-stagger] > .is-fx-wait { opacity: 0; animation: none; }
html.fx-motion [data-fx-reveal].is-fx-in,
html.fx-motion [data-fx-stagger] > .is-fx-in {
    animation: var(--fx-reveal-anim, fx-rise) var(--fx-reveal-dur, var(--fx-dur-4)) var(--fx-reveal-ease, var(--fx-ease-enter)) backwards;
    animation-delay: calc(min(var(--fx-i, 0), 8) * var(--fx-stagger));
}
html.fx-motion [data-fx-reveal="slats"].is-fx-in {
    -webkit-mask-image: repeating-linear-gradient(180deg, #000 0 var(--fx-slat-open), transparent var(--fx-slat-open) var(--fx-slat));
    mask-image: repeating-linear-gradient(180deg, #000 0 var(--fx-slat-open), transparent var(--fx-slat-open) var(--fx-slat));
}
/* Added later by a live update: a short slide, no waiting. */
html.fx-motion [data-fx-reveal].is-fx-new,
html.fx-motion [data-fx-stagger] > .is-fx-new {
    animation: fx-row-in 200ms var(--fx-ease-out) backwards;
}
/* A repeat visit of a scene: one quick fade, no stagger. */
html.fx-motion .is-fx-quick [data-fx-reveal].is-fx-in,
html.fx-motion .is-fx-quick [data-fx-stagger] > .is-fx-in,
html.fx-motion [data-fx-reveal].is-fx-quick {
    animation: fx-fade-in var(--fx-dur-3) var(--fx-ease-out) backwards;
    animation-delay: 0s;
}
/* Arrived: the entrance is removed, so nothing can replay it and no mask stays behind. */
html.fx-motion [data-fx-reveal].is-fx-in.is-fx-done,
html.fx-motion [data-fx-stagger] > .is-fx-in.is-fx-done {
    animation: none;
    -webkit-mask-image: none;
    mask-image: none;
}

/* ---------- NUMBERS ---------- */
[data-fx-count], .fx-count { font-variant-numeric: tabular-nums; }
html.fx-motion [data-fx-count]:not(.is-fx-counted),
html.fx-motion .fx-count[data-to]:not(.is-fx-counted) {
    visibility: hidden;                                         /* no flash of the final value before 0 */
    animation: fx-reveal-failsafe 1ms linear 2.5s forwards;
}

/* ---------- PULSE ---------- */
:root { --fx-pulse-bg: rgb(35 31 32 / 0.08); --fx-pulse-ring: rgb(35 31 32 / 0.12); }
html.fx-tv { --fx-pulse-bg: rgb(255 255 255 / 0.10); --fx-pulse-ring: rgb(255 255 255 / 0.20); }
[data-fx-pulse-tone="ok"] { --fx-pulse-bg: var(--fx-ok-bg); --fx-pulse-ring: color-mix(in oklab, var(--fx-ok-fill) 30%, transparent); }
[data-fx-pulse-tone="warn"] { --fx-pulse-bg: var(--fx-warn-bg); --fx-pulse-ring: color-mix(in oklab, var(--fx-warn-fill) 35%, transparent); }
[data-fx-pulse-tone="bad"] { --fx-pulse-bg: var(--fx-bad-bg); --fx-pulse-ring: color-mix(in oklab, var(--fx-bad-fill) 30%, transparent); }
[data-fx-pulse-tone="remark"] { --fx-pulse-bg: var(--fx-st-remark-bg); --fx-pulse-ring: color-mix(in oklab, var(--fx-st-remark) 35%, transparent); }
[data-fx-pulse-tone="brand"] { --fx-pulse-bg: var(--fx-brand-tint); --fx-pulse-ring: var(--fx-brand-glow); }
/* The pulse runs as a Web Animation from fx-motion.js: it never touches the element's CSS animation, so an
   entrance never replays. With reduced motion the change shows as a tint that comes and goes without fading. */
.is-fx-changed { background-color: var(--fx-pulse-bg); box-shadow: 0 0 0 3px var(--fx-pulse-ring); }

/* ---------- URGENT ---------- */
:where(.fx-breathe) { position: relative; }
.fx-breathe::after {
    content: '';
    position: absolute;
    inset: -3px;
    border-radius: inherit;
    pointer-events: none;
    box-shadow: 0 0 0 2px var(--fx-breathe-c, var(--fx-st-urgent)), 0 0 18px 2px color-mix(in oklab, var(--fx-breathe-c, var(--fx-st-urgent)) 30%, transparent);
    animation: fx-breathe var(--fx-dur-breathe) var(--fx-ease-in-out) 3 both;
}

/* ---------- SUCCESS: a done mark pops in once when it appears ---------- */
.fx-pop { animation: fx-pop var(--fx-dur-4) var(--fx-ease-out) backwards; }

/* ---------- PRESS and LIFT ---------- */
.fx-press, .fx-press-soft { transition: transform var(--fx-dur-1) var(--fx-ease-out); touch-action: manipulation; }
.fx-press:active:not(:disabled):not([aria-disabled="true"]) { transform: scale(0.97); }
.fx-press-soft:active:not(:disabled):not([aria-disabled="true"]) { transform: scale(0.985); }
.fx-lift { transition: transform var(--fx-dur-2) var(--fx-ease-out), box-shadow var(--fx-dur-2) var(--fx-ease-out); }
@media (hover: hover) and (pointer: fine) {
    .fx-lift:hover { transform: translateY(-2px); box-shadow: var(--fx-shadow-2); }
    .fx-lift.fx-press-soft:active, .fx-lift.fx-press:active { transform: translateY(-1px) scale(0.985); }
}

/* ---------- BELT ---------- */
.fx-flow {
    --fx-flow-period: 8px;
    position: relative;
    display: block;
    overflow: hidden;
    contain: paint;
}
.fx-flow::before {
    content: '';
    position: absolute;
    inset: 0 calc(-1 * var(--fx-flow-period)) 0 0;
    background: repeating-linear-gradient(90deg, var(--fx-flow-c, var(--fx-line-2)) 0 3px, transparent 3px var(--fx-flow-period));
}
.fx-flow.is-fx-run::before { animation: fx-belt var(--fx-dur-belt) linear var(--fx-run-n, 2); }
html.fx-live .fx-flow.fx-loop::before { animation: fx-belt var(--fx-dur-belt) linear infinite; }
html.fx-live .fx-loop.is-fx-off::before, html.fx-live .fx-loop.is-fx-off::after { animation-play-state: paused; }

/* ---------- GROW and DRAW ---------- */
.fx-grow-x, .fx-grow-y { transition: transform var(--fx-dur-5) var(--fx-ease-move); }
.fx-grow-x { transform-origin: left center; transform: scaleX(var(--fx-v, 1)); }
[dir="rtl"] .fx-grow-x { transform-origin: right center; }
.fx-grow-y { transform-origin: center bottom; transform: scaleY(var(--fx-v, 1)); }
html.fx-motion .is-fx-in .fx-grow-x, html.fx-motion .fx-grow-x.is-fx-in { animation: fx-grow-x var(--fx-dur-show) var(--fx-ease-move) backwards; animation-delay: calc(120ms + min(var(--fx-i, 0), 12) * 40ms); }
html.fx-motion .is-fx-in .fx-grow-y, html.fx-motion .fx-grow-y.is-fx-in { animation: fx-grow-y var(--fx-dur-show) var(--fx-ease-move) backwards; animation-delay: calc(120ms + min(var(--fx-i, 0), 12) * 40ms); }
.fx-draw { stroke-dasharray: 1; stroke-dashoffset: 0; }
html.fx-motion .is-fx-in .fx-draw, html.fx-motion .fx-draw.is-fx-in { animation: fx-draw var(--fx-dur-show) var(--fx-ease-move) 200ms backwards; }
html.fx-motion .is-fx-quick .fx-grow-x, html.fx-motion .is-fx-quick .fx-grow-y, html.fx-motion .is-fx-quick .fx-draw { animation: none; }

/* ---------- WAIT ---------- */
.fx-skeleton {
    position: relative;
    overflow: hidden;
    background: var(--fx-sunk);
    border-radius: var(--fx-r-ctl);
    box-shadow: var(--fx-shadow-inset);
}
:where(.fx-skeleton.is-line) { height: 0.9em; border-radius: var(--fx-r-pill); box-shadow: none; background: var(--fx-canvas-deep); }
:where(.fx-skeleton.is-circle) { border-radius: 50%; aspect-ratio: 1; }
.fx-skeleton::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent, rgb(255 255 255 / 0.65), transparent);
    transform: translateX(-100%);
    animation: fx-shimmer 1.4s var(--fx-ease-in-out) 0.3s 5;
}
.fx-spinner {
    display: inline-block;
    width: 1.1em;
    height: 1.1em;
    border-radius: 50%;
    border: 2px solid currentColor;
    border-right-color: transparent;
    vertical-align: -0.15em;
    animation: fx-spin 0.7s linear infinite;
}
html.fx-motion .fx-delay-in { animation: fx-fade-in var(--fx-dur-2) var(--fx-ease-out) 200ms backwards; }

/* ---------- ALPINE transitions (x-transition class strings) ---------- */
.fx-t-in { transition: opacity var(--fx-dur-3) var(--fx-ease-enter), transform var(--fx-dur-3) var(--fx-ease-enter); }
.fx-t-out { transition: opacity var(--fx-dur-exit-3) var(--fx-ease-exit), transform var(--fx-dur-exit-3) var(--fx-ease-exit); }
.fx-t-in-slow { transition: opacity var(--fx-dur-4) var(--fx-ease-enter), transform var(--fx-dur-4) var(--fx-ease-enter); }
.fx-t-out-slow { transition: opacity var(--fx-dur-exit-4) var(--fx-ease-exit), transform var(--fx-dur-exit-4) var(--fx-ease-exit); }
.fx-t-1 { opacity: 1; transform: none; }
.fx-t-fade-0 { opacity: 0; }
.fx-t-pop-0 { opacity: 0; transform: translateY(-4px) scale(0.97); }
.fx-t-up-0 { opacity: 0; transform: translateY(8px); }
.fx-t-toast-0 { opacity: 0; transform: translateY(12px) scale(0.98); }
.fx-t-sheet-0 { transform: translateY(100%); }
.fx-t-drawer-0 { transform: translateX(-104%); }
.fx-t-drawer-r-0 { transform: translateX(104%); }

/* ---------- PAGES: cross-document view transitions (Chrome, Edge, Safari 18.2+; others simply load) ---------- */
@media (prefers-reduced-motion: no-preference) {
    @view-transition { navigation: auto; }
}
::view-transition-old(root),
::view-transition-new(root) {
    animation-duration: var(--fx-dur-3);   /* the same for both, so whatever is identical (header, dock) holds still */
    animation-timing-function: var(--fx-ease-move);
}
html.fx-vt .fi-main, html.fx-vt [data-fx-vt="main"] { view-transition-name: fx-main; }
html.fx-vt [data-fx-vt="nav-pill"] { view-transition-name: fx-nav-pill; }
html.fx-vt [data-fx-vt="dock-pill"] { view-transition-name: fx-dock-pill; }
/* The page body stays between the header and the dock (fx-boot measures the strip), so they never wash out. */
::view-transition-group(fx-main) { animation: none; clip-path: var(--fx-vt-clip, none); }
/* The old page body is gone at once: it would be drawn at the new page's place (wrong when it was scrolled). */
::view-transition-old(fx-main) { animation: none; opacity: 0; }
::view-transition-new(fx-main) { animation: var(--fx-dur-4) var(--fx-ease-enter) both fx-fade-up; }
::view-transition-group(fx-nav-pill),
::view-transition-group(fx-dock-pill) { animation-duration: var(--fx-dur-4); animation-timing-function: var(--fx-ease-spring); }

/* ---------- Hidden tab, continuous motion off, reduced motion ---------- */
html.fx-paused *, html.fx-paused *::before, html.fx-paused *::after { animation-play-state: paused !important; }
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 1ms !important;
        animation-delay: 0s !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0s !important;
        transition-delay: 0s !important;
        scroll-behavior: auto !important;
    }
    ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
    .fx-press:active, .fx-press-soft:active, .fx-lift:hover { transform: none; }
    .fx-skeleton::after, .fx-flow::before { animation: none !important; }
}
