/*
 * sso.grey.ooo — the Authelia portal, dressed to match the Grey.ooo chrome.
 *
 * Served by the brandkit nginx and linked into the portal's <head> by the
 * `sso-theme` Traefik middleware (services/service.authelia.tf). It has to be
 * a file the browser fetches, not an inline <style>: Authelia's CSP allows
 * styles only from 'self' and its per-request nonce, and Traefik cannot know
 * the nonce.
 *
 * Authelia 4.39 draws everything from CSS custom properties on
 * [data-theme=...]. Both the light and the dark theme get the same dark
 * palette here, so `theme: auto` can't flip the page to a white card under a
 * dark bar. The palette is the --gooo-* set from brand-kit.css, restated in
 * oklch because Authelia's utilities mix colours with color-mix().
 *
 * Fragile on purpose-built ids: #first-factor-stage and #form-login come from
 * Authelia's own markup. If an upgrade renames them, the card and glow stop
 * applying and the portal falls back to a plain dark page. It never breaks
 * sign-in, because this file only restyles.
 */

/* The mascot mask (--gooo-mascot) and the .gooo-cutout class. An @import has to
   come before every other rule. */
@import url("gooo-mascot.css");

:root[data-theme],
[data-theme] {
    --gooo-sky:     #7dd3fc;
    --gooo-emerald: #34d399;
    --gooo-rose:    #fb7185;

    --background: #0b0f17;
    --foreground: #e2e8f0;
    --card: #0f172a;
    --card-foreground: #f1f5f9;
    --popover: #131c30;
    --popover-foreground: #f1f5f9;

    --primary: #7dd3fc;
    --primary-foreground: #08111f;
    --ring: #7dd3fc;
    --secondary: #fb7185;
    --secondary-foreground: #08111f;

    --muted: #131c30;
    --muted-foreground: #94a3b8;
    --accent: rgba(125, 211, 252, 0.14);
    --accent-foreground: #e2e8f0;

    --border: #1e293b;
    --input: #26344d;
    --divider: rgba(148, 163, 184, 0.18);

    --destructive: #fb7185;
    --destructive-foreground: #1a0a0e;
    --success: #34d399;
    --success-foreground: #04130d;
    --info: #7dd3fc;
    --info-foreground: #08111f;

    --custom-icon: #7dd3fc;
    --custom-loading-bar: #7dd3fc;
    --radius: 0.625rem;

    color-scheme: dark;
}

/* ---- Page ---------------------------------------------------------------- */

html {
    background-color: #0b0f17;
}

/* Transparent, so the glow layer below shows through the body. */
body {
    background: transparent;
    color: #e2e8f0;
    font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, "Noto Sans", sans-serif;
}

/* Three soft glows, one per dot of the logo (sky, emerald, rose), over a faint
   dot grid that echoes the app-switcher icon. Fixed, so it stays put while the
   card scrolls on a short screen. */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    background:
        radial-gradient(60rem 38rem at 12% -8%, rgba(125, 211, 252, 0.16), transparent 62%),
        radial-gradient(48rem 34rem at 100% 8%, rgba(251, 113, 133, 0.10), transparent 60%),
        radial-gradient(56rem 38rem at 55% 112%, rgba(52, 211, 153, 0.12), transparent 62%),
        radial-gradient(rgba(148, 163, 184, 0.16) 1px, transparent 1.5px) 0 0 / 22px 22px,
        #0b0f17;
}

#root,
#root > div {
    background: transparent;
}

/* ---- Login card ---------------------------------------------------------- */

#first-factor-stage > div {
    position: relative;
    width: min(26rem, calc(100% - 2rem));
    max-width: none;
    margin: 1.5rem auto;
    padding: 2rem 2rem 1.5rem;
    background: rgba(15, 23, 42, 0.72);
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
    border: 1px solid #1e293b;
    border-radius: 1rem;
    overflow: hidden;
    box-shadow:
        0 24px 60px -24px rgba(0, 0, 0, 0.7),
        0 0 0 1px rgba(125, 211, 252, 0.04) inset;
}

/* The three-colour hairline across the top edge of the card. */
#first-factor-stage > div::before {
    content: "";
    position: absolute;
    inset: -1px -1px auto -1px;
    height: 3px;
    background: linear-gradient(90deg, #7dd3fc, #34d399 50%, #fb7185);
    opacity: 0.85;
}

#first-factor-stage h5 {
    margin-top: 0.25rem;
    font-size: 1.5rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: #f1f5f9;
}

#form-login input {
    background-color: rgba(11, 15, 23, 0.6);
    border-color: #26344d;
    color: #f1f5f9;
}

#form-login input:focus {
    border-color: #7dd3fc;
    box-shadow: 0 0 0 3px rgba(125, 211, 252, 0.2);
}

#form-login label {
    color: #94a3b8;
}

/* Submit button: solid sky with dark ink, like the bar's accent. */
#form-login button[type="submit"],
#form-login button[id="sign-in-button"] {
    background-color: #7dd3fc;
    color: #08111f;
    font-weight: 600;
    letter-spacing: 0.04em;
    border-radius: 0.625rem;
    box-shadow: 0 8px 24px -10px rgba(125, 211, 252, 0.7);
    transition: filter 0.15s ease, transform 0.15s ease;
}

#form-login button[type="submit"]:hover,
#form-login button[id="sign-in-button"]:hover {
    filter: brightness(1.08);
    transform: translateY(-1px);
}

a {
    color: #7dd3fc;
}

/* ---- Mascot silhouette --------------------------------------------------- *
 * The mask itself is in gooo-mascot.css. Each copy is a <canvas> that
 * sso-theme.js adds. It is a window onto one waving rainbow flag at the size of the
 * screen (gooo-flag.js), cut to the head by the mask. The plain gradients below
 * show only where a script has not run.
 * Both copies tilt right by --sso-tilt, which sso-theme.js sets to a random
 * 20 to 50 degrees.
 */

canvas.sso-flag {
    display: block;
    pointer-events: none;
    transform: rotate(var(--sso-tilt, 35deg));
}

/* The small copy, over the form. */
.p-2 > canvas.sso-flag {
    width: 4.75rem;
    height: 4.4rem;
    margin: 0 auto;
    filter: drop-shadow(0 6px 18px rgba(125, 211, 252, 0.35));
}

/* Names #UserSvg too, to outrank the rule that draws the fallback. */
.p-2:has(> #UserSvg):has(> canvas.sso-flag)::before {
    display: none;
}

/* The flag, at the size of the screen. Dim, like the flag of the greeter. */
canvas#sso-flag-screen {
    position: fixed;
    inset: 0;
    z-index: -1;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    opacity: 0.16;
}

/* The big window, in the corner of the page. It shows the flag at full
   strength, so it stands out from the dim flag around it. */
canvas#sso-flag-bg {
    position: fixed;
    right: -3vw;
    bottom: -5vh;
    z-index: -1;
    width: min(46vw, 34rem);
    aspect-ratio: 384 / 359;
    height: auto;
    opacity: 0.45;
    filter: blur(2px);
}

body:has(#sso-flag-bg)::after {
    display: none;
}

/* The fallback gradients, for a page where the script did not run. */
body::after {
    content: "";
    position: fixed;
    right: -3vw;
    bottom: -5vh;
    z-index: -1;
    width: min(46vw, 34rem);
    aspect-ratio: 384 / 359;
    pointer-events: none;
    background: linear-gradient(135deg, #7dd3fc, #34d399 55%, #fb7185);
    opacity: 0.08;
    filter: blur(2px);
    transform: rotate(var(--sso-tilt, 35deg));
    -webkit-mask: var(--gooo-mascot) center / contain no-repeat;
    mask: var(--gooo-mascot) center / contain no-repeat;
}

/* A small one in place of the round user glyph. Authelia draws that glyph as
   `#UserSvg` on the login card, on the "Hi <name>" page, and on the other
   steps, so the rule keys on the glyph and not on one page. */
.p-2:has(> #UserSvg) > #UserSvg {
    display: none;
}

.p-2:has(> #UserSvg)::before {
    content: "";
    display: block;
    width: 4.75rem;
    height: 4.4rem;
    margin: 0 auto;
    background: linear-gradient(135deg, #7dd3fc, #34d399 60%, #fb7185);
    -webkit-mask: var(--gooo-mascot) center / contain no-repeat;
    mask: var(--gooo-mascot) center / contain no-repeat;
    filter: drop-shadow(0 6px 18px rgba(125, 211, 252, 0.35));
    transform: rotate(var(--sso-tilt, 35deg));
}

/* ---- Signed-in pages ------------------------------------------------------ */

/* The tick of "Authenticated". Authelia darkens it with a relative colour, so
   it reads as a dull green on this dark page. Emerald, with a soft glow. */
.success-icon {
    color: #34d399;
    filter: drop-shadow(0 0 14px rgba(52, 211, 153, 0.45));
}

/* The box around it, drawn like the login card. */
#authenticated-view .border-border {
    background: rgba(15, 23, 42, 0.72);
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
    border-color: #1e293b;
    border-radius: 1rem;
    box-shadow: 0 24px 60px -24px rgba(0, 0, 0, 0.7);
}

/* The round account button in the corner, with the initial of the user. */
[data-slot="avatar-fallback"] {
    background: linear-gradient(135deg, #7dd3fc, #34d399 60%, #fb7185);
    color: #08111f;
    font-weight: 600;
}

#account-menu {
    box-shadow: 0 0 0 1px rgba(125, 211, 252, 0.4), 0 6px 18px -6px rgba(125, 211, 252, 0.45);
}

/* ---- Settings pages ------------------------------------------------------- */

/* Authelia pins its own bar to the top at z-index 50, over the grey.ooo bar,
   and paints it solid blue with dark text. Move it under the grey.ooo bar and
   draw it as dark glass, like the rest of the page. */
nav.fixed.top-0 {
    top: var(--gooo-topbar-h, 44px);
    background: rgba(15, 23, 42, 0.8);
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
    border-bottom: 1px solid #1e293b;
    color: #e2e8f0;
}

nav.fixed.top-0 .text-primary-foreground {
    color: #e2e8f0;
}

nav.fixed.top-0 svg {
    color: #7dd3fc;
}

/* ---- Grey.ooo bar, as an overlay ----------------------------------------- *
 * bar.js writes these rules into an inline <style> that this page's CSP
 * blocks. They live here instead so the bar stays pinned and never paints
 * unstyled before brand-kit.css arrives.
 */
#gooo-topbar {
    visibility: hidden;
    position: fixed !important;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10;
}

#gooo-topbar.gooo-ready {
    visibility: visible;
}

body {
    margin-top: var(--gooo-topbar-h, 44px) !important;
}

/* ---- Snow ---------------------------------------------------------------- */

/* The flakes of sso-theme.js, over the glow and under the card. */
canvas#sso-snow {
    position: fixed;
    inset: 0;
    z-index: -1;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
}

/* ---- Look switch --------------------------------------------------------- */

/* A rocker switch for the look (sso-theme.js). Two halves in one rounded body.
   The half that is pressed in shows the look in use: darker, lit, with an inset
   shadow. The other half stands proud, like the raised end of the rocker. */
#sso-look-toggle {
    position: fixed;
    left: 1rem;
    bottom: 1rem;
    z-index: 20;
    display: flex;
    padding: 2px;
    font: inherit;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #64748b;
    background: #0b0f17;
    border: 1px solid #26344d;
    border-radius: 0.5rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
    cursor: pointer;
}

#sso-look-toggle span {
    padding: 0.4rem 0.85rem;
    border-radius: 0.35rem;
    transition: background 0.12s ease, color 0.12s ease, box-shadow 0.12s ease;
}

/* The pressed half. Colour is pressed unless the switch is on. */
#sso-look-toggle .sso-rocker-colour {
    color: #08111f;
    background: linear-gradient(135deg, #7dd3fc, #34d399 60%, #fb7185);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.45);
}

#sso-look-toggle .sso-rocker-corpo {
    background: linear-gradient(#1e293b, #162033);
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.08) inset, 0 2px 3px rgba(0, 0, 0, 0.5);
}

/* On: the grey half goes down and the colour half comes up. */
#sso-look-toggle[aria-checked="true"] .sso-rocker-colour {
    color: #64748b;
    background: linear-gradient(#1e293b, #162033);
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.08) inset, 0 2px 3px rgba(0, 0, 0, 0.5);
}

#sso-look-toggle[aria-checked="true"] .sso-rocker-corpo {
    color: #c9cccf;
    background: #2a2c2e;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.5);
}

#sso-look-toggle:focus-visible {
    outline: 2px solid #7dd3fc;
    outline-offset: 2px;
}
