/* Sign-in + code screens (_System/_Auth_Screen.php) and the 4xx error screens (_System/_Error_Page.php, "Error pages" block at the end). Stand-alone: no Bootstrap / AdminLTE on these pages.
   Colour tokens are comma-separated, as in the rest of the app. Follows the system theme unless the app's saved choice set html[data-theme]. */

:root {
    --a-page: 248, 246, 244;
    --a-surface: 255, 255, 255;
    --a-ink: 28, 25, 23;
    --a-ink-2: 87, 83, 78;
    --a-line: 214, 211, 209;
    --a-field: 255, 255, 255;
    --a-brand: 79, 70, 229;
    --a-action: 67, 56, 202;        /* brand darkened: white text on it passes WCAG AA */
    --a-action-hi: 55, 48, 163;
    --a-link: 67, 56, 202;
    --a-danger: 185, 28, 28;
    --a-danger-bg: 254, 242, 242;
    --a-warn: 146, 84, 14;
    --a-warn-bg: 255, 247, 237;
    --a-ok: 21, 128, 61;
    --a-ok-bg: 240, 253, 244;
    color-scheme: light;
}
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --a-page: 15, 20, 34;
        --a-surface: 22, 28, 45;
        --a-ink: 241, 245, 249;
        --a-ink-2: 170, 180, 196;
        --a-line: 63, 74, 98;
        --a-field: 15, 20, 34;
        --a-action: 79, 70, 229;
        --a-action-hi: 99, 102, 241;
        --a-link: 165, 180, 252;
        --a-danger: 252, 165, 165;
        --a-danger-bg: 56, 23, 29;
        --a-warn: 253, 186, 116;
        --a-warn-bg: 58, 37, 18;
        --a-ok: 134, 239, 172;
        --a-ok-bg: 18, 48, 33;
        color-scheme: dark;
    }
}
:root[data-theme="dark"] {
    --a-page: 15, 20, 34;
    --a-surface: 22, 28, 45;
    --a-ink: 241, 245, 249;
    --a-ink-2: 170, 180, 196;
    --a-line: 63, 74, 98;
    --a-field: 15, 20, 34;
    --a-action: 79, 70, 229;
    --a-action-hi: 99, 102, 241;
    --a-link: 165, 180, 252;
    --a-danger: 252, 165, 165;
    --a-danger-bg: 56, 23, 29;
    --a-warn: 253, 186, 116;
    --a-warn-bg: 58, 37, 18;
    --a-ok: 134, 239, 172;
    --a-ok-bg: 18, 48, 33;
    color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
.auth-page {
    margin: 0;
    background: rgb(var(--a-page));
    color: rgb(var(--a-ink));
    font: 400 15px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, "Noto Sans Ethiopic", "Helvetica Neue", Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}
.auth-page [hidden] { display: none !important; }
.auth-icon { width: 18px; height: 18px; flex: none; }
.auth-page a { color: rgb(var(--a-link)); }
.auth-page :focus-visible { outline: 2px solid rgb(var(--a-brand)); outline-offset: 2px; }

/* ---- Layout: brand panel + form. Phones: brand becomes a slim bar ---- */
.auth-layout { min-height: 100vh; min-height: 100dvh; display: grid; grid-template-rows: auto 1fr; }
@media (min-width: 960px) {
    .auth-layout { grid-template-rows: none; grid-template-columns: minmax(380px, 42%) 1fr; }
}

.auth-side {
    color: #fff;
    background: #13122e;
    padding: 12px 16px;
    padding-top: max(12px, env(safe-area-inset-top));
    padding-left: max(16px, env(safe-area-inset-left));
    position: relative;
    overflow: hidden;
}
.auth-side::before {   /* the brand accent: a single warm edge */
    content: "";
    position: absolute;
    inset: auto 0 0 0;
    height: 3px;
    background: rgb(var(--a-brand));
}
.auth-side__brand { position: relative; display: inline-flex; align-items: center; gap: 10px; color: #fff !important; text-decoration: none; font-weight: 600; font-size: 16px; }
.auth-side__brand img { width: 32px; height: 32px; object-fit: contain; background: #fff; border-radius: 8px; padding: 3px; }
.auth-side__body, .auth-side__foot { display: none; }

@media (min-width: 960px) {
    .auth-side {
        display: flex;
        flex-direction: column;
        padding: 40px clamp(32px, 4vw, 56px);
        /* Embers low on the left, a faint answer top right, over a warm near-black. Percent sizes, so it holds from a laptop to a wide monitor. */
        background:
            radial-gradient(90% 55% at 0% 100%, rgba(79, 70, 229, .46) 0%, rgba(67, 56, 202, .22) 42%, transparent 72%),
            radial-gradient(70% 40% at 100% 0%, rgba(129, 140, 248, .14) 0%, transparent 70%),
            linear-gradient(165deg, #16143a 0%, #100f26 52%, #1a1640 100%);
    }
    .auth-side::before {   /* the edge line glows brightest beside the embers and fades upward */
        inset: 0 0 0 auto;
        width: 3px;
        height: auto;
        background: linear-gradient(to top, #4f46e5 0%, rgba(79, 70, 229, .55) 55%, rgba(79, 70, 229, .12) 100%);
    }
    .auth-side__brand img { width: 40px; height: 40px; }
    .auth-side__brand { font-size: 18px; }
    .auth-side__body { display: flex; flex-direction: column; gap: 28px; margin-block: auto; padding-block: 32px; position: relative; }
    .auth-side__foot { display: block; margin: 0; font-size: 12.5px; color: rgba(255, 255, 255, .8); position: relative; }
}
.auth-side__headline { margin: 0; font-size: clamp(26px, 2.6vw, 36px); line-height: 1.2; font-weight: 600; letter-spacing: -.015em; max-width: 18ch; text-wrap: balance; }
.auth-side__points { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; font-size: 14.5px; color: rgba(255, 255, 255, .84); }
.auth-side__points li { display: flex; gap: 12px; align-items: flex-start; }
.auth-side__points .auth-icon { color: #a5b4fc; margin-top: 2px; }

/* contain, on white: these are advertisements with text in them, so they must never be cropped */
.auth-slides { position: relative; aspect-ratio: 16 / 9; max-width: 460px; border-radius: 10px; overflow: hidden; background: #fff; }
.auth-slides img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; opacity: 0; transition: opacity .6s ease; }
.auth-slides img.is-active { opacity: 1; }

/* ---- Form column ---- */
.auth-main {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 28px 16px max(20px, env(safe-area-inset-bottom));
    min-width: 0;
}
.auth-box {
    width: 100%;
    max-width: 400px;
    margin-block: auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
}
@media (min-width: 560px) and (max-width: 959px) {
    .auth-box { background: rgb(var(--a-surface)); border: 1px solid rgb(var(--a-line)); border-radius: 14px; padding: 32px; max-width: 460px; }
}
.auth-footer { margin-top: 28px; font-size: 12.5px; color: rgb(var(--a-ink-2)); text-align: center; }
.auth-footer a { text-decoration: none; }
.auth-footer a:hover { text-decoration: underline; }

.auth-head h1 { margin: 2px 0 4px; font-size: 28px; line-height: 1.2; font-weight: 650; letter-spacing: -.015em; }
.auth-head p { margin: 0; color: rgb(var(--a-ink-2)); overflow-wrap: anywhere; }
.auth-head b { color: rgb(var(--a-ink)); font-weight: 600; }
.auth-head .auth-step { font-size: 12.5px; font-weight: 600; color: rgb(var(--a-link)); }

/* ---- Message ---- */
.auth-alert { display: flex; gap: 10px; padding: 12px 14px; border-radius: 10px; font-size: 14px; border: 1px solid; }
.auth-alert .auth-icon { margin-top: 1px; }
.auth-alert strong { display: block; font-weight: 600; }
.auth-alert span { color: rgb(var(--a-ink)); }
.auth-alert--error { color: rgb(var(--a-danger)); background: rgb(var(--a-danger-bg)); border-color: rgba(var(--a-danger), .35); }
.auth-alert--warning { color: rgb(var(--a-warn)); background: rgb(var(--a-warn-bg)); border-color: rgba(var(--a-warn), .35); }
.auth-alert--success { color: rgb(var(--a-ok)); background: rgb(var(--a-ok-bg)); border-color: rgba(var(--a-ok), .35); }

/* ---- Fields ---- */
.auth-form { display: flex; flex-direction: column; gap: 14px; margin: 0; }
.auth-field label { display: block; margin-bottom: 6px; font-size: 14px; font-weight: 600; }
.auth-input {
    position: relative;
    display: flex;
    align-items: center;
    background: rgb(var(--a-field));
    border: 1px solid rgb(var(--a-line));
    border-radius: 10px;
    transition: border-color .12s ease, box-shadow .12s ease;
}
.auth-input:focus-within { border-color: rgb(var(--a-brand)); box-shadow: 0 0 0 3px rgba(var(--a-brand), .2); }
.auth-input > .auth-icon { margin-left: 13px; color: rgb(var(--a-ink-2)); }
.auth-input input {
    flex: 1;
    min-width: 0;
    height: 46px;
    padding: 0 12px 0 10px;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    font-size: 16px;   /* below 16px, iOS Safari zooms the page on focus */
    outline: 0;
}
.auth-input input:focus-visible { outline: 0; }   /* the wrapper above draws the focus ring */
.auth-input input:-webkit-autofill { -webkit-text-fill-color: rgb(var(--a-ink)); -webkit-box-shadow: 0 0 0 40px rgb(var(--a-field)) inset; border-radius: 10px; }
.auth-reveal { flex: none; display: grid; place-items: center; width: 44px; height: 44px; margin-right: 1px; padding: 0; border: 0; border-radius: 9px; background: none; color: rgb(var(--a-ink-2)); cursor: pointer; }
.auth-reveal span { display: grid; }
.auth-reveal:hover { color: rgb(var(--a-ink)); }
.auth-hint { margin: 6px 0 0; font-size: 13px; color: rgb(var(--a-ink-2)); font-variant-numeric: tabular-nums; }
.auth-hint--warn { color: rgb(var(--a-warn)); font-weight: 600; }

.auth-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.auth-check { display: inline-flex; align-items: center; gap: 9px; min-height: 44px; font-size: 14px; cursor: pointer; }
.auth-check input { width: 18px; height: 18px; margin: 0; flex: none; accent-color: rgb(var(--a-action)); cursor: pointer; }

/* ---- Buttons ---- */
.auth-submit {
    position: relative;
    display: grid;
    place-items: center;
    width: 100%;
    min-height: 48px;
    padding: 0 16px;
    border: 0;
    border-radius: 10px;
    background: rgb(var(--a-action));
    color: #fff;
    font: inherit;
    font-size: 15.5px;
    font-weight: 600;
    cursor: pointer;
    transition: background .12s ease;
}
.auth-submit:hover { background: rgb(var(--a-action-hi)); }
.auth-submit:disabled { opacity: .55; cursor: not-allowed; }
.auth-submit.is-loading { pointer-events: none; }
.auth-submit.is-loading span { visibility: hidden; }
.auth-submit.is-loading::after {
    content: "";
    position: absolute;
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, .4);
    border-top-color: #fff;
    border-radius: 50%;
    animation: auth-spin .7s linear infinite;
}
@keyframes auth-spin { to { transform: rotate(360deg); } }

.auth-link { display: inline-flex; align-items: center; gap: 4px; min-height: 44px; padding: 0; border: 0; background: none; color: rgb(var(--a-link)); font: inherit; font-size: 14px; font-weight: 600; text-decoration: none; cursor: pointer; }
.auth-link:hover:not(:disabled) { text-decoration: underline; }
.auth-link:disabled { color: rgb(var(--a-ink-2)); font-weight: 400; cursor: default; font-variant-numeric: tabular-nums; }
.auth-link .auth-icon { width: 16px; height: 16px; }
.auth-link--quiet { color: rgb(var(--a-ink-2)) !important; font-weight: 400; }

.auth-help { font-size: 14px; border-top: 1px solid rgb(var(--a-line)); padding-top: 6px; }
.auth-help summary { display: inline-flex; align-items: center; gap: 7px; min-height: 44px; color: rgb(var(--a-ink-2)); cursor: pointer; list-style: none; }
.auth-help summary::-webkit-details-marker { display: none; }
.auth-help summary:hover { color: rgb(var(--a-ink)); }
.auth-help .auth-icon { width: 16px; height: 16px; }
.auth-help p { margin: 6px 0 0; color: rgb(var(--a-ink-2)); overflow-wrap: anywhere; }

.auth-otp-meta { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0 12px; margin-top: 4px; }
.auth-otp-meta .auth-hint { margin: 0; }
.auth-otp-links { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 16px; }
.auth-otp-links form { margin: 0; }

/* ---- Code entry: one real input (paste, SMS autofill and screen readers just work), drawn as six cells ---- */
.otp { position: relative; }
.otp__input {
    display: block;
    width: 100%;
    height: 56px;
    padding: 0 14px;
    border: 1px solid rgb(var(--a-line));
    border-radius: 10px;
    background: rgb(var(--a-field));
    color: inherit;
    font: inherit;
    font-size: 24px;
    font-weight: 600;
    letter-spacing: .4em;
    text-align: center;
}
.otp__cells { display: none; }
.js .otp__input {
    position: absolute;
    inset: 0;
    height: 100%;
    z-index: 1;
    padding: 0;
    border: 0;
    outline: 0;
    background: transparent;
    color: transparent;
    caret-color: transparent;
    font-size: 16px;
    letter-spacing: 0;
    text-align: left;
}
.js .otp__input::selection { background: transparent; color: transparent; }
.js .otp__cells { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: clamp(5px, 2vw, 10px); }
.otp__cells span {
    display: grid;
    place-items: center;
    height: clamp(50px, 14vw, 58px);
    background: rgb(var(--a-field));
    border: 1px solid rgb(var(--a-line));
    border-radius: 10px;
    font-size: 24px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    transition: border-color .12s ease, box-shadow .12s ease;
}
.otp__cells span.is-filled { border-color: rgb(var(--a-ink-2)); }
.otp__cells span.is-active { border-color: rgb(var(--a-brand)); box-shadow: 0 0 0 3px rgba(var(--a-brand), .2); }

/* ---- Very small phones + landscape ---- */
@media (max-height: 520px) and (max-width: 959px) {
    .auth-main { padding-top: 14px; }
    .auth-box { gap: 14px; }
}
@media (prefers-reduced-motion: reduce) {
    .auth-page *, .auth-page *::before, .auth-page *::after { transition: none !important; }
    .auth-submit.is-loading::after { animation-duration: 2s; }
}

/* ---- Error pages (400 ... 408): brand bar on top, one centred column. Phones: no card, 16px gutters ---- */
.err-layout { min-height: 100vh; min-height: 100dvh; display: grid; grid-template-rows: auto 1fr; }
.err-top {
    position: relative;
    background: #13122e;
    padding: 12px 16px;
    padding-top: max(12px, env(safe-area-inset-top));
    padding-left: max(16px, env(safe-area-inset-left));
}
.err-top::after { content: ""; position: absolute; inset: auto 0 0 0; height: 3px; background: rgb(var(--a-brand)); }
.err-main {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 28px 16px max(20px, env(safe-area-inset-bottom));
    min-width: 0;
}
.err-box { width: 100%; max-width: 520px; margin-block: auto; display: flex; flex-direction: column; gap: 22px; }
@media (min-width: 560px) {
    .err-main { padding-top: 48px; }
    .err-box { background: rgb(var(--a-surface)); border: 1px solid rgb(var(--a-line)); border-radius: 14px; padding: 36px 40px 28px; }
}
.err-sr { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

.auth-head .err-code { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; margin: 0 0 6px; }
.err-num { font-size: clamp(56px, 15vw, 76px); line-height: 1; font-weight: 700; letter-spacing: -.04em; color: rgb(var(--a-action)); font-variant-numeric: tabular-nums; }
.err-name { font-size: 12.5px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: rgb(var(--a-ink-2)); }

.err-tips h2 { margin: 0 0 8px; font-size: 14px; font-weight: 600; }
.err-tips ul { margin: 0; padding: 0; list-style: none; display: grid; gap: 8px; }
.err-tips li { position: relative; padding-left: 18px; color: rgb(var(--a-ink-2)); }
.err-tips li::before { content: ""; position: absolute; left: 3px; top: .62em; width: 6px; height: 6px; border-radius: 50%; background: rgb(var(--a-brand)); }
.err-tips b { color: rgb(var(--a-ink)); font-weight: 600; overflow-wrap: anywhere; }

.err-actions { display: flex; flex-direction: column; gap: 10px; }
@media (min-width: 480px) { .err-actions { flex-direction: row; flex-wrap: wrap; } }
.err-actions .err-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 46px;
    padding: 0 18px;
    border: 1px solid rgb(var(--a-line));
    border-radius: 10px;
    background: rgb(var(--a-surface));
    color: rgb(var(--a-ink));
    font: inherit;
    font-size: 15px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: background .12s ease, border-color .12s ease;
}
.err-actions .err-btn:hover { border-color: rgb(var(--a-ink-2)); }
.err-actions .err-btn--primary { border-color: rgb(var(--a-action)); background: rgb(var(--a-action)); color: #fff; }
.err-actions .err-btn--primary:hover { border-color: rgb(var(--a-action-hi)); background: rgb(var(--a-action-hi)); }
.err-actions .err-btn[hidden] { display: none; }

.err-details p { margin: 4px 0 10px; }
.err-details dl { margin: 0; display: grid; gap: 6px; padding: 12px 14px; border-radius: 10px; background: rgba(var(--a-ink), .05); font-size: 13px; }   /* a tint, not --a-page: on phones there is no card around it */
.err-details dl div { display: grid; grid-template-columns: 7.5em 1fr; gap: 10px; }
.err-details dt { color: rgb(var(--a-ink-2)); }
.err-details dd { margin: 0; color: rgb(var(--a-ink)); font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; overflow-wrap: anywhere; }
.err-page .auth-footer { margin-top: 24px; }
