/* Light theme (default). Accent is Silverware red, sampled from the logo. */
:root {
    color-scheme: light;
    --bg: #f5f5f6;
    --bg-glow: rgba(203, 33, 39, 0.07);
    --surface: #ffffff;
    --surface-highlight: transparent;
    --text: #18181b;
    --muted: #62626b;
    --border: #e4e4e7;
    --border-strong: #c9c9cf;
    --input-bg: #ffffff;
    --accent: #cb2127;
    --accent-hover: #b11c21;
    --accent-text: #ffffff;
    --accent-shadow: rgba(203, 33, 39, 0.28);
    --focus: rgba(24, 24, 27, 0.14);
    --danger-bg: #fef2f2;
    --danger-border: #fecaca;
    --danger-text: #b91c1c;
    --ok-bg: #f0fdf4;
    --ok-border: #bbf7d0;
    --ok-text: #15803d;
    --shadow: 0 1px 2px rgba(24, 24, 27, 0.05), 0 16px 40px rgba(24, 24, 27, 0.08);
    --radius: 18px;
    --radius-sm: 10px;
    font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* Dark theme: explicit choice, or OS preference when no choice was stored (also covers no-JS).
   Warm greys (like Azure DevOps') rather than near-black or navy: easier on the eyes, and the red still reads cleanly.
   Focus is neutral in both themes; red is kept for the brand and the primary button. */
:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #1b1a19;
    --bg-glow: rgba(203, 33, 39, 0.10);
    --surface: #252423;
    --surface-highlight: rgba(255, 255, 255, 0.04);
    --text: #e8e6e4;
    --muted: #a19f9d;
    --border: #3b3a39;
    --border-strong: #52504e;
    --input-bg: #1e1d1c;
    --accent: #cb2127;
    --accent-hover: #dc3a40;
    --accent-text: #ffffff;
    --accent-shadow: rgba(203, 33, 39, 0.35);
    --focus: rgba(232, 230, 228, 0.18);
    --danger-bg: rgba(239, 68, 68, 0.10);
    --danger-border: rgba(239, 68, 68, 0.35);
    --danger-text: #fca5a5;
    --ok-bg: rgba(34, 197, 94, 0.10);
    --ok-border: rgba(34, 197, 94, 0.35);
    --ok-text: #86efac;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 16px 40px rgba(0, 0, 0, 0.35);
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme]) {
        color-scheme: dark;
        --bg: #1b1a19;
        --bg-glow: rgba(203, 33, 39, 0.10);
        --surface: #252423;
        --surface-highlight: rgba(255, 255, 255, 0.04);
        --text: #e8e6e4;
        --muted: #a19f9d;
        --border: #3b3a39;
        --border-strong: #52504e;
        --input-bg: #1e1d1c;
        --accent: #cb2127;
        --accent-hover: #dc3a40;
        --accent-text: #ffffff;
        --accent-shadow: rgba(203, 33, 39, 0.35);
        --focus: rgba(232, 230, 228, 0.18);
        --danger-bg: rgba(239, 68, 68, 0.10);
        --danger-border: rgba(239, 68, 68, 0.35);
        --danger-text: #fca5a5;
        --ok-bg: rgba(34, 197, 94, 0.10);
        --ok-border: rgba(34, 197, 94, 0.35);
        --ok-text: #86efac;
        --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 16px 40px rgba(0, 0, 0, 0.35);
    }
}

*, *::before, *::after { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { margin: 0; }

body {
    min-height: 100vh;
    min-height: 100dvh;
    background:
        radial-gradient(900px 480px at 50% -12%, var(--bg-glow), transparent 70%),
        var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* Layout */
.auth {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
    padding: 2rem 1rem;
}

.card {
    position: relative;
    width: 100%;
    max-width: 420px;
    padding: 2.5rem 2.25rem 2.25rem;
    overflow: hidden;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: inset 0 1px 0 var(--surface-highlight), var(--shadow);
}

/* Thin brand stripe across the top of the card */
.card::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--accent), #e65a5f 50%, var(--accent));
}

/* Brand */
.brand {
    display: flex;
    justify-content: center;
    margin-bottom: 1.25rem;
}

.brand-logo {
    display: block;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    box-shadow: 0 6px 18px var(--accent-shadow);
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--accent-text);
    font-size: 1.5rem;
    font-weight: 700;
    box-shadow: 0 6px 18px var(--accent-shadow);
}

.card-title {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 650;
    letter-spacing: -0.02em;
    text-align: center;
}

.card-subtitle {
    margin: 0.375rem 0 1.75rem;
    color: var(--muted);
    font-size: 0.9375rem;
    text-align: center;
}

/* Form */
.form {
    display: grid;
    gap: 1.125rem;
}

.field {
    display: grid;
    gap: 0.4rem;
}

.field label {
    font-size: 0.875rem;
    font-weight: 550;
}

.field input {
    width: 100%;
    height: 46px;
    padding: 0 0.9375rem;
    font: inherit;
    color: var(--text);
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field input:hover { border-color: var(--border-strong); }

.field input:focus {
    outline: none;
    border-color: var(--text);
    box-shadow: 0 0 0 4px var(--focus);
}

.checkbox {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--muted);
    cursor: pointer;
    user-select: none;
}

.checkbox input {
    width: 1rem;
    height: 1rem;
    margin: 0;
    accent-color: var(--text);
    cursor: pointer;
}

.input-group { position: relative; }

.input-group input { padding-right: 2.875rem; }

.reveal {
    position: absolute;
    top: 5px;
    right: 5px;
    bottom: 5px;
    width: 36px;
    display: grid;
    place-items: center;
    padding: 0;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
}

.reveal:hover { color: var(--text); }

.reveal .icon-eye-off,
.reveal[aria-pressed="true"] .icon-eye { display: none; }

.reveal[aria-pressed="true"] .icon-eye-off { display: block; }

.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    height: 46px;
    margin-top: 0.375rem;
    border: 0;
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: var(--accent-text);
    font: inherit;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12), 0 6px 16px var(--accent-shadow);
    transition: background-color 0.15s ease, box-shadow 0.15s ease, transform 0.05s ease;
}

.btn-primary:hover { background: var(--accent-hover); }

.btn-primary:active { transform: translateY(1px); }

.btn-primary[aria-busy="true"] {
    cursor: progress;
    opacity: 0.85;
}

.spinner {
    display: none;
    width: 16px;
    height: 16px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

.btn-primary[aria-busy="true"] .spinner { display: inline-block; }

@keyframes spin { to { transform: rotate(360deg); } }

.alert {
    display: flex;
    align-items: flex-start;
    gap: 0.625rem;
    margin: 0 0 1.25rem;
    padding: 0.75rem 0.875rem;
    border: 1px solid var(--danger-border);
    border-radius: var(--radius-sm);
    background: var(--danger-bg);
    color: var(--danger-text);
    font-size: 0.875rem;
}

.alert svg {
    flex: none;
    margin-top: 0.125rem;
}

/* MFA method picker: whole row is the click target; :has() highlights the chosen one (radio still works without it) */
.method-list {
    display: grid;
    gap: 0.625rem;
    margin: 0;
    padding: 0;
    border: 0;
    min-width: 0;
}

.method-option {
    display: grid;
    grid-template-columns: auto auto 1fr;
    align-items: center;
    gap: 0.875rem;
    padding: 0.875rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--input-bg);
    cursor: pointer;
    transition: border-color 0.15s ease, background-color 0.15s ease, box-shadow 0.15s ease;
}

.method-option:hover { border-color: var(--border-strong); }

.method-option:has(input:checked) {
    border-color: var(--text);
    background: color-mix(in srgb, var(--text) 6%, var(--input-bg));
}

.method-option:has(input:focus-visible) { box-shadow: 0 0 0 4px var(--focus); }

.method-option input[type="radio"] {
    width: 18px;
    height: 18px;
    margin: 0;
    accent-color: var(--text);
    cursor: pointer;
}

.method-icon {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    /* Neutral, so the red is left for the logo, stripe and the primary button; red circles here were too much in dark */
    background: color-mix(in srgb, var(--text) 8%, transparent);
    color: var(--muted);
}

/* The chosen method's icon steps up to the text colour */
.method-option:has(input:checked) .method-icon { color: var(--text); }

.method-text {
    display: grid;
    min-width: 0;
}

.method-type {
    font-size: 0.9375rem;
    font-weight: 600;
}

.method-target {
    overflow: hidden;
    color: var(--muted);
    font-size: 0.875rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* A quiet note under a method (e.g. email once there's an app); wraps, unlike the target */
.method-hint {
    margin-top: 0.25rem;
    color: var(--muted);
    font-size: 0.8125rem;
    line-height: 1.4;
}

/* MFA code entry */
.field input.code-input {
    height: 56px;
    padding: 0 0.75rem;
    font-size: 1.5rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.5em;
    text-align: center;
    /* letter-spacing adds space after the last digit too; nudge so the code looks centred */
    text-indent: 0.5em;
}

.field input.code-input::placeholder {
    color: var(--border-strong);
    font-weight: 500;
}

/* Authenticator app setup: the QR code on white in both themes (scanners need dark on light), and the key to type */
.totp-setup {
    display: grid;
    justify-items: center;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
}

.totp-qr {
    display: block;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fff;
    image-rendering: pixelated;
}

.totp-key-label {
    margin: 0.25rem 0 0;
    color: var(--muted);
    font-size: 0.8125rem;
}

.totp-key {
    font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
    font-size: 0.9375rem;
    letter-spacing: 0.05em;
    user-select: all;
    overflow-wrap: anywhere;
    text-align: center;
}

.card-subtitle strong {
    color: var(--text);
    font-weight: 600;
}

/* Secondary actions under a form */
.card-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.25rem 1.5rem;
    margin-top: 1.25rem;
}

.card-actions form { margin: 0; }

.btn-link {
    padding: 0.25rem 0;
    border: 0;
    background: none;
    color: var(--muted);
    font: inherit;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
}

.btn-link:hover {
    color: var(--text);
    text-decoration: underline;
    text-underline-offset: 3px;
}

.btn-link:focus-visible {
    outline: none;
    border-radius: 4px;
    box-shadow: 0 0 0 4px var(--focus);
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Theme toggle */
.theme-toggle {
    position: fixed;
    top: 1rem;
    right: 1rem;
    /* Above the card, which is positioned too and comes later in the page */
    z-index: 10;
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    color: var(--muted);
    cursor: pointer;
    transition: color 0.15s ease, border-color 0.15s ease;
}

.theme-toggle:hover {
    color: var(--text);
    border-color: var(--border-strong);
}

.theme-toggle .icon-sun,
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }

.reveal:focus-visible,
.theme-toggle:focus-visible {
    outline: none;
    box-shadow: 0 0 0 4px var(--focus);
}

.btn-primary:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px var(--surface), 0 0 0 5px var(--accent);
}

.alert-ok {
    border-color: var(--ok-border);
    background: var(--ok-bg);
    color: var(--ok-text);
}

a.btn-link { text-decoration: none; }

.btn-link-danger { color: var(--danger-text); }

/* A section's main action (Security > Password > Change): the text colour with a faint underline, like links in
   MyPass and Reporting, a step up from the grey .btn-link. Not red, which reads as an error. */
/* "a." to outrank a.btn-link's text-decoration: none */
a.btn-link-accent,
.btn-link-accent {
    color: var(--text);
    text-decoration: underline;
    text-decoration-color: var(--border-strong);
    text-underline-offset: 3px;
}

.btn-link-accent:hover {
    color: var(--text);
    text-decoration-color: currentColor;
}

/* Confirm dialog (account.js, forms with data-confirm-title): the same look as MyPass's */
/* The padding is on the inner form, so a click on the dialog element itself is always the backdrop */
.dialog {
    width: min(440px, calc(100vw - 2rem));
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow);
}

.dialog > form { padding: 1.5rem; }

.dialog::backdrop { background: rgba(0, 0, 0, 0.45); }

.dialog .section-text { margin-top: 0.5rem; }

.dialog-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.75rem;
    margin-top: 1.5rem;
}

/* Account area actions (Verify, Send code, confirm dialogs): neutral, a light fill and a stronger border, like
   MyPass's and Reporting's primary buttons. Red .btn-primary is kept for the sign-in pages. */
.btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    height: 40px;
    padding: 0 1.125rem;
    border: 1px solid color-mix(in srgb, var(--text) 35%, var(--surface));
    border-radius: var(--radius-sm);
    background: color-mix(in srgb, var(--text) 8%, var(--surface));
    color: var(--text);
    font: inherit;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
}

.btn-secondary:hover {
    border-color: var(--text);
    background: color-mix(in srgb, var(--text) 14%, var(--surface));
}

.btn-secondary:active { transform: translateY(1px); }

.btn-secondary:focus-visible {
    outline: none;
    box-shadow: 0 0 0 4px var(--focus);
}

.btn-secondary[aria-busy="true"] {
    cursor: progress;
    opacity: 0.85;
}

.btn-secondary[aria-busy="true"] .spinner { display: inline-block; }

/* Quiet bordered button (Cancel) */
.btn-ghost {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 40px;
    padding: 0 1.125rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-weight: 550;
    cursor: pointer;
    transition: border-color 0.15s ease;
}

.btn-ghost:hover { border-color: var(--border-strong); }

/* Destructive: outlined, so it never reads as the safe default */
.btn-danger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 40px;
    padding: 0 1.125rem;
    border: 1px solid var(--danger-border);
    border-radius: var(--radius-sm);
    background: var(--danger-bg);
    color: var(--danger-text);
    font: inherit;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
    transition: border-color 0.15s ease, transform 0.05s ease;
}

.btn-danger:hover { border-color: var(--danger-text); }

.btn-danger:active { transform: translateY(1px); }

.btn-ghost:focus-visible,
.btn-danger:focus-visible {
    outline: none;
    box-shadow: 0 0 0 4px var(--focus);
}

/* A one-button form inside a line of text, e.g. "Turn on" beside a badge */
.inline-form {
    display: inline;
    margin: 0;
}

/* A primary button sized to its label, for actions inside a page rather than a form's main submit */
.btn-inline {
    height: 40px;
    margin-top: 0;
    padding: 0 1.125rem;
}

/* Account area (AccountAreaShell): wider card with a user header and tabs */
.card-wide {
    max-width: 720px;
    padding-top: 1.75rem;
}

.area-header {
    display: flex;
    align-items: center;
    gap: 0.875rem;
    margin-bottom: 1.25rem;
}

.area-brand { display: flex; }

.brand-logo-sm,
.brand-mark-sm {
    width: 40px;
    height: 40px;
    font-size: 1rem;
    box-shadow: none;
}

.area-user {
    display: grid;
    flex: 1;
    min-width: 0;
    line-height: 1.3;
}

.area-user-name {
    overflow: hidden;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.area-user-email {
    overflow: hidden;
    color: var(--muted);
    font-size: 0.875rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.area-header form { margin: 0; }

.tabs {
    display: flex;
    gap: 1.5rem;
    margin: 0 0 1.75rem;
    border-bottom: 1px solid var(--border);
}

.tab {
    margin-bottom: -1px;
    padding: 0.5rem 0;
    border-bottom: 2px solid transparent;
    color: var(--muted);
    font-size: 0.9375rem;
    font-weight: 550;
    text-decoration: none;
}

.tab:hover { color: var(--text); }

.tab[aria-current="page"] {
    border-bottom-color: var(--accent);
    color: var(--text);
}

.tab:focus-visible {
    outline: none;
    border-radius: 4px;
    box-shadow: 0 0 0 4px var(--focus);
}

.area-title {
    margin: 0 0 1.25rem;
    font-size: 1.375rem;
    font-weight: 650;
    letter-spacing: -0.02em;
}

.area-section {
    display: grid;
    gap: 0.875rem;
    padding: 1.25rem 0;
    border-top: 1px solid var(--border);
}

.area-section form { margin: 0; }

.section-head {
    display: flex;
    align-items: center;
    gap: 0.625rem;
}

.section-title {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
}

.section-text {
    margin: 0;
    color: var(--muted);
    font-size: 0.9375rem;
}

.section-text strong {
    color: var(--text);
    font-weight: 600;
}

.badge {
    display: inline-block;
    padding: 0.0625rem 0.5rem;
    border: 1px solid var(--border-strong);
    border-radius: 999px;
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 600;
    vertical-align: middle;
}

.method-type .badge { margin-left: 0.5rem; }

.badge-warn {
    border-color: var(--danger-border);
    background: var(--danger-bg);
    color: var(--danger-text);
}

/* Secondary lines under a row's title (sessions, activity) */
.row-detail {
    color: var(--muted);
    font-size: 0.8125rem;
}

.activity-list {
    display: grid;
    margin: 0;
    padding: 0;
    list-style: none;
}

.activity-row {
    display: grid;
    gap: 0.125rem;
    padding: 0.75rem 0 0.75rem 0.875rem;
    border-left: 3px solid var(--border);
}

.activity-row + .activity-row { border-top: 1px solid var(--border); }

.activity-warn { border-left-color: var(--danger-text); }

.activity-text {
    font-size: 0.9375rem;
    font-weight: 550;
}

.pager {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
}

.badge-on {
    border-color: var(--ok-border);
    background: var(--ok-bg);
    color: var(--ok-text);
}

.callout {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.75rem 0.875rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--input-bg);
    font-size: 0.9375rem;
}

.method-rows {
    display: grid;
    gap: 0.625rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.method-row {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 0.875rem;
    padding: 0.875rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--input-bg);
}

.method-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0 1rem;
}

/* Home page apps: a whole row is the link, styled like the method rows */
.app-rows {
    display: grid;
    gap: 0.625rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.app-row {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 0.875rem;
    padding: 0.875rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--input-bg);
    color: var(--text);
    text-decoration: none;
}

.app-row svg { color: var(--muted); }

.app-row:hover { border-color: var(--border-strong); }

.app-row:hover svg { color: var(--accent); }

.app-row:focus-visible {
    outline: none;
    box-shadow: 0 0 0 4px var(--focus);
}

.password-form { max-width: 420px; }

.form-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1rem;
}

.rule-list {
    margin: 0;
    padding-left: 1.25rem;
    color: var(--muted);
    font-size: 0.9375rem;
}

.add-phone {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 0.75rem;
}

.add-phone .field {
    flex: 1;
    min-width: 220px;
}

.add-phone .field input { height: 40px; }

/* Footer */
.auth-footer {
    display: flex;
    gap: 0.75rem;
    color: var(--muted);
    font-size: 0.8125rem;
}

.auth-footer a { color: inherit; }

.auth-footer a:hover { color: var(--text); }

@media (max-width: 480px) {
    /* Start below the theme toggle, so it never sits on the card */
    .auth { padding-top: 4.5rem; }

    .card {
        padding: 2rem 1.25rem 1.75rem;
        border-radius: 14px;
    }

    .method-row { grid-template-columns: auto 1fr; }

    .method-actions {
        grid-column: 1 / -1;
        justify-content: flex-start;
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        transition: none !important;
        animation-duration: 0.01ms !important;
    }
}
