:root {
    --auth-navy: #0c2340;
    --auth-navy-deep: #071829;
    --auth-blue: #1a4d7a;
    --auth-blue-soft: #2563a8;
    --auth-gold: #d4af37;
    --auth-gold-light: #e8c547;
    --auth-gold-muted: #c9a227;
    --auth-gold-glow: rgba(212, 175, 55, 0.22);
    --auth-cream: #f4f7fb;
    --auth-text: #0c2340;
    --auth-text-muted: #64748b;
    --auth-border: rgba(212, 175, 55, 0.28);
    --auth-shadow: 0 24px 60px rgba(12, 35, 64, 0.35);
    --auth-font: "Noto Serif Thai", "Source Serif 4", "TH Sarabun New", "Angsana New", Georgia, "Times New Roman", serif;
    --auth-radius: 18px;
}

html {
    color-scheme: light only;
}

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

.auth-body {
    margin: 0;
    min-height: 100vh;
    min-height: 100dvh;
    min-height: -webkit-fill-available;
    font-family: var(--auth-font);
    font-size: 0.9375rem;
    font-weight: 400;
    line-height: 1.5;
    color: var(--auth-text);
    background-color: var(--auth-navy-deep);
    font-feature-settings: "kern" 1, "liga" 1;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    background-image:
        linear-gradient(180deg, rgba(8, 26, 48, 0.35) 0%, rgba(8, 26, 48, 0.2) 100%),
        url("../images/login-bg.png");
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    background-attachment: scroll;
    overflow-x: hidden;
}

@media (max-width: 991.98px) {
    .auth-body {
        background-position: left center;
    }
}

.auth-page {
    position: relative;
    min-height: 100vh;
    min-height: 100dvh;
    min-height: -webkit-fill-available;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 24px clamp(24px, 8vw, 96px);
    overflow: hidden;
}

@media (display-mode: standalone) {
    .auth-body {
        padding-top: env(safe-area-inset-top, 0px);
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    .auth-body .tracking-data-loading {
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
    }
}

.auth-page--centered {
    padding: 32px 20px;
}

.auth-bg-shape {
    position: absolute;
    border-radius: 50%;
    pointer-events: none;
    filter: blur(1px);
}

.auth-bg-shape--1 {
    width: 420px;
    height: 420px;
    top: -120px;
    right: -80px;
    background: radial-gradient(circle, rgba(212, 175, 55, 0.14) 0%, transparent 70%);
}

.auth-bg-shape--2 {
    width: 320px;
    height: 320px;
    bottom: -60px;
    left: -40px;
    background: radial-gradient(circle, rgba(42, 95, 148, 0.35) 0%, transparent 70%);
}

.auth-bg-shape--3 {
    width: 180px;
    height: 180px;
    top: 40%;
    left: 8%;
    background: radial-gradient(circle, rgba(232, 201, 106, 0.08) 0%, transparent 70%);
}

.auth-shell {
    position: relative;
    z-index: 1;
    display: grid;
    grid-template-columns: minmax(260px, 1fr) minmax(340px, 420px);
    max-width: 920px;
    width: min(100%, 920px);
    min-height: 560px;
    border-radius: calc(var(--auth-radius) + 4px);
    overflow: hidden;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.45);
    border: 1px solid rgba(201, 162, 39, 0.28);
}

@media (display-mode: standalone) {
    .auth-shell {
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
    }
}

.auth-brand-panel {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 48px 36px;
    overflow: hidden;
    background-color: var(--auth-navy-deep);
    background-image:
        linear-gradient(180deg, rgba(8, 26, 48, 0.35) 0%, rgba(8, 26, 48, 0.55) 100%),
        url("../images/login-brand-bg.png");
    background-size: cover;
    background-position: left center;
    background-repeat: no-repeat;
}

.auth-brand-inner {
    position: relative;
    z-index: 1;
    text-align: center;
    max-width: 320px;
}

.auth-logo {
    width: min(100%, 280px);
    height: auto;
    display: block;
    margin: 0 auto 28px;
    background: transparent;
    filter: drop-shadow(0 8px 24px rgba(0, 0, 0, 0.35));
}

.auth-brand-tagline {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 500;
    line-height: 1.65;
    color: var(--auth-cream);
    opacity: 0.92;
}

.auth-form-panel {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px 36px;
    background: linear-gradient(180deg, rgba(255, 253, 246, 0.97) 0%, rgba(248, 242, 228, 0.96) 100%);
}

.auth-card {
    width: 100%;
    max-width: 380px;
}

.auth-card--narrow {
    max-width: 420px;
    padding: 40px 36px;
    background: linear-gradient(180deg, #fffdf6 0%, #f8f2e4 100%);
    border-radius: var(--auth-radius);
    border: 1px solid var(--auth-border);
    box-shadow: var(--auth-shadow);
    text-align: center;
}

.auth-card-header {
    margin-bottom: 28px;
    text-align: center;
}

.auth-title {
    margin: 0 0 6px;
    font-size: 1.65rem;
    font-weight: 700;
    color: var(--auth-navy);
    letter-spacing: -0.02em;
}

.auth-subtitle {
    margin: 0;
    font-size: 0.95rem;
    color: var(--auth-text-muted);
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.auth-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.auth-label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--auth-navy);
}

.auth-input-wrap {
    position: relative;
}

.auth-input-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--auth-gold-muted);
    font-size: 1.05rem;
    pointer-events: none;
}

.auth-input {
    width: 100%;
    padding: 12px 14px 12px 42px;
    font-size: 1rem;
    font-family: inherit;
    color: var(--auth-text);
    background: #fff;
    border: 1.5px solid rgba(26, 74, 122, 0.18);
    border-radius: 12px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.auth-input::placeholder {
    color: #9aa3b2;
}

.auth-input:focus {
    outline: none;
    border-color: var(--auth-gold);
    box-shadow: 0 0 0 3px var(--auth-gold-glow);
}

@media (max-width: 768px) {
    .auth-input {
        scroll-margin-top: 72px;
        scroll-margin-bottom: max(140px, 36vh);
    }
}

.auth-field-error {
    font-size: 0.8rem;
    color: #c0392b;
}

.auth-options {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.auth-check {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--auth-text-muted);
    user-select: none;
}

.auth-check-input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.auth-check-box {
    width: 18px;
    height: 18px;
    border: 1.5px solid rgba(26, 74, 122, 0.35);
    border-radius: 5px;
    background: #fff;
    flex-shrink: 0;
    position: relative;
    transition: background 0.2s, border-color 0.2s;
}

.auth-check-input:checked + .auth-check-box {
    background: var(--auth-gold);
    border-color: var(--auth-gold-muted);
}

.auth-check-input:checked + .auth-check-box::after {
    content: "";
    position: absolute;
    left: 5px;
    top: 2px;
    width: 5px;
    height: 9px;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.auth-submit {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    width: 100%;
    margin-top: 4px;
    padding: 13px 20px;
    font-size: 1rem;
    font-weight: 600;
    font-family: inherit;
    color: var(--auth-text);
    background: linear-gradient(135deg, #e8c547 0%, #d4af37 55%, #b8941f 100%);
    border: none;
    border-radius: 12px;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(212, 175, 55, 0.35);
    transition: transform 0.15s, box-shadow 0.15s;
    text-decoration: none;
}

.auth-submit:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 22px rgba(212, 175, 55, 0.45);
    color: var(--auth-text);
}

.auth-submit:active {
    transform: translateY(0);
}

.auth-submit.is-loading {
    opacity: 0.92;
    cursor: wait;
    transform: none;
}

.auth-submit:disabled {
    opacity: 0.92;
    cursor: wait;
}

.auth-submit-loading {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.auth-submit-spinner {
    width: 1rem;
    height: 1rem;
    border-radius: 50%;
    border: 2px solid rgba(15, 39, 68, 0.18);
    border-top-color: var(--auth-gold);
    animation: authSpin 0.75s linear infinite;
}

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

.auth-submit--inline {
    width: auto;
    min-width: 220px;
    margin-top: 24px;
}

.auth-alert {
    padding: 12px 14px;
    border-radius: 10px;
    font-size: 0.875rem;
    line-height: 1.5;
}

.auth-alert--error {
    background: #fdecea;
    color: #922820;
    border: 1px solid #f5c6cb;
}

.auth-alert:empty {
    display: none;
}

.auth-footer-note {
    margin: 24px 0 0;
    text-align: center;
    font-size: 0.82rem;
    color: var(--auth-text-muted);
}

.auth-denied-icon {
    width: 72px;
    height: 72px;
    margin: 0 auto 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: linear-gradient(135deg, rgba(201, 162, 39, 0.2), rgba(26, 74, 122, 0.15));
    color: var(--auth-gold-muted);
    font-size: 2rem;
}

@media (max-width: 768px) {
    .auth-page {
        align-items: flex-start;
        justify-content: flex-start;
        min-height: 100dvh;
        height: auto;
        padding: max(12px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
        overflow-x: hidden;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
        background-attachment: scroll;
        scroll-padding-top: 72px;
        scroll-padding-bottom: max(140px, 36vh);
    }

    .auth-shell {
        grid-template-columns: 1fr;
        min-height: unset;
        margin: 0 auto;
        width: min(100%, 420px);
    }

    .auth-brand-panel {
        padding: 20px 20px 12px;
        background-image:
            linear-gradient(180deg, rgba(8, 26, 48, 0.35) 0%, rgba(8, 26, 48, 0.55) 100%),
            url("../images/login-brand-bg.png");
        background-size: cover;
        background-position: left center;
    }

    .auth-logo {
        width: min(100%, 160px);
        margin-bottom: 8px;
    }

    .auth-brand-tagline {
        font-size: 0.85rem;
        line-height: 1.45;
    }

    .auth-form-panel {
        padding: 20px 20px 28px;
    }

    .auth-body.auth-keyboard-open .auth-page {
        min-height: var(--auth-viewport-height, 100dvh);
        max-height: var(--auth-viewport-height, 100dvh);
    }

    .auth-body.auth-keyboard-open .auth-brand-panel {
        display: none;
    }

    .auth-body.auth-keyboard-open .auth-card-header {
        margin-bottom: 12px;
    }

    .auth-body.auth-keyboard-open .auth-title {
        font-size: 1.35rem;
    }

    .auth-body.auth-keyboard-open .auth-subtitle {
        display: none;
    }

    .auth-body.auth-keyboard-open .auth-form-panel {
        padding-top: 12px;
        padding-bottom: max(24px, env(safe-area-inset-bottom));
    }

    .auth-body.auth-keyboard-open .auth-footer-note {
        display: none;
    }
}

@media (max-width: 480px) {
    .auth-page {
        padding: 16px;
    }

    .auth-shell {
        border-radius: var(--auth-radius);
    }

    .auth-title {
        font-size: 1.45rem;
    }
}

/* ── Global loading overlay (login / auth pages) ── */
.auth-body .tracking-data-loading {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: max(1.5rem, env(safe-area-inset-top)) max(1.25rem, env(safe-area-inset-right)) max(1.5rem, env(safe-area-inset-bottom)) max(1.25rem, env(safe-area-inset-left));
    background: transparent;
}

.auth-body .tracking-data-loading.is-hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    display: none;
}

@media (display-mode: standalone) {
    .auth-body .tracking-data-loading {
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
    }
}

.auth-body .tracking-data-loading-panel {
    width: min(22rem, 100%);
}

.auth-body .tracking-data-loading-spinner {
    width: 2rem;
    height: 2rem;
    margin: 0 auto 0.85rem;
    border-radius: 50%;
    border: 3px solid rgba(212, 175, 55, 0.22);
    border-top-color: #e8c547;
    animation: authSpin 0.85s linear infinite;
}

.auth-body .tracking-data-loading-retry {
    margin-top: 1rem;
    color: #0c2340;
    background: rgba(212, 175, 55, 0.14);
    border: 1px solid rgba(212, 175, 55, 0.28);
    font-weight: 600;
}

@media (prefers-color-scheme: dark) {
    html {
        color-scheme: light only;
    }

    .auth-body {
        background-color: var(--auth-navy-deep) !important;
        color: var(--auth-text) !important;
    }

    .auth-card,
    .auth-card--narrow {
        background: linear-gradient(180deg, #fffdf6 0%, #f8f2e4 100%) !important;
        color: var(--auth-text) !important;
    }

    .auth-input,
    input[type="text"],
    input[type="password"],
    input[type="email"] {
        background: #fff !important;
        color: var(--auth-text) !important;
        border-color: var(--auth-border) !important;
    }

    input,
    select,
    textarea,
    button {
        color-scheme: light only;
    }
}
