/*
    The sign-in surface for a self-hosted identity server.

    One stylesheet serves all fourteen pages, so everything here is a token or a primitive.
    The palette is defined once on :root and redefined for dark; no rule below names a colour
    directly, because a literal that reads in one theme is unreadable in the other.

    Served under Content-Security-Policy style-src 'self', which rules out a font CDN. That is
    not a compromise worth apologising for: this is the page a person reaches on the way to
    something else, often on a bad connection, and it renders with no font request at all.
*/

:root {
    /* Cool neutrals, biased very slightly toward the accent so they read as chosen rather
       than as whatever grey came to hand. */
    --paper: #eef1f4;
    --card: #ffffff;
    --ink: #16202b;
    --muted: #5a6876;
    --line: #dae1e8;
    --field: #ffffff;

    /* Text with no card under it - only the footer. Its own token because a branded page can
       set any background, and what reads on the card does not necessarily read on the page. */
    --on-paper: #5a6876;

    /* Petrol rather than the bright blue every sign-in page reaches for. This is
       infrastructure an operator runs, and it should look like it was installed rather than
       launched. */
    --accent: #0d6177;
    --accent-ink: #ffffff;
    --accent-weak: #e4eef2;

    --danger: #a32017;
    --danger-bg: #fdeceb;
    --warn-bg: #fdf4e3;
    --warn-line: #c08a1a;

    --shadow: 0 1px 2px rgba(16, 32, 43, .05), 0 8px 24px -12px rgba(16, 32, 43, .18);
    --radius: 10px;
    --radius-sm: 7px;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --paper: #10151b;
        --card: #19212a;
        --ink: #e6ecf2;
        --muted: #93a2b2;
        --line: #2b3643;
        --field: #121920;
        --on-paper: #93a2b2;

        --accent: #5cb4cf;
        --accent-ink: #08202a;
        --accent-weak: #16303a;

        --danger: #f2897e;
        --danger-bg: #2d1917;
        --warn-bg: #2a2215;
        --warn-line: #a3802f;

        --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px -12px rgba(0, 0, 0, .7);
        color-scheme: dark;
    }
}

:root[data-theme="dark"] {
    --paper: #10151b;
    --card: #19212a;
    --ink: #e6ecf2;
    --muted: #93a2b2;
    --line: #2b3643;
    --field: #121920;
    --on-paper: #93a2b2;
    --accent: #5cb4cf;
    --accent-ink: #08202a;
    --accent-weak: #16303a;
    --danger: #f2897e;
    --danger-bg: #2d1917;
    --warn-bg: #2a2215;
    --warn-line: #a3802f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px -12px rgba(0, 0, 0, .7);
    color-scheme: dark;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font: 1rem/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    -webkit-font-smoothing: antialiased;
}

.shell {
    min-height: 100vh;
    /* dvh tracks the viewport as the URL bar retracts; vh does not, so a centred card
       drifts while the bar hides and shows on a phone. vh stays first, as the value for
       anything that does not know dvh. */
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px 16px 32px;
}

.card {
    width: 100%;
    max-width: 436px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 28px;
}

.brand {
    font-weight: 600;
    font-size: .9375rem;
    letter-spacing: -.005em;
    margin-bottom: 20px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--line);
    /* A row, because a mark and a name can both be here. One child alone is unaffected. */
    display: flex;
    align-items: center;
    gap: 10px;
}

/* The name as text rather than baked into the logo, which is how it follows the page into
   dark mode - an image cannot, and a wordmark drawn into one has to read on both surfaces. */
.brand-name { min-width: 0; }

/*
    The client's logo, bounded.

    The file belongs to whoever deployed this, not to us, so a 2000px export must not be
    able to stretch the card: max-height caps the line it sits on, and max-width stops a
    wide wordmark from setting the card's width on a narrow screen.
*/
.brand-logo {
    display: block;
    max-height: 32px;
    max-width: min(160px, 100%);
    width: auto;
    height: auto;
}

/* A real step up from body text. At 1.25rem the heading and the paragraph under it were the
   same voice, and the page had no first thing to read. */
h1 {
    font-size: 1.5rem;
    line-height: 1.2;
    letter-spacing: -.016em;
    font-weight: 620;
    margin: 0 0 7px;
    text-wrap: balance;
}

/* A heading that runs straight into the form, with no standfirst between them, needs the
   gap the standfirst would have provided. The validation summary renders no element at all
   when the form is valid, so this adjacency is the ordinary case rather than the exception. */
h1 + form { margin-top: 22px; }

.lede {
    color: var(--muted);
    margin: 0 0 22px;
    font-size: .9375rem;
    max-width: 48ch;
}

label {
    display: block;
    font-weight: 600;
    font-size: .8125rem;
    letter-spacing: .004em;
    margin-bottom: 6px;
    color: var(--ink);
}

/* "(optional)" beside a field name. Lighter and lighter-weight than the label it sits in,
   so the field still reads as one thing and the qualifier does not compete with it. */
label .hint {
    font-weight: 400;
    color: var(--muted);
}

/* Every text-like input the forms use. A type missing from this list silently falls back
   to the browser's own control, which is narrow, differently bordered, and has none of the
   spacing below — it looks like a mistake rather than a style. */
input[type=text], input[type=email], input[type=password], input[type=tel] {
    width: 100%;
    /* 1rem, not the 15px this used to be: anything under 16px makes iOS Safari zoom the
       page the moment the field takes focus, which on a form is jarring every time. */
    font: inherit;
    font-size: 1rem;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    background: var(--field);
    color: var(--ink);
    transition: border-color .15s ease, box-shadow .15s ease;
}

input::placeholder { color: var(--muted); opacity: .75; }

input:hover { border-color: var(--muted); }

input:focus-visible,
input:focus {
    outline: none;
    border-color: var(--accent);
    /* A ring rather than an outline, so the field grows no wider and nothing below it
       shifts when focus lands. */
    box-shadow: 0 0 0 3px var(--accent-weak);
}

button {
    width: 100%;
    font: inherit;
    font-size: .9375rem;
    font-weight: 600;
    padding: 11px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: var(--accent-ink);
    cursor: pointer;
    transition: background-color .15s ease, border-color .15s ease;
}

button:hover { background: color-mix(in srgb, var(--accent) 88%, var(--ink)); }

button:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

button.secondary {
    background: transparent;
    border-color: var(--line);
    color: var(--ink);
}

button.secondary:hover { background: var(--accent-weak); border-color: var(--accent); }

button + button { margin-top: 10px; }

/*
    A button that reads as a link, for an action that has to be a POST but does not deserve
    the weight of a button — resending a code sits beside "Back to sign in", not beside the
    thing the page is actually for.

    It resets what the button rule above sets rather than fighting it, because a full-width
    block in the middle of a row of links is the thing that looked wrong.
*/
button.as-link {
    width: auto;
    padding: 0;
    border: 0;
    background: none;
    color: var(--accent);
    font-size: inherit;
    font-weight: 400;
    text-decoration: underline;
    text-underline-offset: 2px;
    cursor: pointer;
}

button.as-link:hover { background: none; color: var(--accent); }

button.as-link:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 3px;
}

/*
    Where someone is in signing up.

    Registration is step one of three here — the account, then the emailed code, then the
    authenticator — and the page used to say so in a sentence and then drop it. A rail is
    worth drawing only because the sequence is real: the form redirects to the activation
    page, which leads to enrolment. It marks position, not decoration.
*/
.progress {
    display: flex;
    margin: 0 0 22px;
    padding: 0;
    list-style: none;
    gap: 6px;
}

.progress li {
    flex: 1;
    font-size: .75rem;
    color: var(--muted);
    padding-top: 9px;
    border-top: 2px solid var(--line);
    letter-spacing: .005em;
}

.progress .now {
    color: var(--accent);
    font-weight: 600;
    border-top-color: var(--accent);
}

/* Behind, but finished — a solid rule reads as ground already covered. */
.progress .done { border-top-color: var(--accent); }

.alert {
    background: var(--danger-bg);
    border: 1px solid var(--danger);
    color: var(--danger);
    border-radius: var(--radius-sm);
    padding: 11px 13px;
    margin-bottom: 18px;
    font-size: .9375rem;
}

.alert ul { margin: 0; padding-left: 18px; }

.notice {
    background: var(--warn-bg);
    border: 1px solid var(--warn-line);
    border-radius: var(--radius-sm);
    padding: 11px 13px;
    margin-bottom: 18px;
    font-size: .875rem;
}

.footer {
    color: var(--on-paper);
    font-size: .75rem;
    line-height: 1.6;
    margin-top: 22px;
    text-align: center;
    max-width: 436px;
}

.links {
    margin-top: 18px;
    font-size: .875rem;
    /* A row of equals. The resend control is a one-button form, so the row is laid out
       rather than left to block flow, which would stack the form full width. */
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 6px 18px;
}

/*
    44px is the smallest target a finger hits reliably, and these are about 20px of text.
    They are also the controls someone reaches for once sign-in has already gone wrong,
    which is the worst moment to make them aim. Height comes from the box rather than from
    margin, so the gap above the row does not grow with it.
*/
.links a,
.links button.as-link {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
}

a { color: var(--accent); text-underline-offset: 2px; }

a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }

.scopes { list-style: none; margin: 0 0 20px; padding: 0; }

.scopes li {
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 11px 13px;
    margin-bottom: 8px;
}

.scopes li.sensitive { border-color: var(--warn-line); background: var(--warn-bg); }

.scopes .name { font-weight: 600; display: block; }

.scopes .detail { color: var(--muted); font-size: .875rem; }

.tier {
    font-size: .6875rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
}

code.recovery {
    display: block;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    background: var(--paper);
    border: 1px solid var(--line);
    padding: 7px 9px;
    border-radius: 5px;
    margin-bottom: 6px;
}

.key {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    background: var(--paper);
    border: 1px solid var(--line);
    padding: 9px 11px;
    border-radius: 5px;
    word-break: break-all;
    display: block;
    margin-bottom: 16px;
}

/* White behind the code and a margin around it, both regardless of the surrounding theme:
   a scanner needs the quiet zone and the contrast, not whatever the page is wearing. */
.qr {
    background: #ffffff;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
    /* Sized so each module stays above about four CSS pixels, which is where a phone camera
       stops struggling against a screen's own pixel grid. The symbol is 65 modules square
       once the URI is in it — it was 57 when this was first written, and the issuer growing
       since then is what pushed the modules under three pixels and made it hard to scan. */
    width: min(320px, 100%);
    margin: 0 auto 20px;
}

.qr svg {
    display: block;
    width: 100%;
    height: auto;
    /* Module edges land between device pixels at most sizes; antialiasing them blurs the
       boundary a scanner is looking for. */
    shape-rendering: crispEdges;
}

.key-fallback { margin-bottom: 16px; }

.key-fallback summary {
    cursor: pointer;
    color: var(--muted);
    margin-bottom: 10px;
}

.key-fallback p { color: var(--muted); margin: 0 0 10px; }

/*
    A password field with a Show/Hide control in it. The button is added by
    js/password-reveal.js, so nothing here is relied on until it is.
*/
.password-field {
    position: relative;
    /* The margin moves off the input and onto the wrapper, or it would be measured inside
       it and the button — sized to the wrapper — would hang below the field. */
    margin-bottom: 16px;
}

.password-field input[type=password],
.password-field input[type=text] {
    margin-bottom: 0;
    /* Room for the button, so a long password does not run underneath it. */
    padding-right: 44px;
}

.password-field .reveal {
    position: absolute;
    top: 0;
    right: 0;
    height: 100%;
    /* Buttons on these pages are full-width submit buttons. This one is not. */
    width: auto;
    padding: 0 12px;
    background: none;
    border: 0;
    border-radius: var(--radius-sm);
    color: var(--muted);
    cursor: pointer;
    /* Centres the icon against the field rather than sitting it on the text baseline. */
    display: flex;
    align-items: center;
}

.password-field .reveal:hover { color: var(--ink); background: none; }

.password-field .reveal:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

/*
    Two fields that belong together on one line. They stack below 420px, where a half-width
    name field stops being usable rather than merely tight.
*/
.field-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 14px;
}

.field-row > div { min-width: 0; }

@media (max-width: 420px) {
    .field-row { grid-template-columns: 1fr; gap: 0; }
}

/*
    Full bleed below 480px.

    The card's 28px plus the shell's 16px spends 44px of each edge on a screen that may be
    360px wide, leaving a field 272px. Dropping the gutter and trimming the padding returns
    48px of that. The border, radius and shadow go with it: together they draw a card
    floating on a surface, and at this width there is no surface left for it to float on.
*/
@media (max-width: 480px) {
    .shell { padding-inline: 0; }

    .card {
        padding: 22px 20px 24px;
        border: 0;
        border-radius: 0;
        box-shadow: none;
    }

    /* No longer sitting inside the card's padding, so it needs its own or it runs into the
       edge of the screen. */
    .footer { padding: 0 20px; }
}

/* Nothing here animates on its own; these transitions answer a hover or a focus. Honour the
   setting anyway, because the person who asked for less motion asked for all of it. */
@media (prefers-reduced-motion: reduce) {
    * { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
