/* Maathai Portal — mobile-first auth screens */

:root {
    --auth-header-h: 56px;
    --auth-footer-h: 88px;
    --auth-input-h: 52px;
    --auth-radius: 14px;
    --auth-radius-lg: 20px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
}

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

html {
    -webkit-text-size-adjust: 100%;
}

body.auth-body {
    margin: 0;
    min-height: 100vh;
    min-height: 100dvh;
    background: var(--auth-bg);
    color: var(--auth-text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    overscroll-behavior: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-font-smoothing: antialiased;
}

body.auth-body::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
        radial-gradient(ellipse 80% 50% at 50% -10%, var(--auth-glow-1) 0%, transparent 60%),
        radial-gradient(ellipse 60% 40% at 100% 100%, var(--auth-glow-2) 0%, transparent 50%),
        linear-gradient(180deg, var(--auth-bg) 0%, var(--auth-bg-gradient-end) 100%);
    z-index: 0;
    pointer-events: none;
}

/* ---------- App shell ---------- */

.auth-app {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
    max-width: 100%;
}

.auth-app--desktop-split {
    flex-direction: row;
}

/* ---------- Header bar ---------- */

.auth-header {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    height: calc(var(--auth-header-h) + var(--safe-top));
    padding: var(--safe-top) calc(1rem + var(--safe-right)) 0 calc(1rem + var(--safe-left));
    background: var(--auth-header-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--auth-border);
}

.auth-header-back {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--auth-surface);
    border: 1px solid var(--auth-border);
    color: var(--auth-text);
    text-decoration: none;
    flex-shrink: 0;
    transition: background 0.15s;
}

.auth-header-back:active {
    background: var(--auth-surface-hover);
}

.auth-header-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--auth-text);
    text-decoration: none;
    min-width: 0;
}

.auth-header-brand img {
    height: 30px;
    width: auto;
    display: block;
}

.auth-header-brand span {
    display: none;
}

.auth-header-brand i {
    display: none;
}

.auth-header-title {
    flex: 1;
    font-size: 1rem;
    font-weight: 600;
    text-align: center;
    margin-right: 40px;
}

.auth-header:has(.auth-header-back) .auth-header-brand {
    display: none;
}

/* ---------- Hero panel (desktop login) ---------- */

.auth-hero {
    display: none;
    position: relative;
    flex: 1;
    overflow: hidden;
}

.auth-hero img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.auth-hero-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.45) 0%, rgba(5, 150, 105, 0.55) 100%);
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    padding: 3rem;
}

.auth-hero-overlay h2 {
    font-size: 2rem;
    font-weight: 700;
    margin: 0 0 0.5rem;
    line-height: 1.2;
}

.auth-hero-overlay p {
    margin: 0;
    font-size: 1.05rem;
    opacity: 0.9;
    max-width: 28rem;
}

@media (min-width: 992px) {
    .auth-hero {
        display: block;
    }

    .auth-app--desktop-split .auth-main {
        flex: 0 0 50%;
        max-width: 50%;
    }

    .auth-header {
        position: relative;
        background: transparent;
        border-bottom: none;
        backdrop-filter: none;
    }
}

/* ---------- Main scroll area ---------- */

.auth-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.auth-scroll {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 1.25rem calc(1.25rem + var(--safe-right)) 1rem calc(1.25rem + var(--safe-left));
}

.auth-scroll--register {
    padding-bottom: calc(var(--auth-footer-h) + 1rem + var(--safe-bottom));
}

/* ---------- Intro block ---------- */

.auth-intro {
    text-align: center;
    margin-bottom: 1.75rem;
    padding-top: 1.5rem;
}

.portal-logo-img,
.app-brand-img,
.auth-brand-img {
    height: 44px;
    width: auto;
    margin: 0 auto 1.25rem;
}

.app-topbar-brand .portal-logo,
.app-topbar-brand .app-brand-img,
.app-topbar-brand .auth-brand-img {
    height: 26px;
    margin: 0;
}

.app-sidebar-header .portal-logo,
.app-sidebar-header .app-brand-img {
    height: 32px;
    margin: 0 0 0.5rem;
}

.auth-intro h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0 0 0.35rem;
    letter-spacing: -0.02em;
}

.auth-intro p {
    margin: 0;
    color: var(--auth-text-muted);
    font-size: 0.95rem;
    line-height: 1.45;
}

/* ---------- Form card ---------- */

.auth-card {
    background: var(--auth-surface);
    border: 1px solid var(--auth-border);
    border-radius: var(--auth-radius-lg);
    padding: 1.25rem;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
}

@media (min-width: 576px) {
    .auth-scroll {
        padding-left: calc(1.5rem + var(--safe-left));
        padding-right: calc(1.5rem + var(--safe-right));
    }

    .auth-card {
        padding: 1.5rem;
    }

    .auth-content {
        max-width: 420px;
        margin: 0 auto;
        width: 100%;
    }
}

.auth-content--wide {
    max-width: 480px;
}

/* ---------- Form fields ---------- */

.auth-field {
    margin-bottom: 1rem;
}

.auth-field:last-child {
    margin-bottom: 0;
}

.auth-label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--auth-text-muted);
    margin-bottom: 0.4rem;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.auth-input-wrap {
    position: relative;
    display: flex;
    align-items: stretch;
}

.auth-input-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    flex-shrink: 0;
    background: var(--auth-input-icon-bg);
    border: 1px solid var(--auth-border);
    border-right: none;
    border-radius: var(--auth-radius) 0 0 var(--auth-radius);
    color: var(--auth-text-dim);
    font-size: 0.95rem;
    transition: color 0.15s, border-color 0.15s;
}

.auth-input-wrap:focus-within .auth-input-icon {
    border-color: rgba(var(--auth-primary-rgb), 0.5);
    color: var(--auth-success);
}

.auth-input-wrap.is-invalid .auth-input-icon {
    border-color: rgba(248, 113, 113, 0.5);
    color: var(--auth-error);
}

.auth-input-wrap.is-valid .auth-input-icon {
    border-color: rgba(var(--auth-primary-rgb), 0.5);
    color: var(--auth-success);
}

.auth-input {
    flex: 1;
    min-width: 0;
    height: var(--auth-input-h);
    padding: 0 1rem;
    font-size: 16px;
    line-height: 1.4;
    color: var(--auth-text);
    background: var(--auth-input-bg);
    border: 1px solid var(--auth-border);
    border-radius: var(--auth-radius);
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
    -webkit-appearance: none;
    appearance: none;
}

.auth-input-wrap .auth-input {
    border-radius: 0 var(--auth-radius) var(--auth-radius) 0;
    border-left: none;
}

.auth-input-wrap--toggle .auth-input {
    padding-right: 3rem;
}

.auth-input-wrap--standalone .auth-input {
    width: 100%;
    border-radius: var(--auth-radius);
    border-left: 1px solid var(--auth-border);
    padding-right: 3rem;
}

.auth-input:not(.auth-input-wrap .auth-input) {
    width: 100%;
}

.auth-input::placeholder {
    color: var(--auth-text-dim);
}

.auth-input:focus {
    border-color: rgba(var(--auth-primary-rgb), 0.55);
    background: var(--auth-input-focus-bg);
    box-shadow: 0 0 0 3px rgba(var(--auth-primary-rgb), 0.12);
}

.auth-input.is-invalid,
.auth-input-wrap.is-invalid .auth-input {
    border-color: rgba(248, 113, 113, 0.55) !important;
    box-shadow: 0 0 0 3px rgba(248, 113, 113, 0.1) !important;
}

.auth-input.is-valid,
.auth-input-wrap.is-valid .auth-input {
    border-color: rgba(var(--auth-primary-rgb), 0.55) !important;
}

.auth-toggle-pw {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--auth-text-dim);
    cursor: pointer;
    padding: 0;
    font-size: 1rem;
}

.auth-toggle-pw:active {
    color: var(--auth-text-muted);
}

/* Custom selects — avoid native <select> popups (they force Chromium font loads
   that surface Turnstile's broken challenge WOFF2 as an OTS console error). */
.auth-select {
    position: relative;
    width: 100%;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.auth-select-native {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

.auth-select-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    width: 100%;
    height: var(--auth-input-h);
    padding: 0 2.5rem 0 1rem;
    font-size: 16px;
    line-height: 1.4;
    text-align: left;
    color: var(--auth-text);
    background-color: var(--auth-input-bg);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%23888' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    border: 1px solid var(--auth-border);
    border-radius: var(--auth-radius);
    cursor: pointer;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
    -webkit-appearance: none;
    appearance: none;
    font-family: inherit;
    font-synthesis: none;
}

.auth-select-trigger:focus,
.auth-select.is-open .auth-select-trigger {
    border-color: rgba(var(--auth-primary-rgb), 0.55);
    background-color: var(--auth-input-focus-bg);
    box-shadow: 0 0 0 3px rgba(var(--auth-primary-rgb), 0.12);
}

.auth-select.is-invalid .auth-select-trigger {
    border-color: rgba(248, 113, 113, 0.55) !important;
    box-shadow: 0 0 0 3px rgba(248, 113, 113, 0.1) !important;
}

.auth-select-label {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.auth-select-menu {
    position: absolute;
    z-index: 40;
    left: 0;
    right: 0;
    top: calc(100% + 4px);
    margin: 0;
    padding: 0.35rem;
    list-style: none;
    max-height: 14rem;
    overflow-y: auto;
    background: var(--auth-menu-bg);
    border: 1px solid var(--auth-border);
    border-radius: var(--auth-radius);
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.28);
    font-family: inherit;
}

.auth-select-menu[hidden] {
    display: none !important;
}

.auth-select-option {
    display: block;
    width: 100%;
    padding: 0.7rem 0.85rem;
    border: none;
    border-radius: calc(var(--auth-radius) - 4px);
    background: transparent;
    color: var(--auth-text);
    font-size: 0.95rem;
    text-align: left;
    cursor: pointer;
    font-family: inherit;
}

.auth-select-option:hover,
.auth-select-option:focus {
    background: rgba(var(--auth-primary-rgb), 0.1);
    outline: none;
}

.auth-select-option.is-selected {
    background: rgba(var(--auth-primary-rgb), 0.16);
    font-weight: 600;
}

/* Phone row */
.auth-phone-row {
    display: flex;
    gap: 0;
}

.auth-phone-row .auth-select {
    flex: 0 0 auto;
    width: auto;
    max-width: 9.5rem;
}

.auth-phone-row .auth-select-trigger {
    border-radius: var(--auth-radius) 0 0 var(--auth-radius);
    border-right: none;
}

.auth-phone-row > .auth-input {
    border-radius: 0 var(--auth-radius) var(--auth-radius) 0;
}

/* Field help & errors */
.auth-error-msg {
    display: none;
    margin-top: 0.4rem;
    font-size: 0.8125rem;
    color: var(--auth-error);
    line-height: 1.35;
}

.auth-error-msg.visible,
label.error {
    display: block;
}

label.error {
    margin-top: 0.4rem;
    font-size: 0.8125rem;
    color: var(--auth-error);
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
}

.auth-help {
    margin-top: 0.4rem;
    font-size: 0.8125rem;
    color: var(--auth-text-dim);
    line-height: 1.4;
}

.auth-help strong {
    color: var(--auth-success);
    font-weight: 600;
}

/* jQuery validate overrides */
.auth-form input.error,
.auth-form select.error {
    border-color: rgba(248, 113, 113, 0.55) !important;
}

.auth-form input.valid,
.auth-form select.valid {
    border-color: rgba(var(--auth-primary-rgb), 0.45) !important;
}

/* ---------- Alerts ---------- */

.auth-alert {
    display: flex;
    align-items: flex-start;
    gap: 0.65rem;
    padding: 0.85rem 1rem;
    border-radius: var(--auth-radius);
    font-size: 0.9rem;
    line-height: 1.45;
    margin-bottom: 1.25rem;
}

.auth-alert i {
    flex-shrink: 0;
    margin-top: 0.1rem;
}

.auth-alert--danger {
    background: var(--auth-alert-danger-bg);
    border: 1px solid var(--auth-alert-danger-border);
    color: var(--auth-alert-danger-text);
}

.auth-alert--success {
    background: var(--auth-alert-success-bg);
    border: 1px solid var(--auth-alert-success-border);
    color: var(--auth-alert-success-text);
}

.auth-alert a {
    color: inherit;
    font-weight: 600;
}

/* ---------- Turnstile ---------- */

.auth-turnstile {
    display: flex;
    justify-content: center;
    margin: 1rem 0;
    min-height: 65px;
}

/* ---------- Footer / sticky actions ---------- */

.auth-footer {
    flex-shrink: 0;
    padding: 0.75rem calc(1.25rem + var(--safe-right)) calc(0.75rem + var(--safe-bottom)) calc(1.25rem + var(--safe-left));
    background: var(--auth-footer-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--auth-border);
}

.auth-footer--sticky {
    position: sticky;
    bottom: 0;
    z-index: 100;
}

@media (min-width: 576px) {
    .auth-footer {
        padding-left: calc(1.5rem + var(--safe-left));
        padding-right: calc(1.5rem + var(--safe-right));
    }

    .auth-footer-inner {
        max-width: 420px;
        margin: 0 auto;
    }

    .auth-footer-inner--wide {
        max-width: 480px;
    }
}

.auth-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    min-height: 52px;
    padding: 0.85rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    color: #fff;
    background: linear-gradient(135deg, var(--auth-primary) 0%, var(--auth-primary-dark) 100%);
    border: none;
    border-radius: var(--auth-radius);
    cursor: pointer;
    transition: transform 0.1s, box-shadow 0.15s, opacity 0.15s;
    -webkit-user-select: none;
    user-select: none;
    touch-action: manipulation;
}

.auth-btn:active:not(:disabled) {
    transform: scale(0.98);
}

.auth-btn:disabled,
.auth-btn.loading {
    opacity: 0.75;
    pointer-events: none;
}

.auth-btn .auth-spinner {
    display: none;
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: auth-spin 0.7s linear infinite;
}

.auth-btn.loading .auth-btn-text {
    display: none;
}

.auth-btn.loading .auth-spinner {
    display: block;
}

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

.auth-btn--outline {
    background: transparent;
    border: 1px solid rgba(var(--auth-primary-rgb), 0.45);
    color: var(--auth-success);
    min-height: 44px;
    font-size: 0.9rem;
    margin-top: 0.65rem;
}

.auth-links {
    text-align: center;
    margin-top: 0.85rem;
}

.auth-links p {
    margin: 0 0 0.35rem;
    font-size: 0.875rem;
    color: var(--auth-text-dim);
}

.auth-links a {
    color: var(--auth-success);
    text-decoration: none;
    font-weight: 600;
}

.auth-links a:active {
    opacity: 0.8;
}

/* ---------- Desktop centering ---------- */

@media (min-width: 992px) {
    .auth-app:not(.auth-app--desktop-split) .auth-main,
    .auth-app--desktop-split .auth-main {
        justify-content: center;
    }

    .auth-scroll {
        display: flex;
        align-items: center;
        justify-content: center;
        padding-top: 2rem;
        padding-bottom: 2rem;
    }

    .auth-scroll--register {
        align-items: flex-start;
        padding-top: 1.5rem;
    }

    .auth-footer {
        background: transparent;
        border-top: none;
        backdrop-filter: none;
    }

    .auth-footer--sticky {
        position: static;
    }
}

/* Shake animation for invalid submit */
@keyframes auth-shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-6px); }
    40%, 80% { transform: translateX(6px); }
}

.auth-card.shake {
    animation: auth-shake 0.4s ease;
}
