/* ==========================================================================
   444 NETWORK — GLOBAL MOTION LAYER  (landing • client portal • admin console)
   Loaded on every page through partials/head-seo.ejs.
   Rules: transform / opacity only (GPU), one-shot animations use `backwards`
   fill so elements return to their natural styles afterwards, and everything
   is disabled for users who prefer reduced motion.
   ========================================================================== */

:root {
  --mg-ease: cubic-bezier(0.16, 1, 0.3, 1);
  --mg-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* 1. Reading progress / navigation loading bar ---------------------------- */
.mg-progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  z-index: 100001;
  pointer-events: none;
  transform-origin: 0 50%;
  transform: scaleX(var(--mg-p, 0));
  background: linear-gradient(90deg, #4F46E5, #0EA5E9, #D946EF);
  box-shadow: 0 0 10px rgba(79, 70, 229, 0.5);
  opacity: 0;
  transition: opacity 0.25s ease;
}
.mg-progress.is-on { opacity: 1; }
.mg-progress.is-loading {
  opacity: 1;
  transform: scaleX(1);
  background: linear-gradient(90deg, #4F46E5, #0EA5E9, #D946EF, #4F46E5);
  background-size: 200% 100%;
  animation: mgBarLoad 0.9s linear infinite;
}
@keyframes mgBarLoad { to { background-position: -200% 0; } }

/* 2. Page enter / leave --------------------------------------------------- */
@keyframes mgPageIn {
  from { opacity: 0; transform: translate3d(0, 16px, 0); }
}
main { animation: mgPageIn 0.6s var(--mg-ease) backwards; }

body.mg-leaving main {
  opacity: 0;
  transform: translate3d(0, -8px, 0) scale(0.992);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

/* 3. Scroll reveal (classes are added by motion-global.js) --------------- */
.mg-pre {
  opacity: 0 !important;
  transform: translate3d(0, 28px, 0) scale(0.985) !important;
}
.mg-pre.mg-zoom { transform: translate3d(0, 18px, 0) scale(0.94) !important; }
.mg-pre.mg-blur { transform: translate3d(0, 14px, 0) !important; filter: blur(8px); }

.mg-play { animation: mgUp 0.8s var(--mg-ease) var(--mg-d, 0ms) backwards; }
.mg-play.mg-zoom { animation-name: mgZoom; animation-timing-function: var(--mg-spring); animation-duration: 0.7s; }
.mg-play.mg-blur { animation-name: mgBlur; }

@keyframes mgUp   { from { opacity: 0; transform: translate3d(0, 28px, 0) scale(0.985); } }
@keyframes mgZoom { from { opacity: 0; transform: translate3d(0, 18px, 0) scale(0.94); } }
@keyframes mgBlur { from { opacity: 0; transform: translate3d(0, 14px, 0); filter: blur(8px); } }

/* Hero heading: crisp spring rise without text-blurring or DOM word splitting */
.mg-hero {
  animation: mgHeroIn 0.55s var(--mg-ease) backwards;
}
@keyframes mgHeroIn {
  from { opacity: 0; transform: translate3d(0, 10px, 0); }
}

/* Admin table rows cascade */
.admin-table tbody tr.mg-row {
  animation: mgRow 0.55s var(--mg-ease) backwards;
  animation-delay: calc(var(--r, 0) * 38ms);
}
@keyframes mgRow { from { opacity: 0; transform: translate3d(-14px, 0, 0); } }

.admin-table tbody tr td:first-child { transition: box-shadow 0.25s ease; }
.admin-table tbody tr:hover td:first-child { box-shadow: inset 3px 0 0 var(--brand-indigo, #4F46E5); }

/* 4. Buttons -------------------------------------------------------------- */
.btn-primary,
.hero-btn-primary,
.apple-btn-ios-primary,
.uol-cta-btn { position: relative; overflow: hidden; }

.btn-primary::after,
.hero-btn-primary::after,
.apple-btn-ios-primary::after,
.uol-cta-btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(105deg, transparent 32%, rgba(255, 255, 255, 0.42) 50%, transparent 68%);
  transform: translate3d(-130%, 0, 0);
  pointer-events: none;
}
.btn-primary:hover::after,
.btn-primary:focus-visible::after,
.btn-primary:active::after,
.hero-btn-primary:hover::after,
.hero-btn-primary:active::after,
.apple-btn-ios-primary:hover::after,
.apple-btn-ios-primary:active::after,
.uol-cta-btn:hover::after,
.uol-cta-btn:active::after {
  transform: translate3d(130%, 0, 0);
  transition: transform 0.75s var(--mg-ease);
}
/* idle sheen only on flagship call-to-actions */
.hero-btn-primary::after,
.apple-btn-ios-primary::after,
.uol-cta-btn::after { animation: mgSheen 5.2s var(--mg-ease) 1.4s infinite; }
@keyframes mgSheen {
  0%, 70% { transform: translate3d(-130%, 0, 0); }
  100% { transform: translate3d(130%, 0, 0); }
}

/* Submit / action loading state */
.mg-loading { pointer-events: none; opacity: 0.88; }
.mg-loading::before {
  content: '';
  position: absolute;
  right: 14px;
  top: 50%;
  width: 16px;
  height: 16px;
  margin-top: -8px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: mgSpin 0.7s linear infinite;
}
@keyframes mgSpin { to { transform: rotate(360deg); } }

/* Press feedback for tappable cards & nav */
a.spotlight-card:active,
a.glass-panel:active,
.drawer-link:active,
.admin-menu-toggle-btn:active,
.mobile-drawer-toggle-btn:active,
.nav-item:active { transform: scale(0.97) !important; }

/* 5. Forms ---------------------------------------------------------------- */
.form-label { transition: color 0.2s ease, transform 0.3s var(--mg-ease); }
.form-group:focus-within .form-label { color: var(--brand-indigo, #4F46E5); transform: translateX(3px); }

.mg-shake { animation: mgShake 0.45s cubic-bezier(0.36, 0.07, 0.19, 0.97); border-color: #EF4444 !important; box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.14) !important; }
@keyframes mgShake {
  10%, 90% { transform: translate3d(-1px, 0, 0); }
  20%, 80% { transform: translate3d(3px, 0, 0); }
  30%, 50%, 70% { transform: translate3d(-5px, 0, 0); }
  40%, 60% { transform: translate3d(5px, 0, 0); }
}

/* 6. Navigation ----------------------------------------------------------- */
.mobile-top-bar { transition: background 0.3s ease, box-shadow 0.3s ease; }
.mobile-top-bar.mg-scrolled {
  background: rgba(255, 255, 255, 0.93);
  box-shadow: inset 0 -1px 0 0 rgba(0, 0, 0, 0.04), 0 10px 30px -6px rgba(15, 23, 42, 0.12);
}

/* Liquid pill that glides between bottom-nav tabs */
.mobile-bottom-nav .mg-nav-pill {
  position: absolute;
  top: 50%;
  left: 0;
  width: 60px;
  height: 46px;
  margin-top: -23px;
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(59, 130, 246, 0.18), rgba(99, 102, 241, 0.1));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.85), 0 8px 18px -6px rgba(37, 99, 235, 0.35);
  transform: translate3d(0, 0, 0);
  transition: transform 0.5s var(--mg-spring), width 0.5s var(--mg-spring);
  pointer-events: none;
  z-index: 0;
}
.mobile-bottom-nav .mg-nav-pill.mg-instant { transition: none; }
.mobile-bottom-nav.mg-has-pill .nav-item { z-index: 1; }
.mobile-bottom-nav.mg-has-pill .nav-item.active { background: transparent; }

/* Drawer & admin sidebar cascade when opened */
.public-mobile-drawer.open .drawer-group,
.public-mobile-drawer.open .public-drawer-footer,
#adminSidebar.open #adminNavList > * {
  animation: mgDrawerItem 0.55s var(--mg-ease) backwards;
  animation-delay: calc(var(--i, 0) * 55ms + 110ms);
}
@keyframes mgDrawerItem { from { opacity: 0; transform: translate3d(0, 16px, 0); } }

/* 7. Modals: spring card, bottom-sheet on phones -------------------------- */
.admin-modal-overlay { animation: mgFade 0.28s ease; }
.admin-modal-card { animation: mgPop 0.5s var(--mg-spring); }
@keyframes mgFade { from { opacity: 0; } }
@keyframes mgPop { from { opacity: 0; transform: translate3d(0, 22px, 0) scale(0.94); } }
@keyframes mgSheet { from { transform: translate3d(0, 100%, 0); } }

@media (max-width: 640px) {
  .admin-modal-overlay { align-items: flex-end !important; padding: 0 !important; }
  .admin-modal-card {
    max-height: 92vh !important;
    border-radius: 26px 26px 0 0 !important;
    padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px)) !important;
    animation: mgSheet 0.55s var(--mg-ease);
  }
  .admin-modal-card::before {
    content: '';
    display: block;
    width: 38px;
    height: 5px;
    border-radius: 9999px;
    background: rgba(100, 116, 139, 0.35);
    margin: -8px auto 14px auto;
  }
}

/* 8. Toasts --------------------------------------------------------------- */
.mg-toast-stack {
  position: fixed;
  left: 0;
  right: 0;
  top: calc(env(safe-area-inset-top, 0px) + 12px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  z-index: 100002;
  pointer-events: none;
}
.mg-toast {
  position: relative;
  overflow: hidden;
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 440px;
  padding: 12px 14px 14px 12px;
  border-radius: 18px;
  background: rgba(15, 23, 42, 0.9);
  color: #FFFFFF;
  font-family: var(--font-body, system-ui, sans-serif);
  font-size: 0.86rem;
  font-weight: 600;
  line-height: 1.4;
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  backdrop-filter: blur(20px) saturate(180%);
  box-shadow: 0 18px 40px -10px rgba(15, 23, 42, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.12);
  animation: mgToastIn 0.55s var(--mg-spring) backwards;
}
.mg-toast.is-out { animation: mgToastOut 0.32s ease forwards; }
.mg-toast-ico {
  width: 28px;
  height: 28px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.12);
}
.mg-toast-ico svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.mg-toast.success .mg-toast-ico { background: rgba(52, 211, 153, 0.2); color: #34D399; }
.mg-toast.error .mg-toast-ico { background: rgba(248, 113, 113, 0.2); color: #F87171; }
.mg-toast.info .mg-toast-ico { background: rgba(96, 165, 250, 0.2); color: #60A5FA; }
.mg-toast-msg { flex: 1; min-width: 0; word-break: break-word; }
.mg-toast-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
  transform-origin: 0 50%;
  background: linear-gradient(90deg, #6366F1, #0EA5E9);
  animation: mgToastBar var(--mg-life, 4.5s) linear forwards;
}
.mg-toast.success .mg-toast-bar { background: #34D399; }
.mg-toast.error .mg-toast-bar { background: #F87171; }
@keyframes mgToastIn { from { opacity: 0; transform: translate3d(0, -26px, 0) scale(0.9); } }
@keyframes mgToastOut { to { opacity: 0; transform: translate3d(0, -18px, 0) scale(0.94); } }
@keyframes mgToastBar { to { transform: scaleX(0); } }

/* 9. Ambient layer: parallax container, cursor glow, touch halo ----------- */
.motion-viewport { inset: -30px; will-change: transform; }

.mg-cursor-glow {
  position: absolute;
  left: 0;
  top: 0;
  width: 460px;
  height: 460px;
  margin: -230px 0 0 -230px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(99, 102, 241, 0.17) 0%, rgba(14, 165, 233, 0.08) 42%, transparent 70%);
  transform: translate3d(-999px, -999px, 0);
  opacity: 0;
  transition: opacity 0.5s ease;
  will-change: transform;
  pointer-events: none;
}
.mg-cursor-glow.on { opacity: 1; }

.mg-halo {
  position: fixed;
  width: 120px;
  height: 120px;
  margin: -60px 0 0 -60px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(99, 102, 241, 0.26) 0%, rgba(14, 165, 233, 0.12) 45%, transparent 70%);
  pointer-events: none;
  z-index: 99998;
  animation: mgHalo 0.7s var(--mg-ease) forwards;
}
@keyframes mgHalo {
  from { opacity: 1; transform: scale(0.3); }
  to { opacity: 0; transform: scale(1.7); }
}

/* 10. Utilities ----------------------------------------------------------- */
.mg-skeleton {
  color: transparent !important;
  background: linear-gradient(90deg, #EEF2FF 25%, #F8FAFC 37%, #EEF2FF 63%);
  background-size: 400% 100%;
  animation: mgShimmer 1.4s ease infinite;
  border-radius: 12px;
}
@keyframes mgShimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

.battery-saver-active .mg-cursor-glow,
.battery-saver-active .mg-halo { display: none; }

/* 11. Reduced motion ------------------------------------------------------ */
@media (prefers-reduced-motion: reduce) {
  .mg-pre { opacity: 1 !important; transform: none !important; filter: none !important; }
  main, .mg-play, .mg-hero, .mg-word, .mg-row, .mg-toast,
  .admin-modal-overlay, .admin-modal-card, .mg-halo,
  .btn-primary::after, .hero-btn-primary::after,
  .apple-btn-ios-primary::after, .uol-cta-btn::after { animation: none !important; }
  .mg-cursor-glow, .mg-halo { display: none !important; }
  .mobile-bottom-nav .mg-nav-pill { transition: none; }
}
