/* ==================================================================
   E-Academy — loader
   ------------------------------------------------------------------
   Its own file because both stylesheets need it: the dashboard loads
   app.css, the credential screens load login.css, and a component
   copied into two files drifts apart the first time one of them is
   touched.

   It takes no colours of its own. Every ring reads the palette of
   whichever page it lands on, which is why the theme switcher
   recolours it for free. `--theme-primary` exists in both
   stylesheets; the second and third rings fall back through the
   names each file happens to use, then to a literal, so the loader
   is never invisible even if it is dropped somewhere new.

   As with everything else here, no style="..." and no inline
   handlers — style-src-attr and script-src-attr are 'none'.
   ================================================================== */

.ea-loader {
    --ring-a: var(--theme-primary, #f59e0b);
    --ring-b: var(--theme-primary-light, var(--theme-light, #fbbf24));
    --ring-c: var(--theme-secondary, var(--theme-light, #3b82f6));
    --ring-w: 3px;

    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: none;
    width: 100px;
    height: 100px;

    /* The rings are rotated in 3D; without a perspective they would
       read as three flat circles rather than one tumbling shape. */
    perspective: 780px;
}

/* A full transparent border rather than a single coloured side: the
   element then keeps a uniform circular box, so all three rings share
   one radius instead of each sitting a few pixels off. */
.ea-loader__ring {
    position: absolute;
    inset: 0;
    box-sizing: border-box;
    border: var(--ring-w) solid transparent;
    border-radius: 50%;
}

.ea-loader__ring--a {
    border-bottom-color: var(--ring-a);
    animation: ea-loader-a 1.15s linear infinite;
}

.ea-loader__ring--b {
    border-right-color: var(--ring-b);
    animation: ea-loader-b 1.15s 0.1s linear infinite;
}

.ea-loader__ring--c {
    border-top-color: var(--ring-c);
    animation: ea-loader-c 1.15s 0.15s linear infinite;
}

@keyframes ea-loader-a {
    from { transform: rotateX(45deg) rotateY(-45deg) rotateZ(0deg); }
    to   { transform: rotateX(45deg) rotateY(-45deg) rotateZ(360deg); }
}

@keyframes ea-loader-b {
    from { transform: rotateX(45deg) rotateY(45deg) rotateZ(0deg); }
    to   { transform: rotateX(45deg) rotateY(45deg) rotateZ(360deg); }
}

@keyframes ea-loader-c {
    from { transform: rotateX(-60deg) rotateY(0deg) rotateZ(0deg); }
    to   { transform: rotateX(-60deg) rotateY(0deg) rotateZ(360deg); }
}

/* ─── Inline size, for inside a button ──────────────────────────────
   The 3D tumble is built for a 100px shape; at 18px it just reads as
   jitter. The small variant is one flat ring in the button's own text
   colour, so it works on the gradient sign-in button and on a plain
   one without being told which it is on. */

.ea-loader--sm {
    width: 18px;
    height: 18px;
    perspective: none;
    --ring-w: 2px;
}

.ea-loader--sm .ea-loader__ring--b,
.ea-loader--sm .ea-loader__ring--c {
    display: none;
}

.ea-loader--sm .ea-loader__ring--a {
    border-bottom-color: currentColor;
    border-right-color: currentColor;
    animation: ea-loader-flat 0.7s linear infinite;
}

@keyframes ea-loader-flat {
    to { transform: rotate(360deg); }
}

/* ─── Full-page overlay ─────────────────────────────────────────── */

.ea-loading-overlay {
    position: fixed;
    z-index: 9000;
    inset: 0;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 24px;

    /* Translucent rather than opaque: the page underneath stays
       recognisable, so a slow response reads as "still the page you
       asked for" instead of a blank screen.

       DARK, not light. A pale scrim was chosen when the dashboard was only
       ever light; on the dark theme it washed the whole page out to a milky
       grey that read as a rendering fault rather than as a wait. A dark scrim
       works on both, for the same reason every photo viewer uses one — it
       reads as "dimmed", and dimmed is what is being said.

       The blur does the rest: enough that text behind is no longer legible
       (so a half-drawn page is not competing for attention), not so much that
       the layout stops being recognisable. */
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(8px) saturate(0.9);
    -webkit-backdrop-filter: blur(8px) saturate(0.9);
}

html.is-navigating .ea-loading-overlay {
    display: flex;
    animation: ea-loader-fade 0.18s ease both;
}

@keyframes ea-loader-fade {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.ea-loader__text {
    font-family: Inter, system-ui, sans-serif;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    /* On a dark scrim the theme colour can fall below a readable contrast —
       an academy's palette is its own choice and some of them are deep. The
       label sits on a known dark background now, so it is given a known light
       colour rather than one that depends on the palette. */
    color: #e8ecf6;
}

/* ─── Reduced motion ─────────────────────────────────────────────
   Vestibular triggers are exactly this: several elements spinning on
   three axes at once. The rings keep turning — the spinner still has
   to say "working" — but flat and slowly, and the overlay stops
   fading in. */

@media (prefers-reduced-motion: reduce) {
    .ea-loader {
        perspective: none;
    }

    .ea-loader__ring--a,
    .ea-loader__ring--b,
    .ea-loader__ring--c {
        animation: ea-loader-flat 2.4s linear infinite;
    }

    html.is-navigating .ea-loading-overlay {
        animation: none;
    }
}
