/* login.css — หน้า login standalone lightweight (ไม่โหลด Bootstrap เต็มชุด — first-load เร็ว)
   Theme: light default · dark via [data-theme="dark"] / [data-bs-theme="dark"] */

/* ===== ฟอนต์ default: Chulabhorn Likit (ชุดเดียวกับ app-shell.css) */
@font-face {
    font-family: "ChulabhornLikit";
    src: url("../fonts/chulabhornlikittext-regular.woff2") format("woff2");
    font-weight: 400;
    font-display: swap;
}
@font-face {
    font-family: "ChulabhornLikit";
    src: url("../fonts/chulabhornlikittext-bold.woff2") format("woff2");
    font-weight: 700;
    font-display: swap;
}

/* ===== Light (default) ===== */
:root {
    --login-bg: #f0f4f1;
    --login-card-shell: #f6f5f5;
    --login-card-bg: #ffffff;
    --login-accent: #F29F67;
    --login-accent-hover: #d4834a;
    --login-surface: #F5F5F5;
    --login-primary: #d4834a;
    --login-primary-hover: #c4714a;
    --login-line: rgba(92, 113, 94, 0.2);
    --form-text: #1E1E2C;
    --form-muted: #6b6b80;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    font-family: "ChulabhornLikit", system-ui, "Segoe UI", sans-serif;
    background: var(--login-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.login-card {
    width: 100%;
    max-width: 420px;
    margin: 0 auto;
    background: transparent;
    border: none;
    border-radius: 0;
    padding: 16px 0;
    color: var(--form-text);
    box-shadow: none;
}

.login-card-header {
    display: flex;
    justify-content: flex-end;
    margin: -8px 0 4px;
}

/* Language switcher — same control as app-shell, themed for login pages */
.app-language-switcher {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    width: 72px;
    height: 30px;
    padding: 2px;
    border: 1px solid rgba(242, 159, 103, 0.38);
    border-radius: 7px;
    background: rgba(242, 159, 103, 0.08);
    color: var(--form-muted);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
    line-height: 1;
    text-decoration: none;
    overflow: hidden;
    isolation: isolate;
}

.app-language-switcher::before {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 32px;
    height: 24px;
    border-radius: 5px;
    background: var(--login-accent);
    content: "";
    transition: transform 160ms ease;
    z-index: -1;
}

.app-language-switcher--en::before {
    transform: translateX(34px);
}

.app-language-option {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 50%;
    height: 24px;
    pointer-events: none;
}

.app-language-switcher--th .app-language-option-th,
.app-language-switcher--en .app-language-option-en {
    color: #2b1608;
}

.app-language-switcher:hover,
.app-language-switcher:focus-visible {
    border-color: var(--login-primary);
    background: rgba(242, 159, 103, 0.14);
}

.app-language-switcher:focus {
    outline: none;
}

.app-language-switcher:focus-visible {
    outline: 2px solid var(--login-primary);
    outline-offset: 2px;
}

.login-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}
.login-brand img.logo { width: 56px; height: auto; }
.login-brand .title { font-size: 18px; font-weight: 700; line-height: 1.25; color: var(--login-primary); }
.login-brand .title small { display: block; font-size: 12px; font-weight: 400; color: var(--form-muted); }

.form-group { margin-bottom: 16px; }
label { display: block; font-size: 13px; margin-bottom: 6px; color: var(--form-muted); }

.input-wrap { position: relative; }

.input-group {
    display: flex;
    width: 100%;
    flex-wrap: nowrap;
}

.input-group .form-control {
    flex: 1 1 auto;
    min-width: 0;
    width: 1%;
    height: 44px;
    padding: 0 12px;
    border-radius: 8px 0 0 8px;
    border: 1px solid var(--login-line);
    border-right: 0;
    background: var(--login-card-bg);
    color: var(--form-text);
    font-size: 14px;
    font-family: inherit;
}

.input-group-text {
    display: flex;
    align-items: center;
    height: 44px;
    padding: 0 10px;
    border: 1px solid var(--login-line);
    border-left: 0;
    border-radius: 0 8px 8px 0;
    background: var(--login-surface);
    color: var(--form-muted);
    font-size: 13px;
    white-space: nowrap;
}

.input-group:focus-within .form-control,
.input-group:focus-within .input-group-text {
    border-color: var(--login-primary);
}

.form-hint {
    margin-top: 8px;
    font-size: 12px;
    color: var(--form-muted);
    text-align: center;
}

input[type="email"], input[type="password"], input[type="text"] {
    width: 100%;
    height: 44px;
    padding: 0 12px;
    border-radius: 8px;
    border: 1px solid var(--login-line);
    background: var(--login-card-bg);
    color: var(--form-text);
    font-size: 14px;
    font-family: inherit;
}
input:focus { outline: none; border-color: var(--login-primary); }

.btn-eye {
    position: absolute;
    right: 6px;
    top: 6px;
    height: 32px;
    width: 32px;
    border: none;
    background: transparent;
    color: var(--form-muted);
    cursor: pointer;
}

.btn-primary {
    width: 100%;
    height: 44px;
    border: none;
    border-radius: 8px;
    background: #F29F67;
    color: #000000;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    display: flex;
    align-items: center;
    justify-content: center;
}
.btn-primary:disabled { cursor: not-allowed; background: #b8956a; color: #000000; }
.btn-primary:hover:not(:disabled) { background: #d4834a; }

.btn-google {
    width: 100%;
    height: 44px;
    margin-top: 10px;
    border: 1px solid #dcdce4;
    border-radius: 8px;
    background: var(--login-card-bg);
    color: var(--form-text);
    font-size: 14px;
    font-family: inherit;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
    text-decoration: none;
}
.btn-google:hover { background: var(--login-surface); border-color: #dcdce4; }

.btn-dev {
    width: 100%;
    height: 40px;
    border: 1px solid #F29F67;
    border-radius: 8px;
    background: transparent;
    color: #d4834a;
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
}
.btn-dev:hover { background: #fef3ec; color: #8b4513; }

.error-box {
    background: #fce8e7;
    border: 1px solid rgba(230, 86, 79, 0.35);
    color: #5a1612;
    font-size: 13px;
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 14px;
}

.success-box {
    background: #e6f5ec;
    border: 1px solid rgba(45, 150, 90, 0.35);
    color: #0f4d30;
    font-size: 13px;
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 14px;
}

.link-row {
    margin-top: 14px;
    text-align: center;
}
.link-muted {
    color: var(--login-primary);
    font-size: 13px;
    text-decoration: none;
}
.link-muted:hover { text-decoration: underline; }

.login-public {
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid var(--login-line);
    text-align: center;
    line-height: 1.5;
}

.login-public-link {
    display: inline;
    margin: 0 8px;
    color: var(--login-primary);
    font-size: 13px;
    font-weight: 400;
    text-decoration: none;
}

.login-public-link:hover {
    text-decoration: underline;
}

.login-footer {
    margin-top: 20px;
    text-align: center;
    font-size: 11px;
    color: var(--form-muted);
}

/* Mobile / แผง built-in browser แคบ: ใช้ความกว้างเต็มที่ (ลดช่องว่างขอบจอ) — ยังจัดกลางผ่าน body flex */
@media (max-width: 767.98px) {
    body {
        padding: max(12px, env(safe-area-inset-top, 0px))
            max(12px, env(safe-area-inset-right, 0px))
            max(12px, env(safe-area-inset-bottom, 0px))
            max(12px, env(safe-area-inset-left, 0px));
    }

    .login-card {
        max-width: none;
        padding: 0;
    }
}

/* overlay busy บนการ์ด login/otp ระหว่างรอ htmx request */
#login-card-body,
#verify-otp-card-body,
#forgot-card-body,
#reset-card-body {
    position: relative;
}

.login-busy {
    display: none;
    position: absolute;
    inset: 0;
    align-items: center;
    justify-content: center;
    background: var(--login-bg);
    color: var(--login-primary);
    font-size: 15px;
    font-weight: 600;
    border-radius: 8px;
    z-index: 2;
    pointer-events: all;
}

#login-card-body.htmx-request .login-busy,
#verify-otp-card-body.htmx-request .login-busy,
#forgot-card-body.htmx-request .login-busy,
#reset-card-body.htmx-request .login-busy {
    display: flex;
}

#login-card-body.htmx-request .error-box,
#verify-otp-card-body.htmx-request .error-box,
#forgot-card-body.htmx-request .error-box,
#reset-card-body.htmx-request .error-box {
    display: none;
}

/* spinner บนปุ่มระหว่างรอ htmx (indicator อยู่ที่ #login-card-body ฯลฯ — ใช้ specificity คู่กับ app-shell .app-btn-spin) */
.btn-primary-spinner { display: none; }
#login-card-body.htmx-request .btn-primary-label,
#verify-otp-card-body.htmx-request .btn-primary-label,
#forgot-card-body.htmx-request .btn-primary-label,
#reset-card-body.htmx-request .btn-primary-label {
    display: none;
}
#login-card-body.htmx-request .btn-primary-spinner,
#verify-otp-card-body.htmx-request .btn-primary-spinner,
#forgot-card-body.htmx-request .btn-primary-spinner,
#reset-card-body.htmx-request .btn-primary-spinner {
    display: inline;
    text-align: center;
}

/* ===== Dark — [data-theme="dark"] หรือ [data-bs-theme="dark"] บน <html> ===== */
[data-theme="dark"],
[data-bs-theme="dark"] {
    --login-bg: #16161f;
    --login-card-shell: #27273a;
    --login-card-bg: #27273a;
    --login-accent: #F29F67;
    --login-accent-hover: #f5b484;
    --login-surface: #2e2e44;
    --login-primary: #f5b484;
    --login-primary-hover: #f0a770;
    --login-line: rgba(242, 159, 103, 0.22);
    --form-text: #f0efec;
    --form-muted: #a0a0b8;
}

[data-theme="dark"] body,
[data-bs-theme="dark"] body {
    background: var(--login-bg);
}

[data-theme="dark"] .login-card,
[data-bs-theme="dark"] .login-card {
    background: transparent;
    border: none;
    box-shadow: none;
}

[data-theme="dark"] .form-control,
[data-theme="dark"] .input-group .form-control,
[data-theme="dark"] input[type="email"],
[data-theme="dark"] input[type="password"],
[data-theme="dark"] input[type="text"],
[data-bs-theme="dark"] .form-control,
[data-bs-theme="dark"] .input-group .form-control,
[data-bs-theme="dark"] input[type="email"],
[data-bs-theme="dark"] input[type="password"],
[data-bs-theme="dark"] input[type="text"] {
    background: var(--login-surface);
    border-color: var(--login-line);
    color: var(--form-text);
}

[data-theme="dark"] .input-group-text,
[data-bs-theme="dark"] .input-group-text {
    background: #364438;
    border-color: var(--login-line);
    color: var(--form-text);
}

[data-theme="dark"] .error-box,
[data-bs-theme="dark"] .error-box {
    background: #422826;
    border-color: rgba(240, 113, 103, 0.45);
    color: #ffd4d1;
}

[data-theme="dark"] .btn-dev,
[data-bs-theme="dark"] .btn-dev {
    color: var(--login-primary);
    border-color: var(--login-primary);
}
[data-theme="dark"] .btn-dev:hover,
[data-bs-theme="dark"] .btn-dev:hover {
    background: rgba(242, 159, 103, 0.08);
}