/* OCMS motion layer: portal, upload, sign-in and condition report pages.
   Purely visual. Loaded after portal.css; motion.js adds the classes and CSS variables used here.
   Every moving part sits inside the no-preference media query, so "reduce motion" users get a still page.
   Animations only use transform, opacity and filter so they stay on the GPU and do not slow the page. */

/* ---------- always on (static styling the effects build on) ---------- */
main, .tabs { position: relative; z-index: 1; }

/* top progress bar while the portal talks to the server */
.mo-loadbar {
  position: fixed; left: 0; top: 0; height: 2px; width: 100%; z-index: 120; pointer-events: none;
  transform-origin: 0 50%; transform: scaleX(0); opacity: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent2), #ff7ad9, var(--accent));
  background-size: 200% 100%;
  box-shadow: 0 0 12px rgba(61, 224, 255, .8), 0 0 4px rgba(124, 92, 255, .9);
}

/* ripple host sits inside buttons, tabs and tiles; clips the ripple to the element's shape */
.mo-ink { position: absolute; inset: 0; border-radius: inherit; overflow: hidden; pointer-events: none; z-index: 0; }
.mo-ink > i {
  position: absolute; width: 10px; height: 10px; margin: -5px 0 0 -5px; border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, .55), rgba(61, 224, 255, .25) 45%, transparent 70%);
  transform: scale(0); opacity: 0;
}

/* coverage ring on the "Points with footage" tile */
.tile.mo-has-ring { padding-right: 72px; }
.mo-ring { position: absolute; right: 14px; top: 50%; width: 46px; height: 46px; margin-top: -23px; transform: rotate(-90deg); }
.mo-ring circle { fill: none; stroke-width: 5; }
.mo-ring .track { stroke: rgba(125, 200, 255, .12); }
.mo-ring .fill { stroke: url(#moRingGrad); stroke-linecap: round; filter: drop-shadow(0 0 4px rgba(61, 224, 255, .7)); transition: stroke-dashoffset 1.3s var(--ease); }
.mo-ring-pct { position: absolute; right: 14px; top: 50%; width: 46px; margin-top: -7px; text-align: center; font: 600 10px/14px var(--font-mono); color: #bfefff; }

/* timeline line is drawn with this element so it can grow */
.timeline { position: relative; }

/* ---------- motion (skipped entirely when the viewer asks for reduced motion) ---------- */
@media (prefers-reduced-motion: no-preference) {

  /* drifting aurora light behind the whole page */
  body::before {
    content: ""; position: fixed; inset: -25vmax; z-index: 0; pointer-events: none;
    background:
      radial-gradient(28vmax 22vmax at 22% 30%, rgba(61, 224, 255, .10), transparent 70%),
      radial-gradient(30vmax 24vmax at 78% 24%, rgba(124, 92, 255, .12), transparent 70%),
      radial-gradient(26vmax 20vmax at 60% 78%, rgba(255, 122, 217, .06), transparent 70%);
    animation: mo-aurora 38s ease-in-out infinite alternate;
    will-change: transform;
  }

  /* first paint: header drops in, tabs and content follow */
  .top { animation: mo-drop .6s var(--ease) both; }
  .tabs { animation: mo-fade .6s .12s var(--ease) both; }
  .top nav a, .tabs a { animation: mo-rise .5s var(--ease) both; animation-delay: calc(.14s + var(--mo-i, 0) * 45ms); }
  .brand::before { animation: mo-spin 14s linear infinite; }
  .brand:hover::before { animation-duration: 2.4s; }

  /* the portal's own section fade is replaced by the cascade below */
  main > section.mo-cascade:not([hidden]) { animation: none; }

  /* cascade: tiles, cards, toolbars and table rows rise into place one after another */
  .mo-enter { animation: mo-rise-in .62s var(--ease) both; animation-delay: calc(var(--mo-d, 0) * 1ms); }
  .mo-wait { opacity: 0; }
  tr.mo-enter { animation-name: mo-row-in; animation-duration: .45s; }
  .tile.mo-enter { animation-name: mo-tile-in; animation-duration: .75s; }

  /* rows that are new since the last refresh glow once */
  tr.mo-new > td { animation: mo-new-row 2.4s ease-out both; }
  .list-item.mo-new { animation: mo-new-row 2.4s ease-out both; }

  /* a KPI that changed on refresh flashes */
  .tile.mo-changed { animation: mo-bump .9s var(--ease) both; }
  .tile.mo-changed b { animation: mo-glow-text 1.4s ease-out both; }

  /* tiles tilt toward the pointer (motion.js sets --rx / --ry) */
  .tile.mo-tilt:hover {
    transform: perspective(700px) translateY(-4px) rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg));
    transition: transform .12s linear, border-color .25s, box-shadow .25s;
  }

  /* "Need attention" tile breathes amber while it is above zero */
  #tiles .tile.alert { animation: mo-alert 2.6s ease-in-out infinite; }
  #tiles .tile.alert.mo-enter { animation: mo-tile-in .75s var(--ease) both, mo-alert 2.6s 1s ease-in-out infinite; animation-delay: calc(var(--mo-d, 0) * 1ms), 1s; }

  /* ring gauge sweeps in */
  .mo-ring .fill { animation: mo-ring-in 1.4s var(--ease) both; }

  /* severity meters get a travelling highlight */
  .sev-meter i::after {
    content: ""; position: absolute; inset: 0; border-radius: inherit;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .45), transparent);
    background-size: 40% 100%; background-repeat: no-repeat;
    animation: mo-sweep 2.8s 1s ease-in-out infinite;
  }

  /* work in progress: chips and status text that mean "running" get a moving sheen */
  .chip.mo-busy { position: relative; overflow: hidden; }
  .chip.mo-busy::after {
    content: ""; position: absolute; inset: 0; pointer-events: none;
    background: linear-gradient(100deg, transparent 30%, rgba(255, 255, 255, .28) 50%, transparent 70%);
    background-size: 250% 100%; animation: mo-sheen 1.8s linear infinite;
  }
  select.mo-progress { border-color: rgba(212, 167, 44, .55); animation: mo-alert 2.6s ease-in-out infinite; }

  /* upload bars: animated stripes until finished */
  .bar i { position: relative; overflow: hidden; }
  .bar i::after {
    content: ""; position: absolute; inset: 0;
    background: repeating-linear-gradient(115deg, rgba(255, 255, 255, .22) 0 8px, transparent 8px 16px);
    background-size: 32px 100%; animation: mo-stripes .7s linear infinite;
  }
  .bar i[style*="width: 100%"]::after, .bar i[style*="width:100%"]::after { animation: none; opacity: 0; transition: opacity .4s; }

  /* press ripple */
  .mo-ink > i { animation: mo-ripple .65s cubic-bezier(.2, .7, .3, 1) forwards; }
  button:active:not(:disabled), .button:active { transform: translateY(0) scale(.97); }

  /* dialogs: blurred backdrop fades in, contents cascade */
  dialog[open]::backdrop { animation: mo-backdrop .35s ease both; }
  dialog[open] { animation: mo-dialog-in .42s cubic-bezier(.2, 1.1, .3, 1) both; }

  /* repair and reference point history: the line draws down and each event pops in */
  .timeline.mo-draw { border-image: none; }
  .timeline.mo-draw::before {
    content: ""; position: absolute; left: -2px; top: 0; bottom: 0; width: 2px; transform-origin: 50% 0;
    background: linear-gradient(var(--accent), rgba(124, 92, 255, .5), transparent);
    animation: mo-line .9s var(--ease) both;
  }
  .timeline.mo-draw li { animation: mo-event-in .5s var(--ease) both; animation-delay: calc(120ms + var(--mo-i, 0) * 70ms); }
  .timeline.mo-draw li::before { animation: mo-dot-in .5s cubic-bezier(.3, 1.6, .5, 1) both; animation-delay: calc(160ms + var(--mo-i, 0) * 70ms); }

  /* toast slides with a little spring */
  #flash.flash:not([hidden]) { animation: mo-toast .55s cubic-bezier(.2, 1.3, .35, 1) both; }

  /* empty-state cards float gently */
  div.card.empty:not([hidden]) { animation: mo-rise-in .6s var(--ease) both, mo-float 6s 1s ease-in-out infinite; }

  /* sign-in card: a light trace runs around the border */
  form.card.form#form { isolation: isolate; }
  .mo-trace { position: absolute; inset: -1px; border-radius: inherit; pointer-events: none; z-index: -1; padding: 1px;
    background: conic-gradient(from var(--mo-a, 0deg), transparent 0 70%, rgba(61, 224, 255, .9) 82%, rgba(124, 92, 255, .9) 90%, transparent 100%);
    -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0); -webkit-mask-composite: xor;
            mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
    animation: mo-trace 5s linear infinite; }
}

@property --mo-a { syntax: "<angle>"; inherits: false; initial-value: 0deg; }

@keyframes mo-aurora {
  0% { transform: translate3d(0, 0, 0) rotate(0deg) scale(1); }
  50% { transform: translate3d(4vmax, -3vmax, 0) rotate(8deg) scale(1.08); }
  100% { transform: translate3d(-3vmax, 2vmax, 0) rotate(-6deg) scale(1.02); }
}
@keyframes mo-drop { from { opacity: 0; transform: translateY(-100%); } to { opacity: 1; transform: none; } }
@keyframes mo-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes mo-rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes mo-spin { to { transform: rotate(360deg); } }
@keyframes mo-rise-in {
  from { opacity: 0; transform: translateY(18px) scale(.985); filter: blur(4px); }
  to { opacity: 1; transform: none; filter: none; }
}
@keyframes mo-tile-in {
  0% { opacity: 0; transform: perspective(700px) translateY(22px) rotateX(18deg) scale(.96); filter: blur(5px); }
  60% { opacity: 1; filter: none; }
  100% { opacity: 1; transform: none; }
}
@keyframes mo-row-in { from { opacity: 0; transform: translateX(-10px); } to { opacity: 1; transform: none; } }
@keyframes mo-new-row {
  0%, 25% { background-color: rgba(61, 224, 255, .16); box-shadow: inset 3px 0 0 var(--accent); }
  100% { background-color: transparent; box-shadow: inset 0 0 0 transparent; }
}
@keyframes mo-bump { 0% { transform: scale(1); } 30% { transform: scale(1.04); box-shadow: 0 0 0 1px rgba(61, 224, 255, .5), 0 0 34px -6px rgba(61, 224, 255, .8); } 100% { transform: none; } }
@keyframes mo-glow-text { 0% { filter: drop-shadow(0 0 10px rgba(61, 224, 255, .95)); } 100% { filter: none; } }
@keyframes mo-alert {
  0%, 100% { box-shadow: var(--shadow), 0 0 0 1px rgba(212, 167, 44, .18), 0 0 0 0 rgba(212, 167, 44, 0); }
  50% { box-shadow: var(--shadow), 0 0 0 1px rgba(212, 167, 44, .55), 0 0 30px -4px rgba(212, 167, 44, .55); }
}
@keyframes mo-ring-in { from { stroke-dashoffset: var(--mo-len, 126); } }
@keyframes mo-sweep { 0% { background-position: -60% 0; } 60%, 100% { background-position: 160% 0; } }
@keyframes mo-sheen { from { background-position: 150% 0; } to { background-position: -100% 0; } }
@keyframes mo-stripes { to { background-position: 32px 0; } }
@keyframes mo-ripple { 0% { transform: scale(0); opacity: .9; } 100% { transform: scale(var(--mo-s, 30)); opacity: 0; } }
@keyframes mo-backdrop { from { opacity: 0; backdrop-filter: blur(0); } to { opacity: 1; } }
@keyframes mo-dialog-in { from { opacity: 0; transform: translateY(24px) scale(.94); filter: blur(6px); } to { opacity: 1; transform: none; filter: none; } }
@keyframes mo-line { from { transform: scaleY(0); } to { transform: scaleY(1); } }
@keyframes mo-event-in { from { opacity: 0; transform: translateX(14px); } to { opacity: 1; transform: none; } }
@keyframes mo-dot-in { from { transform: scale(0); } to { transform: scale(1); } }
@keyframes mo-toast { from { opacity: 0; transform: translateY(-18px) scale(.92); } to { opacity: 1; transform: none; } }
@keyframes mo-float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }
@keyframes mo-trace { to { --mo-a: 360deg; } }

@media print {
  body::before, .mo-loadbar, .mo-ink, .mo-trace { display: none !important; }
  .mo-wait { opacity: 1 !important; }
}
