/* นำเข้าฟอนต์ภาษาไทย Sarabun จาก Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=Sarabun:wght@400;500;600&display=swap');

:root {
    /* สีหลักมาตรฐาน ไร้โทนม่วง */
    --primary-color: #0d6efd; /* น้ำเงินมาตรฐาน */
    --success-color: #198754; /* เขียว */
    --danger-color: #dc3545;  /* แดง */
    --warning-color: #ffc107; /* เหลือง */
    --info-color: #0dcaf0;    /* ฟ้าอ่อน */
    --gray-color: #6c757d;    /* เทา */
    
    --text-color: #333333;
    --bg-color: #f8f9fa; /* พื้นหลังสว่างขึ้น */
    --card-bg: #ffffff;
    --border-color: #dee2e6;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* บังคับฟอนต์ Sarabun และล็อกขนาดตายตัวที่ 16px */
body {
    font-family: 'Sarabun', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    font-size: 16px; 
    line-height: 1.5;
}

/* ล็อกขนาดหัวข้อทั้งหมดไม่ให้เกิน 16px แต่ใช้ตัวหนา (600) เพื่อแยกความแตกต่าง */
h1, h2, h3, h4, h5, h6, .header-title {
    font-size: 16px;
    font-weight: 600;
    text-align: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
    color: #1a1a1a;
}

/* ---------------------------------------------------
   โครงสร้างหลัก (ความเรียบหรู Modern & Luxury UI)
----------------------------------------------------- */
.container {
    max-width: 1000px;
    margin: 30px auto;
    padding: 30px;
    background-color: var(--card-bg);
    border-radius: 8px; 
    border: 1px solid var(--border-color); /* เปลี่ยนจากเงาเข้มๆ เป็นกรอบบางๆ */
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.02); 
}

/* ส่วนตัวกรองข้อมูล */
.filter-group {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
    margin-bottom: 25px;
    background-color: #ffffff;
    padding: 15px 20px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.02);
}

.filter-group label {
    color: #495057;
    font-weight: 500;
    margin-right: -5px;
}

/* ช่องกรอกข้อมูล */
input[type="text"], 
input[type="number"], 
input[type="password"], 
input[type="date"], 
select,
input[type="file"] {
    padding: 8px 12px;
    font-family: 'Sarabun', sans-serif;
    font-size: 16px; 
    border: 1px solid #ced4da;
    border-radius: 4px;
    outline: none;
    vertical-align: middle;
    background-color: #ffffff;
    transition: border-color 0.15s ease-in-out;
}

input[type="text"]:focus, 
input[type="number"]:focus, 
input[type="password"]:focus, 
input[type="date"]:focus, 
select:focus {
    border-color: #86b7fe;
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.15);
}

/* ---------------------------------------------------
   ตาราง Desktop (คลีนและสะอาดตา)
----------------------------------------------------- */
.table-responsive {
    width: 100%;
    overflow-x: auto; /* เปิดให้เลื่อนขวาได้กรณีตารางกว้างมาก */
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
}

th, td {
    padding: 12px 15px;
    text-align: left;
    vertical-align: middle; 
    font-size: 16px;
    border-bottom: 1px solid var(--border-color);
}

th {
    background-color: #f8f9fa;
    color: #212529;
    font-weight: 600;
    text-align: center;
}

tr:hover td {
    background-color: #f8f9fa;
}

/* ---------------------------------------------------
   ปุ่มกด (Buttons) - ปรับโทนสีใหม่ให้เป็นทางการ
----------------------------------------------------- */
.btn {
    padding: 10px 18px;
    border: none;
    border-radius: 4px; /* ปรับมุมให้เหลี่ยมขึ้นนิดนึงดูเป็นทางการ */
    cursor: pointer;
    font-family: 'Sarabun', sans-serif;
    font-size: 16px; 
    font-weight: 500;
    color: white;
    vertical-align: middle;
    transition: background-color 0.2s;
}

.btn:hover { opacity: 0.9; }

.btn-primary { background-color: var(--primary-color); }
.btn-success { background-color: var(--success-color); }
.btn-danger  { background-color: var(--danger-color); }
.btn-warning { background-color: var(--warning-color); color: #212529; }
.btn-info    { background-color: var(--info-color); color: #212529; }
.btn-gray    { background-color: var(--gray-color); }

/* ---------------------------------------------------
   แถบเมนูนำทาง (Navbar)
----------------------------------------------------- */
.navbar {
    background-color: #ffffff;
    box-shadow: 0 1px 4px rgba(0,0,0,0.05);
    padding: 0 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 65px;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 1000;
}
.nav-brand {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-color);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 8px;
}
.nav-menu-wrapper {
    display: flex;
    flex-grow: 1;
    justify-content: space-between;
    align-items: center;
    margin-left: 30px;
}
.nav-links {
    display: flex;
    gap: 25px;
    list-style: none;
}
.nav-links a {
    text-decoration: none;
    color: #495057;
    font-weight: 500;
    font-size: 15px;
    transition: color 0.2s;
    padding: 20px 0;
    border-bottom: 2px solid transparent;
}
.nav-links a:hover, .nav-links a.active {
    color: var(--primary-color);
    border-bottom: 2px solid var(--primary-color);
}
.nav-user {
    display: flex;
    align-items: center;
    gap: 15px;
}
.btn-logout {
    background-color: #f8f9fa;
    color: var(--danger-color);
    border: 1px solid #dee2e6;
    padding: 6px 14px;
    border-radius: 4px;
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
}
.btn-logout:hover { 
    background-color: var(--danger-color); 
    color: white;
}

/* ปุ่ม Hamburger สำหรับมือถือ */
.nav-toggle { display: none; background: none; border: none; font-size: 24px; cursor: pointer; color: #333;}

/* ---------------------------------------------------
   ปุ่มเช็คชื่อ (Custom Radio Buttons)
----------------------------------------------------- */
.custom-radios {
    display: flex;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
}

.custom-radios input[type="radio"] {
    display: none; 
}

.custom-radios label {
    display: inline-block;
    padding: 6px 16px;
    border-radius: 4px; /* ปรับเป็นมุมมนเล็กน้อยแทนแคปซูล */
    border: 1px solid #ced4da;
    background-color: #ffffff;
    color: #495057;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.15s ease-in-out;
    user-select: none;
}

.custom-radios label:hover {
    background-color: #f8f9fa;
}

/* สีเมื่อปุ่มถูกคลิกเลือก (มา = เขียว) */
.custom-radios input[value="present"]:checked + label {
    background-color: var(--success-color);
    color: white;
    border-color: var(--success-color);
}

/* สีเมื่อปุ่มถูกคลิกเลือก (ขาด = แดง) */
.custom-radios input[value="absent"]:checked + label {
    background-color: var(--danger-color);
    color: white;
    border-color: var(--danger-color);
}

/* สีเมื่อปุ่มถูกคลิกเลือก (ลา = ฟ้า) */
.custom-radios input[value="leave"]:checked + label {
    background-color: var(--info-color);
    color: #212529; /* ข้อความสีเข้มเพราะพื้นสีฟ้าอ่อน */
    border-color: var(--info-color);
}

/* สีเมื่อปุ่มถูกคลิกเลือก (สาย = เหลือง) */
.custom-radios input[value="late"]:checked + label {
    background-color: var(--warning-color);
    color: #212529;
    border-color: var(--warning-color);
}

/* ป่วย (ส้ม) - เพิ่มคลาสเฉพาะ */
.custom-radios input[value="sick"]:checked + label {
    background-color: #fd7e14;
    color: white;
    border-color: #fd7e14;
}

/* ---------------------------------------------------
   สีตัวอักษรเฉพาะสำหรับตารางสรุป (ไม่มีสีม่วง)
----------------------------------------------------- */
.text-blue { color: var(--primary-color); }
.text-green { color: var(--success-color); }
.text-red { color: var(--danger-color); }
.text-orange { color: #fd7e14; } /* ป่วย */
.text-cyan { color: var(--info-color); } /* ลา (สีฟ้าแทนสีม่วง) */


/* 📢 ---------------------------------------------------
   ตกแต่ง Pop-up SweetAlert2 แบบ Global (ใช้ได้ทั้งระบบ)
----------------------------------------------------- */
div.swal2-popup {
    font-family: 'Sarabun', sans-serif !important; 
    border-radius: 12px !important;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1) !important;
    padding: 20px !important;
}

h2.swal2-title {
    color: var(--text-color) !important;
    font-weight: 600 !important;
    font-size: 20px !important;
}

div.swal2-html-container {
    color: var(--gray-color) !important;
    font-size: 16px !important;
}

/* ปุ่มยืนยัน (OK/Confirm) ดึงสีหลักของเว็บมาใช้ */
button.swal2-confirm {
    background-color: var(--primary-color) !important; 
    color: white !important;
    border-radius: 6px !important;
    padding: 10px 24px !important;
    font-weight: 500 !important;
    font-size: 16px !important;
    font-family: 'Sarabun', sans-serif !important;
    box-shadow: none !important;
}

button.swal2-confirm:hover {
    opacity: 0.9 !important;
}

/* ปุ่มยกเลิก (Cancel) ให้เป็นโทนสีเทาอ่อน สุภาพๆ */
button.swal2-cancel {
    background-color: #f8f9fa !important; 
    color: var(--text-color) !important;
    border: 1px solid var(--border-color) !important;
    border-radius: 6px !important;
    padding: 10px 24px !important;
    font-weight: 500 !important;
    font-size: 16px !important;
    font-family: 'Sarabun', sans-serif !important;
}

button.swal2-cancel:hover {
    background-color: #e2e6ea !important;
}


/* 📱 --------------------------------------------------------
   ระบบ Responsive (มือถือ / หน้าจอเล็กกว่า 768px)
---------------------------------------------------------- */
@media screen and (max-width: 768px) {
    .container {
        margin: 10px;
        padding: 15px;
    }

    /* แถบค้นหา/ตัวกรอง */
    .filter-group {
        flex-direction: column; 
        align-items: stretch;
        gap: 10px;
    }
    .filter-group input, 
    .filter-group select, 
    .filter-group button {
        width: 100% !important; 
        margin-bottom: 5px;
    }

    /* เปลี่ยนตารางเป็นการ์ด (Card View) สำหรับหน้าธรรมดา */
    table:not(.report-table) thead { display: none; }
    table:not(.report-table), table:not(.report-table) tbody, table:not(.report-table) tr, table:not(.report-table) td { display: block; width: 100%; }
    
    table:not(.report-table) tr {
        margin-bottom: 15px;
        border: 1px solid var(--border-color);
        border-radius: 6px;
        background: #fff;
    }
    
    table:not(.report-table) td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        text-align: right;
        padding: 10px 15px;
        border-bottom: 1px dashed #eee;
    }
    
    table:not(.report-table) td:last-child {
        border-bottom: none;
    }
    
    /* เอาชื่อคอลัมน์มาแปะไว้ข้างหน้า (ดึงจาก data-label ใน HTML) */
    table:not(.report-table) td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #495057;
        text-align: left;
        margin-right: 10px;
    }

    /* ขยายปุ่มเช็คชื่อให้เต็มจอและกดง่ายบนมือถือ */
    .custom-radios {
        justify-content: space-between;
        width: 100%;
        margin-top: 10px;
    }
    .custom-radios label {
        flex: 1;
        padding: 10px 0;
        text-align: center;
    }
    
    table:not(.report-table) td[data-label="สถานะ (คลิกเลือก)"] {
        flex-direction: column;
        align-items: stretch;
    }

    /* Navbar มือถือ */
    .navbar { padding: 0 15px; }
    .nav-toggle { display: block; }
    .nav-menu-wrapper {
        display: none;
        flex-direction: column;
        position: absolute;
        top: 65px;
        left: 0;
        width: 100%;
        background: white;
        box-shadow: 0 4px 6px rgba(0,0,0,0.1);
        padding: 20px;
        z-index: 1000;
        margin-left: 0;
    }
    .nav-menu-wrapper.show { display: flex; }
    .nav-links { flex-direction: column; gap: 10px; border-bottom: 1px solid #eee; padding-bottom: 15px; margin-bottom: 15px; width: 100%;}
    .nav-links a { padding: 10px 0; border: none; }
    .nav-user { flex-direction: column; align-items: stretch; gap: 15px; width: 100%; text-align: center; }
}