/* ============================================================================
   EduLoader — unified waiting-state system
   ----------------------------------------------------------------------------
   One loader for the whole platform. Three surfaces, one visual language:

     .edu-loader      full-screen overlay for long AI jobs (minutes)
     .edu-panel       in-place panel for a section that is regenerating
     .edu-spin        inline circular indicator for buttons / tiles / rows

   Rules this file follows on purpose:
   - Exactly ONE moving element per surface. The circular indicator carries the
     motion; nothing else spins, throbs, wobbles or floats.
   - No images, no GIFs, no emoji. Pure CSS/SVG so it inherits the active theme.
   - Every colour comes from the theme token spine (themes_config.json emits
     .theme-<key> blocks in header.php), so all 13 themes work with no per-theme
     rules here.
   - prefers-reduced-motion collapses rotation to a static, still-legible state
     instead of leaving a frozen half-drawn arc.
   ========================================================================== */

:root {
    --edu-loader-z: 100050;         /* above modals (10002) and the old overlays (99999) */
    --edu-loader-ring: 56px;
    --edu-loader-stroke: 4px;
}

/* ---------------------------------------------------------------- overlay -- */

.edu-loader {
    position: fixed;
    inset: 0;
    z-index: var(--edu-loader-z);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
    box-sizing: border-box;
    overflow-y: auto;
    font-family: var(--font-ui, 'Nunito Sans', system-ui, sans-serif);
    /* Dim + blur, not black out: the page stays faintly readable behind the card,
       which is what makes a multi-minute wait feel like the app is still there.
       A deliberately fixed value -- deriving it from --page-bg via color-mix
       produced a flat opaque grey on light themes. */
    background: rgba(15, 23, 42, 0.55);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
    opacity: 0;
    transition: opacity 0.22s ease;
}

.edu-loader.is-open {
    display: flex;
    opacity: 1;
}

.edu-loader__card {
    position: relative;
    width: 100%;
    max-width: 440px;
    margin: auto;
    box-sizing: border-box;
    padding: 40px 32px 28px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    text-align: center;
    background: var(--card-bg-default, #fff);
    border: 1px solid var(--card-border, #e5e7eb);
    border-radius: 20px;
    box-shadow: 0 24px 60px -12px rgba(9, 16, 30, 0.45);
    color: var(--text-dark, #212529);
    transform: translateY(8px) scale(0.985);
    transition: transform 0.28s cubic-bezier(0.2, 0, 0, 1);
}

.edu-loader.is-open .edu-loader__card { transform: none; }

/* Brand hairline along the top edge — the only decorative flourish, and it is
   static (the motion budget belongs to the indicator). */
.edu-loader__card::before {
    content: "";
    position: absolute;
    top: 0;
    left: 24px;
    right: 24px;
    height: 3px;
    border-radius: 0 0 3px 3px;
    background: var(--brand-gradient, linear-gradient(90deg, #1250A4 0%, #7EB4FD 100%));
}

/* ------------------------------------------------- circular indicator (M3) -- */

.edu-spin {
    width: var(--edu-loader-ring);
    height: var(--edu-loader-ring);
    flex: none;
    display: block;
    color: var(--brand, #4684a9);
    animation: eduSpinRotate 1.55s linear infinite;
}

.edu-spin circle {
    fill: none;
    stroke: currentColor;
    stroke-width: var(--edu-loader-stroke);
    stroke-linecap: round;
    /* r=22 → circumference ≈ 138.2. The dash pair plus the offset sweep is what
       produces Material's grow/shrink arc without a second element. */
    stroke-dasharray: 138.2;
    stroke-dashoffset: 110;
    transform-origin: center;
    animation: eduSpinArc 1.55s ease-in-out infinite;
}

.edu-spin__track {
    stroke: var(--card-border, #e5e7eb);
    stroke-dasharray: none;
    stroke-dashoffset: 0;
    animation: none;
    opacity: 0.75;
}

@keyframes eduSpinRotate { to { transform: rotate(360deg); } }

@keyframes eduSpinArc {
    0%   { stroke-dashoffset: 130; transform: rotate(0deg); }
    50%  { stroke-dashoffset: 38;  transform: rotate(50deg); }
    100% { stroke-dashoffset: 130; transform: rotate(360deg); }
}

/* Inline sizes for buttons and tiles. */
.edu-spin--sm { width: 18px; height: 18px; --edu-loader-stroke: 5px; }
.edu-spin--md { width: 28px; height: 28px; --edu-loader-stroke: 4.5px; }
.edu-spin--on-brand { color: var(--on-brand, #fff); }

/* ------------------------------------------------------------ copy blocks -- */

.edu-loader__title {
    margin: 0;
    font-family: var(--font-display, var(--font-ui, sans-serif));
    font-size: 1.35rem;
    font-weight: 700;
    line-height: 1.25;
    color: var(--text-dark, #212529);
}

/* Fixed height so a 1-line message followed by a 2-line one does not shunt the
   card up and down every rotation — the single worst tell of a cheap loader. */
.edu-loader__msg {
    margin: -8px 0 0;
    min-height: 3.6em;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    opacity: 1;
    transition: opacity 0.32s ease;
}

.edu-loader__msg.is-swapping { opacity: 0; }

.edu-loader__msg-head {
    font-size: 0.98rem;
    font-weight: 600;
    color: var(--text-dark, #212529);
    line-height: 1.35;
}

.edu-loader__msg-sub {
    font-size: 0.85rem;
    font-weight: 400;
    color: var(--text-muted, #6c757d);
    line-height: 1.4;
}

/* Elapsed time + "you can leave" reassurance. Hidden until it is actually
   relevant (see EduLoader's patience thresholds). */
.edu-loader__meta {
    display: none;
    font-size: 0.78rem;
    color: var(--text-muted, #6c757d);
    line-height: 1.45;
    max-width: 34ch;
}

.edu-loader__meta.is-visible { display: block; }

.edu-loader__clock {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}

/* Retry / degraded-service notice. */
.edu-loader__notice {
    display: none;
    align-items: flex-start;
    gap: 10px;
    width: 100%;
    box-sizing: border-box;
    padding: 11px 14px;
    text-align: left;
    font-size: 0.85rem;
    line-height: 1.45;
    color: var(--text-dark, #212529);
    background: rgba(245, 158, 11, 0.12);
    border: 1px solid rgba(245, 158, 11, 0.32);
    border-left: 3px solid #f59e0b;
    border-radius: 10px;
}

.edu-loader__notice.is-visible { display: flex; }

/* Host for optional extra content during the wait (promo video, tips). Empty
   and zero-height unless a caller fills it. */
.edu-loader__slot:empty { display: none; }
.edu-loader__slot { width: 100%; }

/* ------------------------------------------------------------- exit action -- */

.edu-loader__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    width: 100%;
}

.edu-loader__exit {
    display: none;
    align-items: center;
    gap: 8px;
    min-height: 42px;
    padding: 0 20px;
    border-radius: 999px;
    border: 1.5px solid var(--card-border, #e5e7eb);
    background: none;
    color: var(--text-dark, #212529);
    font-family: inherit;
    font-size: 0.88rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: border-color 0.18s ease, color 0.18s ease, background-color 0.18s ease;
}

.edu-loader__exit.is-visible { display: inline-flex; }

.edu-loader__exit:hover {
    border-color: var(--brand, #4684a9);
    color: var(--brand, #4684a9);
    background: var(--modal-tile-hover, rgba(0, 0, 0, 0.04));
}

/* ------------------------------------------------------------------ brand -- */

/* The header lockup, reproduced at the foot of the overlay card. Deliberately
   the last thing in the visual hierarchy: it sits below the exit action, at
   roughly half the weight of the aside line, and it never moves.
   Only on the overlay -- .edu-panel renders inside a page whose real header is
   still on screen, so branding there would be a second logo, not a discreet one.
   The negative margin pulls it up out of the card's 20px flex gap; without it
   the signature floats in the middle of the bottom padding. */
.edu-loader__brand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    margin-top: -8px;
    opacity: 0.55;
    /* Not a hover target -- clicking through to the homepage mid-generation is
       exactly what the exit link exists to offer deliberately. */
    pointer-events: none;
    user-select: none;
}

.edu-loader__brand-mark {
    width: 22px;
    height: 22px;
    object-fit: contain;
    flex: none;
}

/* Matches header.css's .logo-wordmark: same font, same hairline weight, same
   gradient on the second syllable, same superscript TLD -- just scaled down. */
.edu-loader__brand-word {
    font-family: var(--font-display, "Bricolage Grotesque", sans-serif);
    font-weight: 100;
    font-size: 0.95rem;
    line-height: 1;
    white-space: nowrap;
    color: var(--text-dark, #212529);
}

.edu-loader__brand-word strong {
    font-weight: 100;
    background: linear-gradient(90deg, var(--brand, #1E6FC7), var(--guest-bg-teal, #6DDCCC));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.edu-loader__brand-word small {
    font-weight: 700;
    font-size: 0.55em;
    color: var(--brand, #1E6FC7);
    vertical-align: super;
}

/* Once the job has resolved the card is a result, not a wait -- the signature
   would be competing with the check for the last thing the eye lands on. */
.edu-loader[data-state="success"] .edu-loader__brand,
.edu-loader[data-state="error"]   .edu-loader__brand { display: none; }

/* -------------------------------------------------------- success / error -- */

/* The check and the cross are drawn, not popped — same motion vocabulary as the
   arc, so the resolution reads as the same object settling. */
.edu-loader__mark {
    width: var(--edu-loader-ring);
    height: var(--edu-loader-ring);
    flex: none;
    display: none;
}

.edu-loader__mark circle {
    fill: none;
    stroke-width: var(--edu-loader-stroke);
    opacity: 0.28;
}

.edu-loader__mark path {
    fill: none;
    stroke-width: var(--edu-loader-stroke);
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-dasharray: 60;
    stroke-dashoffset: 60;
    animation: eduMarkDraw 0.45s 0.06s cubic-bezier(0.2, 0, 0, 1) forwards;
}

@keyframes eduMarkDraw { to { stroke-dashoffset: 0; } }

.edu-loader[data-state="success"] .edu-loader__mark--ok,
.edu-loader[data-state="error"]   .edu-loader__mark--err { display: block; }

.edu-loader[data-state="success"] .edu-spin,
.edu-loader[data-state="error"]   .edu-spin,
.edu-loader[data-state="success"] .edu-loader__meta,
.edu-loader[data-state="error"]   .edu-loader__meta { display: none; }

/* For pages that own their overlay markup and reveal the mark themselves
   instead of going through data-state. */
.edu-loader__mark--static { display: block; }

.edu-loader__mark--ok  { color: var(--success-color, #28a745); }
.edu-loader__mark--err { color: #dc3545; }
.edu-loader__mark circle, .edu-loader__mark path { stroke: currentColor; }

/* ------------------------------------------------------------ in-place panel -- */

/* For a section that is regenerating while the rest of the page stays usable.
   Same tokens, same indicator, no scrim. */
.edu-panel {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    text-align: center;
    padding: 34px 22px;
    min-height: 180px;
    box-sizing: border-box;
    background: var(--card-bg-default, #fff);
    border: 1px solid var(--card-border, #e5e7eb);
    border-radius: var(--card-border-radius, 12px);
    color: var(--text-dark, #212529);
    font-family: var(--font-ui, 'Nunito Sans', system-ui, sans-serif);
    overflow: hidden;
}

/* Android-style indeterminate rail pinned to the panel's top edge. */
.edu-panel::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 35%;
    height: 3px;
    border-radius: 999px;
    background: var(--brand-gradient, linear-gradient(90deg, #1250A4 0%, #7EB4FD 100%));
    animation: eduRailSweep 1.7s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

@keyframes eduRailSweep {
    0%   { transform: translateX(-105%); }
    100% { transform: translateX(390%); }
}

.edu-panel .edu-loader__msg { min-height: 3.2em; }
.edu-panel .edu-spin { --edu-loader-ring: 40px; width: 40px; height: 40px; }

/* Compact row form — for a list item or a card that is being filled in. */
.edu-panel--row {
    flex-direction: row;
    justify-content: flex-start;
    text-align: left;
    gap: 12px;
    min-height: 0;
    padding: 12px 16px;
}

.edu-panel--row .edu-loader__msg { min-height: 0; }
.edu-panel--row .edu-spin { width: 22px; height: 22px; --edu-loader-stroke: 5px; }

/* Bare form — indicator + text with no card chrome, for use inside an existing
   tile that already has a background and border. */
.edu-panel--bare {
    background: none;
    border: none;
    border-radius: 0;
}

.edu-panel--bare::before { display: none; }

/* ------------------------------------------------------------ button state -- */

/* Buttons keep their width while busy so the layout does not jump. */
.edu-busy {
    position: relative;
    pointer-events: none;
    opacity: 0.75;
}

.edu-busy > .edu-spin { vertical-align: -3px; margin-right: 7px; display: inline-block; }

/* ------------------------------------------------------- legacy adapters -- */

/* Some pages own their overlay element and toggle style.display directly rather
   than going through EduLoader. They get the same card and indicator by adding
   .edu-loader--static, which skips the open/close transition the JS drives. */
.edu-loader--static {
    opacity: 1;
    transition: none;
}

.edu-loader--static .edu-loader__card { transform: none; }

/* The platform had eleven near-identical `.spinner` definitions, each with its
   own size, border width and hardcoded blue. This is the single definition;
   the per-page ones were deleted. Size it per use with --spin-size.
   The track is derived from currentColor so it stays legible on both a light
   card and a dark panel without a modifier class. */
.spinner {
    width: var(--spin-size, 28px);
    height: var(--spin-size, 28px);
    box-sizing: border-box;
    border: var(--spin-stroke, 3px) solid rgba(128, 128, 128, 0.22);
    border-color: color-mix(in srgb, currentColor 20%, transparent);
    border-top-color: var(--brand, #4684a9);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: auto;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------- responsive -- */

@media (max-width: 520px) {
    .edu-loader { padding: 12px; align-items: flex-end; }
    .edu-loader__card {
        max-width: none;
        padding: 32px 20px 22px;
        border-radius: 20px;
        gap: 18px;
    }
    .edu-loader__title { font-size: 1.18rem; }
    :root { --edu-loader-ring: 48px; }
}

/* Short viewports (landscape phones): the card must scroll, not clip. */
@media (max-height: 560px) {
    .edu-loader { align-items: flex-start; }
    .edu-loader__card { padding-top: 28px; }
}

/* ------------------------------------------------------- reduced motion -- */

@media (prefers-reduced-motion: reduce) {
    .edu-spin { animation: none; }
    .edu-spin circle { animation: none; stroke-dashoffset: 60; }
    .edu-panel::before { animation: none; width: 100%; opacity: 0.65; }
    .spinner { animation: none; border-top-color: var(--brand, #4684a9); opacity: 0.8; }
    .edu-loader__mark path { animation: none; stroke-dashoffset: 0; }
    .edu-loader,
    .edu-loader__card,
    .edu-loader__msg { transition: none; }
}
