/* Micro-interactions for the admin app. Rules and numbers: docs/frontend/motion_guidelines.md.
   Everything moving is inside prefers-reduced-motion: no-preference, and nothing is applied on the entry screens
   (POS, Purchases, Opening stock: body.transaction-screen), where people type fast. Transform and opacity only. */

:root {
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --motion-press: 160ms;
  --motion-pop: 180ms;
  --motion-modal-in: 320ms;
  --motion-modal-out: 170ms;
}

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

  /* Buttons: a small press. */
  body:not(.transaction-screen) .btn {
    transition:
      color 0.15s ease-in-out,
      background-color 0.15s ease-in-out,
      border-color 0.15s ease-in-out,
      box-shadow 0.15s ease-in-out,
      transform var(--motion-press) var(--ease-out);
  }
  body:not(.transaction-screen) .btn:active:not(:disabled):not(.disabled) {
    transform: scale(0.95);
  }

  /* Modals: a small rise and settle in, a quicker exit. Full-screen phone sheets rise a little further. */
  body:not(.transaction-screen) .modal.fade .modal-dialog {
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    transition: transform var(--motion-modal-in) var(--ease-out), opacity 220ms ease-out;
  }
  body:not(.transaction-screen) .modal.fade .modal-dialog.modal-fullscreen,
  body:not(.transaction-screen) .modal.fade .modal-dialog.modal-fullscreen-sm-down {
    transform: translateY(28px);
  }
  body:not(.transaction-screen) .modal.fade.show .modal-dialog {
    opacity: 1;
    transform: none;
  }
  body:not(.transaction-screen) .modal.fade:not(.show) .modal-dialog {
    transition-duration: var(--motion-modal-out), 140ms;
  }
  body:not(.transaction-screen) .modal-backdrop.fade {
    transition: opacity 160ms ease-out;
  }

  /* Dropdowns: opacity only (Popper positions them with transform). */
  body:not(.transaction-screen) .dropdown-menu.show {
    animation: motion-fade var(--motion-pop) ease-out;
  }

  /* Page load: one orchestrated rise on the first few blocks, once. */
  body:not(.transaction-screen) .content-wrapper > *:nth-child(-n+6),
  body:not(.transaction-screen) .content-wrapper > [data-permission] > *:nth-child(-n+6) {
    animation: motion-rise 520ms var(--ease-out) backwards;
  }
  body:not(.transaction-screen) .content-wrapper > *:nth-child(2),
  body:not(.transaction-screen) .content-wrapper > [data-permission] > *:nth-child(2) { animation-delay: 70ms; }
  body:not(.transaction-screen) .content-wrapper > *:nth-child(3),
  body:not(.transaction-screen) .content-wrapper > [data-permission] > *:nth-child(3) { animation-delay: 140ms; }
  body:not(.transaction-screen) .content-wrapper > *:nth-child(4),
  body:not(.transaction-screen) .content-wrapper > [data-permission] > *:nth-child(4) { animation-delay: 210ms; }
  body:not(.transaction-screen) .content-wrapper > *:nth-child(5),
  body:not(.transaction-screen) .content-wrapper > [data-permission] > *:nth-child(5) { animation-delay: 280ms; }
  body:not(.transaction-screen) .content-wrapper > *:nth-child(6),
  body:not(.transaction-screen) .content-wrapper > [data-permission] > *:nth-child(6) { animation-delay: 350ms; }

  /* The global toast slides in; the success tick draws itself. Also on the entry screens: it is a toast, not part of
     the entry area, and it blocks nothing. */
  #globalToast.show {
    animation: motion-toast-in 380ms var(--ease-out);
  }
  #globalToastBody .toast-tick path {
    stroke-dasharray: 1;
    stroke-dashoffset: 1;
    animation: motion-draw 440ms var(--ease-out) 140ms forwards;
  }

  /* Loading placeholder: add class "skeleton" to anything whose text is still on its way. */
  .skeleton {
    color: transparent !important;
    border-radius: 6px;
    background: linear-gradient(90deg, #eceef2 25%, #f5f6f8 37%, #eceef2 63%);
    background-size: 400% 100%;
    animation: motion-shimmer 1.4s ease infinite;
    user-select: none;
  }
}

/* Reduced motion: no movement. The tick is simply shown, and a placeholder is a still grey block. */
@media (prefers-reduced-motion: reduce) {
  #globalToastBody .toast-tick path { stroke-dasharray: none; stroke-dashoffset: 0; }
  .skeleton {
    color: transparent !important;
    border-radius: 6px;
    background: #eceef2;
    user-select: none;
  }
}

#globalToastBody { display: block; }
#globalToastBody .toast-tick { display: inline-block; vertical-align: -3px; margin-right: 0.45rem; }

@keyframes motion-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes motion-rise { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }
@keyframes motion-toast-in { from { opacity: 0; transform: translateY(-20px) scale(0.96); } to { opacity: 1; transform: none; } }
@keyframes motion-draw { to { stroke-dashoffset: 0; } }
@keyframes motion-shimmer { from { background-position: 100% 50%; } to { background-position: 0 50%; } }

/* Dashboard setup bar: fills to its value instead of snapping. */
@media (prefers-reduced-motion: no-preference) {
  #dashboard-progress-bar { transition: width 900ms var(--ease-out); }
}

/* ── Sign-in, register, forgot and reset password (body.auth-page) ─────────────────────────────────────────
   Separate pages without the admin layout. The card rises, its parts follow one by one, the button shows a spinner
   while the request is out, and a failed attempt shakes the card (auth-motion.js). */
body.auth-page .auth-form-light .form-control { transition: border-color 0.2s ease, box-shadow 0.2s var(--ease-out); }
body.auth-page .auth-form-light .form-control:focus { box-shadow: 0 0 0 4px rgba(75, 73, 172, 0.14); }

@media (prefers-reduced-motion: no-preference) {
  body.auth-page .content-wrapper > *:nth-child(-n+6) { animation: none; }
  body.auth-page .auth-form-light { animation: auth-rise 640ms var(--ease-out) backwards; }
  body.auth-page .auth-form-light .brand-logo { animation: auth-part 560ms var(--ease-out) 120ms backwards; }
  body.auth-page .auth-form-light > h4 { animation: auth-part 560ms var(--ease-out) 200ms backwards; }
  body.auth-page .auth-form-light > h6 { animation: auth-part 560ms var(--ease-out) 260ms backwards; }
  body.auth-page .auth-form-light form > *:nth-child(1) { animation: auth-part 560ms var(--ease-out) 320ms backwards; }
  body.auth-page .auth-form-light form > *:nth-child(2) { animation: auth-part 560ms var(--ease-out) 390ms backwards; }
  body.auth-page .auth-form-light form > *:nth-child(3) { animation: auth-part 560ms var(--ease-out) 460ms backwards; }
  body.auth-page .auth-form-light form > *:nth-child(4) { animation: auth-part 560ms var(--ease-out) 530ms backwards; }
  body.auth-page .auth-form-light form > *:nth-child(n+5) { animation: auth-part 560ms var(--ease-out) 600ms backwards; }

  body.auth-page .auth-form-light.auth-shake { animation: auth-shake 440ms cubic-bezier(0.36, 0.07, 0.19, 0.97); }

  body.auth-page .btn.is-loading { position: relative; color: transparent !important; pointer-events: none; }
  body.auth-page .btn.is-loading::after {
    content: ""; position: absolute; left: 50%; top: 50%; width: 20px; height: 20px; margin: -10px 0 0 -10px;
    border: 2.5px solid rgba(255, 255, 255, 0.45); border-top-color: #fff; border-radius: 50%;
    animation: auth-spin 700ms linear infinite;
  }
}
@media (prefers-reduced-motion: no-preference) {
  /* Success: the spinner becomes a tick, then the whole card lifts away before the next page. */
  body.auth-page .btn.is-done { position: relative; color: transparent !important; pointer-events: none; }
  body.auth-page .btn.is-done .auth-tick { position: absolute; left: 50%; top: 50%; width: 26px; height: 26px; margin: -13px 0 0 -13px; }
  body.auth-page .btn.is-done .auth-tick path { stroke-dasharray: 1; stroke-dashoffset: 1; animation: motion-draw 380ms var(--ease-out) forwards; }
  body.auth-page .auth-form-light.auth-leaving { animation: auth-leave 380ms var(--ease-out) forwards; pointer-events: none; }
}
@media (prefers-reduced-motion: reduce) {
  body.auth-page .btn.is-loading { opacity: 0.7; pointer-events: none; }
}

@keyframes auth-rise { from { opacity: 0; transform: translateY(32px) scale(0.97); } to { opacity: 1; transform: none; } }
@keyframes auth-part { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes auth-shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(5px); }
  30%, 50%, 70% { transform: translateX(-9px); }
  40%, 60% { transform: translateX(9px); }
}
@keyframes auth-spin { to { transform: rotate(360deg); } }
@keyframes auth-leave { to { opacity: 0; transform: translateY(-22px) scale(0.97); } }
