/*
 * public/app.css — afroz.co.in ID. Calm, accessible auth UI.
 * Mobile-first, light + dark via prefers-color-scheme, WCAG 2.2 AA contrast,
 * visible :focus-visible rings, 44px minimum targets, reduced-motion aware.
 * System fonts only (CSP default-src 'self'; no third-party requests).
 */

:root {
    color-scheme: light dark;

    --bg:          #f6f5f3;
    --surface:     #ffffff;
    --text:        #17161a;   /* 18.0:1 on --surface */
    --muted:       #55525c;   /*  7.6:1 on --surface */
    --border:      #d9d6dd;
    --field-border:#8a8691;   /*  3.6:1 non-text contrast on --surface */
    --accent:      #b3121f;   /*  6.9:1 on --surface; white text on it 6.9:1 */
    --accent-hover:#8f0e19;
    --on-accent:   #ffffff;
    --focus:       #1f5fd6;   /*  5.7:1 on --surface */
    --error-bg:    #fdecee;
    --error-text:  #8f0e19;   /*  8.2:1 on --error-bg */
    --ok-bg:       #e8f5ec;
    --ok-text:     #1b5e32;   /*  6.9:1 on --ok-bg */
    --danger:      #b3121f;
    --shadow:      0 1px 2px rgba(20, 16, 24, .06), 0 8px 24px rgba(20, 16, 24, .06);
    --radius:      14px;
    --radius-sm:   10px;
    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg:          #0a0a0a;
        --surface:     #151517;
        --text:        #f2f1f3;   /* 16.2:1 on --surface */
        --muted:       #b4b1b9;   /*  8.6:1 on --surface */
        --border:      #2c2b30;
        --field-border:#7a7781;   /*  4.1:1 on --surface */
        --accent:      #ff6b74;   /*  6.6:1 on --surface; --on-accent on it 7.2:1 */
        --accent-hover:#ff8a91;
        --on-accent:   #0a0a0a;
        --focus:       #8ab4ff;   /*  8.7:1 on --surface */
        --error-bg:    #3a1216;
        --error-text:  #ffc2c6;   /* 10.8:1 on --error-bg */
        --ok-bg:       #10301c;
        --ok-text:     #aee8bf;   /* 10.3:1 on --ok-bg */
        --danger:      #ff6b74;
        --shadow:      0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
    }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 1rem;
    line-height: 1.55;
    padding-inline: 16px;
    padding-block: 0 48px;
}

[hidden] { display: none !important; }

/* ── Header ─────────────────────────────────────────────────────────────── */
.site-header {
    max-width: 960px;
    margin: 0 auto;
    padding-block: 20px;
}
.brand {
    font-weight: 650;
    letter-spacing: .01em;
    font-size: 1rem;
}
.brand-id {
    display: inline-block;
    margin-left: .25em;
    padding: 0 .45em;
    border-radius: 6px;
    background: var(--accent);
    color: var(--on-accent);
    font-size: .8em;
    line-height: 1.6;
    vertical-align: .08em;
}

/* ── Typography ─────────────────────────────────────────────────────────── */
h1 {
    font-size: 1.625rem;
    line-height: 1.25;
    margin: 0 0 .75rem;
    font-weight: 650;
    letter-spacing: -.01em;
}
h2 {
    font-size: 1.125rem;
    line-height: 1.3;
    margin: 0 0 .5rem;
    font-weight: 620;
}
p { margin: 0 0 1rem; }
.lede, .hint, small { color: var(--muted); }
.hint { font-size: .9375rem; }
small { display: block; font-size: .875rem; margin-top: -.25rem; margin-bottom: 1rem; }

a {
    color: var(--accent);
    text-underline-offset: .2em;
    text-decoration-thickness: 1px;
}
a:hover { color: var(--accent-hover); text-decoration-thickness: 2px; }

/* ── Layout containers ──────────────────────────────────────────────────── */
.auth-box {
    width: 100%;
    max-width: 420px;
    margin: 6vh auto 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 28px 20px;
}
.account-page {
    max-width: 960px;
    margin: 0 auto;
}
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 20px;
}

@media (min-width: 640px) {
    .auth-box { padding: 36px 36px 32px; }
    .card { padding: 28px; }
    h1 { font-size: 1.875rem; }
}

/* ── Forms ──────────────────────────────────────────────────────────────── */
form { margin: 0; }
label {
    display: block;
    font-weight: 560;
    font-size: .9375rem;
    margin: 0 0 .375rem;
}
input[type="email"],
input[type="password"],
input[type="text"] {
    display: block;
    width: 100%;
    min-height: 44px;
    margin: 0 0 1rem;
    padding: 10px 12px;
    font: inherit;
    font-size: 1rem;           /* ≥16px: no iOS zoom on focus */
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--field-border);
    border-radius: var(--radius-sm);
}
input::placeholder { color: var(--muted); }
input:hover { border-color: var(--text); }
input[aria-invalid="true"] { border-color: var(--danger); }
#code { font-family: var(--mono); letter-spacing: .3em; font-size: 1.25rem; }

button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    min-width: 44px;
    padding: 10px 18px;
    font: inherit;
    font-weight: 600;
    color: var(--on-accent);
    background: var(--accent);
    border: 1px solid var(--accent);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background-color .15s ease, border-color .15s ease, color .15s ease;
}
.auth-box button[type="submit"] { width: 100%; }
button:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
button:disabled { opacity: .6; cursor: progress; }

.btn-secondary {
    color: var(--text);
    background: transparent;
    border-color: var(--field-border);
}
.btn-secondary:hover { background: var(--bg); border-color: var(--text); color: var(--text); }
.btn-danger {
    color: var(--danger);
    background: transparent;
    border-color: var(--danger);
}
.btn-danger:hover { color: var(--on-accent); background: var(--danger); border-color: var(--danger); }
.btn-small { padding: 8px 12px; font-size: .9375rem; }
.inline-form { display: inline; }
.signout { margin-top: 8px; }

/* ── Focus: always visible for keyboard users ───────────────────────────── */
:focus { outline: none; }
:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
    border-radius: 4px;
}
input:focus-visible, button:focus-visible { border-radius: var(--radius-sm); }

/* ── Messages ───────────────────────────────────────────────────────────── */
.error, .success {
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: .9375rem;
}
.error   { background: var(--error-bg); color: var(--error-text); }
.success { background: var(--ok-bg);    color: var(--ok-text); }
.badge {
    display: inline-block;
    padding: 0 .5em;
    border-radius: 999px;
    border: 1px solid var(--border);
    color: var(--muted);
    font-size: .8125rem;
    white-space: nowrap;
}

/* ── Recovery codes ─────────────────────────────────────────────────────── */
.codes-output { margin-top: 1rem; }
.codes {
    display: grid;
    grid-template-columns: 1fr;
    gap: 6px 16px;
    margin: 0;
    padding: 14px 14px 14px 2.2em;
    background: var(--bg);
    border: 1px dashed var(--field-border);
    border-radius: var(--radius-sm);
    font-family: var(--mono);
    font-size: 1rem;
}
@media (min-width: 480px) { .codes { grid-template-columns: 1fr 1fr; } }

/* ── Details / hr (TOTP page) ───────────────────────────────────────────── */
hr { border: 0; border-top: 1px solid var(--border); margin: 1.5rem 0; }
details > summary {
    display: flex;
    align-items: center;
    min-height: 44px;
    cursor: pointer;
    color: var(--accent);
    font-weight: 560;
}
details[open] > summary { margin-bottom: .75rem; }

/* ── Tables (sessions, activity) ────────────────────────────────────────── */
.table-wrap {
    overflow-x: auto;
    margin: 0 0 1rem;
    -webkit-overflow-scrolling: touch;
}
table {
    width: 100%;
    border-collapse: collapse;
    font-size: .9375rem;
}
th, td {
    text-align: left;
    padding: 10px 12px 10px 0;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
th { color: var(--muted); font-weight: 560; white-space: nowrap; }
td { overflow-wrap: anywhere; }

.visually-hidden {
    position: absolute !important;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0);
    white-space: nowrap; border: 0;
}

/* ── Motion ─────────────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        transition-duration: .01ms !important;
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        scroll-behavior: auto !important;
    }
}

/* ── Forced colours (Windows high contrast) ─────────────────────────────── */
@media (forced-colors: active) {
    button, .brand-id, .badge { border: 1px solid ButtonText; }
    :focus-visible { outline-color: Highlight; }
}
.auth-links { margin-top: 1rem; }
.notice { padding: .75rem 1rem; border-radius: 6px; border: 1px solid currentColor; }
.totp-key { display: block; font-size: 1.1rem; letter-spacing: .05em; word-break: break-all; margin: .5rem 0; }
.hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
