/* ==========================================================================
   Onix motion — how the interface moves. The manners are iOS's, the look is
   the product's own: no colour, size or layout is set here, only motion.

   The rule of the house stands (docs/CONVENTIONS.md, "A page arrives rendered
   and stays put"): nothing moves because a page arrived. Everything here is
   the answer to what the person just did —

     press      a control gives under the finger and springs back
     open       a panel grows out of the place that opened it; a drawer
                glides in from the edge as a sheet does
     close      what leaves is seen leaving (js/onix-motion.js keeps a
                drawer's picture for the way out; the rest is CSS)
     switch     a choice cross-fades to the next one
     arrive     only what arrives by itself, later: a toast, Mayla's answer,
                the bell on a new notification

   One page does come up: the sign-in card, the app opening (and it shakes
   its head at a wrong password) — it is outside the shell and its pages.

   `scale` / `translate` (the individual transform properties) carry the
   motion, so a rule's own `transform` (a hover lift, a centring) is never
   overwritten. Panels that a script measures as they open (the top bar's
   drop-downs, the grid's popups, the lookup and date panels) keep their
   plain entrance: a scale would skew the measure.

   Linked last (Components/App.razor). app.css turns every duration to nothing
   under prefers-reduced-motion; the loops are stopped by name at the end.
   ========================================================================== */

/* ─── The curves ───────────────────────────────────────────────────────── */

:root {
    /* The sheet's curve: off fast, a long settle (UIKit's critically damped spring) — the rail's own (--rail-motion). */
    --motion-glide: cubic-bezier(0.32, 0.72, 0, 1);
    /* The way out: gathering speed, gone. */
    --motion-exit: cubic-bezier(0.4, 0, 1, 1);
    /* Springs as "duration curve" pairs. The fallbacks overshoot once; linear() below draws the real thing. */
    --spring-press: 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    --spring-pop: 0.36s cubic-bezier(0.34, 1.3, 0.64, 1);
    --spring-soft: 0.5s cubic-bezier(0.32, 0.72, 0, 1);
    --sheet-in: 0.44s;
    --sheet-out: 0.24s;
}
/* Damped springs sampled into linear(): press — response 0.32s, bounce 0.38 (a released control);
   pop — 0.38s, 0.24 (a panel, a toast); soft — 0.42s, no bounce (what must not wobble). */
@supports (transition-timing-function: linear(0, 1)) {
    :root {
        --spring-press: 0.57s linear(0, 0.006 1%, 0.028 2.2%, 0.064 3.5%, 0.122 5%, 0.241 7.5%, 0.523 12.8%, 0.638 15%, 0.752 17.5%, 0.84 19.8%, 0.913 22%, 0.977 24.5%, 1.024 27%, 1.055 29.5%, 1.078 33%, 1.083 36.8%, 1.072 41.2%, 1.017 54.5%, 0.998 62.7%, 0.993 72.5%, 1);
        --spring-pop: 0.55s linear(0, 0.006 1.2%, 0.027 2.8%, 0.061 4.2%, 0.104 5.8%, 0.209 8.8%, 0.556 17.8%, 0.657 20.8%, 0.744 23.8%, 0.817 26.8%, 0.877 29.8%, 0.923 32.8%, 0.961 36%, 0.988 39.2%, 1.006 42.5%, 1.025 50.7%, 1.004 81.5%, 1);
        --spring-soft: 0.62s linear(0, 0.004 1%, 0.019 2.2%, 0.079 5%, 0.161 7.8%, 0.465 17%, 0.557 20.2%, 0.638 23.5%, 0.706 26.8%, 0.768 30.2%, 0.817 33.8%, 0.86 37.5%, 0.899 42%, 0.929 46.8%, 0.953 52.2%, 0.971 58.5%, 0.991 73.8%, 1);
    }
}

@keyframes motion-fade { from { opacity: 0; } }
@keyframes motion-pop { from { scale: 0.94; } }
@keyframes motion-rise { from { translate: 0 14px; scale: 0.96; } }

/* ─── Press: a control gives under the finger and springs back ─────────── */

/* The colours keep the pace they had (--dur); the spring is the scale's alone. */
:is(.button, .shell-iconbtn, .shell-pill, .onix-pillbtn, .app-tile, .home-add-tile, .dxg-tool, .mayla-iconbtn,
    .mayla-launcher, .shell-fab, .shell-railtoggle, .page-trail-back, .onix-auth-submit, .onix-auth-sso) {
    transition: background-color var(--dur) var(--ease), border-color var(--dur) var(--ease), color var(--dur) var(--ease),
                box-shadow var(--dur) var(--ease), opacity var(--dur) var(--ease), transform var(--dur) var(--ease),
                scale var(--spring-press);
}
/* Down at once, back on the spring. */
:is(.button, .shell-iconbtn, .shell-pill, .onix-pillbtn, .app-tile, .home-add-tile, .dxg-tool, .mayla-iconbtn,
    .mayla-launcher, .shell-fab, .shell-railtoggle, .page-trail-back, .onix-auth-submit, .onix-auth-sso):active {
    transition-duration: 0.09s;
    transition-timing-function: ease-out;
}
.button:active:not(:disabled) { scale: 0.97; }
:is(.shell-pill, .onix-pillbtn, .mayla-launcher):active { scale: 0.97; }
:is(.onix-auth-submit, .onix-auth-sso):active { transform: none; scale: 0.98; }
:is(.shell-iconbtn, .dxg-tool, .mayla-iconbtn, .page-trail-back):active:not(:disabled) { scale: 0.9; }
:is(.shell-railtoggle, .shell-fab):active { transform: none; scale: 0.9; }
:is(.app-tile, .home-add-tile):active { scale: 0.95; }
/* A joined row of choices is one piece: its buttons do not shrink apart. */
.onix-segmented .button:active { scale: none; }

/* The rail and the phone's tab bar: the picture gives, the pill stays — as a tab bar's symbol does. */
:is(.shell-nav, .shell-tab) > :is(img, svg, .shell-nav-glyph) {
    transition: opacity 0.16s ease, box-shadow 0.16s ease, scale var(--spring-press);
}
:is(.shell-nav, .shell-tab):active > :is(img, svg, .shell-nav-glyph) {
    scale: 0.84;
    transition-duration: 0.09s;
    transition-timing-function: ease-out;
}
.shell-rail.is-editing .shell-nav:active > :is(img, svg, .shell-nav-glyph) { scale: none; }

/* A tick and a radio dot. */
input:is([type=checkbox], [type=radio]) { transition: scale var(--spring-press); }
input:is([type=checkbox], [type=radio]):active:not(:disabled) { scale: 0.8; transition: scale 0.09s ease-out; }

/* A list's row under the finger takes the selected tint (a table cell's highlight); the form's lines do not. */
.dxg .dxg-table tbody tr.dxg-row.dxg-clickable:not(.edg-row):active { --dxg-row: var(--dxg-selected); }

/* ─── Switch: a choice cross-fades to the next ─────────────────────────── */

.onix-segmented button, .view-switcher-btn {
    transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}
/* A bar that fills, a column that grows: on the sheet's curve. */
.onix-progress > span { transition: width 0.6s var(--motion-glide); }
.home-plot-bar { transition: height 0.5s var(--motion-glide); }

/* The theme: one soft change, not a flash (js/onix-motion.js marks the root for the length of it). */
:root.is-theming, :root.is-theming *, :root.is-theming *::before, :root.is-theming *::after {
    transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease, fill 0.3s ease, stroke 0.3s ease,
                box-shadow 0.3s ease !important;
}

/* ─── Open: a panel grows out of the place that opened it ──────────────── */

/* The shell's popovers — companies, notifications, the account, the apps — out of their corner. The top bar's
   drop-downs (.shell-menu-panel) are measured as they open (js/onix-shell.js) and keep their entrance. */
.shell-pop-panel:not(.shell-menu-panel) {
    transform-origin: top right;
    animation: motion-pop var(--spring-pop) backwards, motion-fade 0.16s ease-out backwards;
}
.shell-company-panel { transform-origin: top center; }
.shell-rail .shell-pop-panel:not(.shell-menu-panel) { transform-origin: left top; }
.shell-rail-editbar { transform-origin: left bottom; animation: motion-pop var(--spring-pop) backwards, motion-fade 0.16s ease-out backwards; }
@media (max-width: 767.98px) {
    .shell-company-panel { transform-origin: top left; }
}

/* Where a closed <details> keeps its content styled (::details-content — the browsers of today), an entrance drawn
   with keyframes has played out, unseen, long before the panel opens. There the open state itself is the motion:
   the content fades both ways, the panel springs out of its corner and draws back into it. */
@supports selector(::details-content) {
    .shell-pop::details-content {
        opacity: 0;
        transition: opacity 0.14s ease, content-visibility 0.16s allow-discrete;
    }
    .shell-pop[open]::details-content { opacity: 1; }

    .shell-pop > .shell-pop-panel:not(.shell-menu-panel) {
        animation: none;
        scale: 0.94;
        transition: scale 0.16s var(--motion-exit);
    }
    .shell-pop[open] > .shell-pop-panel:not(.shell-menu-panel) { scale: none; transition: scale var(--spring-pop); }

    /* The apps, as a home screen lays its icons out: each tile a beat after the one before. Closed, a tile waits
       where it starts from — put back only once the panel has faded. */
    .shell-pop > .shell-apps-panel .app-tile {
        opacity: 0;
        translate: 0 12px;
        transition: opacity 0s 0.16s, translate 0s 0.16s;
    }
    .shell-pop[open] > .shell-apps-panel .app-tile {
        opacity: 1;
        translate: none;
        transition: opacity 0.2s ease-out calc(var(--motion-i, 0) * 18ms), translate var(--spring-pop) calc(var(--motion-i, 0) * 18ms),
                    scale var(--spring-press), transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease),
                    border-color var(--dur) var(--ease), background-color var(--dur) var(--ease);
    }
    .shell-pop[open] > .shell-apps-panel .app-tile:active { transition-duration: 0.09s; transition-delay: 0s; }
}
.shell-apps-panel .app-tile:nth-child(2) { --motion-i: 1; }
.shell-apps-panel .app-tile:nth-child(3) { --motion-i: 2; }
.shell-apps-panel .app-tile:nth-child(4) { --motion-i: 3; }
.shell-apps-panel .app-tile:nth-child(5) { --motion-i: 4; }
.shell-apps-panel .app-tile:nth-child(6) { --motion-i: 5; }
.shell-apps-panel .app-tile:nth-child(7) { --motion-i: 6; }
.shell-apps-panel .app-tile:nth-child(8) { --motion-i: 7; }
.shell-apps-panel .app-tile:nth-child(9) { --motion-i: 8; }
.shell-apps-panel .app-tile:nth-child(10) { --motion-i: 9; }
.shell-apps-panel .app-tile:nth-child(11) { --motion-i: 10; }
.shell-apps-panel .app-tile:nth-child(12) { --motion-i: 11; }
.shell-apps-panel .app-tile:nth-child(n+13) { --motion-i: 12; }
.shell-apps-panel .app-tile:nth-child(n+19) { --motion-i: 13; }

/* The search palette: down out of the bar, and back. */
.palette-backdrop { transition: opacity 0.18s ease, display 0.18s allow-discrete; }
.palette-backdrop:not(.open) { opacity: 0; }
.palette {
    transform-origin: top center;
    animation: motion-pop var(--spring-pop) backwards;
    transition: scale 0.18s var(--motion-exit), translate 0.18s var(--motion-exit);
}
.palette-backdrop:not(.open) .palette { scale: 0.97; translate: 0 -8px; }

/* ─── The drawer: a sheet from the edge, and back to it ────────────────── */

@keyframes motion-sheet-in { from { translate: 100% 0; } }
@keyframes motion-sheet-out { to { translate: 100% 0; } }
/* The scrim's colour comes and goes, not its opacity: the sheet on it stays solid all the way. */
@keyframes motion-scrim-in { from { background-color: transparent; -webkit-backdrop-filter: none; backdrop-filter: none; } }
@keyframes motion-scrim-out { to { background-color: transparent; -webkit-backdrop-filter: none; backdrop-filter: none; } }

.drawer-backdrop { animation: motion-scrim-in 0.3s ease-out backwards; }
.drawer { animation: motion-sheet-in var(--sheet-in) var(--motion-glide) backwards; }
/* A drawer the page was rendered with, drawn anew in its place (js/onix-motion.js): it is already there. */
.drawer-backdrop.is-settled, .drawer-backdrop.is-settled > .drawer { animation: none; }

/* The way out: the picture js/onix-motion.js keeps of a drawer that was closed — under the pointer, out of the tree. */
.drawer-backdrop.is-leaving {
    pointer-events: none;
    animation: motion-scrim-out var(--sheet-out) ease-in both;
}
.drawer-backdrop.is-leaving > .drawer { animation: motion-sheet-out var(--sheet-out) var(--motion-exit) both; }

/* Mayla's panel is the drawer with no scrim, shown and hidden in place (js/onix-mayla.js, [hidden]). */
.mayla-panel { transition: translate var(--sheet-out) var(--motion-exit), display var(--sheet-out) allow-discrete; }
.mayla-panel[hidden] { translate: 100% 0; }

/* ─── Arrive: what comes by itself ─────────────────────────────────────── */

/* A toast rises as a banner does; it leaves the way it came. */
.toast { animation: motion-rise var(--spring-pop) backwards, motion-fade 0.18s ease-out backwards; }
.toast.leaving {
    opacity: 0; transform: none; translate: 0 10px; scale: 0.96;
    transition: opacity 0.22s ease-in, translate 0.22s var(--motion-exit), scale 0.22s var(--motion-exit);
}

/* Mayla's turn in the conversation (js/onix-motion.js marks a turn as it is added, never the history). */
.mayla-turn.motion-in { transform-origin: left bottom; animation: motion-rise var(--spring-pop) backwards, motion-fade 0.2s ease-out backwards; }

/* A new notification: the bell swings once, its count lands (js/onix-motion.js, .is-ringing). */
@keyframes motion-ring {
    0%, 100% { rotate: 0deg; }
    15% { rotate: 14deg; }
    35% { rotate: -11deg; }
    55% { rotate: 7deg; }
    75% { rotate: -4deg; }
}
@keyframes motion-badge { 0% { scale: 0.4; } 55% { scale: 1.25; } 100% { scale: 1; } }
.shell-bell.is-ringing svg { transform-origin: 50% 10%; animation: motion-ring 0.8s ease-in-out; }
.shell-bell.is-ringing .shell-badge { animation: motion-badge 0.5s ease-out; }

/* ─── The rail being arranged: the icons wait to be moved ──────────────── */

@keyframes motion-jiggle { from { rotate: -1.4deg; } to { rotate: 1.4deg; } }
.shell-rail.is-editing .shell-nav[data-kind] { animation: motion-jiggle 0.15s ease-in-out infinite alternate; }
.shell-rail.is-editing .shell-nav[data-kind]:nth-child(even) { animation-duration: 0.17s; animation-direction: alternate-reverse; }
.shell-rail.is-editing .shell-nav[data-kind]:is(.is-dragging, :active) { animation: none; }

/* ─── The top bar over a scrolled page: lifted off it ──────────────────── */

:root { --motion-bar-shadow: 0 1px 2px rgba(0, 0, 0, 0.05), 0 10px 26px rgba(0, 0, 0, 0.10); }
:root[data-theme="dark"] { --motion-bar-shadow: 0 1px 2px rgba(0, 0, 0, 0.30), 0 12px 30px rgba(0, 0, 0, 0.50); }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) { --motion-bar-shadow: 0 1px 2px rgba(0, 0, 0, 0.30), 0 12px 30px rgba(0, 0, 0, 0.50); }
}
@keyframes motion-bar-lift { to { box-shadow: var(--motion-bar-shadow), var(--glass-highlight); } }
@supports (animation-timeline: scroll()) {
    @media (min-width: 768px) {
        .shell-topbar {
            animation: motion-bar-lift linear both;
            animation-timeline: scroll(root block);
            animation-range: 0 96px;
        }
    }
}

/* ─── Signing in: the card comes up once; a refusal shakes it ──────────── */

@keyframes motion-shake {
    0%, 100% { translate: 0 0; }
    18% { translate: -9px 0; }
    36% { translate: 8px 0; }
    54% { translate: -6px 0; }
    72% { translate: 4px 0; }
    88% { translate: -2px 0; }
}
.onix-auth-card { animation: motion-rise var(--spring-soft) backwards, motion-fade 0.3s ease-out backwards; }
.onix-auth-card:has(.onix-auth-error) { animation: motion-shake 0.46s ease-in-out; }

/* ─── Less motion ──────────────────────────────────────────────────────── */

/* app.css cuts every duration to nothing; a loop would still flicker, a held first frame still hide. */
@media (prefers-reduced-motion: reduce) {
    .shell-rail.is-editing .shell-nav[data-kind], .shell-topbar, .shell-bell.is-ringing svg,
    .shell-bell.is-ringing .shell-badge, .onix-auth-card, .onix-auth-card:has(.onix-auth-error) { animation: none; }
    .shell-pop[open] > .shell-apps-panel .app-tile { transition-delay: 0s; }
}
@media print {
    .drawer-backdrop.is-leaving { display: none !important; }
}
