/* ============================================================
   Page loader — full-screen splash shown while the page loads.
   Theme-aware (light/dark via body.dark-mode + the existing
   --loader-primary/--loader-accent tokens from combined.css).
   Hidden by static/js/main.js's initPageLoader() once the window
   has finished loading (min. display time + window "load" event,
   with a safety timeout).
============================================================ */

/* combined.css's generic `.loading { opacity: 0 }` rule (meant only for
   `body.loading .main-content`) also matches <body class="loading"> itself.
   Since CSS opacity composites a whole subtree as one transparent layer,
   that accidentally hid #pageLoader too (a child of body) despite its own
   opacity being 1. `body.loading` is more specific than the bare `.loading`
   it's overriding, so this wins regardless of stylesheet order. */
body.loading {
    opacity: 1;
}

.page-loader {
    position: fixed;
    inset: 0;
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--theme-bg, #e8ecf0);
    opacity: 1;
    visibility: visible;
    transition: opacity .5s ease, visibility .5s ease;
}

.page-loader.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.page-loader .loader-content {
    display: flex;
    align-items: center;
    justify-content: center;
}

.loader-logo-wrap {
    position: relative;
    width: 120px;
    height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.loader-logo-wrap .loader-logo {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 2;
    width: 64px;
    height: auto;
    animation: loaderPulse 1.6s ease-in-out infinite;
}

/* Only one logo variant renders at a time, matching the theme. */
.loader-logo--dark { display: none; }
body.dark-mode .loader-logo--light { display: none; }
body.dark-mode .loader-logo--dark { display: block; }

.loader-ring {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 3px solid rgba(0, 0, 0, .12);
    border-top-color: var(--loader-accent, #007aff);
    animation: loaderSpin 1s linear infinite;
}

body.dark-mode .loader-ring {
    border-color: rgba(255, 255, 255, .15);
    border-top-color: var(--loader-accent, #007aff);
}

/* A second, slower counter-rotating ring for a bit more depth. */
.loader-ring--outer {
    inset: -14px;
    border-width: 2px;
    border-color: transparent;
    border-bottom-color: var(--loader-accent, #007aff);
    opacity: .5;
    animation: loaderSpinReverse 2.2s linear infinite;
}

/* Re-applied after the general body.dark-mode .loader-ring override above
   (same selector specificity) so the outer ring keeps its transparent base
   instead of picking up the inner ring's solid border color in dark mode. */
body.dark-mode .loader-ring--outer {
    border-color: transparent;
    border-bottom-color: var(--loader-accent, #007aff);
}

/* Four Material Icons pulsing in sequence around the logo. */
.loader-icons {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.loader-icon-slot {
    position: absolute;
    display: flex;
}

.loader-icon-slot--top { top: -6px; left: 50%; transform: translate(-50%, -100%); }
.loader-icon-slot--right { top: 50%; right: -6px; transform: translate(100%, -50%); }
.loader-icon-slot--bottom { bottom: -6px; left: 50%; transform: translate(-50%, 100%); }
.loader-icon-slot--left { top: 50%; left: -6px; transform: translate(-100%, -50%); }

.loader-icon-slot .material-icons {
    font-size: 18px;
    color: var(--loader-accent, #007aff);
    opacity: 0;
    transform: scale(.5);
    animation: loaderIconPulse 2.4s ease-in-out infinite;
}

.loader-icon-slot--top .material-icons { animation-delay: 0s; }
.loader-icon-slot--right .material-icons { animation-delay: .6s; }
.loader-icon-slot--bottom .material-icons { animation-delay: 1.2s; }
.loader-icon-slot--left .material-icons { animation-delay: 1.8s; }

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

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

@keyframes loaderPulse {
    0%, 100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
    50% { transform: translate(-50%, -50%) scale(.92); opacity: .82; }
}

@keyframes loaderIconPulse {
    0%, 70%, 100% { opacity: 0; transform: scale(.5); }
    35% { opacity: 1; transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
    .loader-logo-wrap .loader-logo,
    .loader-ring,
    .loader-ring--outer,
    .loader-icon-slot .material-icons {
        animation: none;
    }
    .loader-icon-slot .material-icons {
        opacity: .8;
        transform: none;
    }
}
