/* ==========================================================================
   Auth — mobile-first
   --------------------------------------------------------------------------
   Base styles target 360 px. Enhancements at 600 px and 840 px live at the
   bottom of the file. Loaded after theme.css so tokens are available.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Shell — mobile: single column, brand on top, form below
   -------------------------------------------------------------------------- */
.auth-shell {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    padding: 24px 20px calc(24px + env(safe-area-inset-bottom));
    background: var(--md-surface);
}
.auth-hero {
    display: flex;
    justify-content: center;
    margin-bottom: 24px;
}
.auth-content {
    width: 100%;
    max-width: 400px;
    margin: 0 auto;
    flex: 1;
}
.auth-footer {
    margin-top: 32px;
    font-size: 13px;
    color: var(--md-on-surface-variant);
    text-align: center;
}
.auth-footer a { color: var(--md-primary); font-weight: 500; }

/* --------------------------------------------------------------------------
   2. Brand mark
   -------------------------------------------------------------------------- */
.auth-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    text-align: center;
}
.auth-brand-mark {
    width: 64px;
    height: 64px;
    border-radius: 20px;
    background: color-mix(in srgb, var(--md-primary) 14%, transparent);
    color: var(--md-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    flex-shrink: 0;
}
.auth-brand-name {
    font-size: 22px;
    font-weight: 700;
    color: var(--md-on-surface);
    letter-spacing: -0.02em;
    line-height: 1.2;
}
.auth-brand-tagline {
    font-size: 13px;
    color: var(--md-on-surface-variant);
    margin-top: 2px;
}

/* --------------------------------------------------------------------------
   3. Form layout
   -------------------------------------------------------------------------- */
.auth-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.auth-form-header {
    text-align: center;
    margin-bottom: 8px;
}
.auth-form-title {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: 4px;
}
.auth-form-sub {
    font-size: 14px;
    color: var(--md-on-surface-variant);
}

/* --------------------------------------------------------------------------
   4. Fields
   -------------------------------------------------------------------------- */
.field { position: relative; }

.field-label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--md-on-surface-variant);
    margin-bottom: 6px;
}

.field-input {
    width: 100%;
    height: 48px;
    padding: 0 14px;
    font-size: 16px;                    /* prevents iOS zoom-on-focus */
    border: 1px solid var(--md-outline-variant);
    border-radius: var(--md-radius-lg);
    background: var(--md-surface);
    color: var(--md-on-surface);
    transition: border-color 0.12s, box-shadow 0.12s;
}
.field-input:hover { border-color: var(--md-outline); }
.field-input:focus {
    outline: none;
    border-color: var(--md-primary);
    box-shadow: 0 0 0 3px rgba(26,86,50,0.12);
}
.field-input[aria-invalid="true"] { border-color: var(--md-error); }
.field-input[aria-invalid="true"]:focus {
    box-shadow: 0 0 0 3px rgba(220,38,38,0.14);
}
.field-input::placeholder { color: var(--md-on-surface-variant); opacity: 0.55; }

.field-help {
    margin-top: 6px;
    font-size: 12px;
    color: var(--md-on-surface-variant);
    line-height: 1.4;
}
.field-error {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
    font-size: 13px;
    color: var(--md-error);
}

/* Password wrapper with eye toggle */
.field-password { position: relative; }
.field-password .field-input { padding-right: 48px; }
.field-eye {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    width: 40px;
    height: 40px;
    border: 0;
    background: transparent;
    color: var(--md-on-surface-variant);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    border-radius: var(--md-radius);
    cursor: pointer;
}
.field-eye:hover { color: var(--md-on-surface); }

/* Phone input with fixed +265 prefix */
.field-phone {
    display: flex;
    align-items: stretch;
    border: 1px solid var(--md-outline-variant);
    border-radius: var(--md-radius-lg);
    overflow: hidden;
    background: var(--md-surface);
    transition: border-color 0.12s, box-shadow 0.12s;
}
.field-phone:focus-within {
    border-color: var(--md-primary);
    box-shadow: 0 0 0 3px rgba(26,86,50,0.12);
}
.field-prefix {
    display: flex;
    align-items: center;
    padding: 0 12px;
    background: var(--md-surface-bright);
    color: var(--md-on-surface-variant);
    font-size: 15px;
    font-weight: 500;
    border-right: 1px solid var(--md-outline-variant);
    flex-shrink: 0;
}
.field-phone .field-input {
    border: 0;
    border-radius: 0;
    box-shadow: none;
    flex: 1;
}
.field-phone .field-input:focus { box-shadow: none; }

/* Checkbox */
.checkbox {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    font-size: 13px;
    line-height: 1.4;
    color: var(--md-on-surface-variant);
    cursor: pointer;
    user-select: none;
}
.checkbox input[type="checkbox"] {
    width: 20px;
    height: 20px;
    margin-top: 1px;
    accent-color: var(--md-primary);
    flex-shrink: 0;
}
.checkbox a { color: var(--md-primary); }

/* --------------------------------------------------------------------------
   5. Buttons & links
   -------------------------------------------------------------------------- */
.btn-auth {
    height: 48px;
    font-size: 15px;
    font-weight: 600;
    border-radius: var(--md-radius-lg);
    width: 100%;
}
.btn-outline {
    background: var(--md-surface);
    border: 1px solid var(--md-outline-variant);
    color: var(--md-on-surface);
}
.btn-outline:hover {
    background: var(--md-surface-bright);
    border-color: var(--md-outline);
    color: var(--md-on-surface);
}

.auth-links {
    text-align: center;
    font-size: 13px;
    margin-top: 4px;
}
.auth-links a { color: var(--md-primary); font-weight: 500; }
.auth-links a:hover { text-decoration: underline; }

.auth-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--md-on-surface-variant);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin: 4px 0;
}
.auth-divider::before,
.auth-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--md-outline-variant);
}

/* --------------------------------------------------------------------------
   6. Auth state (verify email, OTP confirm, reset done, etc.)
   -------------------------------------------------------------------------- */
.auth-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 12px;
}
.auth-state-icon {
    width: 72px;
    height: 72px;
    border-radius: 24px;
    background: color-mix(in srgb, var(--md-primary) 14%, transparent);
    color: var(--md-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 36px;
    margin-bottom: 8px;
}
.auth-state-icon.success {
    background: var(--status-success-bg);
    color: var(--status-success-fg);
}
.auth-state-icon.danger {
    background: var(--status-danger-bg);
    color: var(--status-danger-fg);
}
.auth-state-title {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin: 0;
}
.auth-state-body {
    font-size: 14px;
    line-height: 1.55;
    color: var(--md-on-surface-variant);
    margin: 0;
}
.auth-state-body strong { color: var(--md-on-surface); font-weight: 600; }
.auth-state-actions { width: 100%; margin-top: 12px; }
.auth-state-help {
    font-size: 13px;
    color: var(--md-on-surface-variant);
    margin-top: 12px;
}
.auth-state-help a { color: var(--md-primary); font-weight: 500; }

/* --------------------------------------------------------------------------
   7. Portal chooser (multi-role users)
   -------------------------------------------------------------------------- */
.portal-greeting {
    font-size: 14px;
    color: var(--md-on-surface-variant);
    margin: 0;
}
.portal-name {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin: 0 0 4px;
}
.portal-sub {
    font-size: 13px;
    color: var(--md-on-surface-variant);
    margin: 0 0 20px;
}
.portal-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 20px;
}
.portal-card {
    display: flex;
    align-items: center;
    gap: 14px;
    width: 100%;
    padding: 16px;
    background: var(--md-surface);
    border: 1px solid var(--md-outline-variant);
    border-radius: var(--md-radius-lg);
    text-align: left;
    cursor: pointer;
    transition: border-color 0.12s, background 0.12s;
}
.portal-card:hover {
    border-color: var(--md-primary);
    background: var(--md-surface-bright);
}
.portal-icon {
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: color-mix(in srgb, var(--md-primary) 14%, transparent);
    color: var(--md-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
}
.portal-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}
.portal-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--md-on-surface);
}
.portal-desc {
    font-size: 12px;
    color: var(--md-on-surface-variant);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.portal-arrow { flex-shrink: 0; color: var(--md-on-surface-variant); }

/* --------------------------------------------------------------------------
   8. OTP inputs — six-digit code
   -------------------------------------------------------------------------- */
.otp-form { width: 100%; }
.otp-inputs {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 6px;
    margin: 20px 0;
}
.otp-digit {
    width: 100%;
    aspect-ratio: 1;
    min-height: 52px;
    font-family: var(--font-mono);
    font-size: 22px;
    font-weight: 600;
    text-align: center;
    border: 2px solid var(--md-outline-variant);
    border-radius: var(--md-radius-lg);
    background: var(--md-surface);
    color: var(--md-on-surface);
    transition: border-color 0.12s, box-shadow 0.12s, background 0.12s;
    -moz-appearance: textfield;
}
.otp-digit::-webkit-outer-spin-button,
.otp-digit::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.otp-digit:focus {
    outline: none;
    border-color: var(--md-primary);
    box-shadow: 0 0 0 3px rgba(26,86,50,0.14);
}
.otp-digit.filled {
    border-color: var(--md-primary);
    background: color-mix(in srgb, var(--md-primary) 8%, transparent);
}
.otp-digit.error {
    border-color: var(--md-error);
    animation: otp-shake 0.4s;
}
@keyframes otp-shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-4px); }
    40%, 80% { transform: translateX(4px); }
}
.otp-resend {
    margin-top: 16px;
    font-size: 13px;
    color: var(--md-on-surface-variant);
    text-align: center;
}
.otp-resend button {
    background: none;
    border: 0;
    padding: 0;
    color: var(--md-primary);
    font-weight: 500;
    font-size: 13px;
    cursor: pointer;
}
.otp-resend button:disabled {
    color: var(--md-on-surface-variant);
    cursor: not-allowed;
}

/* --------------------------------------------------------------------------
   9. Password strength meter
   -------------------------------------------------------------------------- */
.password-strength {
    display: flex;
    gap: 4px;
    margin-top: 8px;
}
.password-strength-bar {
    flex: 1;
    height: 4px;
    border-radius: 2px;
    background: var(--md-outline-variant);
    transition: background 0.2s;
}
.password-strength[data-strength="weak"]   .password-strength-bar:nth-child(1) { background: #dc2626; }
.password-strength[data-strength="fair"]   .password-strength-bar:nth-child(-n+2) { background: #f59e0b; }
.password-strength[data-strength="good"]   .password-strength-bar:nth-child(-n+3) { background: #10b981; }
.password-strength[data-strength="strong"] .password-strength-bar { background: #059669; }

.password-strength-label {
    margin-top: 6px;
    font-size: 12px;
    color: var(--md-on-surface-variant);
}

/* --------------------------------------------------------------------------
   10. Progress steps (multi-step verification)
   -------------------------------------------------------------------------- */
.auth-steps {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    margin-bottom: 24px;
}
.auth-step {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--md-surface-2);
    color: var(--md-on-surface-variant);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    flex-shrink: 0;
}
.auth-step.active { background: var(--md-primary); color: #fff; }
.auth-step.completed { background: var(--status-success-bg); color: var(--status-success-fg); }
.auth-step-line {
    width: 32px;
    height: 2px;
    background: var(--md-outline-variant);
    border-radius: 1px;
}
.auth-step-line.completed { background: var(--status-success-bg); }

/* --------------------------------------------------------------------------
   11. Submit spinner
   -------------------------------------------------------------------------- */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-right: 8px;
    vertical-align: -2px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .otp-digit.error { animation: none; }
    .spinner { animation-duration: 1.6s; }
    .field-input, .otp-digit, .btn-auth, .portal-card { transition: none; }
}

/* --------------------------------------------------------------------------
   12. Dark mode
   -------------------------------------------------------------------------- */
[data-theme="dark"] .field-input,
[data-bs-theme="dark"] .field-input { background: var(--md-surface-1); }
[data-theme="dark"] .otp-digit,
[data-bs-theme="dark"] .otp-digit { background: var(--md-surface-1); }
[data-theme="dark"] .auth-brand-mark,
[data-bs-theme="dark"] .auth-brand-mark { background: rgba(76,154,110,0.16); }
[data-theme="dark"] .field-prefix,
[data-bs-theme="dark"] .field-prefix { background: var(--md-surface-2); }

/* ==========================================================================
   ENHANCEMENTS — all min-width media queries
   ========================================================================== */

/* --------------------------------------------------------------------------
   600 px — Medium: centered card on an elevated backdrop
   -------------------------------------------------------------------------- */
@media (min-width: 600px) {
    .auth-shell {
        background: var(--md-surface-bright);
        padding: 40px 24px;
        align-items: center;
        justify-content: center;
    }
    .auth-hero { margin-bottom: 20px; }
    .auth-content {
        max-width: 440px;
        background: var(--md-surface);
        border: 1px solid var(--md-outline-variant);
        border-radius: 20px;
        padding: 40px 32px;
        box-shadow: 0 8px 32px rgba(0,0,0,0.08);
        flex: 0 0 auto;
    }
    .auth-footer { margin-top: 20px; }

    .field-input { height: 44px; font-size: 14px; }
    .btn-auth    { height: 44px; font-size: 14px; }
}

/* --------------------------------------------------------------------------
   840 px — Expanded: two-column split (brand hero | form)
   -------------------------------------------------------------------------- */
@media (min-width: 840px) {
    .auth-shell {
        display: grid;
        grid-template-columns: 1fr 1fr;
        grid-template-rows: 1fr auto;
        grid-template-areas:
            "hero content"
            "hero footer";
        align-items: stretch;
        justify-content: stretch;
        padding: 0;
        min-height: 100dvh;
    }
    .auth-hero {
        grid-area: hero;
        display: flex;
        flex-direction: column;
        justify-content: center;
        padding: 48px;
        margin: 0;
        background: linear-gradient(160deg,
            color-mix(in srgb, var(--md-primary) 14%, var(--md-surface)) 0%,
            var(--md-surface) 100%);
    }
    .auth-brand {
        align-items: flex-start;
        text-align: left;
        max-width: 400px;
    }
    .auth-brand-name { font-size: 28px; }

    .auth-content {
        grid-area: content;
        max-width: 440px;
        margin: auto;
        border: 0;
        box-shadow: none;
        background: transparent;
        padding: 48px 40px 24px;
    }
    .auth-footer {
        grid-area: footer;
        margin: 0;
        padding-bottom: 32px;
    }

    /* Bonus: hero can hold a short marketing blurb if the template wants it */
    .auth-hero-blurb {
        margin-top: 32px;
        font-size: 15px;
        line-height: 1.6;
        color: var(--md-on-surface-variant);
        max-width: 360px;
    }
    .auth-hero-blurb strong { color: var(--md-on-surface); }

    /* OTP boxes get a bit wider on desktop */
    .otp-inputs { gap: 8px; }
    .otp-digit  { font-size: 24px; min-height: 60px; }
}