@font-face {
    font-family: 'THSarabunNew';
    src: url('../fonts/THSarabunNew.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
}

/* --- สไตล์สำหรับส่วนหัวฟอร์มแบบใหม่ --- */
.form-header-container {
    display: flex;
    align-items: center;
    background-color: #ffffff;
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 25px;
    border: 1px solid #c5d9ed;
}

.form-header-icon {
    width: 60px;
    height: 60px;
    margin-right: 20px;
    flex-shrink: 0; 
}

.form-header-text {
    display: flex;
    flex-direction: column;
}

.form-header-text p {
    margin: 0; 
    line-height: 1.4;
}

.form-header-text .header-title {
    font-size: 32px;
    font-weight: 600;
    color: #333;
}
/* --- จบส่วนหัวฟอร์ม --- */

body {
    font-family: 'THSarabunNew', sans-serif;
    background-color: #6c90fb;
    margin: 0;
    padding: 20px;
    font-size: 24px; 
}
form {
    max-width: 900px;
    margin: 20px auto;
    padding: 30px;
    background-color: #d1e3f7;
    border-radius: 10px;
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.2);
    border: 1px solid #e0e0e0;
}
h3 {
    text-align: center;
    color: #333;
    margin-bottom: 25px;
    font-size: 24px;
}
fieldset {
    border: 1px solid #c5d9ed;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
    background-color: #ffffff; /* ⬅️ พื้นหลังสีขาว */
    transition: opacity 0.3s ease;
}

fieldset.disabled-fieldset {
    opacity: 0.6;
    background-color: #f9f9f9;
}

legend {
    font-size: 28px;
    font-weight: 600;
    color: #ffffff;
    margin-left: 10px;
    background-color: #005a9e;
    border: 1px solid #004a8e;
    border-radius: 5px;
}
.form-group { margin-bottom: 15px; }
.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    color: #555;
}
input[type="text"],
input[type="number"],
select {
    width: 100%;
    padding: 10px 12px;
    border: 5px solid #ccc;
    border-radius: 5px;
    box-sizing: border-box; 
    font-family: 'THSarabunNew', sans-serif;
    font-size: 24px;
}
input:focus, select:focus {
    border: 10px solid #005a9e;
    outline: none;
    box-shadow: 0 0 5px rgba(0, 90, 158, 0.4); 
}

.form-row {
    display: flex;
    gap: 20px; 
}
.form-row .form-group { flex: 1; }
.form-group.flex-1 { flex: 1; }
.form-group.flex-2 { flex: 2; }
.form-group.flex-3 { flex: 3; }
.checkbox-group { padding: 10px 0; }

fieldset > label {
    margin-left: 8px;
    margin-right: 20px;
    font-weight: 600;
    color: #444;
    font-size: 24px; 
}
input[type="radio"], input[type="checkbox"] {
    transform: scale(1.5);
    margin-right: 5px;
    vertical-align: middle;
    accent-color: #005a9e;
}


fieldset > p {
    margin-top: 15px;
    font-size: 24px;
}
fieldset > p input[type="number"] {
    width: 150px;
    display: inline-block;
    margin: 0 5px;
}
table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 15px;
}
th, td {
    border: 1px solid #ddd;
    padding: 10px;
    text-align: left;
    vertical-align: middle;
    font-size: 24px; 
}
th {
    background-color: #eaf2fa;
    font-weight: 600;
}
td {
    background-color: #fff;
    line-height: 1.4; 
}
table input[type="number"] { width: 150px; }
th input[type="number"] {
    font-weight: normal; 
    font-size: 24px;
    width: 150px;
    padding: 8px 10px;
}


input[readonly] {
    background-color: #eee !important;
    font-weight: bold;
    color: #555;
}

button[type="submit"] {
    display: block;
    width: 100%;
    padding: 12px;
    background-color: #005a9e;
    color: white;
    border: none;
    border-radius: 5px;
    font-family: 'THSarabunNew', sans-serif;
    font-size: 24px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.3s ease;
    margin-top: 20px;
}
button[type="submit"]:hover { 
    background-color: #004a8e;
}

/* ======================================= */
/* ▼▼▼ โค้ดสำหรับทำให้รองรับมือถือ ▼▼▼ */
/* ======================================= */

@media (max-width: 768px) {
    
    body {
        padding: 10px; /* ลด padding รอบนอกสุด */
    }

    form {
        padding: 20px 15px; /* ลด padding ในฟอร์ม */
    }

    h3 {
        font-size: 24px; /* ลดขนาดหัวข้อเล็กน้อย */
    }

    legend {
        font-size: 28px; /* ลดขนาด legend */
    }

    /* * !!! นี่คือส่วนที่สำคัญที่สุด !!!
     * สั่งให้ .form-row (ที่ปกติเป็นแนวนอน)
     * เปลี่ยนเป็น "แนวตั้ง" (เรียงต่อกัน)
     */
    .form-row {
        flex-direction: column; /* เปลี่ยนเป็นแนวตั้ง */
        gap: 15px; /* กำหนดช่องว่างระหว่างช่อง (จากบนลงล่าง) */
    }

    /* * ▼▼▼ [ นี่คือส่วนที่แก้ไข ] ▼▼▼
     * สั่งให้ .table-wrapper (ที่ครอบตาราง) เลื่อนซ้าย-ขวาได้
     */
    .table-wrapper {
        overflow-x: auto;
        width: 100%;
    }

    .table-wrapper table {
        min-width: 600px; 
    }

    /* นี่คือโค้ดที่เพิ่มเข้ามาใหม่ */
    #fs_both,
    #fs_tuition,
    #fs_living {
        display: grid;
        grid-template-columns: auto 1fr; /* สร้าง 2 คอลัมน์: [auto] [ที่เหลือ] */
        align-items: center; /* จัดให้ radio และ label อยู่กลางแนวตั้ง */
        gap: 0 8px; /* เว้นช่องว่างระหว่าง radio กับ label (ปรับได้) */
    }
    #fs_both > p,
    #fs_tuition > p,
    #fs_both > .table-wrapper,
    #fs_tuition > .table-wrapper,
    #fs_living > .table-wrapper {
        grid-column: 1 / -1; /* 1 / -1 หมายถึง "ตั้งแต่เส้นแรกสุดถึงเส้นสุดท้าย" */
    }

    /* สำหรับตารางติ๊กเอกสาร ให้มันยืดหยุ่นได้ */
    fieldset:last-of-type table {
        font-size: 24px;
        display: table;
        overflow-x: visible;
        white-space: normal;
        min-width: 0; /* [เพิ่ม] รีเซ็ตค่า min-width ของตารางสุดท้าย */
    }

    /* ลดขนาด input ในตารางให้เล็กลงหน่อย */
    fieldset > p input[type="number"],
    table input[type="number"] {
        width: 120px;
    }

    /* ลดขนาดตัวอักษรของตารางติ๊กเอกสาร */
    fieldset:last-of-type th,
    fieldset:last-of-type td {
        font-size: 24px;
        padding: 8px 5px;
    }
    
    /* แก้ไขส่วน checkbox ยืนยันตัวตนท้ายฟอร์ม */
    #confirm_truth + label {
        font-size: 24px;
    }
}

/* สำหรับจอมือถือที่แคบมากๆ (น้อยกว่า 400px) */
@media (max-width: 400px) {
    h3 {
        font-size: 20px;
    }
    
    /* ลดขนาดตัวอักษรของตารางติ๊กเอกสารอีก */
    fieldset:last-of-type td {
        font-size: 20px;
    }

    #confirm_truth + label {
        font-size: 16px;
    }
}