/* =============================================================================
   TADASH LOADERS — universal loading-state kit
   Single source of truth for every loading affordance. Token-only.
   Implements design-system components.md §10 (spinner, bar, skeleton, overlay).

   QUICK USE
   ---------
   Spinner (static, zero markup):
     <span class="loader-spinner"></span>                    16/20/24 via --sm/--md/--lg
   Progress bar (driven from JS):
     <partial name="_LoaderBar" model='new { Id = "x", Label = "file.pdf" }' />
     TadashLoader.setProgress('x', 68);                       // or 100 + { state:'success' }
   Block / overlay (section is loading):
     <div style="position:relative"> ... <partial name="_LoaderOverlay" /> </div>
     TadashLoader.showOverlay(hostEl) / hideOverlay(hostEl)
   Skeleton (content placeholder):
     <div class="loader-skeleton loader-skeleton--text" style="width:60%"></div>

   All loaders honour prefers-reduced-motion automatically.
   ============================================================================= */

/* ── Spinner — indeterminate, component scale ────────────────────────────────
   CSS-only: a faint full ring with a cobalt arc, rotating 800ms linear. */

.loader-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-strong);
    border-top-color: var(--accent-base);
    border-radius: var(--radius-circle);
    animation: loader-spin 800ms var(--ease-linear) infinite;
    vertical-align: middle;
    flex-shrink: 0;
}

.loader-spinner--sm { width: 16px; height: 16px; }
.loader-spinner--lg { width: 24px; height: 24px; border-width: 2.5px; }

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

@media (prefers-reduced-motion: reduce) {
    .loader-spinner {
        animation: none;
        opacity: var(--opacity-muted);
    }
}

/* ── Progress bar — determinate ──────────────────────────────────────────────
   4px track + cobalt fill. State modifiers recolour the fill (status, not decor). */

.loader-bar {
    width: 100%;
}

.loader-bar__head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: var(--space-3);
    margin-bottom: var(--space-2);
}

.loader-bar__label {
    font-size: var(--text-small-size);
    line-height: var(--text-small-line);
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.loader-bar__value {
    font-size: var(--text-caption-size);
    line-height: var(--text-caption-line);
    color: var(--text-tertiary);
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
}

.loader-bar__track {
    height: 4px;
    background: var(--bg-muted);
    border-radius: var(--radius-pill);
    overflow: hidden;
}

.loader-bar__fill {
    height: 100%;
    width: 0%;
    background: var(--accent-base);
    border-radius: var(--radius-pill);
    transition: width var(--duration-standard) var(--ease-out);
}

.loader-bar--success .loader-bar__fill { background: var(--status-success-bg); }
.loader-bar--success .loader-bar__value { color: var(--status-success-text); }
.loader-bar--danger .loader-bar__fill { background: var(--status-danger-bg); }
.loader-bar--danger .loader-bar__value { color: var(--status-danger-text); }

/* Indeterminate — a sweeping fill for unknown-duration waits. */
.loader-bar--indeterminate .loader-bar__fill {
    width: 34%;
    animation: loader-sweep 1.4s var(--ease-out) infinite;
}

@keyframes loader-sweep {
    0%   { transform: translateX(-110%); }
    100% { transform: translateX(295%); }
}

@media (prefers-reduced-motion: reduce) {
    .loader-bar__fill { transition: none; }
    .loader-bar--indeterminate .loader-bar__fill {
        animation: none;
        width: 100%;
        opacity: var(--opacity-muted);
    }
}

/* ── Block / overlay — a whole section is loading ────────────────────────────
   Host must be position:relative. Toggle visibility with the [hidden] attribute. */

.loader-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-3);
    background: var(--bg-elevated);
    background: color-mix(in srgb, var(--bg-elevated) 78%, transparent);
    z-index: var(--z-overlay);
}

.loader-overlay[hidden] { display: none; }

.loader-overlay--fixed { position: fixed; }

.loader-overlay__label {
    font-size: var(--text-caption-size);
    line-height: var(--text-caption-line);
    color: var(--text-tertiary);
}

/* ── Skeleton — shimmer placeholder shaped like the content it replaces ──────── */

.loader-skeleton {
    background: linear-gradient(90deg,
        var(--bg-muted) 25%,
        var(--bg-subtle) 50%,
        var(--bg-muted) 75%);
    background-size: 200% 100%;
    animation: loader-shimmer 1500ms var(--ease-linear) infinite;
    border-radius: var(--radius-sm);
}

.loader-skeleton--text { height: 12px; border-radius: var(--radius-sm); }
.loader-skeleton--circle { border-radius: var(--radius-circle); }
.loader-skeleton--card { border-radius: var(--radius-md); }

@keyframes loader-shimmer {
    to { background-position: -200% 0; }
}

@media (prefers-reduced-motion: reduce) {
    .loader-skeleton {
        animation: none;
        background: var(--bg-muted);
    }
}

/* ── Navigation progress — top-of-viewport bar for full-page navigations ──────
   A thin bar that trickles while the next page loads, then completes and fades.
   Driven by navigation-progress.js. App-wide feedback for slow navigations;
   hidden entirely on fast ones (the script delays showing it past a threshold).
   aria-hidden — the page change itself is what assistive tech announces.
   Reduced motion is handled globally in tokens.css (transitions neutralised). */

.nav-progress {
    position: fixed;
    top: 0;
    left: 0;
    height: 3px;
    width: 0;
    z-index: var(--z-command);
    background: var(--accent-base);
    opacity: 0;
    pointer-events: none;
    transition: width var(--duration-standard) var(--ease-out),
                opacity var(--duration-short) var(--ease-out);
    box-shadow: 0 0 8px color-mix(in srgb, var(--accent-base) 60%, transparent);
}

.nav-progress.is-active { opacity: 1; }

/* ── Boot loader — full-screen branded cover for the sign-in transition ───────
   An opaque canvas takeover with the wordmark and a large spinner, shown while
   an auth form submits and the app boots. Distinct from .loader-overlay (a
   translucent section scrim): this is a solid, branded, full-viewport cover.
   Driven by navigation-boot.js. */

.boot-loader {
    position: fixed;
    inset: 0;
    z-index: var(--z-command);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-6);
    background: var(--bg-canvas);
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--duration-medium) var(--ease-out),
                visibility var(--duration-medium) var(--ease-out);
}

.boot-loader.is-active {
    opacity: 1;
    visibility: visible;
}

/* Size the wordmark for the centred boot context (see _Wordmark partial). */
.boot-loader .brand-logo { height: 32px; width: auto; }

.boot-loader__label {
    font-size: var(--text-caption-size);
    line-height: var(--text-caption-line);
    color: var(--text-tertiary);
}
