body {
    background-color: #fcfcfc;
    /* Notion-like minimal dot grid background */
    background-image: radial-gradient(#d1d5db 1px, transparent 1px);
    background-size: 24px 24px;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-wrapper {
    width: 100%;
    max-width: 480px;
    padding: 1rem; /* Reduced padding on mobile */
}

@media (min-width: 576px) {
    .login-wrapper {
        padding: 2rem;
    }
}

.login-card {
    background: #ffffff;
    border-radius: 16px;
    padding: 2.5rem 1.5rem; /* Adjusted padding for better mobile fit */
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.05), 0 8px 10px -6px rgba(0, 0, 0, 0.01);
    border: 1px solid rgba(0,0,0,0.04);
    position: relative;
    z-index: 10;
}

@media (min-width: 576px) {
    .login-card {
        padding: 3rem 2.5rem;
    }
}

/* ใช้ flex เพื่อจัดกึ่งกลาง — กันกรณี img เป็น display:block จาก Tailwind preflight */
.login-logo {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    margin-bottom: 2.5rem;
}

/* รูป logo ในหน้า login */
.login-logo-img {
    display: block;
    width: 80px;
    max-width: 100%;
    height: auto;
    margin-bottom: 10px;
    margin-left: auto;
    margin-right: auto;
}

/* สถานะเริ่มต้นของ mascot ที่ถูกซ่อน (ควบคุมด้วย JS) */
.mascot-hidden {
    display: none;
    opacity: 0;
}

.login-logo h4 {
    width: 100%;
    text-align: center;
    font-weight: 700;
    color: #111827;
    margin-top: 1rem;
    margin-bottom: 0.25rem;
    letter-spacing: -0.5px;
}

.login-logo p {
    width: 100%;
    text-align: center;
    color: #6b7280;
    font-size: 0.875rem;
    line-height: 1.5;
    margin: 0;
}

.login-logo p + p {
    margin-top: 0.125rem;
}

/* Inputs styling */
.form-control, .input-group-text {
    padding: 0.625rem 1rem;
    border-color: #d9dee3;
    background-color: #ffffff;
    color: #566a7f;
    transition: all 0.2s ease;
    border-radius: 0.375rem;
}

.input-group-text {
    background-color: transparent;
    color: #b4bdc6;
    border-right: none;
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}

.form-control {
    border-left: none;
    padding-left: 0;
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
}

/*
 * หน้า login / จำลองคู่มือ: จัด input-group ให้สม่ำเสมอ (บางหน้า preview ไม่โหลด bootstrap-shim)
 */
.login-wrapper .input-group {
    display: flex;
    align-items: stretch;
    width: 100%;
}

.login-wrapper .input-group > .input-group-text {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.login-wrapper .input-group > .form-control {
    flex: 1 1 auto;
    min-width: 0;
    line-height: 1.5;
    min-height: 2.75rem;
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
}

.input-group.position-relative .form-control {
    padding-right: 2.5rem; /* Fix text overlapping the toggle eye icon */
    border-top-right-radius: 0.375rem !important;
    border-bottom-right-radius: 0.375rem !important;
}

.form-control:focus {
    background-color: #ffffff;
    border-color: var(--primary);
    box-shadow: none;
}

.input-group:focus-within .input-group-text,
.input-group:focus-within .form-control {
    border-color: var(--primary);
    background-color: #ffffff;
}

.input-group:focus-within .input-group-text {
    color: var(--primary);
}

/* Custom Button */
.btn-primary {
    border-radius: 0.375rem;
    padding: 0.625rem 1.5rem;
    font-weight: 500;
    width: 100%;
    margin-top: 1rem;
}

.login-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 2rem;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid #e5e7eb;
    background: #f9fafb;
    padding: 0.25rem;
}

.login-tab {
    flex: 1;
    padding: 0.625rem;
    text-align: center;
    font-size: 0.875rem;
    font-weight: 500;
    font-family: 'LINE Seed Sans TH', 'Sarabun', 'Inter', system-ui, sans-serif;
    background: transparent;
    color: #6b7280;
    cursor: pointer;
    border: none;
    transition: all 0.2s ease;
    border-radius: 8px;
}

.login-tab.active {
    font-weight: 600;
    background: #ffffff;
    color: var(--primary);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.login-tab:hover:not(.active) {
    color: #374151;
}

.login-form-section {
    display: none;
}

.login-form-section.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

.password-toggle {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: #9ecaed;
    cursor: pointer;
    font-size: 1.1rem;
    z-index: 5;
    padding: 0;
}

.password-toggle:hover {
    color: var(--primary);
}

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

/* PSU SSO Button Styles */
.psu-sso-section {
    padding: 0 0 1rem;
    text-align: center;
}

.psu-sso-info {
    margin-bottom: 2rem;
    color: #4b5563;
}

.psu-sso-info i {
    font-size: 2.5rem;
    color: var(--primary);
    margin-bottom: 0.5rem;
    display: inline-block;
}

.psu-sso-info p {
    margin: 0;
    font-size: 1rem;
    font-weight: 500;
    line-height: 1.4;
}

.psu-sso-info small {
    font-weight: 400;
    color: #6b7280;
}

.btn-psu-sso {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1.5rem;
    position: relative;
    background-color: #002060;
    color: #ffffff;
    border: none;
    border-radius: 8px;
    padding: 0.625rem 1rem;
    font-size: 1rem;
    font-weight: 600;
    width: 100%;
    margin-bottom: 1rem;
    transition: all 0.2s ease;
    text-decoration: none;
    box-shadow: 0 4px 6px -1px rgba(0, 32, 96, 0.1), 0 2px 4px -1px rgba(0, 32, 96, 0.06);
}

.btn-psu-sso:hover {
    background-color: #001848;
    color: #ffffff;
    /* ลบ transform hover animation ตาม rule (เลือกเฉพาะ transition ที่จำเป็น) */
    box-shadow: 0 2px 4px 0 rgba(0, 32, 96, 0.15); /* ลด box-shadow ให้เบาลง */
}

.btn-psu-sso .psu-icon {
    height: 38px;
    width: auto;
    object-fit: contain;
    background-color: #ffffff;
    padding: 10px 14px;
    border-radius: 8px;
}

.btn-psu-sso span {
    flex: 1;
    text-align: center;
    font-size: 1.05rem;
}

.btn-psu-sso .bx-chevron-right {
    font-size: 1.5rem;
    opacity: 0.8;
}

/*
 * ไอคอน + ข้อความ: ห้ามใช้ flex:1 ที่ข้อความ — จะทำให้ไอคอนห่างจากตัวหนังสือ (เดสก์ท็อป/มือถือ)
 */
.psu-sso-notice {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    gap: 0.35rem;
    margin: 0;
    padding: 0 0.25rem;
    font-size: 0.875rem;
    line-height: 1.5;
    color: #9ca3af;
}

.psu-sso-notice-icon {
    flex-shrink: 0;
    margin-top: 0.12rem;
    font-size: 1.05rem;
}

.psu-sso-notice-text {
    flex: 0 1 auto;
    max-width: 100%;
    text-align: center;
}

/* ช่องว่างเหนือ © — เดสก์ท็อปค่าเดิม */
.login-copyright-wrap {
    margin-top: 1.5rem;
}

/* ===== หน้า login มือถือ: บีบระยะแท็บเจ้าหน้าที่ + ข้อความแจ้ง ===== */
@media (max-width: 767.98px) {
    .login-tabs {
        margin-bottom: 1.25rem;
    }

    .psu-sso-section {
        padding: 0 0 0.5rem;
    }

    .psu-sso-info {
        margin-bottom: 1rem;
    }

    .psu-sso-info i {
        font-size: 2.25rem;
        margin-bottom: 0.35rem;
    }

    .btn-psu-sso {
        margin-bottom: 0.65rem;
    }

    .psu-sso-notice {
        gap: 0.28rem;
        font-size: 0.8125rem;
        padding: 0 0.125rem;
    }

    .psu-sso-notice-icon {
        margin-top: 0.1rem;
        font-size: 1rem;
    }

    .login-copyright-wrap {
        margin-top: 1rem;
    }
}

/* Mascot Positioning */
.mascot-container {
    position: absolute;
    width: 220px;
    bottom: -10px;
    z-index: 5;
    pointer-events: none;
    display: block; /* Use block for layout, but JS will control display: none if needed */
    transition: opacity 0.3s ease; /* Add transition for fade effect */
}

.mascot-right {
    right: -160px;
    bottom: -10px;
    animation: float 4s ease-in-out infinite;
}

.mascot-left {
    left: -140px;
    top: -60px; /* Move to top corner */
    transform: scaleX(-1); /* Flip horizontally */
    animation: float-left 4s ease-in-out infinite 0.5s;
}

@keyframes float-left {
    0% { transform: scaleX(-1) translateY(0px) rotate(0deg); }
    50% { transform: scaleX(-1) translateY(-15px) rotate(-2deg); }
    100% { transform: scaleX(-1) translateY(0px) rotate(0deg); }
}

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

.mascot-container img {
    width: 100%;
    height: auto;
    filter: drop-shadow(0 15px 15px rgba(0,0,0,0.08));
}

@keyframes float {
    0% { transform: translateY(0px) rotate(0deg); }
    50% { transform: translateY(-15px) rotate(2deg); }
    100% { transform: translateY(0px) rotate(0deg); }
}

/* Ensure wrapper is relative for absolute mascot positioning */
.login-wrapper {
    position: relative;
    z-index: 10;
}

/* ===== เดสก์ท็อป: มาสคอตฝั่ง user ไม่ทับฟอร์ม (ดันล่าง + ขวา + ลดการเด้ง) ===== */
@media (min-width: 992px) {
    @keyframes float-desktop {
        0% {
            transform: translateY(0) rotate(0deg);
        }
        50% {
            transform: translateY(-4px) rotate(1deg);
        }
        100% {
            transform: translateY(0) rotate(0deg);
        }
    }

    .mascot-right {
        /* เดิม right: -160px bottom: -10px — ดันออกจากปุ่ม/ลิขสิทธิ์ */
        right: -210px;
        bottom: -128px;
        animation: float-desktop 4.5s ease-in-out infinite;
    }
}

/* ===== มือถือ / แท็บเล็ก: โหมดมาสคอต (สลับที่ body[data-login-mascot]) =====
 * below      — ใต้การ์ด ชัดเจน ไม่ถูกการ์ดบัง (แนะนำถ้าอยากเห็นตัวการ์ตูน)
 * corner     — มุมล่างขวาของการ์ด ทับขอบ (มาสคอตอยู่ใน .login-card)
 * watermark  — กลางจอแบบจางๆ เป็นองค์ประกอบพื้นหลัง (เลเยอร์หลังการ์ด)
 * เดสก์ท็อป (≥992px) ใช้ตำแหน่งเดิมใน .mascot-right / .mascot-left
 */
@keyframes mascot-img-bob {
    0%,
    100% {
        transform: translateY(0) rotate(0deg);
    }
    50% {
        transform: translateY(-10px) rotate(2deg);
    }
}

@keyframes mascot-img-bob-mirror {
    0%,
    100% {
        transform: scaleX(-1) translateY(0) rotate(0deg);
    }
    50% {
        transform: scaleX(-1) translateY(-10px) rotate(-2deg);
    }
}

@media (max-width: 991.98px) {
    .login-card {
        position: relative;
        z-index: 2;
    }

    /* --- โหมด below: ลำดับ DOM ใต้การ์ด — เห็นตัวได้เต็มๆ --- */
    body[data-login-mascot="below"] .mascot-container {
        position: relative;
        left: auto !important;
        right: auto !important;
        top: auto !important;
        bottom: auto !important;
        transform: none !important;
        width: min(172px, 46vw);
        max-width: 200px;
        margin: 1.25rem auto 0;
        z-index: 1;
        animation: none !important;
    }

    body[data-login-mascot="below"] .mascot-left {
        transform: none !important;
    }

    body[data-login-mascot="below"] .mascot-container img {
        filter: drop-shadow(0 8px 14px rgba(0, 0, 0, 0.07));
    }

    body[data-login-mascot="below"] .mascot-right img {
        animation: mascot-img-bob 4.5s ease-in-out infinite;
    }

    body[data-login-mascot="below"] .mascot-left img {
        animation: mascot-img-bob-mirror 4.5s ease-in-out infinite 0.4s;
    }

    /* --- โหมด corner: มุมล่างขวาของการ์ด — ทับขอบ (ไม่ใช้มุมบน) --- */
    body[data-login-mascot="corner"] .login-wrapper {
        padding-bottom: 1.5rem;
    }

    body[data-login-mascot="corner"] .login-card {
        overflow: visible;
    }

    body[data-login-mascot="corner"] .mascot-container {
        position: absolute;
        left: auto !important;
        right: -0.35rem;
        /* ดึงขึ้นใกล้บรรทัด © (มุมขวาล่าง — ไม่ทับปุ่มเต็มความกว้าง) */
        top: calc(100% - 2.65rem);
        bottom: auto !important;
        margin-top: 0;
        transform: none !important;
        width: min(118px, 32vw);
        max-width: 142px;
        margin-left: 0;
        margin-right: 0;
        margin-bottom: 0;
        z-index: 6;
        animation: none !important;
    }

    body[data-login-mascot="corner"] .mascot-left {
        transform: none !important;
    }

    body[data-login-mascot="corner"] .mascot-container img {
        filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.1));
    }

    body[data-login-mascot="corner"] .mascot-right img {
        animation: mascot-img-bob 5s ease-in-out infinite;
    }

    /*
     * แอมโม: ไฟล์รูปหันหน้าเข้ากล่องอยู่แล้ว — ไม่ใช้ scaleX(-1) (เดิมทำให้หันหลังออก)
     */
    body[data-login-mascot="corner"] .mascot-left img {
        animation: mascot-img-bob 5s ease-in-out infinite 0.35s;
    }

    /* --- โหมด watermark: ใหญ่กลางจอ จาง — อยู่หลังการ์ด --- */
    body[data-login-mascot="watermark"] .mascot-container {
        position: fixed;
        left: 50% !important;
        right: auto !important;
        top: 44%;
        bottom: auto !important;
        transform: translate(-50%, -50%) !important;
        width: min(115vw, 500px);
        margin: 0;
        z-index: 0;
        animation: none !important;
    }

    body[data-login-mascot="watermark"] .mascot-left {
        transform: translate(-50%, -50%) !important;
    }

    body[data-login-mascot="watermark"] .mascot-container img {
        opacity: 0.22;
        filter: drop-shadow(0 8px 28px rgba(0, 0, 0, 0.05));
    }

    body[data-login-mascot="watermark"] .mascot-right img {
        animation: mascot-img-bob 6s ease-in-out infinite;
    }

    body[data-login-mascot="watermark"] .mascot-left img {
        animation: mascot-img-bob-mirror 6s ease-in-out infinite 0.5s;
    }
}
