/* ==========================================================
   Loading feedback (driven by static/js/loader.js)
   1. #page-progress   - top progress bar for every request
   2. .k-sync          - "Syncing..." indicator in the header
   3. .is-loading      - spinner on the button that triggered it
   4. #page.is-swapping - page dims while the next one loads
   5. #request-error   - toast when a request fails
   6. #global-loader   - overlay for full page loads / plain forms
   All colors come from the theme variables in theme.css.
   ========================================================== */

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

/* 1. Progress bar */
#page-progress {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 100;
    height: 3px;
    width: 0;
    opacity: 0;
    background: rgb(var(--accent));
    box-shadow: 0 0 8px rgb(var(--accent));
    pointer-events: none;
}

/* 2. Syncing indicator */
.k-sync {
    display: none;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
    color: rgb(var(--accent));
}

.net-busy .k-sync {
    display: inline-flex;
}

.k-spinner {
    width: 1rem;
    height: 1rem;
    flex-shrink: 0;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 9999px;
    animation: k-spin 0.6s linear infinite;
}

/* 3. Busy buttons */
.is-loading,
[aria-busy="true"] {
    pointer-events: none;
    opacity: 0.75;
}

.is-loading::after,
button[aria-busy="true"]::after {
    content: "";
    display: inline-block;
    flex-shrink: 0;
    width: 0.85em;
    height: 0.85em;
    margin-left: 0.5em;
    vertical-align: -0.1em;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 9999px;
    animation: k-spin 0.6s linear infinite;
}

/* 4. Page dims while the next page loads */
#page {
    transition: opacity 0.15s ease;
}

#page.is-swapping {
    opacity: 0.55;
    pointer-events: none;
}

/* 5. Error toast */
#request-error {
    position: fixed;
    top: 1rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    max-width: 90vw;
    padding: 0.625rem 1rem;
    border-radius: 0.75rem;
    background: rgb(var(--surface));
    border: 1px solid rgb(var(--border));
    box-shadow: 0 25px 50px -12px rgb(0 0 0 / 0.5);
    font-family: "IBM Plex Mono", ui-monospace, monospace;
    font-size: 0.75rem;
    font-weight: 700;
    color: rgb(248 113 113);
}

[data-theme="light"] #request-error {
    color: rgb(220 38 38);
}

/* 6. Full-page overlay */
#global-loader {
    position: fixed;
    inset: 0;
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: rgb(var(--canvas) / 0.7);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.2s ease, visibility 0.2s;
}

#global-loader.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.loader-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    padding: 1.75rem 2.25rem;
    border-radius: 1rem;
    background: rgb(var(--surface));
    border: 1px solid rgb(var(--border));
    box-shadow: 0 25px 50px -12px rgb(0 0 0 / 0.5);
}

.loader-mark {
    position: relative;
    width: 4rem;
    height: 4rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.loader-mark::before {
    content: "";
    position: absolute;
    inset: 0;
    border: 2px solid rgb(var(--border));
    border-top-color: rgb(var(--accent));
    border-radius: 9999px;
    animation: k-spin 0.9s linear infinite;
}

.loader-mark img {
    width: 2.25rem;
    height: 2.25rem;
}

.loader-text {
    font-family: "IBM Plex Mono", ui-monospace, monospace;
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: rgb(var(--muted));
}

/* Skeleton placeholders */
.k-skeleton {
    min-height: 1rem;
    border-radius: 0.5rem;
    background: rgb(var(--surface-hover));
    animation: k-skeleton 1.4s ease-in-out infinite;
}

@keyframes k-skeleton {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.45; }
}

/* ==========================================================
   Ambient background
   A faint dot field, a slowly rotating wheel and the brand
   mark at its center, drawn in the theme's accent.
   ========================================================== */
.ambient-bg {
    color: rgb(var(--accent));
}

.ambient-grid {
    position: absolute;
    inset: 0;
    background-image: radial-gradient(rgb(var(--muted) / 0.12) 1px, transparent 1px);
    background-size: 22px 22px;
    -webkit-mask-image: radial-gradient(ellipse at center, black 35%, transparent 80%);
    mask-image: radial-gradient(ellipse at center, black 35%, transparent 80%);
}

.ambient-mark {
    animation: ambient-mark-breathe 6s ease-in-out infinite;
}

@keyframes ambient-mark-breathe {
    0%, 100% { transform: translate(-50%, -50%) scale(1); }
    50% { transform: translate(-50%, -50%) scale(1.04); }
}

.ambient-wheel {
    animation: ambient-wheel-spin 30s linear infinite;
    transform-origin: center;
}

@keyframes ambient-wheel-spin {
    from { transform: translate(-50%, -50%) rotate(0deg); }
    to { transform: translate(-50%, -50%) rotate(360deg); }
}

.wheel-light {
    opacity: 0.2;
    animation: wheel-light-pulse 2.4s ease-in-out infinite;
}

@keyframes wheel-light-pulse {
    0% { opacity: 0.2; }
    15% { opacity: 1; }
    40%, 100% { opacity: 0.2; }
}

@media (prefers-reduced-motion: reduce) {
    .ambient-mark,
    .ambient-wheel,
    .wheel-light,
    .k-skeleton {
        animation: none !important;
    }
    .wheel-light { opacity: 0.6; }
    #page, #page-progress { transition: none !important; }
}
