/* ====== BRAND SPLASH: the neutral full-screen logo screen. One set of rules for
   the four places that must look identical:
     1. MAUI's MauiSplashScreen (native OS-level launch screen, matched by hand)
     2. MAUI's index.html before Blazor bootstraps (two copies, see ANDROID HOLD COPY)
     3. the web host's served page before its circuit connects (BrandSplash with
        Boot, written by SkillMatch.Web's App.razor)
     4. AuthInitializer's gate phase (BrandSplash)
   Background matches MauiSplashScreen Color (#FFFFFF) so the OS-level splash
   transitions into the WebView splash with no visible seam.

   Its own file, and first in app.css, because of place 3. A browser paints nothing
   until every stylesheet in <head> has arrived, so on a page whose served body is
   empty the web host leaves ONLY this file in <head> and moves the rest below the
   splash. That works while this file stays small and stands alone: nothing here
   may read a token or lean on a rule from another stylesheet. ====== */
.brand-splash {
    position: fixed;
    inset: 0;
    background: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    /* The fallback is for the first paint: on a page that waits for its circuit this file is
       the only stylesheet in <head>, before theme.css (where --z-system lives) has arrived. */
    z-index: var(--z-system, 10000);
}

/* In-session reloads (forceLoad navigations) re-boot the app and would re-show
   the splash. The host inline script flags those with .app-rebooted so the
   splash only ever covers a genuine cold start; reloads stay blank until the
   gated content renders. */
.app-rebooted .brand-splash {
    display: none;
}

.brand-splash-logo {
    width: 128px;
    height: 128px;
    background-position: center;
    background-size: contain;
    background-repeat: no-repeat;
    /* Modern browsers (97%+ coverage) take the WebP via image-set; older browsers
       fall back to the prior url() declaration. PNG is the safe default; image-set
       overrides when supported. */
    background-image: url('../images/logo.png');
    background-image: image-set(
        url('../images/logo.webp') type('image/webp'),
        url('../images/logo.png') type('image/png')
    );
}

/* Dark mode: the splash background matches the app's dark canvas (#111418, same
   as --bg-page in dark theme). Swap to logo_dark.png which has white "Jasa"
   text + handle baked in, so the dark navy strokes don't disappear on the
   dark background. Hard-coded colors (not vars) because the splash is on screen
   before the token stylesheets are. */
[data-theme='dark'] .brand-splash {
    background: #111418;
}

[data-theme='dark'] .brand-splash-logo {
    background-image: url('../images/logo_dark.png');
    background-image: image-set(
        url('../images/logo_dark.webp') type('image/webp'),
        url('../images/logo_dark.png') type('image/png')
    );
}

/* A page with no theme set at all follows the device. "Ikuti sistem" needs no rule here:
   theme-init.js has already turned it into dark or light on <html>. */
@media (prefers-color-scheme: dark) {
    html:not([data-theme]) .brand-splash {
        background: #111418;
    }
    html:not([data-theme]) .brand-splash-logo {
        background-image: url('../images/logo_dark.png');
        background-image: image-set(
            url('../images/logo_dark.webp') type('image/webp'),
            url('../images/logo_dark.png') type('image/png')
        );
    }
}

/* ====== LOADING BAR: a thin line under the logo that fills while the app starts. It is
   drawn by CSS alone, so on a slow connection it is on screen before the logo image has
   arrived.

   It fills in three steps, each tied to something that has really happened:
     1. the page is on screen                         fills towards 40%
     2. the app has started (its own splash exists)   fills towards 75%
     3. the session and the language are in place     fills to 100%
   Within steps 1 and 2 it creeps towards that step's cap, quickly at first and then slower
   and slower, and stops at the cap. The cap sits short of where the next step starts, so
   a slow step leaves the bar nearly still and never shows progress that has not happened.
   When a step is done the cap moves on and the bar carries on from where it is.

   Step 3 fills the rest in 0.2 s, and AuthInitializer waits a moment before it draws the
   page, so the bar is seen full however fast the app started. On Android that wait is
   what lets the fill be drawn at all: drawing the page holds the main thread, and a fill
   that ran at the same time would be over before the next frame reached the screen.

   Why steps and not a line that keeps sliding: on Android the WebView can only put a
   frame on screen when the app's main thread is free, and starting the app keeps that
   thread busy for a few hundred milliseconds at a time (measured 2026-11-05). No CSS can
   draw through that. A sliding line that stops looks broken; a filling bar that stops
   reads as the work it is.

   Out of the flex flow on purpose: the logo has to stay on the exact pixels of the
   native Android splash, which has no bar. Its width is the width of the visible
   mark inside the 128px logo box (the image has transparent padding), and it sits
   22px under the mark. The blue is the magnifier's own blue from the logo file,
   the same on both canvases. ====== */
.brand-splash-bar {
    position: absolute;
    left: 50%;
    top: calc(50% + 60px);
    width: 92px;
    height: 3px;
    transform: translateX(-50%);
    border-radius: 99px;
    background: rgba(8, 40, 80, 0.1);
    overflow: hidden;
}

/* The fill is as wide as the bar and slides in from the left, so its leading end keeps
   its round cap. translateX(-60%) shows 40% of it. A change of step changes the target,
   and the transition sets off from wherever the fill is at that moment. */
.brand-splash-fill {
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: #2880d8;
    transform: translateX(-60%);
    transition: transform 2.5s cubic-bezier(0.1, 0.75, 0.25, 1);
}

/* Step 1 starts empty. The app's own splash only exists from step 2 on, so it starts
   where step 1 stops; that copy is on screen only where the copy painted over it is not
   (an Android WebView without :has()), and there it carries on instead of emptying. */
@starting-style {
    .brand-splash-fill {
        transform: translateX(-100%);
    }

    .brand-splash[data-stage] .brand-splash-fill {
        transform: translateX(-60%);
    }
}

/* Step 2, read from the app's own splash: on that copy itself, on the web host's boot
   copy after it, and on Android's hold copy beside #app. The :has() rule stands alone, so
   a browser that does not understand it drops that rule and keeps the other two. */
.brand-splash[data-stage='started'] .brand-splash-fill,
.brand-splash[data-stage='started'] ~ .brand-splash-boot .brand-splash-fill {
    transform: translateX(-25%);
}

#app:has(> .brand-splash[data-stage='started']) ~ .brand-splash-hold .brand-splash-fill {
    transform: translateX(-25%);
}

/* Step 3, the same three places: full, quickly. */
.brand-splash[data-stage='ready'] .brand-splash-fill,
.brand-splash[data-stage='ready'] ~ .brand-splash-boot .brand-splash-fill {
    transform: translateX(0);
    transition: transform 0.2s ease-out;
}

#app:has(> .brand-splash[data-stage='ready']) ~ .brand-splash-hold .brand-splash-fill {
    transform: translateX(0);
    transition: transform 0.2s ease-out;
}

[data-theme='dark'] .brand-splash-bar {
    background: rgba(255, 255, 255, 0.14);
}

@media (prefers-color-scheme: dark) {
    html:not([data-theme]) .brand-splash-bar {
        background: rgba(255, 255, 255, 0.14);
    }
}

/* Someone who turned animation off on their device gets the same steps without the
   creep: the fill stands at each step's cap, then full. Important because the step 3
   rules above, which set their own transition, are more specific. */
@media (prefers-reduced-motion: reduce) {
    .brand-splash-fill {
        transition: none !important;
    }
}

/* ====== ANDROID HOLD COPY (MAUI's index.html only): a second static copy beside #app.
   The app replaces what is inside #app with its own splash when it starts, which would
   start the bar again from empty. This copy is never replaced, so its bar keeps its
   progress and fills on as the app's splash says (LOADING BAR). It paints over the copy
   inside #app (same pixels, later in the page) while #app still holds a splash, and goes
   the moment the app's gate opens.

   Hidden by default and shown only through :has(). A WebView too old to understand :has()
   drops the whole rule, so the copy stays hidden and the copy inside #app works as it
   always did. It can never be left covering the app. A reload inside a session shows no
   splash at all, as above. ====== */
.brand-splash-hold {
    display: none;
}

html:not(.app-rebooted) #app:has(> .brand-splash) ~ .brand-splash-hold {
    display: flex;
}

/* ====== BOOT COPY (web host only): the splash written into the served page, on
   screen until the app draws. ====== */

/* A reload inside a session shows no logo and no bar (.app-rebooted above), but
   the cover itself has to stay. The page stylesheets now arrive after the first
   paint, so without the cover a dark-theme reload would paint a white page until
   base.css lands. */
.app-rebooted .brand-splash-boot {
    display: flex;
}

/* Hidden, not removed: App.razor preloads the logo, and a preload nothing draws is
   reported in the console on every reload. */
.app-rebooted .brand-splash-boot .brand-splash-logo {
    visibility: hidden;
}

.app-rebooted .brand-splash-boot .brand-splash-bar {
    display: none;
}

/* How it leaves. Blazor inserts the app at its marker, which App.razor places just
   above this element with nothing else before it, so the rule is positional: once
   anything other than the app's own splash sits above the boot copy, it is gone.
   Positional on purpose. If a later edit puts something above it, the splash never
   shows, which is the old behaviour; it can never be left covering the app.

   The app's own splash (AuthInitializer's gate) is the exception so the bar never
   starts again from empty. While the gate is up the two copies sit on the same pixels
   and this one, later in the page, paints on top; its bar fills on as the app's splash
   says (LOADING BAR). */
:not(.brand-splash) ~ .brand-splash.brand-splash-boot {
    display: none;
}
