/* =============================================================================
   Delta Iota Brothers Portal — auth.css
   Login, callback, and access-denied shared visual system.
   Extends the existing navy, gold, black, glass, Inter + Outfit design language.
   ============================================================================= */

:root {
    --portal-bg: #03050a;
    --portal-surface: #080c15;
    --portal-surface-raised: #0e1523;
    --portal-card: rgba(255, 255, 255, 0.04);
    --portal-card-hover: rgba(255, 255, 255, 0.075);
    --portal-glass: linear-gradient(165deg, rgba(255, 255, 255, 0.068) 0%, rgba(255, 255, 255, 0.022) 55%, rgba(255, 255, 255, 0.04) 100%);
    --portal-border: rgba(255, 255, 255, 0.085);
    --portal-border-strong: rgba(255, 200, 58, 0.38);
    --portal-navy: #001a4d;
    --portal-blue: #2b74f0;
    --portal-blue-soft: rgba(43, 116, 240, 0.16);
    --portal-blue-glow: rgba(43, 116, 240, 0.42);
    --portal-gold: #ffc83a;
    --portal-gold-soft: rgba(255, 200, 58, 0.13);
    --portal-gold-glow: rgba(255, 200, 58, 0.24);
    --portal-text: #f5f7fb;
    --portal-text-muted: #9aa6bb;
    --portal-success: #3fd9a0;
    --portal-warning: #f7bd45;
    --portal-danger: #ff6f7b;
    --portal-info: #6fb0ff;
    --portal-shadow: 0 40px 90px -30px rgba(0, 0, 0, 0.78), inset 0 1px 0 rgba(255, 255, 255, 0.05);
    --portal-card-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 24px 48px -32px rgba(0, 0, 0, 0.9);
    --portal-radius-sm: 12px;
    --portal-radius-md: 18px;
    --portal-radius-lg: 26px;
    --portal-ease: cubic-bezier(0.22, 1, 0.36, 1);
    --font-main: 'Inter', sans-serif;
    --font-heading: 'Outfit', sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

/* [hidden] must win over component display rules so no layer can accidentally
   reveal a hidden fallback/veil. */
[hidden] {
    display: none !important;
}

.auth-body {
    background-color: var(--portal-bg);
    background-image:
        radial-gradient(1000px 640px at 0% -10%, rgba(0, 52, 150, 0.30), transparent 62%),
        radial-gradient(860px 600px at 100% 110%, rgba(255, 200, 58, 0.09), transparent 60%);
    color: var(--portal-text);
    font-family: var(--font-main);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

/* ---------- Loading veil ---------- */

.auth-loading {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--portal-bg);
    transition: opacity 200ms ease;
}

.auth-loading.is-hidden {
    opacity: 0;
    pointer-events: none;
}

.auth-loading-card {
    text-align: center;
}

.auth-loading-crest {
    width: 64px;
    margin: 0 auto 1.25rem;
    opacity: 0.85;
}

.auth-loading-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid rgba(255, 255, 255, 0.12);
    border-top-color: var(--portal-gold);
    border-radius: 50%;
    margin: 0 auto 1rem;
    animation: auth-spin 0.8s linear infinite;
}

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

.auth-loading-text {
    color: var(--portal-text-muted);
    font-size: 0.9rem;
}

/* Wider config-error copy inside the loading veil (CSP-safe replacement for
   the former inline p.style.maxWidth assignment). */
.auth-loading-text--wide {
    max-width: 360px;
    line-height: 1.5;
}

/* ---------- Login split layout ---------- */

.auth-root { min-height: 100vh; }

.auth-split {
    display: grid;
    grid-template-columns: 56% 44%;
    min-height: 100vh;
}

/* Left brand panel */
.auth-brand {
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: flex-end;
}

.auth-brand-img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: 0;
}

.auth-brand-overlay {
    position: absolute;
    inset: 0;
    z-index: 1;
    background: linear-gradient(135deg, rgba(0, 35, 102, 0.82), rgba(3, 5, 10, 0.92));
}

.auth-brand-content {
    position: relative;
    z-index: 2;
    padding: 3rem;
    max-width: 520px;
}

.auth-brand-content img { width: 56px; margin-bottom: 1.25rem; }

.auth-brand-kicker {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.16em;
    color: var(--portal-gold);
    margin-bottom: 0.75rem;
}

.auth-brand-title {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: clamp(1.75rem, 3vw, 2.5rem);
    line-height: 1.1;
    margin-bottom: 0.75rem;
}

.auth-brand-copy {
    color: var(--portal-text-muted);
    font-size: 1rem;
    line-height: 1.6;
}

/* Right form side */
.auth-form-side {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    background: var(--portal-bg);
}

.auth-card {
    width: 100%;
    max-width: 460px;
    padding: clamp(1.75rem, 4vw, 2.5rem);
    background: var(--portal-glass);
    border: 1px solid var(--portal-border);
    border-radius: var(--portal-radius-lg);
    box-shadow: var(--portal-card-shadow), 0 40px 80px -40px rgba(0, 0, 0, 0.8);
    animation: auth-rise 720ms var(--portal-ease) both;
}
@keyframes auth-rise {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: none; }
}

.auth-card-crest {
    width: 56px;
    margin-bottom: 1.25rem;
}

.eyebrow {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.16em;
    color: var(--portal-gold);
    margin-bottom: 0.5rem;
}

/* ---------- Environment badge (local test only) ---------- */

.env-badge {
    display: inline-block;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    padding: 0.3rem 0.6rem;
    border-radius: 6px;
    margin-bottom: 0.75rem;
}

.env-badge-local {
    color: var(--portal-warning);
    background: rgba(245, 185, 66, 0.12);
    border: 1px solid rgba(245, 185, 66, 0.3);
}

.auth-heading {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: clamp(1.85rem, 3.4vw, 2.4rem);
    line-height: 1.08;
    letter-spacing: -0.02em;
    margin-bottom: 0.6rem;
    background: linear-gradient(118deg, #ffffff 0%, #f4f6fb 50%, #ffd766 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}
@media (forced-colors: active) { .auth-heading { background: none; color: CanvasText; } }

.auth-subhead {
    color: var(--portal-text-muted);
    line-height: 1.6;
    margin-bottom: 1.75rem;
}

/* ---------- Form controls ---------- */

.auth-form { display: flex; flex-direction: column; gap: 1.1rem; }

.field { display: flex; flex-direction: column; gap: 0.4rem; }

.field label {
    font-size: 0.82rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--portal-text);
}

.field input {
    width: 100%;
    padding: 0.8rem 0.95rem;
    background: var(--portal-surface-raised);
    border: 1px solid var(--portal-border);
    border-radius: var(--portal-radius-sm);
    color: var(--portal-text);
    font-family: var(--font-main);
    font-size: 1rem;
    transition: border-color 160ms ease, box-shadow 160ms ease;
}

.field input::placeholder { color: rgba(156, 168, 186, 0.5); }

.field input:focus {
    outline: none;
    border-color: var(--portal-blue);
    box-shadow: 0 0 0 3px var(--portal-blue-soft);
}

.field input[aria-invalid="true"] {
    border-color: var(--portal-danger);
    box-shadow: 0 0 0 3px rgba(255, 107, 117, 0.14);
}

.field input:focus-visible {
    outline: 2px solid var(--portal-gold);
    outline-offset: 2px;
}

.password-field { position: relative; }

.password-field input { padding-right: 4.5rem; }

.password-toggle {
    position: absolute;
    top: 50%;
    right: 0.5rem;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: var(--portal-text-muted);
    font-family: var(--font-main);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    padding: 0.35rem 0.5rem;
    border-radius: 6px;
    min-height: 32px;
}

.password-toggle:hover { color: var(--portal-text); }

.password-toggle:focus-visible {
    outline: 2px solid var(--portal-gold);
    outline-offset: 2px;
}

.field-error {
    color: var(--portal-danger);
    font-size: 0.8125rem;
    min-height: 1em;
    line-height: 1.3;
}

.auth-form-row {
    display: flex;
    justify-content: flex-end;
    margin-top: -0.35rem;
}

.link-btn {
    background: none;
    border: none;
    color: var(--portal-blue);
    font-family: var(--font-main);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    padding: 0;
}

.link-btn:hover { text-decoration: underline; }

.link-btn:focus-visible {
    outline: 2px solid var(--portal-gold);
    outline-offset: 3px;
    border-radius: 4px;
}

/* ---------- Buttons ---------- */

.btn-primary {
    appearance: none;
    border: 1px solid rgba(255, 255, 255, 0.14);
    cursor: pointer;
    font-family: var(--font-main);
    font-size: 0.95rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    padding: 0.9rem 1.5rem;
    border-radius: 13px;
    color: #fff;
    background: linear-gradient(135deg, #3b82f6 0%, #1d5fd6 48%, #0d3f9e 100%);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.22), 0 10px 26px -12px var(--portal-blue-glow);
    transition: transform 220ms var(--portal-ease), box-shadow 220ms ease, opacity 220ms ease, filter 220ms ease;
    min-height: 48px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    text-decoration: none;
}

.btn-primary:hover { box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.26), 0 16px 34px -12px var(--portal-blue-glow); transform: translateY(-1px); filter: brightness(1.07); }
.btn-primary:active { transform: translateY(0) scale(0.985); }

.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; transform: none; box-shadow: none; }

.btn-primary:focus-visible {
    outline: 2px solid var(--portal-gold);
    outline-offset: 3px;
}

.btn-primary.is-loading { pointer-events: none; }

.btn-primary.is-loading::after {
    content: '';
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: auth-spin 0.7s linear infinite;
}

.btn-secondary {
    appearance: none;
    cursor: pointer;
    font-family: var(--font-main);
    font-size: 0.9rem;
    font-weight: 600;
    padding: 0.85rem 1.5rem;
    border-radius: var(--portal-radius-sm);
    color: var(--portal-text);
    background: var(--portal-surface-raised);
    border: 1px solid var(--portal-border);
    text-decoration: none;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: border-color 160ms ease, background 160ms ease;
}

.btn-secondary:hover { border-color: var(--portal-border-strong); background: var(--portal-card-hover); }

.btn-secondary:focus-visible { outline: 2px solid var(--portal-gold); outline-offset: 3px; }

.auth-status {
    font-size: 0.875rem;
    min-height: 1.2em;
    line-height: 1.4;
}

.auth-status.is-error { color: var(--portal-danger); }
.auth-status.is-success { color: var(--portal-success); }
.auth-status.is-info { color: var(--portal-info); }

.auth-fineprint {
    margin-top: 1.5rem;
    font-size: 0.8125rem;
    color: var(--portal-text-muted);
    line-height: 1.5;
}

.auth-fineprint a { color: var(--portal-blue); text-decoration: none; }
.auth-fineprint a:hover { text-decoration: underline; }

.auth-back {
    display: inline-block;
    margin-top: 1rem;
    font-size: 0.85rem;
    color: var(--portal-text-muted);
    text-decoration: none;
}

.auth-back:hover { color: var(--portal-text); }

/* ---------- Forgot-password dialog ---------- */

.dialog-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(3, 5, 10, 0.7);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    animation: dialog-fade 160ms ease;
}

@keyframes dialog-fade { from { opacity: 0; } to { opacity: 1; } }

.dialog {
    width: 100%;
    max-width: 440px;
    background: var(--portal-surface);
    border: 1px solid var(--portal-border);
    border-radius: var(--portal-radius-lg);
    box-shadow: var(--portal-shadow);
    padding: 1.75rem;
    animation: dialog-rise 200ms cubic-bezier(0.25, 1, 0.5, 1);
}

@keyframes dialog-rise {
    from { transform: translateY(12px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.dialog-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.dialog-title {
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 1.35rem;
}

.dialog-close {
    background: none;
    border: none;
    color: var(--portal-text-muted);
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 6px;
}

.dialog-close:hover { color: var(--portal-text); }
.dialog-close:focus-visible { outline: 2px solid var(--portal-gold); outline-offset: 2px; }

.dialog-copy {
    color: var(--portal-text-muted);
    font-size: 0.9rem;
    margin-bottom: 1.25rem;
    line-height: 1.5;
}

.reset-hint {
    margin-top: 1rem;
    font-size: 0.85rem;
    color: var(--portal-success);
    line-height: 1.5;
    background: rgba(66, 211, 146, 0.08);
    border: 1px solid rgba(66, 211, 146, 0.2);
    border-radius: var(--portal-radius-sm);
    padding: 0.75rem 0.85rem;
}

/* ---------- Retryable system-error veil (login page) ---------- */

.auth-system-error {
    position: fixed;
    inset: 0;
    z-index: 9998;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--portal-bg);
    padding: 1.5rem;
    animation: dialog-fade 200ms ease;
}

.auth-system-error-card {
    width: 100%;
    max-width: 460px;
    background: var(--portal-surface);
    border: 1px solid var(--portal-border);
    border-radius: var(--portal-radius-lg);
    box-shadow: var(--portal-shadow);
    padding: 2.5rem;
    text-align: center;
}

.auth-system-error-card .auth-heading { text-align: center; }
.auth-system-error-card .auth-subhead { text-align: center; }

.auth-system-error-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 1.5rem;
}

/* Safe support code shown on fatal/terminal Auth screens (Section 10.7). */
.portal-support-code {
    margin-top: 0.5rem;
    font-size: 0.8125rem;
    color: var(--portal-text-muted);
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
    letter-spacing: 0.02em;
    text-align: center;
}

@media (max-width: 560px) {
    .auth-system-error-card { padding: 1.75rem 1.25rem; }
}

/* ---------- Protocol-recovery instruction block ----------
   Shown only when #auth-actions-protocol is visible (file:// or wrong local
   port). The command and canonical HTTP URL wrap safely on narrow screens and
   remain real links so a user can leave file:// without retyping. */
.auth-protocol-instruction {
    margin-top: 1.25rem;
    text-align: left;
}

.auth-protocol-steps {
    color: var(--portal-text-muted);
    font-size: 0.875rem;
    margin-bottom: 0.6rem;
    line-height: 1.5;
}

.auth-protocol-command {
    margin-bottom: 0.6rem;
}

.auth-protocol-command code {
    display: inline-block;
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
    font-size: 0.825rem;
    color: var(--portal-text);
    background: var(--portal-surface-raised);
    border: 1px solid var(--portal-border);
    border-radius: var(--portal-radius-sm);
    padding: 0.5rem 0.75rem;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.auth-protocol-url-wrap {
    margin-bottom: 0.25rem;
}

/* The canonical URL wraps on narrow screens and keeps a visible focus ring. */
.auth-protocol-url {
    display: inline-block;
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
    font-size: 0.825rem;
    color: var(--portal-blue);
    background: var(--portal-blue-soft);
    border: 1px solid rgba(23, 105, 224, 0.3);
    border-radius: var(--portal-radius-sm);
    padding: 0.5rem 0.75rem;
    text-decoration: none;
    word-break: break-word;
    overflow-wrap: anywhere;
    line-height: 1.5;
}

.auth-protocol-url:hover { text-decoration: underline; }

.auth-protocol-url:focus-visible {
    outline: 2px solid var(--portal-gold);
    outline-offset: 3px;
}

@media (max-width: 560px) {
    .auth-protocol-command code,
    .auth-protocol-url {
        font-size: 0.78rem;
    }
}

/* ---------- Callback page ---------- */

.callback-root {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

.callback-card {
    width: 100%;
    max-width: 460px;
    background: var(--portal-surface);
    border: 1px solid var(--portal-border);
    border-radius: var(--portal-radius-lg);
    box-shadow: var(--portal-shadow);
    padding: 2.5rem;
    text-align: center;
}

.callback-card .auth-card-crest { margin: 0 auto 1.25rem; }
.callback-card .auth-heading { text-align: center; }
.callback-card .auth-subhead { text-align: center; }

.callback-state { animation: dialog-fade 200ms ease; }

.callback-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 1.5rem;
}

.callback-icon {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0 auto 1.25rem;
}

.callback-icon-success { background: rgba(66, 211, 146, 0.14); color: var(--portal-success); border: 1px solid rgba(66, 211, 146, 0.3); }
.callback-icon-danger { background: rgba(255, 107, 117, 0.14); color: var(--portal-danger); border: 1px solid rgba(255, 107, 117, 0.3); }
.callback-icon-info { background: rgba(100, 165, 255, 0.14); color: var(--portal-info); border: 1px solid rgba(100, 165, 255, 0.3); }

/* Password strength checklist */
.password-checklist {
    list-style: none;
    display: grid;
    gap: 0.3rem;
    margin-top: 0.5rem;
}

.password-checklist li {
    font-size: 0.8125rem;
    color: var(--portal-text-muted);
    padding-left: 1.4rem;
    position: relative;
}

.password-checklist li::before {
    content: '\25CB';
    position: absolute;
    left: 0;
    top: 0;
}

.password-checklist li.is-met {
    color: var(--portal-success);
}

.password-checklist li.is-met::before { content: '\2713'; }

/* ---------- Static no-JS / module-failure fallback (login page) ----------
   Reveals a recovery screen after 12 seconds with NO JavaScript required.
   CSS-driven: works even if auth-loader.js is missing or unparseable. */

.auth-static-fallback {
    position: fixed;
    inset: 0;
    z-index: 10001;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background: var(--portal-bg);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.auth-body[data-auth-boot="pending"] .auth-static-fallback {
    animation: auth-static-fallback-reveal 1ms linear 12s forwards;
}

.auth-body:not([data-auth-boot="pending"]) .auth-static-fallback {
    display: none;
}

@keyframes auth-static-fallback-reveal {
    to {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }
}

/* ---------- Loop-stopped recovery screen ---------- */

.auth-loop-stopped {
    position: fixed;
    inset: 0;
    z-index: 9998;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--portal-bg);
    padding: 1.5rem;
    animation: dialog-fade 200ms ease;
}

/* ---------- Responsive ---------- */

@media (max-width: 900px) {
    .auth-split { grid-template-columns: 1fr; }

    .auth-brand {
        min-height: 180px;
        align-items: flex-end;
    }

    .auth-brand-content { padding: 1.5rem; }
    .auth-brand-title { font-size: 1.35rem; }
    .auth-brand-copy { display: none; }

    .auth-form-side { padding: 1rem; }
    .auth-card { max-width: 100%; }
}

@media (max-width: 560px) {
    .callback-card { padding: 1.75rem 1.25rem; }
    .dialog { padding: 1.25rem; }
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }

    .auth-loading-spinner { animation: none; border-top-color: var(--portal-gold); }

    /* The static fallback is a SAFETY TIMEOUT, not decorative motion. Its
       12-second delay must be preserved under reduced-motion so a broken
       module graph can never leave the spinner visible forever. */
    .auth-body[data-auth-boot="pending"] .auth-static-fallback {
        animation-delay: 12s !important;
        animation-duration: 1ms !important;
    }
}

/* ---------- No-script recovery (CSP-safe: no inline styles) ----------
   Used by both the login and callback pages. Styles live here so the
   JavaScript-disabled recovery state is dependable under a production CSP
   that omits 'unsafe-inline' (gap 7 in Section 3.4). */
.auth-noscript {
    position: fixed;
    inset: 0;
    z-index: 10002;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--portal-bg);
    padding: 1.5rem;
}

.auth-noscript-inner {
    max-width: 460px;
    text-align: center;
    color: var(--portal-text);
    font-family: 'Inter', sans-serif;
}

.auth-noscript-inner h1 {
    margin-bottom: 0.75rem;
}

.auth-noscript-inner p {
    color: var(--portal-text-muted);
    line-height: 1.6;
    margin-bottom: 1.5rem;
}

.auth-noscript-inner a {
    color: var(--portal-blue);
}


@media (prefers-reduced-motion: reduce) {
    .auth-card { animation: none; }
}

/* The chapter name is always "Delta Iota" followed by the red ",,". */
.di-mark {
    color: #e8141c;
    font-size: 1.2em;
    font-weight: 800;
    line-height: 0;
    letter-spacing: 0;
}
