/* ==========================================================================
   UMS Centralized Loading / Processing System
   LoadingService -> GlobalLoadingOverlay -> SectionLoader -> ButtonLoadingState -> InlineLoader
   Uses the same --primary / --accent / --gradient / --app-font tokens as the
   rest of the app so the loader automatically matches each role's theme.

   This file is pure CSS -- every element it styles is already emitted by
   loading.js as-is (no new markup, no new classes required from JS). Only
   the visual language changed; every DOM hook, class name and animation
   trigger loading.js relies on is untouched.
   ========================================================================== */

/* ---------- Core spinner unit (gradient comet-ring, counter-rotating) ----
   A conic-gradient ring masked to a hollow donut reads as considerably
   more premium than a bordered circle, while staying pure CSS -- no SVG,
   no Lottie runtime, nothing extra to load or cache. Two rings counter-
   rotate at different speeds and radii for depth, in the brand's two
   accent tones by default.

   Colours are custom properties rather than literal border-colors, so a
   context (a filled button, a themed card) can restyle the spinner by
   overriding two variables instead of re-declaring every rule -- see the
   button-loading overrides below. */
.ums-spin {
  --spin-c1: var(--primary, #6C5CE7);
  --spin-c2: var(--accent, #e84393);
  position: relative;
  display: inline-block;
  flex-shrink: 0;
}
.ums-spin::before,
.ums-spin::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: conic-gradient(
    from 0deg,
    transparent 0deg,
    transparent 30deg,
    var(--spin-c1) 150deg,
    var(--spin-c1) 190deg,
    transparent 360deg
  );
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 3px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 3px));
}
.ums-spin::before {
  animation: ums-orbit-a .95s cubic-bezier(.5, .05, .5, .95) infinite;
}
.ums-spin::after {
  inset: 22%;
  background: conic-gradient(
    from 180deg,
    transparent 0deg,
    transparent 30deg,
    var(--spin-c2) 150deg,
    var(--spin-c2) 190deg,
    transparent 360deg
  );
  animation: ums-orbit-b .75s cubic-bezier(.5, .05, .5, .95) infinite reverse;
}

.ums-spin-sm { width: 16px; height: 16px; }
.ums-spin-sm::before, .ums-spin-sm::after {
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 2px), #000 calc(100% - 2px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 2px), #000 calc(100% - 2px));
}
.ums-spin-md { width: 30px; height: 30px; }
.ums-spin-lg { width: 52px; height: 52px; }

@keyframes ums-orbit-a {
  to { transform: rotate(360deg); }
}
@keyframes ums-orbit-b {
  to { transform: rotate(360deg); }
}

/* Soft ambient glow behind the larger spinner sizes only (overlay/section) --
   a subtle premium-SaaS touch, not applied to button/inline spinners so it
   never adds render cost to the buttons used everywhere. */
.ums-loader-halo {
  position: relative;
  display: inline-flex;
}
.ums-loader-halo::before {
  content: '';
  position: absolute;
  inset: -18px;
  border-radius: 50%;
  background: var(--gradient, linear-gradient(135deg, #6C5CE7, #8f7bff));
  filter: blur(20px);
  opacity: .22;
  animation: ums-halo-pulse 1.6s ease-in-out infinite;
}
@keyframes ums-halo-pulse {
  0%, 100% { opacity: .16; transform: scale(.9); }
  50% { opacity: .3; transform: scale(1.06); }
}

/* ---------- Global full-screen overlay ---------- */
#umsGlobalLoader {
  position: fixed;
  inset: 0;
  z-index: 99990; /* below the 99999 system status/lockdown banner, above all app content */
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(15, 18, 32, .42);
  backdrop-filter: blur(7px) saturate(1.3);
  -webkit-backdrop-filter: blur(7px) saturate(1.3);
}
#umsGlobalLoader.active {
  display: flex;
  animation: ums-backdrop-in .18s ease;
}
@keyframes ums-backdrop-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ---------- Processing card: frosted glass with a 1px gradient edge ------
   The gradient border is a padding-box/border-box double-background trick
   -- no extra wrapper element needed, so loading.js's existing markup
   (.ums-loader-card > .ums-loader-halo + .ums-loader-text) needs no
   changes at all. A faint top hairline highlight and a layered shadow
   are what read as "considered glass" rather than a flat white box. */
.ums-loader-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  padding: 34px 40px;
  min-width: 220px;
  background:
    linear-gradient(#fff, #fff) padding-box,
    var(--gradient, linear-gradient(135deg, #6C5CE7, #8f7bff)) border-box;
  border: 1px solid transparent;
  border-radius: 22px;
  box-shadow:
    0 28px 60px -12px rgba(20, 15, 45, .3),
    0 8px 20px -6px rgba(20, 15, 45, .16),
    inset 0 1px 0 rgba(255, 255, 255, .9);
  animation: ums-pop-in .26s cubic-bezier(.22, 1, .36, 1);
}
@keyframes ums-pop-in {
  from { opacity: 0; transform: scale(.88) translateY(6px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.ums-loader-text {
  font-family: var(--app-font, 'Quicksand', sans-serif);
  font-weight: 600;
  font-size: .96rem;
  color: #1c1c28;
  text-align: center;
  letter-spacing: .01em;
}

/* ---------- Section / local loader (relative-positioned container) ---------- */
.ums-section-loading {
  position: relative;
  min-height: 80px;
}
.ums-section-loader {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: rgba(255, 255, 255, .88);
  backdrop-filter: blur(1.5px);
  -webkit-backdrop-filter: blur(1.5px);
  border-radius: inherit;
}
.ums-section-loader .ums-loader-text {
  font-size: .82rem;
  color: #555;
}

/* ---------- Button processing state ---------- */
.ums-btn-loading {
  position: relative;
  pointer-events: none;
  opacity: .85;
}
.ums-btn-loading .ums-btn-label {
  visibility: hidden;
}
.ums-btn-loading .ums-spin {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  --spin-c1: #fff;
  --spin-c2: rgba(255, 255, 255, .6);
}
.ums-btn-loading.btn-outline-primary .ums-spin,
.ums-btn-loading.btn-outline-danger .ums-spin,
.ums-btn-loading.btn-light .ums-spin {
  --spin-c1: var(--primary, #6C5CE7);
  --spin-c2: var(--accent, #e84393);
}

/* ---------- Inline loader (small, for search boxes / dropdowns / filters) --- */
.ums-inline-loader {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--app-font, 'Quicksand', sans-serif);
  font-size: .8rem;
  color: #6a6a7a;
}

/* ---------- Reduced motion: no spin, no pop, keep a static, visible state ---------- */
@media (prefers-reduced-motion: reduce) {
  .ums-spin::before,
  .ums-spin::after {
    animation: none;
  }
  .ums-loader-halo::before {
    animation: none;
    opacity: .18;
  }
  #umsGlobalLoader.active,
  .ums-loader-card {
    animation: none;
  }
}
