/* =============================================================================
   IBA Availability Form — Shared Component Library
   Sections: Loading Screen | Error Screen | Success Screen | Card Surface |
   Buttons (unified) | Error/Success Messages | Auth Divider | OAuth Buttons |
   Form Elements | Progress Steps (unified) | Passcode Input | Info Box |
   Success Screen Page Overrides | Button Loading Pattern | Toast Notifications
   Requires: tokens.css, base.css
   Legacy class names from per-page stylesheets are kept as grouped selectors —
   restyle here, never rename (js/app.js and inline page JS emit these names).
   ============================================================================= */

/* =============================================================================
   Loading Screen
   ============================================================================= */

.loading-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 80vh;
    gap: var(--space-5);
}

.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--border-subtle);
    border-left-color: var(--cta-blue);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.loading-screen p {
    color: var(--text-muted);
    font-size: var(--text-footnote);
}

/* =============================================================================
   Error Screen
   ============================================================================= */

.error-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 80vh;
    text-align: center;
    gap: var(--space-4);
}

.error-icon {
    width: 64px;
    height: 64px;
    background: var(--color-danger-light);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    font-weight: 600;
    color: var(--color-danger);
}

.error-screen h2 {
    color: var(--text-primary);
    font-size: var(--text-title2);
    font-weight: 600;
    letter-spacing: -0.022em;
}

.error-screen p {
    color: var(--text-secondary);
    font-size: var(--text-subhead);
    max-width: 320px;
    line-height: 1.47;
}

/* =============================================================================
   Success Screen
   ============================================================================= */

.success-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 80vh;
    text-align: center;
    gap: var(--space-3);
}

.success-icon {
    width: 64px;
    height: 64px;
    background: var(--color-success-light);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    color: var(--color-success);
    margin-bottom: var(--space-2);
}

.success-screen h2 {
    color: var(--text-primary);
    font-size: var(--text-title2);
    font-weight: 600;
    letter-spacing: -0.022em;
}

/* Higher-specificity variant included so the note keeps its spacing/color
   inside .success-screen, whose `p { margin: 0 }` override would otherwise win */
.success-note,
.success-screen p.success-note {
    color: var(--text-muted);
    margin-top: var(--space-4);
    font-size: var(--text-footnote);
}

/* =============================================================================
   Card Surface — one base for every page card
   ============================================================================= */

.surface-card,
.login-card,
.onboard-card,
.setup-card {
    background: var(--bg-surface);
    border: 0.5px solid var(--border-hairline);
    border-radius: var(--radius-xl);
    box-shadow: var(--elevation-3);
    padding: var(--space-8);
    width: 100%;
    max-width: 400px;
}

/* Onboarding/setup flows use the wider card */
.surface-card--wide {
    max-width: 480px;
}

/* =============================================================================
   Buttons — unified system (one ruleset per variant; legacy names grouped)
   ============================================================================= */

.submit-btn,
.btn-primary {
    width: 100%;
    padding: var(--space-3) var(--space-6);
    font-family: var(--font-sans);
    font-size: var(--text-subhead);
    font-weight: 600;
    background: linear-gradient(180deg, #3b8df8 0%, #0071e3 100%);
    color: #ffffff;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-normal);
    min-height: var(--touch-target);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    box-shadow: inset 0 0.5px 0 rgba(255,255,255,0.2), 0 1px 3px rgba(0,0,0,0.2);
}

/* Anchors styled as buttons (status screens link back to login) */
a.submit-btn,
a.btn-primary,
a.secondary-btn,
a.btn-secondary {
    text-decoration: none;
}

@media (hover: hover) {
    .submit-btn:hover:not(:disabled),
    .btn-primary:hover:not(:disabled) {
        filter: brightness(1.1);
        box-shadow: inset 0 0.5px 0 rgba(255,255,255,0.2), 0 4px 12px var(--cta-blue-glow);
    }
}

.submit-btn:active:not(:disabled),
.btn-primary:active:not(:disabled) {
    transform: scale(0.98);
    filter: brightness(0.95);
}

.submit-btn:disabled,
.btn-primary:disabled {
    background: var(--bg-surface-3);
    color: var(--text-muted);
    cursor: not-allowed;
    box-shadow: none;
}

.secondary-btn,
.btn-secondary {
    width: 100%;
    padding: var(--space-3) var(--space-5);
    font-size: var(--text-footnote);
    font-weight: 500;
    font-family: var(--font-sans);
    background: rgba(128, 128, 128, 0.12);
    color: var(--text-primary);
    border: 0.5px solid rgba(128, 128, 128, 0.2);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    margin-top: var(--space-3);
    min-height: var(--touch-target);
    display: flex;
    align-items: center;
    justify-content: center;
}

@media (hover: hover) {
    .secondary-btn:hover,
    .btn-secondary:hover {
        background: rgba(128, 128, 128, 0.18);
    }
}

.secondary-btn:active,
.btn-secondary:active {
    transform: scale(0.98);
}

/* =============================================================================
   Error/Success Messages
   ============================================================================= */

.error-message {
    padding: var(--space-3) var(--space-4);
    background: var(--color-danger-light);
    color: var(--color-danger);
    border-radius: var(--radius-md);
    font-size: var(--text-footnote);
    border: 1px solid rgba(255, 59, 48, 0.25);
    margin-bottom: var(--space-4);
    text-align: center;
}

.success-message {
    padding: var(--space-3) var(--space-4);
    background: var(--color-success-light);
    color: var(--color-success);
    border-radius: var(--radius-md);
    font-size: var(--text-footnote);
    border: 1px solid rgba(52, 199, 89, 0.25);
    margin-bottom: var(--space-4);
    text-align: center;
}

/* Onboarding-flow message variants (error/info banners) */
.message {
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    font-size: var(--text-footnote);
    margin-bottom: var(--space-6);
    text-align: center;
}

.message.error {
    background: var(--color-danger-light);
    border: 1px solid rgba(255, 59, 48, 0.25);
    color: var(--color-danger);
}

.message.info {
    background: var(--cta-blue-light);
    border: 1px solid rgba(0, 113, 227, 0.2);
    color: var(--cta-blue);
}

/* =============================================================================
   Auth Divider
   ============================================================================= */

.auth-divider,
.divider {
    display: flex;
    align-items: center;
    margin: var(--space-5) 0;
    color: var(--text-muted);
    font-size: var(--text-footnote);
}

.auth-divider::before,
.auth-divider::after,
.divider::before,
.divider::after {
    content: '';
    flex: 1;
    height: 0.5px;
    background: var(--border-subtle);
}

.auth-divider span,
.divider span {
    padding: 0 var(--space-3);
}

/* =============================================================================
   OAuth Buttons
   ============================================================================= */

.oauth-buttons {
    display: flex;
    gap: var(--space-2);
    margin-bottom: var(--space-4);
}

.oauth-btn,
.auth-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-3);
    font-size: var(--text-footnote);
    font-weight: 500;
    font-family: var(--font-sans);
    border: 0.5px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-primary);
    cursor: pointer;
    transition: all var(--transition-fast);
    min-height: var(--touch-target);
}

.oauth-btn:active,
.auth-btn:active {
    transform: scale(0.98);
}

.oauth-btn svg,
.auth-btn svg {
    flex-shrink: 0;
}

@media (hover: hover) {
    .oauth-btn:hover,
    .auth-btn:hover {
        background: var(--bg-surface-hover);
    }

    .oauth-btn-google:hover,
    .auth-btn-google:hover {
        border-color: #4285F4;
        background: rgba(66, 133, 244, 0.08);
    }

    /* Theme-aware inversion: white-on-dark, black-on-light */
    .oauth-btn-apple:hover,
    .auth-btn-apple:hover {
        background: var(--text-primary);
        color: var(--bg-surface);
        border-color: var(--text-primary);
    }

    .oauth-btn-microsoft:hover,
    .auth-btn-microsoft:hover {
        border-color: #00a4ef;
        background: rgba(0, 164, 239, 0.08);
    }
}

/* =============================================================================
   Form Elements
   ============================================================================= */

.form-group {
    margin-bottom: var(--space-4);
}

.form-group label {
    display: block;
    font-size: var(--text-footnote);
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: var(--space-2);
}

.form-group label .required {
    color: var(--color-danger);
}

.form-group input,
.form-group select {
    width: 100%;
    padding: var(--space-3) var(--space-3);
    font-size: var(--text-subhead);
    font-family: var(--font-sans);
    border: 0.5px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    background: var(--bg-surface-2);
    color: var(--text-primary);
    transition: border-color var(--transition-fast);
    min-height: var(--touch-target-sm);
    box-shadow: inset 0 0.5px 1px rgba(0,0,0,0.04);
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--cta-blue);
    box-shadow: 0 0 0 4px var(--cta-blue-light);
}

.form-group input::placeholder {
    color: var(--text-muted);
}

.form-group input.error {
    border-color: var(--color-danger);
}

.form-hint {
    font-size: var(--text-caption1);
    color: var(--text-muted);
    margin-top: var(--space-1);
}

/* =============================================================================
   Progress Steps — unified (bar segments default, dots via modifier)
   ============================================================================= */

.progress-steps {
    display: flex;
    justify-content: center;
    gap: var(--space-2);
    margin-bottom: var(--space-8);
}

.progress-step {
    width: 32px;
    height: 4px;
    border-radius: 2px;
    background: var(--bg-surface-3);
    transition: background var(--transition-slow);
}

.progress-steps--dots .progress-step {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.progress-step.active {
    background: var(--cta-blue);
}

.progress-step.completed {
    background: var(--color-success);
}

/* =============================================================================
   Passcode Input
   ============================================================================= */

.passcode-input {
    display: flex;
    gap: var(--space-2);
    justify-content: center;
}

.passcode-digit {
    width: 48px;
    height: 56px;
    text-align: center;
    font-size: var(--text-title1);
    font-weight: 600;
    letter-spacing: 0;
    border: 2px solid var(--border-subtle);
    border-radius: var(--radius-md);
    background: var(--bg-surface-2);
    color: var(--text-primary);
    transition: all var(--transition-fast);
}

.passcode-digit:focus {
    outline: none;
    border-color: var(--cta-blue);
    background: var(--cta-blue-light);
    box-shadow: 0 0 0 4px var(--cta-blue-light);
}

/* =============================================================================
   Info Box
   ============================================================================= */

.info-box {
    background: var(--cta-blue-light);
    border: 1px solid rgba(0, 113, 227, 0.2);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    margin-bottom: var(--space-6);
    text-align: center;
}

.info-box .icon {
    width: 48px;
    height: 48px;
    background: var(--cta-blue-light);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto var(--space-4);
}

.info-box .icon svg {
    color: var(--cta-blue);
}

.info-box p {
    color: var(--text-secondary);
    font-size: var(--text-footnote);
    line-height: 1.6;
    margin: 0;
}

.info-box strong {
    color: var(--text-primary);
}

.info-box p + p {
    margin-top: var(--space-3);
}

/* =============================================================================
   Form Section Headings (in-card step titles: 2FA, forgot password, etc.)
   ============================================================================= */

.form-section-title {
    color: var(--text-primary);
    font-size: var(--text-title3);
    font-weight: 600;
    letter-spacing: -0.022em;
    margin: 0 0 var(--space-2) 0;
    text-align: center;
}

.form-section-hint {
    color: var(--text-muted);
    font-size: var(--text-footnote);
    margin: 0 0 var(--space-6) 0;
    text-align: center;
}

/* One-time-code input (2FA, passcodes typed as a single field) */
.code-input {
    text-align: center;
    font-size: var(--text-title1);
    letter-spacing: 8px;
    font-variant-numeric: tabular-nums;
}

/* =============================================================================
   In-Card Status Screens (success / expired / invalid inside a card)
   ============================================================================= */

.invalid-screen,
.expired-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: var(--space-3);
}

.invalid-screen .icon,
.expired-screen .icon {
    width: 64px;
    height: 64px;
    background: var(--color-danger-light);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: var(--space-2);
}

.invalid-screen .icon svg,
.expired-screen .icon svg {
    color: var(--color-danger);
}

.invalid-screen h2,
.expired-screen h2 {
    color: var(--text-primary);
    font-size: var(--text-title3);
    font-weight: 600;
    letter-spacing: -0.022em;
    margin: 0;
}

.invalid-screen p,
.expired-screen p {
    color: var(--text-secondary);
    font-size: var(--text-footnote);
    margin: 0;
}

.invalid-screen .submit-btn,
.expired-screen .submit-btn,
.success-screen .submit-btn {
    margin-top: var(--space-4);
}

/* Status screens nested in a card are compact — the 80vh stretch is for
   full-page (containerless) states on index.html only */
.surface-card .success-screen,
.login-card .success-screen,
.onboard-card .success-screen,
.setup-card .success-screen {
    min-height: 0;
}

/* In-card loading state */
.loading {
    text-align: center;
    padding: var(--space-10) var(--space-4);
}

.loading .spinner {
    margin: 0 auto var(--space-4);
}

.loading p {
    color: var(--text-muted);
    font-size: var(--text-footnote);
}

/* =============================================================================
   Success Screen — page-level overrides (apply after base rules above)
   ============================================================================= */

.success-screen .icon {
    width: 64px;
    height: 64px;
    background: var(--color-success-light);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: var(--space-4);
}

.success-screen .icon svg {
    color: var(--color-success);
}

.success-screen h2 {
    color: var(--text-primary);
    font-size: var(--text-title3);
    margin: 0 0 var(--space-2) 0;
}

.success-screen p {
    color: var(--text-secondary);
    font-size: var(--text-footnote);
    margin: 0;
}

.back-link {
    display: inline-block;
    margin-top: var(--space-6);
    color: var(--cta-blue);
    font-size: var(--text-footnote);
    text-decoration: none;
}

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

/* =============================================================================
   Button Loading Pattern (.btn-text / .btn-loading spans toggled via .hidden)
   ============================================================================= */

.btn-loading {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
}

.submit-btn .spinner {
    width: 18px;
    height: 18px;
    border: 2px solid transparent;
    border-top-color: #ffffff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* =============================================================================
   Toast Notifications
   ============================================================================= */

.toast-container {
    position: fixed;
    top: calc(var(--space-4) + env(safe-area-inset-top, 0px));
    left: 50%;
    transform: translateX(-50%);
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    pointer-events: none;
    width: calc(100% - var(--space-8));
    max-width: 400px;
}

.toast {
    background: var(--bg-surface);
    border: 0.5px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: var(--space-3) var(--space-4);
    box-shadow: var(--shadow-lg);
    font-size: var(--text-footnote);
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: var(--space-3);
    pointer-events: auto;
    transform: translateY(-20px);
    opacity: 0;
    animation: toast-in 300ms var(--ease-out) forwards;
}

.toast.toast-out {
    animation: toast-out 200ms var(--ease-in) forwards;
}

.toast-icon {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
}

.toast.success .toast-icon {
    background: var(--color-success-light);
    color: var(--color-success);
}

.toast.info .toast-icon {
    background: var(--cta-blue-light);
    color: var(--cta-blue);
}

.toast.warning .toast-icon {
    background: var(--color-warning-light);
    color: var(--color-warning);
}

.toast.error .toast-icon {
    background: var(--color-danger-light);
    color: var(--color-danger);
}

.toast-message {
    flex: 1;
    line-height: 1.4;
}

@keyframes toast-in {
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes toast-out {
    to {
        transform: translateY(-20px);
        opacity: 0;
    }
}

@media (min-width: 769px) {
    /* Toast: wider max on desktop */
    .toast-container {
        max-width: 480px;
    }
}
