/*
 * Cenaris logo loader.
 *
 * Draws the Cenaris mark (app/static/images/cenaris-mark*.svg, traced from Logo_NoBackground.png) as a loading
 * animation: the colour slides in from the left across the logo, holds, then slides out the right. Pure CSS.
 *
 * Two uses:
 *   1. <span class="cn-loader" aria-hidden="true"></span>        small / inline (faint logo + colour sweep)
 *      <span class="cn-loader cn-loader--outline"></span>        large (outline only, colour sweeps in)
 *      Size comes from --cn-size (default 1em). Colour is currentColor (brand blue unless a parent sets `color`).
 *   2. Every Bootstrap .spinner-border and the global .btn.loading spinner, but only when <body> carries
 *      data-brand-loader. base.html leaves that attribute off the AI Review, Gap Analysis, Compliance Requirements
 *      (auto-link) and Policy Studio pages, so those keep the stock Bootstrap spinner. See docs/standards/ui-rules.md.
 *
 * Reduced motion: the sweep becomes a slow fade.
 */

:root {
  --cn-loader-color: #1a94e7;
}

@keyframes cn-sweep {
  0%   { clip-path: inset(0 100% 0 0); }
  45%  { clip-path: inset(0 0 0 0); }
  55%  { clip-path: inset(0 0 0 0); }
  100% { clip-path: inset(0 0 0 100%); }
}

@keyframes cn-pulse {
  0%, 100% { opacity: 0.35; }
  50%      { opacity: 1; }
}

/* ---- the component and the Bootstrap spinners it replaces share one shape ---- */
.cn-loader,
body[data-brand-loader] .spinner-border {
  position: relative;
  display: inline-block;
  vertical-align: -0.125em;
  border: 0;
  border-radius: 0;
  background: none;
  animation: none;
}

.cn-loader {
  width: var(--cn-size, 1em);
  height: var(--cn-size, 1em);
  color: var(--cn-loader-color);
}

.cn-loader::before,
.cn-loader::after,
body[data-brand-loader] .spinner-border::before,
body[data-brand-loader] .spinner-border::after {
  content: "";
  position: absolute;
  inset: 0;
  background-color: currentColor;
  -webkit-mask: url("../images/cenaris-mark.svg") center / contain no-repeat;
  mask: url("../images/cenaris-mark.svg") center / contain no-repeat;
}

/* faint logo underneath ... */
.cn-loader::before,
body[data-brand-loader] .spinner-border::before {
  opacity: 0.25;
}

/* ... and the colour that slides across it */
.cn-loader::after,
body[data-brand-loader] .spinner-border::after {
  animation: cn-sweep var(--cn-speed, 2s) cubic-bezier(0.65, 0, 0.35, 1) infinite both;
}

/* ---- large version: outline only, then the colour slides in ---- */
.cn-loader--outline::before {
  opacity: 1;
  -webkit-mask-image: url("../images/cenaris-mark-outline.svg");
  mask-image: url("../images/cenaris-mark-outline.svg");
}

.cn-loader--outline::after {
  -webkit-mask-image: url("../images/cenaris-mark-bold.svg");
  mask-image: url("../images/cenaris-mark-bold.svg");
  --cn-speed: 2.8s;
}

/* ---- global "button is busy" spinner (rule lives in base.html as .btn.loading) ---- */
body[data-brand-loader] .btn.loading::before,
body[data-brand-loader] .btn.loading::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 18px;
  height: 18px;
  margin: -9px 0 0 -9px;
  border: 0;
  border-radius: 0;
  background-color: #ffffff;
  -webkit-mask: url("../images/cenaris-mark.svg") center / contain no-repeat;
  mask: url("../images/cenaris-mark.svg") center / contain no-repeat;
}

body[data-brand-loader] .btn.loading::before {
  opacity: 0.3;
}

body[data-brand-loader] .btn.loading::after {
  animation: cn-sweep 1.8s cubic-bezier(0.65, 0, 0.35, 1) infinite both;
}

/* ---- full-page splash (login and the first dashboard load) ---- */
.cn-splash {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bs-body-bg, #ffffff);
  transition: opacity 0.35s ease, visibility 0.35s ease;
  /* Failsafe: if cenaris-splash.js never runs (blocked, 404, error), the splash still goes away after 10 s. */
  animation: cn-splash-failsafe 0s linear 10s forwards;
}

@keyframes cn-splash-failsafe {
  to { opacity: 0; visibility: hidden; pointer-events: none; }
}

.cn-splash .cn-loader {
  --cn-size: clamp(88px, 16vw, 132px);
}

.cn-splash.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
  .cn-loader::after,
  body[data-brand-loader] .spinner-border::after,
  body[data-brand-loader] .btn.loading::after {
    animation: cn-pulse 1.8s ease-in-out infinite both;
    clip-path: none;
  }

  .cn-splash {
    transition: none;
  }
}
