@import url('https://fonts.googleapis.com/css2?family=Sarabun:wght@300;400;500;600;700;800&display=swap');

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Sarabun', sans-serif;
}

html,
body {
    width: 100%;
    min-height: 100%;
}

body {
    position: relative;
    min-height: 100vh;
    overflow: hidden;
    background-color: #eef2f7;
    background-image: url('../image/background-login.jpg?v=20260701c');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.12); /* ลดลงจาก 0.42 ให้เห็นพื้นหลังชัดขึ้น */
    z-index: 0;
}

body::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    background:
        radial-gradient(circle at 8% 8%, rgba(59, 130, 246, 0.06) 0, rgba(59, 130, 246, 0) 160px),
        radial-gradient(circle at 92% 90%, rgba(15, 23, 42, 0.05) 0, rgba(15, 23, 42, 0) 220px),
        radial-gradient(circle at 78% 18%, rgba(255, 255, 255, 0.04) 0, rgba(255, 255, 255, 0) 180px);
    animation: bgFloat 14s ease-in-out infinite alternate;
}

@keyframes bgFloat {
    from {
        transform: translate3d(-1.2%, -0.8%, 0) scale(1);
    }

    to {
        transform: translate3d(1.2%, 1%, 0) scale(1.03);
    }
}

.login-page {
    position: relative;
    z-index: 1;
    min-height: 100vh;
    padding: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.container {
    background: #ffffff;
    border-radius: 24px;
    box-shadow: 0 40px 100px rgba(15, 23, 42, 0.22), 0 8px 32px rgba(15, 23, 42, 0.12);
    position: relative;
    overflow: hidden;
    width: 920px;
    max-width: 100%;
    min-height: 540px;
    border: 1px solid rgba(15, 23, 42, 0.06);
    animation: loginFadeIn 0.6s ease both;
}

@keyframes loginFadeIn {
    from {
        opacity: 0;
        transform: translateY(24px) scale(0.98);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.container h1 {
    white-space: nowrap;
    font-size: 30px;
    font-weight: 700;
    letter-spacing: -0.5px;
    color: #111111;
    margin-bottom: 12px;
}

.toggle-panel h1 {
    color: #ffffff !important;
    font-size: 34px;
    line-height: 1.25;
    white-space: normal;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0;
    margin-bottom: 22px;
    text-align: left;
    width: 100%;
}

.brand--small {
    justify-content: center;
    margin-bottom: 10px;
}

.brand--center {
    justify-content: center;
    text-align: center;
}

.brand span {
    font-size: 14px;
    font-weight: 500;
    color: #6b7280;
    display: block;
    margin-bottom: 24px;
    line-height: 1.6;
}

.field-group {
    width: 100%;
    text-align: left;
    margin-bottom: 14px;
}

.field-group label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: #374151;
    margin-bottom: 7px;
}

.input-group {
    position: relative;
    width: 100%;
    display: block;
}

.input-icon {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: #4f6b86;
    z-index: 2;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    margin: 0 !important;
    pointer-events: none;
}

.input-icon svg {
    width: 18px;
    height: 18px;
    display: block;
}

.container p {
    font-size: 15px;
    line-height: 1.75;
    letter-spacing: 0.02em;
    margin: 16px 0;
    color: #4b5563;
}

.container a {
    color: #111111;
    font-size: 13px;
    text-decoration: none;
    margin: 12px 0 0;
}

#btnLogin,
#btnForgot,
.container button.hidden {
    background: #f8fafc;
    color: #111827;
    font-size: 14px;
    padding: 14px 24px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-weight: 600;
    letter-spacing: 0.02em;
    margin-top: 16px;
    cursor: pointer;
    transition: transform 0.22s ease, box-shadow 0.22s ease, background-color 0.22s ease, border-color 0.22s ease;
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.08);
}

#btnLogin:hover,
#btnForgot:hover,
.container button.hidden:hover {
    background: #e5e7eb;
    transform: translateY(-1px);
    box-shadow: 0 10px 20px rgba(15, 23, 42, 0.10);
}

#btnLogin:disabled,
#btnForgot:disabled {
    opacity: 0.65;
    cursor: not-allowed;
    transform: none;
}

.container button.hidden {
    background: #ffffff;
    border: 1px solid #d1d5db;
    color: #111827;
    box-shadow: none;
}

.container form {
    background-color: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    padding: 48px 42px;
    height: 100%;
    text-align: center;
}

.container input {
    background-color: #f9fafb;
    border: 1px solid #e5e7eb;
    margin: 0;
    padding: 14px 16px;
    font-size: 15px;
    border-radius: 12px;
    width: 100%;
    height: 52px;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
    color: #111827;
}

.input-group input {
    padding-left: 46px;
    padding-right: 50px;
}

.input-group .password-toggle {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 34px;
    height: 34px;
    border-radius: 999px;
    border: none !important;
    background: transparent !important;
    color: #4f6b86 !important;
    box-shadow: none !important;
    margin: 0 !important;
    padding: 0 !important;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    z-index: 3;
    min-height: 34px !important;
    min-width: 34px !important;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    outline: none;
}

.input-group .password-toggle:hover {
    background: #eef4f8 !important;
    color: #24435c !important;
    transform: translateY(-50%) !important;
    box-shadow: none !important;
    border: none !important;
}

.password-toggle span {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    margin: 0 !important;
    width: 18px;
    height: 18px;
    color: inherit;
}

.password-toggle svg {
    width: 18px;
    height: 18px;
    display: block;
}

.input-group .password-toggle::before,
.input-group .password-toggle::after {
    content: "";
    position: absolute;
    width: 18px;
    height: 2px;
    background: transparent;
    border-radius: 999px;
    transform: rotate(-35deg);
    transition: background-color 0.2s ease;
}

.input-group .password-toggle.is-visible::before {
    background: currentColor;
}

.container input::placeholder {
    color: #9ca3af;
}

.container input:focus {
    border-color: #4f6b86;
    background-color: #ffffff;
    box-shadow: 0 0 0 4px rgba(79, 107, 134, 0.10);
}

.error-msg {
    width: 100%;
    display: none;
    margin: 0 0 12px;
    padding: 12px 14px;
    border-radius: 12px;
    background: #fdecec;
    color: #d93025;
    border: 1px solid #f5c2c0;
    font-size: 14px;
    font-weight: 500;
    text-align: left;
    line-height: 1.45;
}

.error-msg.is-visible {
    display: block;
    animation: loginErrorIn 0.38s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.error-msg--success {
    background: #ecfdf5;
    color: #047857;
    border-color: #a7f3d0;
}

@keyframes loginErrorIn {
    from {
        opacity: 0;
        transform: translateY(-6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes loginShake {
    0%,
    100% {
        transform: translateX(0);
    }

    28% {
        transform: translateX(-6px);
    }

    52% {
        transform: translateX(4px);
    }
}

.container.login-shake,
.reset-container.login-shake {
    animation: loginShake 0.26s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

.form-container {
    position: absolute;
    top: 0;
    height: 100%;
    transition: transform 0.72s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.52s ease;
}

.container.is-panel-switching .form-container {
    transition-duration: 0.82s;
}

.container.is-panel-switching .toggle-container {
    transition-duration: 0.82s;
}

.container.is-panel-switching .toggle {
    transition-duration: 0.82s;
}

.container.is-panel-switching .toggle-panel {
    transition-duration: 0.82s;
}

.sign-in {
    left: 0;
    width: 50%;
    z-index: 2;
    opacity: 1;
    pointer-events: auto;
}

.container.active .sign-in {
    transform: translateX(100%) scale(0.98);
    opacity: 0;
    pointer-events: none;
}

.sign-up {
    left: 0;
    width: 50%;
    opacity: 0;
    z-index: 1;
    pointer-events: none;
}

.container.active .sign-up {
    transform: translateX(100%) scale(1);
    opacity: 1;
    z-index: 5;
    pointer-events: auto;
    animation: loginPanelReveal 0.82s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes loginPanelReveal {
    0% {
        opacity: 0;
        transform: translateX(88%) scale(0.97);
        z-index: 1;
    }

    45% {
        opacity: 0.35;
        z-index: 3;
    }

    100% {
        opacity: 1;
        transform: translateX(100%) scale(1);
        z-index: 5;
    }
}

.toggle-container {
    position: absolute;
    top: 0;
    left: 50%;
    width: 50%;
    height: 100%;
    overflow: hidden;
    transition: transform 0.72s cubic-bezier(0.4, 0, 0.2, 1), border-radius 0.72s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 140px 0 0 100px;
    z-index: 1000;
}

.container.active .toggle-container {
    transform: translateX(-100%);
    border-radius: 0 140px 100px 0;
}

.toggle {
    background: linear-gradient(135deg, #1ca7fe 0%, #0062ff 100%); /* ปรับเป็นสีน้ำเงินสดใสตามรูป */
    color: #f8fafc;
    position: relative;
    left: -100%;
    height: 100%;
    width: 200%;
    transform: translateX(0);
    transition: transform 0.72s cubic-bezier(0.4, 0, 0.2, 1);
}

.container.active .toggle {
    transform: translateX(50%);
}

.toggle::before,
.toggle::after {
    content: "";
    position: absolute;
    border-radius: 50%;
    pointer-events: none;
}

.toggle::before {
    width: 340px;
    height: 340px;
    top: -90px;
    right: 70px;
    background: rgba(255, 255, 255, 0.13);
}

.toggle::after {
    width: 230px;
    height: 230px;
    bottom: -60px;
    left: 70px;
    background: rgba(255, 255, 255, 0.08);
    border: 18px solid rgba(255, 255, 255, 0.10);
}

.toggle-panel {
    position: absolute;
    width: 50%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    text-align: center;
    padding: 0 44px;
    top: 0;
    transform: translateX(0);
    transition: transform 0.72s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.45s ease;
    z-index: 2;
}

.container.is-panel-switching .toggle-panel h1,
.container.is-panel-switching .toggle-panel p,
.container.is-panel-switching .toggle-panel button {
    animation: loginToggleCopyIn 0.55s cubic-bezier(0.22, 1, 0.36, 1) 0.12s both;
}

@keyframes loginToggleCopyIn {
    from {
        opacity: 0;
        transform: translateY(12px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.toggle-panel p {
    color: rgba(248, 250, 252, 0.86);
    font-size: 15px;
    font-weight: 500;
    margin: 18px 0 24px;
    line-height: 1.7;
}

.toggle-left {
    transform: translateX(-200%);
}

.container.active .toggle-left {
    transform: translateX(0);
}

.toggle-right {
    right: 0;
    transform: translateX(0);
}

.container.active .toggle-right {
    transform: translateX(200%);
}

@media (max-width: 991px) {
    .container {
        width: 100%;
        min-height: 560px;
    }

    .toggle-panel h1 {
        font-size: 28px;
    }
}

@media (max-width: 768px) {
    html, body {
        overflow: hidden;
        height: 100%;
        width: 100%;
        position: fixed; /* Prevents rubber-banding on iOS */
    }

    body {
        padding: 0;
        margin: 0;
    }

    .login-page {
        padding: 16px;
        align-items: center;
        justify-content: center;
        height: 100%;
        width: 100%;
        overflow-y: auto; /* Allows scrolling only if the keyboard pops up */
    }

    .container {
        width: 100%;
        max-width: 480px;
        height: auto;
        min-height: auto; /* Override desktop min-height: 540px to remove bottom white gap */
        display: flex;
        flex-direction: column;
        border-radius: 28px;
        overflow: hidden;
        box-shadow: 0 24px 60px rgba(15, 23, 42, 0.12);
        border: none;
        flex-shrink: 0;
        margin: auto;
    }

    /* FORMS */
    .form-container {
        position: relative;
        width: 100%;
        height: auto;
        left: auto;
        top: auto;
        transform: none !important;
        transition: none;
    }

    .sign-in {
        display: flex;
        animation: formFadeIn 0.4s ease;
    }

    .container.active .sign-in {
        display: none !important;
    }

    .sign-up {
        display: none;
    }

    .container.active .sign-up {
        display: flex !important;
        animation: formFadeIn 0.4s ease;
    }

    @keyframes formFadeIn {
        from { opacity: 0; transform: translateY(10px); }
        to { opacity: 1; transform: translateY(0); }
    }

    .container form {
        padding: 40px 24px 32px;
        justify-content: flex-start;
        height: auto;
        width: 100%;
    }

    .container h1 {
        font-size: 26px;
        margin-bottom: 4px;
    }

    .brand {
        justify-content: center;
        text-align: center;
        flex-direction: column;
        gap: 4px;
        margin-bottom: 24px;
    }

    .brand span {
        margin-bottom: 0;
    }

    .container form > span {
        display: block;
        text-align: center;
        color: #4b5563;
        font-size: 14px;
        margin-top: -12px;
        margin-bottom: 24px;
        line-height: 1.6;
    }

    .field-group {
        margin-bottom: 16px;
    }

    #btnLogin, #btnForgot {
        width: 100%;
        padding: 16px;
        font-size: 16px;
        border-radius: 12px;
        margin-top: 12px;
    }

    /* TOGGLE CONTAINER (Bottom) */
    .toggle-container {
        position: relative;
        display: block !important;
        width: 100%;
        height: auto;
        min-height: 240px;
        left: auto;
        top: auto;
        border-radius: 0;
        transform: none !important;
        z-index: 10;
        overflow: hidden; /* Important for background circles */
    }

    .container.active .toggle-container {
        transform: none !important;
        border-radius: 0;
    }

    .toggle {
        position: absolute;
        width: 100%;
        height: 100%;
        left: 0;
        top: 0;
        transform: none !important;
        transition: none !important;
    }
    
    .toggle::before {
        width: 400px;
        height: 400px;
        top: -100px;
        right: -100px;
    }

    .toggle::after {
        width: 300px;
        height: 300px;
        bottom: -50px;
        left: -100px;
    }

    .toggle-panel {
        position: absolute;
        width: 100%;
        height: 100%;
        top: 0;
        left: 0;
        padding: 32px 24px;
        transform: none !important;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        transition: opacity 0.4s ease, visibility 0.4s;
    }

    .toggle-right {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }

    .container.active .toggle-right {
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
    }

    .toggle-left {
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
    }

    .container.active .toggle-left {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }

    .toggle-panel h1 {
        font-size: 24px;
        margin-bottom: 12px;
        color: #ffffff !important;
    }

    .toggle-panel p {
        font-size: 15px;
        margin: 0 0 24px 0;
        opacity: 0.9;
    }

    .container button.hidden {
        background: #ffffff;
        color: #111111;
        border: none;
        border-radius: 12px;
        padding: 14px 32px;
        font-weight: 600;
        margin-top: 0;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    }
    
    .container button.hidden:hover {
        background: #f8f9fa;
        transform: translateY(-1px);
        box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
    }
}

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

    .container {
        max-width: 100%;
    }

    .container form {
        padding: 32px 20px 24px;
    }

    .container h1 {
        font-size: 24px;
    }
    
    .toggle-panel {
        padding: 24px 20px;
    }
    
    .toggle-container {
        min-height: 220px;
    }
}

/* Login card + language switch (stacked, centered) */
.login-shell {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    width: 920px;
    max-width: 100%;
}

.login-shell > .login-lang-switch {
    align-self: center;
    flex-shrink: 0;
}

.login-shell--narrow {
    width: 420px;
}

.login-lang-switch {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 6px 8px;
    margin: 0;
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid rgba(15, 23, 42, 0.08);
    border-radius: 999px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
    backdrop-filter: blur(8px);
}

.login-lang-switch__link {
    display: inline-block;
    padding: 6px 14px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
    line-height: 1.2;
    color: #64748b;
    text-decoration: none;
    transition: color 0.2s ease, background-color 0.2s ease;
}

.login-lang-switch__link:hover {
    color: #1a73e8;
    background: rgba(26, 115, 232, 0.08);
}

.login-lang-switch__link.is-active,
.login-lang-switch__link[aria-current="true"] {
    color: #1a73e8;
    background: rgba(26, 115, 232, 0.12);
}

.login-lang-switch__sep {
    width: 1px;
    height: 16px;
    background: #e2e8f0;
    flex-shrink: 0;
}

/* Flag dropdown — slides with blue toggle panel (same timing as .toggle-container) */
.login-lang-picker {
    position: absolute;
    top: 14px;
    left: calc(100% - 14px);
    right: auto;
    transform: translateX(-100%);
    z-index: 1101;
    transition:
        left 0.72s cubic-bezier(0.4, 0, 0.2, 1),
        transform 0.72s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: left, transform;
}

.container.is-panel-switching .login-lang-picker {
    transition-duration: 0.82s;
}

.container.active .login-lang-picker {
    left: 14px;
    transform: translateX(0);
}

.login-lang-picker__btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px 6px 8px;
    border: 1px solid rgba(15, 23, 42, 0.1);
    border-radius: 999px;
    background: #ffffff;
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.08);
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    color: #334155;
    line-height: 1.2;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.login-lang-picker__btn:hover,
.login-lang-picker.is-open .login-lang-picker__btn {
    border-color: rgba(26, 115, 232, 0.35);
    box-shadow: 0 6px 18px rgba(26, 115, 232, 0.12);
}

.login-lang-picker__flag {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid #e2e8f0;
    flex-shrink: 0;
}

.login-lang-picker__label {
    max-width: 7rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.login-lang-picker__chev {
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 5px solid #94a3b8;
    margin-left: 2px;
}

.login-lang-picker__menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    left: auto;
    min-width: 168px;
    padding: 6px;
    margin: 0;
    background: #ffffff;
    border: 1px solid rgba(15, 23, 42, 0.08);
    border-radius: 12px;
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.14);
}

.login-lang-picker__menu[hidden] {
    display: none !important;
}

.container.active .login-lang-picker__menu {
    left: 0;
    right: auto;
}

.login-lang-picker__option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 8px;
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    color: #334155;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.login-lang-picker__option:hover {
    background: rgba(26, 115, 232, 0.08);
    color: #1a73e8;
}

.login-lang-picker__option.is-active {
    background: rgba(26, 115, 232, 0.12);
    color: #1a73e8;
}

.login-lang-picker__option img {
    border-radius: 50%;
    border: 1px solid #e2e8f0;
    flex-shrink: 0;
}

@media (max-width: 520px) {
    .login-lang-picker__label {
        display: none;
    }

    .login-lang-picker__btn {
        padding: 6px 8px;
    }
}
