/* =====================================================================
   Miftah — Motion
   The smoothness layer of the workspace, the same in every style: a few
   orchestrated entrances (a view arriving, its tiles and bars, popovers,
   the modal, the toast), pressed and hover states, and a cross-fade when
   the theme or the style changes under the page. Transform and opacity
   only. base.css switches all of it off under prefers-reduced-motion.
   app.js adds .is-entering to the page only when the view changes, so a
   filter, a toggle or a save never replays the entrance.
   ===================================================================== */

@keyframes mf-rise  { from { opacity: 0; transform: translateY(10px); } }
@keyframes mf-fade  { from { opacity: 0; } }
@keyframes mf-pop   { from { opacity: 0; transform: translateY(-6px) scale(.98); } }
@keyframes mf-modal { from { opacity: 0; transform: translateY(14px) scale(.985); } }
@keyframes mf-grow  { from { transform: scaleX(0); } }
@keyframes mf-grow-y { from { transform: scaleY(0); } }
@keyframes mf-focus { from { transform: scale(1.04); } }

/* --- A view arriving ------------------------------------------------- */
.page.is-entering > * { animation: mf-rise .32s var(--ease) both; }
.page.is-entering > :nth-child(2) { animation-delay: 40ms; }
.page.is-entering > :nth-child(3) { animation-delay: 80ms; }
.page.is-entering > :nth-child(4) { animation-delay: 120ms; }
.page.is-entering > :nth-child(n+5) { animation-delay: 160ms; }

/* Grids hand the entrance to their children, one beat apart */
.page.is-entering > .kpi-grid,
.page.is-entering > .grid-2,
.page.is-entering > .grid-3,
.page.is-entering > .grid-main-side,
.page.is-entering > .grid-side-main { animation: none; }
.page.is-entering .kpi-grid > .kpi,
.page.is-entering > .grid-2 > *,
.page.is-entering > .grid-3 > *,
.page.is-entering > .grid-main-side > *,
.page.is-entering > .grid-side-main > * { animation: mf-rise .34s var(--ease) 80ms both; }
.page.is-entering .kpi-grid > .kpi:nth-child(2),
.page.is-entering > .grid-2 > :nth-child(2),
.page.is-entering > .grid-3 > :nth-child(2),
.page.is-entering > .grid-main-side > :nth-child(2),
.page.is-entering > .grid-side-main > :nth-child(2) { animation-delay: 130ms; }
.page.is-entering .kpi-grid > .kpi:nth-child(3),
.page.is-entering > .grid-3 > :nth-child(3) { animation-delay: 180ms; }
.page.is-entering .kpi-grid > .kpi:nth-child(4) { animation-delay: 230ms; }
.page.is-entering .kpi-grid > .kpi:nth-child(5) { animation-delay: 280ms; }
.page.is-entering .kpi-grid > .kpi:nth-child(n+6) { animation-delay: 330ms; }

/* Bars and meters grow from their start edge */
.page.is-entering .score-bar .track i,
.page.is-entering .meter > i,
.page.is-entering .funnel-row .bar i,
.page.is-entering .compbar > i {
  animation: mf-grow .6s cubic-bezier(.2, .7, .2, 1) .16s both;
  transform-origin: 0 50%;
}
:root[dir="rtl"] .page.is-entering .score-bar .track i,
:root[dir="rtl"] .page.is-entering .meter > i,
:root[dir="rtl"] .page.is-entering .funnel-row .bar i,
:root[dir="rtl"] .page.is-entering .compbar > i { transform-origin: 100% 50%; }

/* Chart columns rise from the baseline, their values fade in after them */
.page.is-entering .chart .bar {
  transform-box: fill-box;
  transform-origin: 50% 100%;
  animation: mf-grow-y .5s cubic-bezier(.2, .7, .2, 1) .2s both;
}
.page.is-entering .chart .chart-value { animation: mf-fade .2s var(--ease) .6s both; }


/* --- Layers ---------------------------------------------------------- */
.pop-panel { animation: mf-pop .18s var(--ease) both; transform-origin: top right; }
:root[dir="rtl"] .pop-panel { transform-origin: top left; }
.search-results { transform-origin: top left; }          /* anchored at the start edge */
:root[dir="rtl"] .search-results { transform-origin: top right; }
.overlay { animation: mf-fade .2s var(--ease) both; }
.modal { animation: mf-modal .3s cubic-bezier(.2, .8, .2, 1) both; }
#toast .toast-inner { transform: translateY(10px) scale(.97); }
#toast.show .toast-inner { transform: none; }

/* --- Touch and hover ------------------------------------------------- */
.btn, .icon-btn, .topnav-item, .nav-item, .more-item, .segmented button, .tabs button,
.toggle-group label, .lang-switch button, .user-btn, .chip {
  transition:
    background var(--t-fast) var(--ease), color var(--t-fast) var(--ease),
    border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease),
    transform var(--t-fast) var(--ease);
}
.btn:active, .icon-btn:active, .topnav-item:active, .nav-item:active, .more-item:active,
.segmented button:active, .tabs button:active { transform: scale(.97); }
.btn-primary:hover { box-shadow: 0 8px 18px -8px color-mix(in srgb, var(--accent) 60%, transparent); }
.btn-primary:active { box-shadow: none; }

table.data tbody tr, .search-hit, .notif-item, .why { transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease); }
.mcard { transition: border-color var(--t-fast) var(--ease), box-shadow var(--t) var(--ease); }
.kpi, .panel { transition: box-shadow var(--t) var(--ease), border-color var(--t) var(--ease); }
.input, .select, textarea.input {
  transition: border-color var(--t-fast) var(--ease), background var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.switch .track { transition: background var(--t) var(--ease); }

/* Keyboard focus settles into place; the page title takes focus silently */
.btn:focus-visible, .icon-btn:focus-visible, .topnav-item:focus-visible, .nav-item:focus-visible,
.tabs button:focus-visible, .segmented button:focus-visible { animation: mf-focus .2s var(--ease); }
.page-head h1:focus { outline: none; }

/* --- Changing the theme or the style under the page ------------------ */
:root.is-switching *,
:root.is-switching *::before,
:root.is-switching *::after {
  transition:
    background-color .45s var(--ease), color .45s var(--ease), border-color .45s var(--ease),
    box-shadow .45s var(--ease), fill .45s var(--ease), stroke .45s var(--ease) !important;
}
