/*
 * Motion for the EHR: quick, quiet feedback for people doing the same things all
 * day. Everything here sits inside the "no-preference" check, so anyone who asks
 * their device to reduce motion simply does not get it.
 *
 * Only transform and opacity move, which stays smooth on heavy pages. The sidebar
 * has no entrance: it renders on every page and would soon become tiresome.
 * Dashboard rules need .dx-anim, so they cannot reach other dashboard-styled pages.
 * Patient screens opt in through body.motion-patients (set by the layout). Fixed
 * action bars sit on those pages, so only cards and panels move, never the page.
 */
:root {
  --m-fast: 100ms;
  --m-base: 200ms;
  --m-slow: 300ms;
  --m-ease: cubic-bezier(.2, .8, .2, 1);
}

@keyframes ehr-rise { from { opacity: 0; transform: translateY(8px); } }
@keyframes ehr-fade-in { from { opacity: 0; } }
/* translate, not transform: a positioned element (a dropdown, say) keeps its own. */
@keyframes ehr-lift { from { opacity: 0; translate: 0 8px; } }
@keyframes ehr-drop { from { opacity: 0; translate: 0 -4px; } }

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

  /* ── Sidebar ──────────────────────────────────────────────────────────── */

  /* Starts once the page has settled, so a section opened on load does not slide. */
  .ehr2-shell.nav-ready .ehr2-nav-section.is-collapsible > .ehr2-nav-section-clip { transition: grid-template-rows var(--m-base) var(--m-ease); }
  .ehr2-shell.nav-ready .ehr2-nav-section.is-collapsible > .ehr2-nav-section-clip > .ehr2-nav-section-body { transition: visibility 0s linear var(--m-base); }
  .ehr2-shell.nav-ready .ehr2-nav-section.is-collapsible.is-open > .ehr2-nav-section-clip > .ehr2-nav-section-body { transition-delay: 0s; }

  .ehr-bs5 .ehr2-nav-item { transition: background-color var(--m-base) ease, color var(--m-base) ease, border-color var(--m-base) ease, transform var(--m-fast) ease; }
  .ehr2-nav-item i { transition: transform var(--m-base) var(--m-ease), color var(--m-base) ease; }
  .ehr2-nav-item:hover i { transform: translateX(2px); }
  .ehr-bs5 .ehr2-nav-item:active { transform: scale(.98); }
  .ehr-bs5 .ehr2-nav-section-toggle { transition: color var(--m-base) ease; }
  .ehr2-nav-section-toggle .ehr2-nav-chevron { transition: transform var(--m-base) var(--m-ease); }

  .ehr2-sidebar-cta a { transition: transform var(--m-base) var(--m-ease), box-shadow var(--m-base) ease, background-color var(--m-base) ease; }
  .ehr2-sidebar-cta a:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(1, 43, 28, .22); }
  .ehr2-sidebar-cta a:active { transform: scale(.98); }

  /* ── Dashboard: on load ───────────────────────────────────────────────── */

  .dx-anim > .et-card,
  .dx-anim .ehr2-kpi-card2,
  .dx-anim > .row > * { animation: ehr-rise var(--m-slow) var(--m-ease) backwards; }
  .dx-anim .ehr2-kpi-card2:nth-child(1) { animation-delay: 60ms; }
  .dx-anim .ehr2-kpi-card2:nth-child(2) { animation-delay: 100ms; }
  .dx-anim .ehr2-kpi-card2:nth-child(3) { animation-delay: 140ms; }
  .dx-anim .ehr2-kpi-card2:nth-child(4) { animation-delay: 180ms; }
  .dx-anim > .et-card { animation-delay: 220ms; }
  .dx-anim > .row > :nth-child(1) { animation-delay: 260ms; }
  .dx-anim > .row > :nth-child(2) { animation-delay: 300ms; }
  .dx-anim > .row > :nth-child(3) { animation-delay: 340ms; }

  /* Tracker numbers arrive after the page does, in place of their skeletons. */
  .dx-anim .et-card.is-loaded .et-tile-num,
  .dx-anim .et-card.is-loaded .et-hero-what { animation: ehr-fade-in var(--m-slow) ease; }

  /* ── Dashboard: hover and click. Only what can be clicked moves. ──────── */

  .dx-anim .et-tile { transition: transform var(--m-base) var(--m-ease), box-shadow var(--m-base) ease; }
  .dx-anim .et-tile:hover { transform: translateY(-2px); }
  .dx-anim .et-tile:active { transform: scale(.98); }

  .dx-anim .btn-ehr2-primary { transition: transform var(--m-fast) ease, box-shadow var(--m-base) ease, background-color var(--m-base) ease; }
  .dx-anim .btn-ehr2-primary:active { transform: scale(.97); }

  /* ── Patient screens: on load ─────────────────────────────────────────── */

  .motion-patients .ehr2-shell-content > * { animation: ehr-fade-in var(--m-base) ease backwards; }
  .motion-patients .p3-header,
  .motion-patients .ehr2-profile-header { animation: ehr-lift var(--m-slow) var(--m-ease) backwards; }

  /* Only the first few, so a long page is not a long wait. Modals have their own motion. */
  .motion-patients .ehr2-shell-content .card:nth-child(-n+6):not(.modal *),
  .motion-patients .ehr2-shell-content .ehr2-card:nth-child(-n+6):not(.modal *) { animation: ehr-lift var(--m-slow) var(--m-ease) 60ms backwards; }

  /* Rows fade rather than move; the countdown table redraws itself, so it stays out. */
  .motion-patients .ehr2-shell-content tbody tr:nth-child(-n+10):not(.modal *):not(#etPatient *) { animation: ehr-fade-in var(--m-slow) ease backwards; }
  .motion-patients .ehr2-shell-content tbody tr:nth-child(2):not(.modal *):not(#etPatient *) { animation-delay: 30ms; }
  .motion-patients .ehr2-shell-content tbody tr:nth-child(3):not(.modal *):not(#etPatient *) { animation-delay: 60ms; }
  .motion-patients .ehr2-shell-content tbody tr:nth-child(4):not(.modal *):not(#etPatient *) { animation-delay: 90ms; }
  .motion-patients .ehr2-shell-content tbody tr:nth-child(5):not(.modal *):not(#etPatient *) { animation-delay: 120ms; }
  .motion-patients .ehr2-shell-content tbody tr:nth-child(6):not(.modal *):not(#etPatient *) { animation-delay: 150ms; }
  .motion-patients .ehr2-shell-content tbody tr:nth-child(7):not(.modal *):not(#etPatient *) { animation-delay: 180ms; }
  .motion-patients .ehr2-shell-content tbody tr:nth-child(8):not(.modal *):not(#etPatient *) { animation-delay: 210ms; }
  .motion-patients .ehr2-shell-content tbody tr:nth-child(9):not(.modal *):not(#etPatient *) { animation-delay: 240ms; }
  .motion-patients .ehr2-shell-content tbody tr:nth-child(10):not(.modal *):not(#etPatient *) { animation-delay: 270ms; }

  /* Chart tabs: display: none to block restarts this each time one opens. */
  .motion-patients .ehr2-tab-panel.active { animation: ehr-lift var(--m-base) var(--m-ease) backwards; }

  /* ── Patient screens: hover and click ─────────────────────────────────── */

  .motion-patients .table > tbody > tr > * { transition: box-shadow var(--m-base) ease, background-color var(--m-base) ease; }
  .motion-patients .ehr2-patient-avatar { transition: scale var(--m-base) var(--m-ease); }
  .motion-patients tr:hover .ehr2-patient-avatar { scale: 1.08; }

  .motion-patients .ehr2-sidenav-item i { transition: translate var(--m-base) var(--m-ease), color var(--m-base) ease; }
  .motion-patients .ehr2-sidenav-item:not(.ehr2-sidenav-item-locked):hover i { translate: 2px 0; }
  .motion-patients .ehr2-sidenav-item:not(.ehr2-sidenav-item-locked) { transition: background-color var(--m-base) ease, color var(--m-base) ease, border-color var(--m-base) ease, scale var(--m-fast) ease; }
  .motion-patients .ehr2-sidenav-item:not(.ehr2-sidenav-item-locked):active { scale: .98; }

  .motion-patients .btn,
  .motion-patients [class*="btn-ehr2-"],
  .motion-patients [class*="btn-ehr-"] { transition: background-color var(--m-base) ease, border-color var(--m-base) ease, color var(--m-base) ease, box-shadow var(--m-base) ease, scale var(--m-fast) ease, translate var(--m-base) var(--m-ease); }
  .motion-patients .btn-primary:not(:disabled):hover,
  .motion-patients .btn-ehr2-primary:not(:disabled):hover { translate: 0 -1px; }
  .motion-patients .btn:not(:disabled):active,
  .motion-patients [class*="btn-ehr2-"]:not(:disabled):active,
  .motion-patients [class*="btn-ehr-"]:not(:disabled):active { scale: .97; translate: 0 0; }

  .motion-patients .page-link { transition: background-color var(--m-base) ease, color var(--m-base) ease, scale var(--m-fast) ease; }
  .motion-patients .page-link:active { scale: .95; }
  .motion-patients .dropdown-item { transition: background-color var(--m-fast) ease, color var(--m-fast) ease; }

  /* ── Patient screens: menus and modals ────────────────────────────────── */

  .motion-patients .dropdown-menu.show { animation: ehr-drop 130ms var(--m-ease); }

  body.motion-patients .modal.fade .modal-dialog { transform: translateY(10px) scale(.98); transition: transform var(--m-base) var(--m-ease); }
  body.motion-patients .modal.show .modal-dialog { transform: none; }
  body.motion-patients .modal.fade.modal-static .modal-dialog { transform: scale(1.01); }

  /* ── My Profile ───────────────────────────────────────────────────────── */

  .pf-page .gs-hero { animation: ehr-lift var(--m-slow) var(--m-ease) backwards; }
  .pf-page .pf-card, .pf-page .profile-form-card { animation: ehr-lift var(--m-slow) var(--m-ease) 80ms backwards; }
}
