/*
|===================================================================================
| 1. GLOBAL RESET & BASE STYLES - SEA BLUE / AQUA THEME
|===================================================================================
*/

/* 1) ให้ทุกอย่างคำนวณความกว้างแบบไม่ล้น (Responsive Foundation) */
*,
*::before,
*::after {
    box-sizing: border-box;
}

/* 2) ปรับ body ให้รองรับมือถือ/คีย์บอร์ดโผล่ขึ้น */
html,
body {
    height: 100%;
}

body {
    /* ใช้ Sarabun พร้อมฟอนต์สำรองที่ดี */
    font-family: 'Sarabun', system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif;
    background-color: #E0FFFF;
    /* สี Azure อ่อนมาก */
    /* ไล่สีพื้นหลังเป็นน้ำทะเลลึก */
    background-image: linear-gradient(135deg, #E0FFFF 0%, #B0E0E6 50%, #4682B4 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100dvh;
    /* ดีกว่า 100vh บนมือถือ */
    margin: 0;
    color: #003366;
    /* สีข้อความหลักเป็นน้ำเงินเข้ม */
}

/* ทำให้ input/button ใช้ฟอนต์หลักของ body */
button,
input,
select,
textarea {
    font-family: inherit;
}

@media (max-width: 480px) {
    body {
        /* ยอมให้มี scroll บนจอเล็กมาก ๆ เมื่อคีย์บอร์ดเปิด */
        overflow: auto;
    }
}

/*
|===================================================================================
| 2. LOGIN CONTAINER & HEADER - SEA BLUE / AQUA THEME
|===================================================================================
*/

/* 3) ทำกล่องให้ยืดหยุ่นตามจอ - AQUA EFFECT */
.login-container {
    background-color: rgba(255, 255, 255, 0.9);
    /* สีขาวเกือบเต็ม */
    /* ใช้ backdrop-filter เพื่อเพิ่มมิติ (ถ้าเบราว์เซอร์รองรับ) */
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    border: 1px solid rgba(0, 206, 209, 0.3);
    /* ขอบสีเขียวอมฟ้าอ่อน */
    /* ใช้ min() เพื่อกำหนดความกว้างแบบยืดหยุ่น */
    width: min(92vw, 400px);
    max-width: 400px;
    margin: 12px;
    /* ใช้ clamp() เพื่อกำหนด padding แบบยืดหยุ่น */
    padding: clamp(18px, 5vw, 40px);
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 51, 102, 0.2);
    /* เงาสีน้ำเงินเข้มอ่อนๆ */
    text-align: center;
}

/* 7) กันล้นแนวสูง: ถ้าจอเตี้ยมาก ให้ลด padding เพิ่มอีก */
@media (max-height: 600px) and (max-width: 480px) {
    .login-container {
        padding: 16px;
    }
}

/* ส่วนโลโก้ */
.logo-area {
    margin-bottom: 25px;
}

.logo-icon-placeholder {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    /* ปรับขนาดให้ยืดหยุ่น/เล็กลงได้เล็กน้อย */
    width: 56px;
    height: 56px;
    /* ไล่สีเขียวอมฟ้าสดใส */
    background: linear-gradient(135deg, #1E90FF 0%, #00CED1 100%);
    color: #fff;
    /* สีไอคอนเป็นสีขาว */
    border-radius: 50%;
    font-size: 30px;
    margin-bottom: 10px;
}

.app-name {
    font-size: 1.4rem;
    font-weight: 600;
    color: #003366;
    /* สีน้ำเงินเข้ม */
    letter-spacing: 2px;
}

/* 6) เฮดเดอร์/ซับไตเติลให้ย่อบนจอเล็ก */
.login-header {
    margin-bottom: 20px;
    font-size: clamp(1.4rem, 4.8vw, 1.8rem);
    font-weight: 700;
    letter-spacing: .5px;
    color: #003366;
    /* สีน้ำเงินเข้ม */
}

.login-header-desc {
    margin-top: 4px;
    margin-bottom: 20px;
    font-size: .98rem;
    color: #4682B4;
    /* สีน้ำเงินเทา (Steel Blue) */
}


/*
|===================================================================================
| 3. INPUT FIELDS & BUTTONS - SEA BLUE / AQUA THEME
|===================================================================================
*/

/* 5) ช่องกรอก/ปุ่ม ย่อ padding และฟอนต์ให้พอดีมือบนมือถือ */
.input-group {
    position: relative;
    margin-bottom: 16px;
    display: block;
}

.input-group .icon {
    position: absolute;
    top: 50%;
    left: 15px;
    transform: translateY(-50%);
    color: #1E90FF;
    /* สีฟ้าสดใส */
    font-size: 16px;
    line-height: 1;
}

input[type="text"],
input[type="password"] {
    width: 100%;
    /* กัน iOS ซูมอัตโนมัติ & พอดีมือถือ */
    font-size: 16px;
    padding: 14px 14px 14px 44px;
    /* เผื่อไอคอนซ้าย */
    border: 1px solid #B0E0E6;
    /* ขอบสีฟ้าอ่อน */
    border-radius: 8px;
    background-color: #F0FFFF;
    /* พื้นหลังสีขาวฟ้าอ่อน */
    color: #003366;
    transition: border-color 0.3s, box-shadow 0.3s;
}

input::placeholder {
    color: #778899;
    /* สีเทาน้ำเงิน */
}

input:focus {
    border-color: #1E90FF;
    outline: none;
    box-shadow: 0 0 0 3px rgba(30, 144, 255, 0.3);
    /* เงาสีฟ้าอ่อน */
    background-color: #fff;
}

/* ปุ่มแสดง/ซ่อนรหัสผ่าน */
.toggle-password {
    position: absolute;
    top: 50%;
    /* ใช้ right: 12px; เพื่อกันติดขอบ */
    right: 12px;
    transform: translateY(-50%);
    color: #1E90FF;
    /* สีฟ้าสดใส */
    cursor: pointer;
    transition: color 0.2s;
    background: transparent;
    border: 0;
    padding: 0;
    font-size: 16px;
    line-height: 1;
}

.toggle-password:hover {
    color: #00CED1;
}

/* ปุ่มเข้าสู่ระบบ - สไตล์ Sea Blue */
.login-button {
    width: 100%;
    padding: 14px;
    /* ปรับให้เข้ากับ input padding */
    margin-top: 15px;
    border: none;
    border-radius: 8px;
    /* ไล่สีเขียวอมฟ้าและน้ำเงินสดใส */
    background: linear-gradient(135deg, #1E90FF 0%, #00CED1 100%);
    color: #fff;
    /* สีข้อความเป็นสีขาว */
    font-size: 1.4rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, opacity 0.2s, box-shadow 0.2s;
    box-shadow: 0 4px 15px rgba(30, 144, 255, 0.4);
}

.login-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(30, 144, 255, 0.5);
    opacity: 0.95;
}

.login-button:active {
    transform: translateY(0);
}


/*
|===================================================================================
| 4. OPTIONS & CHECKBOX - SEA BLUE / AQUA THEME
|===================================================================================
*/

/* ตัวเลือก (จดจำฉันไว้ / ลืมรหัสผ่าน) */
.options-group {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    font-size: 1.4rem;
}

.forgot-link {
    color: #1E90FF;
    /* สีฟ้าสดใส */
    text-decoration: none;
    transition: color 0.2s;
}

.forgot-link:hover {
    color: #00CED1;
    text-decoration: underline;
}

/* Custom Checkbox (จดจำฉันไว้) - โค้ดดีอยู่แล้ว */
.checkbox-container {
    display: block;
    position: relative;
    padding-left: 25px;
    cursor: pointer;
    user-select: none;
    color: #003366;
    /* สีข้อความเป็นน้ำเงินเข้ม */
}

.checkbox-container input {
    position: absolute;
    opacity: 0;
    cursor: pointer;
    height: 0;
    width: 0;
}

.checkmark {
    position: absolute;
    top: 0;
    left: 0;
    height: 18px;
    width: 18px;
    background-color: #F0FFFF;
    /* สีขาวฟ้าอ่อน */
    border-radius: 4px;
    border: 1px solid #B0E0E6;
    transition: background-color 0.2s;
}

.checkbox-container:hover input~.checkmark {
    background-color: #B0E0E6;
    /* สีฟ้าอ่อนเมื่อ hover */
}

.checkbox-container input:checked~.checkmark {
    background-color: #1E90FF;
    border: 1px solid #1E90FF;
}

.checkmark:after {
    content: "";
    position: absolute;
    display: none;
}

.checkbox-container input:checked~.checkmark:after {
    display: block;
}

.checkbox-container .checkmark:after {
    left: 6px;
    top: 2px;
    width: 5px;
    height: 10px;
    border: solid #fff;
    /* เปลี่ยนสีเครื่องหมายเป็นขาว */
    border-width: 0 3px 3px 0;
    transform: rotate(45deg);
}

/* ลิงก์สมัครใช้งาน */
.signup-link-area {
    margin-top: 25px;
    font-size: 1.4rem;
    /* 6) ย่อ/ขยายตามจอ */
    color: #4682B4;
    /* สีน้ำเงินเทา (Steel Blue) */
}

.signup-link-area a {
    color: #1E90FF;
    text-decoration: none;
    font-weight: 600;
}

.signup-link-area a:hover {
    text-decoration: underline;
    color: #00CED1;
}

/* ให้ .login-button ใช้ได้ทั้งกับ <button> และ <a> */
.login-button {
    display: block;
    /* ให้เต็มความกว้างเหมือนปุ่ม */
    text-align: center;
    /* จัดกลางข้อความ */
    text-decoration: none;
    /* ตัดเส้นใต้ของ <a> */
    user-select: none;
    /* เผลอลากเลือกข้อความยากขึ้น */
}

/* สีตัวอักษรของลิงก์ให้ตรงกับปุ่มเสมอ */
.login-button:link,
.login-button:visited {
    color: #fff;
    /* ให้ตรงกับปุ่มหลัก */
}

/* โฟกัสด้วยคีย์บอร์ดให้เห็นชัด */
.login-button:focus-visible {
    outline: 3px solid rgba(30, 144, 255, 0.6);
    outline-offset: 2px;
}

/*
|===================================================================================
| 5. CUSTOM MODAL STYLES (MATCHING SEA BLUE / AQUA THEME)
|===================================================================================
*/

/* 1) สไตล์หลักของ Modal Content */
.login-modal-content {
    /* ใช้สีพื้นหลังเดียวกับ .login-container */
    background-color: rgba(255, 255, 255, 1);
    color: #003366;
    /* สีข้อความหลัก */
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 51, 102, 0.2);
    border: 1px solid #B0E0E6;
    /* ลบเส้นขอบเริ่มต้นของ Bootstrap */
}

/* 2) ส่วนหัว Modal Header */
.modal-header {
    border-bottom: 1px solid #B0E0E6;
    /* ใช้สีเส้นแบ่งสีฟ้าอ่อน */
    padding: 15px 20px;
}

.modal-header .modal-title {
    color: #003366;
    /* สีข้อความหัวข้อ */
    font-weight: 600;
}

/* 3) ปุ่มปิด (x) */
.modal-header .close.login-close-button {
    /* Override สีและขนาดของปุ่มปิด */
    font-size: 28px;
    font-weight: 200;
    line-height: 1;
    color: #4682B4;
    /* สีฟ้าเทาอ่อน */
    opacity: 0.8;
    text-shadow: none;
    margin-top: 0;
}

.modal-header .close.login-close-button:hover {
    color: #1E90FF;
    /* สีฟ้าเมื่อ hover */
    opacity: 1;
}

/* 4) ส่วนเนื้อหา Modal Body */
.modal-body {
    padding: 20px;
}

/* 5) ส่วนท้าย Modal Footer */
.modal-footer {
    border-top: 1px solid #B0E0E6;
    /* ใช้สีเส้นแบ่งสีฟ้าอ่อน */
    padding: 15px 20px;
    text-align: right;
    /* จัดปุ่มไปทางขวา */
}

/* 6) ปุ่มหลัก (ส่งคำขอ) - ใช้สไตล์เดียวกับ .login-button */
.modal-submit-button {
    padding: 12px 25px;
    border: none;
    border-radius: 8px;
    background: linear-gradient(135deg, #1E90FF 0%, #00CED1 100%);
    color: #fff !important;
    font-size: 1.4rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, opacity 0.2s, box-shadow 0.2s;
    box-shadow: 0 4px 15px rgba(30, 144, 255, 0.3);
}

.modal-submit-button:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 18px rgba(30, 144, 255, 0.4);
    opacity: 0.95;
}

.modal-submit-button:active {
    transform: translateY(0);
}

/* ไม่เปลี่ยน modal-submit-button ของเดิม */

/* Cancel: เทาโปรเฟสชันนัล เข้ากับโทนฟ้า-เขียวของ Submit */
.modal-cancel-button {
    padding: 12px 25px;
    border: none;
    border-radius: 8px;
    background: linear-gradient(135deg, #CD5C5C 0%, #FFA07A 100%);
    color: #FFF !important;
    font-size: 1.4rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, opacity 0.2s, box-shadow 0.2s;
    box-shadow: 0 4px 15px #E9967A;
}

.modal-cancel-button:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 18px #E9967A;
    opacity: 0.95;
}

.modal-cancel-button:active {
    transform: translateY(0);
}

/* Edit: ฟ้า Steel รองจาก Submit แต่ยังเด่นพอ */
.modal-edit-button {
    padding: 12px 25px;
    border: none;
    border-radius: 8px;
    background: linear-gradient(135deg, #6FA2C8 0%, #4682B4 100%);
    color: #fff !important;
    font-size: 1.4rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, opacity 0.2s, box-shadow 0.2s;
    box-shadow: 0 4px 15px rgba(70, 130, 180, 0.33);
}

.modal-edit-button:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 18px rgba(70, 130, 180, 0.43);
    opacity: 0.95;
}

.modal-edit-button:active {
    transform: translateY(0);
}


/* 8) ปรับสไตล์ Icon ใน Input (เพื่อให้เข้ากับ .input-group ใน main.style.css) */
/* เนื่องจาก .glyphicon ถูกใช้ เราต้องกำหนดสีให้ตรงกับธีม */
.input-group .glyphicon {
    color: #1E90FF;
    /* ใช้สีเดียวกับ icon ในหน้า Login */
}

/*
|===================================================================================
| 6. VERTICAL CENTERING MODAL (BOOTSTRAP 3 FIX)
|===================================================================================
*/

/* 1) กำหนดให้ Modal ใช้พื้นที่เต็มจอและเปิดใช้งานการจัดเรียงข้อความแนวนอน */
.modal {
    text-align: center;
    padding: 0 !important;
    /* ลบ padding ที่อาจรบกวนการจัดแนวตั้ง */
}

/* 2) ใช้ Pseudo-element เพื่อผลัก Modal ลงมาตรงกลางในแนวตั้ง */
.modal:before {
    content: '';
    display: inline-block;
    /* height: 35%; */
    /* ความสูงเต็ม viewport */
    vertical-align: middle;
    /* margin-right: -4px; */
    /* ปรับ spacing */
}

/* 3) จัด Modal Dialog ให้อยู่กึ่งกลางตามแนวตั้งและกำหนดให้เนื้อหาอยู่ชิดซ้าย */
.modal-dialog {
    /* display: inline-block; */
    text-align: left;
    /* รีเซ็ตให้เนื้อหาใน Modal จัดชิดซ้ายตามปกติ */
    vertical-align: middle;
}

.help-block {
    color: #d9534f;
    font-size: 1.4rem;
}

.spinner {
    display: none;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, .8);
    border-right-color: transparent;
    border-radius: 50%;
    margin-right: 6px;
    vertical-align: -2px;
    animation: spin .6s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg)
    }
}

.btn.is-loading .spinner {
    display: inline-block;
}

.btn.is-loading .btn-text {
    opacity: .85;
}

/* ===== Freeze background (ไม่ให้เลื่อน) ===== */
/* ตัดพื้นหลังที่ body (กันซ้อนทับ) แล้วใช้ pseudo-element แบบ fixed แทน */
body {
    background-image: none !important;
    /* override ของเดิม */
    overflow-x: hidden;
    /* กันล้นซ้ายขวาเผื่อมี margin ลบ */
    position: relative;
    /* สร้าง context ให้ ::before */
}

/* พื้นหลังแบบ fixed เต็มหน้าจอ จะไม่เลื่อนตามสกรอล */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    /* อยู่หลังทุกอย่าง */
    background: linear-gradient(135deg, #E0FFFF 0%, #B0E0E6 50%, #4682B4 100%);
    background-repeat: no-repeat;
    background-position: center;
    background-size: cover;
    /* fallback เผื่อบางเบราว์เซอร์ */
    background-attachment: fixed;
    pointer-events: none;
    /* ไม่บังการคลิก */
    transform: translateZ(0);
    /* ลดอาการกระตุกบน iOS */
}