/* Loading screen container */
#loading-screen {
    position: fixed;
    width: 100%;
    height: 100%;
    background: white;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-family: 'Inter', system-ui, sans-serif;
    color: #333;
    /* Mirrors `--z-loading-screen` in app.css. Kept as a literal here so the
       overlay paints even if app.css is delayed; if you change the var, also
       change this and the matching rule in App.razor's inline critical CSS. */
    z-index: 9999;
    opacity: 1;
    transition: opacity 250ms ease;
}

#loading-screen.is-hiding {
    opacity: 0;
    pointer-events: none;
}

[data-bs-theme="dark"] #loading-screen {
    background: var(--color-primary-bg-dark); /* #171717 — matches actual page background */
    color: white;
}

/* Wrapper for the logo and spinner */
#loading-wrapper {
    position: relative;
    width: 160px;
    height: 160px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Faint full-ring track behind the spinning arc */
#loading-wrapper::before {
    content: '';
    position: absolute;
    width: 200px;
    height: 200px;
    border-radius: var(--radius-circle);
    border: 3px solid rgba(0, 0, 0, 0.1);
    pointer-events: none;
}

[data-bs-theme="dark"] #loading-wrapper::before {
    border-color: rgba(255, 255, 255, 0.12);
}

/* Logo — gentle breathing pulse to indicate activity */
#loading-logo {
    width: 95px;
    height: 95px;
    background: url("/favicons/logo-mark.svg") no-repeat center;
    background-size: contain;
    position: absolute;
    z-index: 3;
    animation: logo-breathe 3s ease-in-out infinite;
}

[data-bs-theme="dark"] #loading-logo {
    filter: invert(1);
}

/* System-theme + dark-OS race: themeManager.js is defer-loaded so data-bs-theme
   is not set on first paint for system-theme users. The critical inline CSS in
   App.razor already darkens the bg via prefers-color-scheme, so the inner
   elements must mirror the same gate or they render dark-on-dark and disappear
   until themeManager.js runs. Excludes data-bs-theme="light" so an explicit
   light override on a dark OS still gets light styling. */
@media (prefers-color-scheme: dark) {
    html:not([data-bs-theme="light"]) #loading-wrapper::before {
        border-color: rgba(255, 255, 255, 0.12);
    }
    html:not([data-bs-theme="light"]) #loading-logo {
        filter: invert(1);
    }
}

/* Conic-gradient arc spinner — fades from transparent tail to opaque head */
#loading-circle {
    position: absolute;
    width: 200px;
    height: 200px;
    border-radius: var(--radius-circle);
    animation: spin 1.1s linear infinite;
    z-index: 2;
    background: conic-gradient(
        from 0deg,
        transparent 0deg,
        rgba(0, 0, 0, 0.85) 270deg,
        transparent 360deg
    );
    /* Punch out center to create a thin ring */
    -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 4px), #000 calc(100% - 3px));
    mask: radial-gradient(farthest-side, transparent calc(100% - 4px), #000 calc(100% - 3px));
}

[data-bs-theme="dark"] #loading-circle {
    background: conic-gradient(
        from 0deg,
        transparent 0deg,
        rgba(255, 255, 255, 0.95) 270deg,
        transparent 360deg
    );
}

/* Wordmark below the spinner */
#loading-wordmark {
    margin-top: 2.5rem;
    font-family: 'Outfit', system-ui, sans-serif;
    font-size: var(--font-size-loading-wordmark);
    font-weight: var(--font-weight-semibold);
    letter-spacing: var(--letter-spacing-snug);
    color: #1a1a1a;
}

[data-bs-theme="dark"] #loading-wordmark {
    color: #f0f0f0;
}

/* Companion to the prefers-color-scheme block above — keeps the spinner and
   wordmark legible on the dark bg the inline CSS paints before themeManager.js
   sets data-bs-theme. */
@media (prefers-color-scheme: dark) {
    html:not([data-bs-theme="light"]) #loading-circle {
        background: conic-gradient(
            from 0deg,
            transparent 0deg,
            rgba(255, 255, 255, 0.95) 270deg,
            transparent 360deg
        );
    }
    html:not([data-bs-theme="light"]) #loading-wordmark {
        color: #f0f0f0;
    }
}

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

@keyframes logo-breathe {
    0%, 100% { transform: scale(1);    opacity: var(--opacity-strong); }
    50%       { transform: scale(1.05); opacity: 1;                    }
}

/* Navigation progress bar — replaces the full loading screen for in-app navigation */
#nav-progress-bar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 2px;
    /* Mirrors `--z-nav-progress` in app.css. One layer above the loading
       overlay so an in-app nav can render the progress bar before the
       overlay finishes fading. Keep in sync with the var. */
    z-index: 10000;
    display: none;
    overflow: hidden;
}

#nav-progress-bar.active {
    display: block;
}

#nav-progress-bar::after {
    content: '';
    position: absolute;
    top: 0;
    left: -40%;
    width: 40%;
    height: 100%;
    background: #1a1a1a;
    animation: nav-progress-slide 0.9s ease-in-out infinite;
}

[data-bs-theme="dark"] #nav-progress-bar::after {
    background: #e0e0e0;
}

@keyframes nav-progress-slide {
    0%   { left: -40%; }
    100% { left: 100%; }
}
