/* =====================================================================
   auth.css — shared styles for rProxy sign-in / sign-out / reset pages
   Served from /login/ (pre-auth) and used by:
     /login/login.htm, /logout/*, me (reset/2fa/done), register (index/done)
   Branding: <html class="brand-citicom"> shows [data-brand="citicom"],
             otherwise [data-brand="neutral"] is shown.
   ===================================================================== */

:root,
[data-theme="light"] {
    --navy:        #1a3a5c;
    --navy-dark:   #122840;
    --navy-light:  #2a5280;
    --gold:        #f0a500;
    --gold-dark:   #c98900;
    --gold-text:   #1e2432;

    --bg:          #f4f7fb;
    --bg-alt:      #edf1f7;
    --card-bg:     #ffffff;
    --card-foot:   #edf1f7;
    --border:      #dde3ec;
    --text:        #1e2432;
    --text-muted:  #6b7794;
    --label:       #1e2432;

    --input-bg:    #ffffff;
    --input-border:#dde3ec;
    --input-icon:  #8a95ad;
    --focus:       #2a5280;
    --focus-ring:  rgba(42, 82, 128, .18);

    --head-bg:     linear-gradient(135deg, #1a3a5c 55%, #2a5280);
    --topbar-bg:   #1a3a5c;
    --footer-bg:   #ffffff;
    --pill-bg:     rgba(255, 255, 255, .14);
    --link:        #2a5280;

    --success:     #1e7e34;  --success-bg: #d4edda;
    --danger:      #c0392b;  --danger-bg:  #fde8e8;
    --warning:     #856404;  --warning-bg: #fff3cd;

    --shadow:      0 1px 4px rgba(0,0,0,.08), 0 6px 24px rgba(0,0,0,.08);
    --overlay:     rgba(244, 247, 251, .72);

    color-scheme: light;
}

[data-theme="dark"] {
    --navy:        #4a90c4;
    --navy-dark:   #6aaed8;
    --navy-light:  #3a7ab0;

    --bg:          #0f1923;
    --bg-alt:      #162030;
    --card-bg:     #1c2b3a;
    --card-foot:   #162030;
    --border:      #2a3f54;
    --text:        #d8e4f0;
    --text-muted:  #7a96b0;
    --label:       #d8e4f0;

    --input-bg:    #162030;
    --input-border:#2a3f54;
    --input-icon:  #7a96b0;
    --focus:       #4a90c4;
    --focus-ring:  rgba(74, 144, 196, .25);

    --head-bg:     linear-gradient(135deg, #0d1e2e 55%, #1c3450);
    --topbar-bg:   #0d1e2e;
    --footer-bg:   #1c2b3a;
    --pill-bg:     rgba(255, 255, 255, .10);
    --link:        #6aaed8;

    --success:     #4caf6e;  --success-bg: #0d2e1a;
    --danger:      #e57373;  --danger-bg:  #2e0d0d;
    --warning:     #ffd54f;  --warning-bg: #2e2200;

    --shadow:      0 1px 4px rgba(0,0,0,.3), 0 6px 24px rgba(0,0,0,.3);
    --overlay:     rgba(15, 25, 35, .72);

    color-scheme: dark;
}

/* ---------- Branding switch ---------- */
html:not(.brand-citicom) [data-brand="citicom"] { display: none !important; }
html.brand-citicom [data-brand="neutral"]        { display: none !important; }

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    color: var(--text);
    font-family: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 15px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
    -webkit-text-size-adjust: 100%;
}

a { color: var(--link); text-decoration: none; font-weight: 600; }
a:hover { text-decoration: underline; }

.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;
}

/* ---------- Top bar ---------- */
.auth-topbar {
    background: var(--topbar-bg);
    color: #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,.18);
}

.auth-topbar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    height: 56px;
    padding: 0 20px;
}

.auth-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    color: #fff;
    font-weight: 700;
    font-size: 15px;
    white-space: nowrap;
}

.auth-logo { height: 20px; width: auto; display: block; }

.auth-divider {
    width: 1px;
    height: 22px;
    background: rgba(255,255,255,.35);
}

.theme-toggle {
    width: 36px;
    height: 36px;
    flex: 0 0 auto;
    border: 0;
    border-radius: 50%;
    background: rgba(255,255,255,.15);
    color: #fff;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background .15s;
}
.theme-toggle:hover { background: rgba(255,255,255,.25); }
.theme-toggle:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.theme-toggle svg { width: 18px; height: 18px; }
.theme-toggle .icon-sun  { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun  { display: block; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

/* ---------- Main / card ---------- */
.auth-main {
    flex: 1 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px 16px;
}

.auth-card {
    width: 100%;
    max-width: 440px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.auth-card-head {
    position: relative;
    background: var(--head-bg);
    color: #fff;
    padding: 26px 24px 18px;
    border-bottom: 3px solid var(--gold);
}

.auth-card-head h1 {
    margin: 0;
    font-size: 22px;
    font-weight: 600;
    line-height: 1.25;
    padding-right: 120px;   /* room for the IP pill */
}

.auth-card-head p {
    margin: 6px 0 0;
    font-size: 13.5px;
    color: rgba(255,255,255,.85);
}

.ip-pill {
    position: absolute;
    top: 12px;
    right: 12px;
    max-width: 46%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 2px 9px;
    border-radius: 999px;
    background: var(--pill-bg);
    color: rgba(255,255,255,.9);
    font: 500 11px/1.6 ui-monospace, "Cascadia Mono", Consolas, "SFMono-Regular", Menlo, monospace;
    letter-spacing: .02em;
}
.ip-pill:empty { display: none; }

.auth-card-body { padding: 24px; }

.auth-card-foot {
    background: var(--card-foot);
    border-top: 1px solid var(--border);
    padding: 14px 24px 16px;
    text-align: center;
    font-size: 13px;
    color: var(--text-muted);
}

.foot-links {
    margin-top: 4px;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 4px 12px;
}
.foot-sep { width: 1px; height: 14px; background: var(--text-muted); opacity: .6; }

/* ---------- Forms ---------- */
.field { margin-bottom: 18px; }

.field-label {
    display: block;
    margin-bottom: 6px;
    font-size: 13.5px;
    font-weight: 700;
    color: var(--label);
}

.input-wrap { position: relative; }

.input-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 17px;
    height: 17px;
    color: var(--input-icon);
    pointer-events: none;
}

/* !important on background overrides the legacy inline colors set by
   scripts.js (noblank / checkpass / comparepass). */
.form-control {
    display: block;
    width: 100%;
    height: 44px;
    padding: 0 12px;
    border: 1px solid var(--input-border);
    border-radius: 6px;
    background: var(--input-bg) !important;
    color: var(--text);
    font: inherit;
    font-size: 16px;            /* 16px prevents iOS zoom-on-focus */
    transition: border-color .15s, box-shadow .15s;
    -webkit-appearance: none;
    appearance: none;
}
.input-wrap .form-control.has-icon   { padding-left: 38px; }
.input-wrap .form-control.has-toggle { padding-right: 44px; }

.form-control::placeholder { color: var(--input-icon); opacity: 1; }

.form-control:focus {
    outline: none;
    border-color: var(--focus);
    box-shadow: 0 0 0 3px var(--focus-ring);
}

.form-control.is-invalid { border-color: var(--danger); }
.form-control.is-invalid:focus { box-shadow: 0 0 0 3px rgba(192,57,43,.18); }
.form-control.is-valid   { border-color: var(--success); }

.form-control.code-input {
    text-align: center;
    letter-spacing: .3em;
    font-family: ui-monospace, "Cascadia Mono", Consolas, Menlo, monospace;
    font-size: 20px;
}

.pw-toggle {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--input-icon);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.pw-toggle:hover { color: var(--text); }
.pw-toggle:focus-visible { outline: 2px solid var(--focus); }
.pw-toggle svg { width: 18px; height: 18px; }
.pw-toggle .icon-eye-off { display: none; }
.pw-toggle[aria-pressed="true"] .icon-eye     { display: none; }
.pw-toggle[aria-pressed="true"] .icon-eye-off { display: block; }

.field-hint {
    margin-top: 6px;
    font-size: 12.5px;
    color: var(--text-muted);
}

.caps-warn {
    display: none;
    margin-top: 6px;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--warning);
}
.caps-warn.show { display: flex; align-items: center; gap: 6px; }
.caps-warn svg { width: 14px; height: 14px; }

/* Password rules checklist */
.pw-rules {
    list-style: none;
    margin: 8px 0 0;
    padding: 0;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 3px 12px;
    font-size: 12.5px;
    color: var(--text-muted);
}
.pw-rules li { display: flex; align-items: center; gap: 6px; }
.pw-rules li::before {
    content: "";
    width: 8px; height: 8px;
    border-radius: 50%;
    border: 1.5px solid currentColor;
    flex: 0 0 auto;
}
.pw-rules li.ok { color: var(--success); }
.pw-rules li.ok::before { background: currentColor; }
.pw-rules .rule-note { grid-column: 1 / -1; font-style: italic; }
.pw-rules .rule-note::before { display: none; }

/* Segmented radio (Personal Cell / Personal eMail) */
.segmented {
    position: relative;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
    border: 1px solid var(--input-border);
    border-radius: 6px;
    overflow: hidden;
    background: var(--input-bg);
}
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
    padding: 0 10px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-muted);
    transition: background .15s, color .15s;
}
.segmented label:nth-of-type(2) { border-left: 1px solid var(--input-border); }
.segmented label svg { width: 17px; height: 17px; }
.segmented input:checked + label { background: var(--navy); color: #fff; }
[data-theme="dark"] .segmented input:checked + label { background: var(--navy-light); }
.segmented input:focus-visible + label { box-shadow: inset 0 0 0 2px var(--gold); }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
    padding: 0 18px;
    border: 1px solid transparent;
    border-radius: 6px;
    font: inherit;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none !important;
    transition: background .15s, transform .08s, box-shadow .15s;
}
.btn svg { width: 17px; height: 17px; flex: 0 0 auto; }
.btn span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--focus-ring); }
.btn[disabled] { opacity: .6; cursor: not-allowed; }

.btn-block { display: flex; width: 100%; }

.btn-gold { background: var(--gold); color: var(--gold-text); }
.btn-gold:hover { background: var(--gold-dark); }

.btn-outline {
    background: transparent;
    color: var(--text);
    border-color: var(--border);
}
.btn-outline:hover { background: var(--bg-alt); }

.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row .btn { flex: 1 1 140px; }

/* ---------- Status blocks (logout / done) ---------- */
.status-block { text-align: center; padding: 8px 0 4px; }
.status-icon {
    width: 56px;
    height: 56px;
    margin: 0 auto 14px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--success-bg);
    color: var(--success);
}
.status-icon svg { width: 28px; height: 28px; }
.status-block h2 { margin: 0 0 6px; font-size: 18px; }
.status-block p  { margin: 0 0 18px; color: var(--text-muted); word-break: break-word; }
.status-block strong { color: var(--text); }

.step-intro { margin: 0 0 18px; font-size: 14px; color: var(--text-muted); }
.step-intro strong { color: var(--text); word-break: break-all; }

.spinner {
    width: 40px;
    height: 40px;
    margin: 6px auto 16px;
    border: 4px solid var(--border);
    border-top-color: var(--gold);
    border-radius: 50%;
    animation: auth-spin .8s linear infinite;
}

/* ---------- Busy overlay (busy()/notbusy()) ---------- */
.cover-spin {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
    background: var(--overlay);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
}
.cover-spin.show { display: flex; }
.cover-spin::after {
    content: "";
    width: 44px;
    height: 44px;
    border: 4px solid var(--border);
    border-top-color: var(--gold);
    border-radius: 50%;
    animation: auth-spin .8s linear infinite;
}

@keyframes auth-spin { to { transform: rotate(360deg); } }

/* ---------- Page footer ---------- */
.auth-footer {
    flex-shrink: 0;
    background: var(--footer-bg);
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    text-align: center;
    font-size: 12.5px;
    padding: 12px 16px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
}

/* ---------- Responsive ---------- */
@media (max-width: 520px) {
    .auth-topbar-inner { height: 52px; padding: 0 14px; }
    .auth-logo { height: 18px; }
    .auth-main { align-items: flex-start; padding: 20px 12px 28px; }
    .auth-card-head { padding: 34px 18px 16px; }
    .auth-card-head h1 { font-size: 20px; padding-right: 0; }
    .ip-pill { top: 10px; right: 10px; max-width: calc(100% - 20px); }
    .auth-card-body { padding: 20px 18px; }
    .auth-card-foot { padding: 14px 18px 16px; }
    .pw-rules { grid-template-columns: 1fr; }
}

@media (max-height: 560px) and (orientation: landscape) {
    .auth-main { align-items: flex-start; padding-top: 16px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .001ms !important; transition: none !important; }
}

/* Inline error under the Register / Forgot Password link */
#forgotmsg { color: var(--danger); font-weight: 600; margin-top: 4px; }

/* Respect the hidden attribute even on elements whose class sets display */
[hidden] { display: none !important; }
