/*
 * Operations Portal startup shell (Feature #999, Tasks #1008 / #1010).
 *
 * Static, framework-independent styles for the branded shell that is part of the first HTML response and
 * covers the page until the interactive application shell has rendered (see js/oppo-startup.js).
 * Colours are Operations Portal Visual Identity v1.0.0 tokens
 * (docs/branding/OperationsPortal_Visual_Identity_v1.0.0/guidelines/OPPO_Visual_Identity_Spec_v1.0.0.md).
 */

.oppo-startup {
    --oppo-navy: #042A44;
    --oppo-steel: #496C8B;
    --oppo-blue-600: #0B56BB;
    --oppo-blue-500: #2A7BE5;
    --oppo-track: #E4EBF3;
    --oppo-startup-accent: var(--oppo-blue-500);
    --oppo-app-label-light: #0F4793;

    position: fixed;
    inset: 0;
    /* Below the framework error notification (#blazor-error-ui, z-index 1000) and the reconnect dialog, so a
       genuine failure is never hidden behind the startup shell. */
    z-index: 990;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: #FFFFFF;
    color: var(--oppo-steel);
    font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
    opacity: 1;
    transition: opacity 200ms ease-out;
}

.oppo-startup__content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 28px;
    max-width: 100%;
}

/*
 * Identity (Feature #999, Task #1009): the approved symbol or application icon plus the approved name as live text,
 * composed like the OPPO Native App Assets v1.0.0 "XL" lockup (64 px icon, name at x = 85, Segoe UI 38 px weight 350,
 * light label colour). The OPPO Core shell uses the Core reference symbol; application shells (--app) use the
 * application icon and the native accent. Tokens from
 * docs/branding/OPPO_Native_App_Assets_v1.0.0_Production_Master/tokens/oppo-native-assets.css. The width and height
 * attributes on the icon reserve its space before the file arrives, so it causes no layout shift.
 */
.oppo-startup--app {
    --oppo-app-accent: #1168E2;
    --oppo-startup-accent: var(--oppo-app-accent);
}

.oppo-startup__identity {
    display: flex;
    align-items: center;
    gap: 21px;
    max-width: 100%;
}

.oppo-startup__icon {
    display: block;
    flex: none;
    width: 64px;
    height: 64px;
}

.oppo-startup__name {
    font-family: "Segoe UI", Arial, sans-serif;
    font-size: 38px;
    font-weight: 350;
    line-height: 1.2;
    color: var(--oppo-app-label-light);
    white-space: nowrap;
}

/* Narrow screens: the approved "L" lockup proportions (48 px icon, name at x = 64, 28 px). */
@media (max-width: 480px) {
    .oppo-startup__identity {
        gap: 16px;
    }

    .oppo-startup__icon {
        width: 48px;
        height: 48px;
    }

    .oppo-startup__name {
        font-size: 28px;
    }
}

/* Indeterminate progress line: the logo stays still, only this line moves. */
.oppo-startup__progress {
    position: relative;
    width: 160px;
    height: 3px;
    overflow: hidden;
    border-radius: 3px;
    background: var(--oppo-track);
}

.oppo-startup__progress::before {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    width: 40%;
    border-radius: 3px;
    background: var(--oppo-startup-accent);
    animation: oppo-startup-progress 1.4s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

@keyframes oppo-startup-progress {
    from { transform: translateX(-100%); }
    to { transform: translateX(250%); }
}

.oppo-startup__slow {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    margin: 0;
    font-size: 14px;
    line-height: 20px;
    text-align: center;
}

.oppo-startup__slow p {
    margin: 0;
}

.oppo-startup__reload {
    padding: 6px 16px;
    border: 1px solid var(--oppo-blue-600);
    border-radius: 4px;
    background: #FFFFFF;
    color: var(--oppo-blue-600);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

.oppo-startup__reload:hover {
    background: #F0F5FC;
}

.oppo-startup__reload:focus-visible {
    outline: 2px solid var(--oppo-navy);
    outline-offset: 2px;
}

/* Text for assistive technology only. */
.oppo-startup__sr {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Still loading after the slow threshold: keep the progress line and offer a reload. */
.oppo-startup[data-state="slow"] .oppo-startup__slow {
    display: flex;
}

/* A genuine startup failure: the progress line stops; the framework error notification is shown above. */
.oppo-startup[data-state="error"] .oppo-startup__progress {
    visibility: hidden;
}

/* The application shell has rendered: fade out, then the script removes the element. The :has() rule reaches the
   same result from the readiness marker alone, so the shell never covers a running application even if the
   script did not load. */
.oppo-startup[data-state="ready"],
body:has([data-oppo-app-ready]) .oppo-startup:not(.oppo-startup--launch) {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 200ms ease-out, visibility 0s linear 200ms;
}

/* Application launch layer: the same layer, entering with the same 200 ms fade, while the browser loads the selected
   application. It never delays the navigation; the application's own startup shell continues the same identity. */
.oppo-startup--launch {
    animation: oppo-startup-enter 200ms ease-out both;
}

@keyframes oppo-startup-enter {
    from { opacity: 0; }
    to { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
    .oppo-startup,
    .oppo-startup[data-state="ready"],
    body:has([data-oppo-app-ready]) .oppo-startup:not(.oppo-startup--launch) {
        transition: none;
    }

    .oppo-startup--launch {
        animation: none;
    }

    .oppo-startup__progress::before {
        width: 100%;
        transform: none;
        animation: oppo-startup-pulse 2s ease-in-out infinite;
    }

    @keyframes oppo-startup-pulse {
        0%, 100% { opacity: 0.35; }
        50% { opacity: 1; }
    }
}
