/* static/css/auth.css — the four auth pages (login, signup, forgot_password,
   reset_password) on the tokens (UX-B8, Identity I; qa/UX-PLAN.md §2 B8).

   Rewritten from the pre-B8 sheet: its 116 colour literals and its 23
   importance overrides are gone; every colour is a static/css/tokens.css role, so the two
   themes need no twin rules (html.dark-mode re-values the tokens). The card
   is Atelier's (qa/ux-v/atelier/skin.css .auth-card: the card surface, the
   22 px radius, the sheet shadow, no border; the dark sheet's 1 px edge is in
   the token), the fields are 48 px, the buttons pills. Font Awesome left these
   pages: the glyphs are Lucide (partials/_lucide.html at render time,
   window.icon() for what auth.js and dark-mode.js draw later). Under 768 px
   the theme toggle leaves the card's corner (UX-1 F-23): it takes a row of its
   own at the top of the page, in the flow, so the two boxes never overlap.
   Breakpoints: the 768 grid (UX-B4), no 480 step. */

/* ── The page ────────────────────────────────────────────────────────── */

/* B21 s3 (CODE-13): this sheet is the `components` cascade layer; the order is declared once, in tokens.css. */
@layer components {

body {
    min-height: 100vh;
    min-height: 100dvh;
    margin: 0;
    display: flex;
    flex-direction: column;
    background: var(--color-background);
    color: var(--color-foreground);
    font-family: var(--font-sans);
    font-size: var(--text-base);
    line-height: var(--leading-normal, 1.5);
}

/* FIX-1a (JRN-SKIP-1; journey-NEW-008): hidden by its own height, not by a fixed
   -40px (the link is 41.6px tall, so 1.6px showed above every auth page). */
.skip-link {
    position: absolute;
    inset-block-start: 0;
    inset-inline-start: var(--space-2);
    z-index: var(--z-sticky);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    background: var(--color-primary);
    color: var(--color-primary-foreground);
    text-decoration: none;
    transform: translateY(calc(-100% - var(--space-2)));
    transition: transform var(--dur-base) var(--ease-standard);
}

.skip-link:focus {
    transform: translateY(var(--space-2));
}

/* ── The theme toggle ────────────────────────────────────────────────── */
.floating-theme-toggle {
    position: fixed;
    inset-block-start: var(--space-4);
    inset-inline-end: var(--space-4);
    z-index: var(--z-sticky);
}

.floating-theme-toggle button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    inline-size: 44px;
    block-size: 44px;
    padding: 0;
    border: 0;
    border-radius: var(--radius-pill);
    background: transparent;
    color: var(--color-muted-foreground);
    cursor: pointer;
    transition: background-color var(--dur-base) var(--ease-standard),
                color var(--dur-base) var(--ease-standard);
}

.floating-theme-toggle button:hover {
    background: var(--color-surface-2);
    color: var(--color-foreground);
}

.floating-theme-toggle button:focus-visible {
    outline: none;
    box-shadow: 0 0 0 var(--ring-width) var(--ring-color);
}

/* ── The layout ──────────────────────────────────────────────────────── */
.auth-main {
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-8) var(--space-4)
             calc(var(--space-8) + env(safe-area-inset-bottom, 0px));
}

.auth-container {
    inline-size: 100%;
    max-width: 520px;
    margin-inline: auto;
}

/* Atelier's card: the card surface, 22 px corners, the sheet shadow (its
   dark twin carries the 1 px edge), no border. */
.auth-card {
    position: relative;
    padding: var(--space-8) var(--space-6);
    border-radius: var(--radius-xl);
    background: var(--color-card);
    color: var(--color-card-foreground);
    box-shadow: var(--shadow-sheet);
}

.auth-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2);
    margin-block-end: var(--space-6);
    text-align: center;
}

.auth-header .auth-wordmark {
    margin-block-end: var(--space-2);
}

.auth-header h1 {
    margin: 0;
    font-size: var(--text-2xl);
    font-weight: var(--weight-title);
    letter-spacing: -0.01em;
    line-height: 1.25;
    color: var(--color-foreground);
}

.auth-header p {
    margin: 0;
    color: var(--color-muted-foreground);
    font-size: var(--text-base);
}

/* ── Flash messages ──────────────────────────────────────────────────── */
.flash {
    position: relative;
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    padding-inline-end: var(--space-12);
    margin-block-end: var(--space-5);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface-2);
    color: var(--color-foreground);
    animation: authSlideIn var(--dur-slow) var(--ease-standard);
}

.flash .lc {
    flex: 0 0 auto;
}

.flash-close {
    position: absolute;
    inset-inline-end: var(--space-2);
    inset-block-start: 50%;
    transform: translateY(-50%);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    inline-size: 32px;
    block-size: 32px;
    padding: 0;
    border: 0;
    border-radius: var(--radius-pill);
    background: transparent;
    color: inherit;
    cursor: pointer;
    opacity: .7;
    transition: opacity var(--dur-fast) var(--ease-standard);
}

.flash-close:hover {
    opacity: 1;
}

.flash-error {
    background: var(--color-danger-tint);
    border-color: color-mix(in srgb, var(--color-danger) 30%, transparent);
    color: var(--color-danger);
}

.flash-success {
    background: color-mix(in srgb, var(--color-success) 10%, var(--color-background));
    border-color: color-mix(in srgb, var(--color-success) 30%, transparent);
    color: var(--color-success);
}

.flash-info {
    background: var(--color-accent);
    border-color: color-mix(in srgb, var(--color-primary) 30%, transparent);
    color: var(--color-primary-text);
}

.flash-warning {
    background: var(--color-warning-tint);
    border-color: color-mix(in srgb, var(--color-warning) 30%, transparent);
    color: var(--color-warning);
}

/* ── The form ────────────────────────────────────────────────────────── */
.auth-form {
    inline-size: 100%;
}

.form-group {
    margin-block-end: var(--space-5);
}

.form-label {
    display: block;
    margin-block-end: var(--space-2);
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--color-foreground);
}

.required {
    margin-inline-start: var(--space-1);
    color: var(--color-danger);
}

.optional-label {
    margin-inline-start: var(--space-1);
    font-size: var(--text-xs);
    font-weight: 400;
    color: var(--color-muted-foreground);
}

.input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

/* The field's glyph at the inline start; the password toggle at the end. */
.input-wrapper .input-icon {
    position: absolute;
    inset-inline-start: var(--space-4);
    z-index: 2;
    color: var(--color-muted-foreground);
    pointer-events: none;
}

.auth-card .form-input {
    inline-size: 100%;
    block-size: 48px;
    padding-block: 0;
    padding-inline: var(--space-12) var(--space-4);
    border: 1px solid var(--color-input);
    border-radius: var(--radius-md);
    background: var(--color-card);
    color: var(--color-foreground);
    font-family: inherit;
    font-size: var(--text-base);
    transition: border-color var(--dur-base) var(--ease-standard),
                box-shadow var(--dur-base) var(--ease-standard);
}

.auth-card .form-input::placeholder {
    color: var(--color-muted-foreground);
}

.auth-card .form-input:focus,
.auth-card .form-input:focus-visible {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 var(--ring-width) var(--ring-color);
}

.auth-card .form-input:invalid:not(:focus):not(:placeholder-shown),
.auth-card .form-input[aria-invalid="true"],
.auth-card .form-input.error {
    border-color: var(--color-danger);
    box-shadow: 0 0 0 var(--ring-width) var(--color-danger-tint);
}

.auth-card .form-input.success {
    border-color: var(--color-success);
}

.input-wrapper:has(.password-toggle) .form-input {
    padding-inline-end: var(--space-12);
}

.password-toggle {
    position: absolute;
    inset-inline-end: var(--space-1);
    z-index: 3;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    inline-size: 40px;
    block-size: 40px;
    padding: 0;
    border: 0;
    border-radius: var(--radius-pill);
    background: transparent;
    color: var(--color-muted-foreground);
    cursor: pointer;
    transition: color var(--dur-fast) var(--ease-standard),
                background-color var(--dur-fast) var(--ease-standard);
}

.password-toggle:hover {
    background: var(--color-surface-2);
    color: var(--color-foreground);
}

.field-help {
    margin-block-start: var(--space-1);
    font-size: var(--text-xs);
    line-height: 1.4;
    color: var(--color-muted-foreground);
}

.field-error {
    display: none;
    margin-block-start: var(--space-2);
    font-size: var(--text-sm);
    color: var(--color-danger);
}

.field-error.show {
    display: block;
    animation: authFadeIn var(--dur-slow) var(--ease-standard);
}

.field-success,
.field-error.show.success {
    color: var(--color-success);
}

.field-success {
    display: none;
    margin-block-start: var(--space-2);
    font-size: var(--text-sm);
}

.field-success:not(:empty) {
    display: block;
    animation: authFadeIn var(--dur-slow) var(--ease-standard);
}

/* ── Options row, checkbox, links ────────────────────────────────────── */
.form-options {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    margin-block-end: var(--space-6);
}

.checkbox-label {
    position: relative;
    display: flex;
    align-items: center;
    gap: var(--space-2);
    cursor: pointer;
    font-size: var(--text-sm);
    color: var(--color-foreground);
}

.checkbox-label input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    inline-size: 1px;
    block-size: 1px;
    cursor: pointer;
}

.checkbox-custom {
    position: relative;
    flex: 0 0 auto;
    inline-size: 20px;
    block-size: 20px;
    border: 1px solid var(--color-input);
    border-radius: var(--radius-sm);
    background: var(--color-card);
    transition: background-color var(--dur-fast) var(--ease-standard),
                border-color var(--dur-fast) var(--ease-standard);
}

.checkbox-label input[type="checkbox"]:checked + .checkbox-custom {
    background: var(--color-primary);
    border-color: var(--color-primary);
}

/* The tick, drawn (no icon font): two borders of a rotated box. */
.checkbox-label input[type="checkbox"]:checked + .checkbox-custom::after {
    content: '';
    position: absolute;
    inset-inline-start: 50%;
    inset-block-start: 50%;
    inline-size: 5px;
    block-size: 10px;
    border: solid var(--color-primary-foreground);
    border-width: 0 2px 2px 0;
    transform: translate(-50%, -60%) rotate(45deg);
}

.checkbox-label input[type="checkbox"]:focus-visible + .checkbox-custom {
    box-shadow: 0 0 0 var(--ring-width) var(--ring-color);
}

.checkbox-text {
    color: var(--color-foreground);
}

.checkbox-text a,
.forgot-password,
.auth-link,
.btn-link {
    color: var(--color-primary-text);
    text-decoration: none;
    transition: color var(--dur-fast) var(--ease-standard);
}

.checkbox-text a:hover,
.forgot-password:hover,
.auth-link:hover,
.btn-link:hover {
    text-decoration: underline;
}

.forgot-password {
    font-size: var(--text-sm);
}

.auth-link {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    font-weight: 500;
}

/* A text button (the backup-code switch): a link's look on a button. */
.btn-link {
    padding: var(--space-1) var(--space-2);
    border: 0;
    background: none;
    font: inherit;
    font-size: var(--text-sm);
    text-decoration: underline;
    cursor: pointer;
}

/* ── Buttons ─────────────────────────────────────────────────────────── */
.btn-primary {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    inline-size: 100%;
    block-size: 48px;
    padding-inline: var(--space-6);
    border: 0;
    border-radius: var(--radius-pill);
    background: var(--color-primary);
    color: var(--color-primary-foreground);
    font-family: inherit;
    font-size: var(--text-base);
    font-weight: 600;
    cursor: pointer;
    transition: background-color var(--dur-base) var(--ease-standard),
                box-shadow var(--dur-base) var(--ease-standard);
}

.btn-primary:hover:not(:disabled) {
    background: color-mix(in srgb, var(--color-primary) 88%, var(--color-foreground));
    box-shadow: var(--shadow-sm);
}

.btn-primary:disabled {
    opacity: .6;
    cursor: not-allowed;
}

.btn-loading {
    display: none;
}

.btn-primary.loading .btn-text,
.btn-primary.loading .btn-icon {
    opacity: 0;
}

.btn-primary.loading .btn-loading {
    display: block;
    position: absolute;
}

/* ── OAuth ───────────────────────────────────────────────────────────── */
.oauth-section {
    margin-block: var(--space-6);
}

.oauth-divider {
    position: relative;
    margin-block: var(--space-6);
    text-align: center;
}

.oauth-divider::before {
    content: '';
    position: absolute;
    inset-inline: 0;
    inset-block-start: 50%;
    block-size: 1px;
    background: var(--color-border);
}

.oauth-divider span {
    position: relative;
    padding-inline: var(--space-4);
    background: var(--color-card);
    color: var(--color-muted-foreground);
    font-size: var(--text-sm);
}

.oauth-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-3);
}

.btn-oauth {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    block-size: var(--h-control);
    padding-inline: var(--space-4);
    border: 1px solid var(--color-input);
    border-radius: var(--radius-pill);
    background: var(--color-card);
    color: var(--color-foreground);
    font-family: inherit;
    font-size: var(--text-base);
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: background-color var(--dur-base) var(--ease-standard),
                border-color var(--dur-base) var(--ease-standard);
}

.btn-oauth:hover {
    background: var(--color-surface-2);
    border-color: var(--color-foreground);
}

/* Ruling 37: the providers' official marks (static/img/brand/, vendored with
   their provenance). The files keep the brand colours their guidelines
   require; nothing here recolours them. GitHub's mark is black on the light
   theme and white on the dark one, so the button carries both and shows one. */
.oauth-mark {
    display: block;
    flex: 0 0 auto;
    inline-size: 18px;
    block-size: 18px;
}

.oauth-mark-dark { display: none; }
html.dark-mode .oauth-mark-light { display: none; }
html.dark-mode .oauth-mark-dark { display: block; }

/* ── Footer ──────────────────────────────────────────────────────────── */
.auth-footer {
    margin-block-start: var(--space-6);
    padding-block-start: var(--space-6);
    border-block-start: 1px solid var(--color-border);
    text-align: center;
}

.auth-footer p {
    margin: 0;
    color: var(--color-muted-foreground);
}

.auth-footer p + p {
    margin-block-start: var(--space-3);
}

/* ── Loading overlay ─────────────────────────────────────────────────── */
.loading-overlay {
    position: fixed;
    inset: 0;
    z-index: var(--z-loading);
    display: none;
    align-items: center;
    justify-content: center;
    background: color-mix(in srgb, var(--color-foreground) 50%, transparent);
}

.loading-overlay.show {
    display: flex;
}

.loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-8);
    border-radius: var(--radius-lg);
    background: var(--color-card);
    color: var(--color-foreground);
    box-shadow: var(--shadow-sheet);
}

.loading-spinner .lc {
    color: var(--color-primary);
}

.loading-spinner p {
    margin: 0;
    font-weight: 500;
}

/* ── Password strength ───────────────────────────────────────────────── */
.password-strength {
    margin-block-start: var(--space-3);
    padding: var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface-2);
}

.strength-bar {
    block-size: 6px;
    margin-block-end: var(--space-2);
    border-radius: var(--radius-pill);
    background: var(--color-border);
    overflow: hidden;
}

.strength-fill,
.strength-bar-fill {
    block-size: 100%;
    border-radius: var(--radius-pill);
    transition: width var(--dur-slow) var(--ease-standard),
                background-color var(--dur-base) var(--ease-standard);
}

.strength-fill.weak,
.strength-bar-fill[data-strength="1"] { background: var(--color-danger); }
.strength-fill.fair,
.strength-bar-fill[data-strength="2"] { background: var(--color-warning); }
.strength-fill.good,
.strength-bar-fill[data-strength="3"] { background: var(--color-primary); }
.strength-fill.strong,
.strength-bar-fill[data-strength="4"] { background: var(--color-success); }

.strength-bar-fill[data-strength="0"] { inline-size: 0; }
.strength-bar-fill[data-strength="1"] { inline-size: 25%; }
.strength-bar-fill[data-strength="2"] { inline-size: 50%; }
.strength-bar-fill[data-strength="3"] { inline-size: 75%; }
.strength-bar-fill[data-strength="4"] { inline-size: 100%; }

.strength-text {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin: 0;
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--color-text-secondary);
}

.strength-text::before {
    content: '';
    display: inline-block;
    inline-size: 8px;
    block-size: 8px;
    border-radius: 50%;
    background: currentColor;
}

.strength-text.weak   { color: var(--color-danger); }
.strength-text.fair   { color: var(--color-warning); }
.strength-text.good   { color: var(--color-primary-text); }
.strength-text.strong { color: var(--color-success); }

.password-requirements {
    margin-block-start: var(--space-3);
}

.req-title {
    margin: 0 0 var(--space-2);
    font-size: var(--text-sm);
    font-weight: 500;
}

.req-list {
    margin: 0;
    padding-inline-start: var(--space-5);
    font-size: var(--text-xs);
    color: var(--color-muted-foreground);
}

/* ── Two-factor step (login) ─────────────────────────────────────────── */
.otp-input-container {
    display: flex;
    justify-content: center;
    gap: var(--space-2);
    margin-block-end: var(--space-3);
}

.otp-input {
    inline-size: 45px;
    block-size: 52px;
    border: 1px solid var(--color-input);
    border-radius: var(--radius-sm);
    background: var(--color-card);
    color: var(--color-foreground);
    font-family: inherit;
    font-size: var(--text-xl);
    font-weight: 600;
    text-align: center;
    outline: none;
    transition: border-color var(--dur-fast) var(--ease-standard),
                box-shadow var(--dur-fast) var(--ease-standard);
}

.otp-input:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 var(--ring-width) var(--ring-color);
}

.otp-input:disabled {
    opacity: .5;
    cursor: not-allowed;
}

.backup-code-input {
    text-align: center;
    font-size: var(--text-base);
    font-weight: 500;
    letter-spacing: .125em;
}

#twofa-group {
    animation: authSlideDown var(--dur-slow) var(--ease-standard);
    transform-origin: top;
}

.twofa-switch {
    margin-block-start: var(--space-3);
    text-align: center;
}

.form-group.hidden-for-2fa {
    display: none;
}

.twofa-identity {
    margin-block-end: var(--space-5);
    padding: var(--space-3);
    border-radius: var(--radius-md);
    background: var(--color-surface-2);
    text-align: center;
}

.twofa-identity p {
    margin: 0;
    font-size: var(--text-sm);
    color: var(--color-muted-foreground);
}

.twofa-identity strong {
    color: var(--color-foreground);
}

/* ── Motion ──────────────────────────────────────────────────────────── */
@keyframes authSlideIn {
    from { opacity: 0; transform: translateY(-10px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes authSlideDown {
    from { opacity: 0; transform: translateY(-10px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes authFadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* ── Screen-reader-only ──────────────────────────────────────────────── */
.sr-only {
    position: absolute;
    inline-size: 1px;
    block-size: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ── Focus ───────────────────────────────────────────────────────────── */
.btn-primary:focus-visible,
.btn-oauth:focus-visible,
.auth-link:focus-visible,
.forgot-password:focus-visible,
.checkbox-text a:focus-visible,
.btn-link:focus-visible,
.password-toggle:focus-visible,
.flash-close:focus-visible {
    outline: none;
    box-shadow: 0 0 0 var(--ring-width) var(--ring-color);
}

/* ── Preferences ─────────────────────────────────────────────────────── */
@media (prefers-contrast: more) {
    .auth-card {
        border: 1px solid var(--color-foreground);
    }

    .auth-card .form-input,
    .btn-oauth {
        border-width: 2px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .flash,
    .field-error.show,
    .field-success:not(:empty),
    #twofa-group {
        animation: none;
    }

    .skip-link,
    .floating-theme-toggle button,
    .flash-close,
    .auth-card .form-input,
    .password-toggle,
    .checkbox-custom,
    .checkbox-text a,
    .forgot-password,
    .auth-link,
    .btn-link,
    .btn-primary,
    .btn-oauth,
    .strength-fill,
    .strength-bar-fill,
    .otp-input {
        transition: none;
    }

    .icon-spin {
        animation: none;
    }
}

/* ── Phones (the 768 grid) ───────────────────────────────────────────── */
@media (max-width: 768px) {
    /* F-23: the toggle leaves the card's corner. It is a row of its own at the
       top of the page, in the flow and end-aligned; the card sits below it,
       so the two never overlap (test_ux8_browser.py reads the two boxes). */
    .floating-theme-toggle {
        position: static;
        display: flex;
        justify-content: flex-end;
        inline-size: 100%;
        max-width: 520px;
        margin-inline: auto;
        padding: var(--space-2) var(--space-2) 0;
        box-sizing: border-box;
    }

    .auth-main {
        align-items: flex-start;
        padding: var(--space-4) var(--space-4)
                 calc(var(--space-6) + env(safe-area-inset-bottom, 0px));
    }

    .auth-card {
        padding: var(--space-6) var(--space-4);
    }

    .auth-header h1 {
        font-size: var(--text-xl);
    }

    .oauth-buttons {
        grid-template-columns: 1fr;
    }

    .form-options {
        flex-direction: column;
        align-items: flex-start;
    }

    .otp-input {
        inline-size: 40px;
        block-size: 48px;
    }
}

} /* end @layer components */
