/* === 0. Import Google Font (เหมือนเดิม) === */
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700&display=swap');

/* === 1. Basic Reset & Font (เหมือนเดิม) === */
body {
    font-family: 'Poppins', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
    background-color: #f0f2f5;
    color: #3d4f68;
    margin: 0;
    line-height: 1.6;
}
.container {
    width: 90%;
    max-width: 950px;
    margin: 30px auto;
}
/* ลบ header h1 ออกไป เพราะเราจะสร้าง header ใหม่ */

/* === 1. การ์ด Header หลัก (จัด ซ้าย | ขวา) === */
.document-header-card {
    background: #ffffff;
    padding: 25px 30px;
    border-radius: 12px;
    border: 1px solid #e7eaf3;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04), 0 10px 20px rgba(0,0,0,0.06);
    margin-bottom: 30px;
    display: flex;
    align-items: center; /* จัดกลางแนวตั้ง */
    gap: 30px; /* ระยะห่างระหว่าง ซ้าย-ขวา */
}

/* === 2. ส่วนหัวข้อ (ซ้าย) === */
.document-header-card .header-title {
    font-size: 1.3rem;
    font-weight: 600;
    color: #2c3e50;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0; /* ไม่ให้หด */
}
.document-header-card .header-title .fa-file-alt {
    color: #007bff;
}

/* === 3. Wrapper (ขวา) (จัด บน | ล่าง) === */
.document-header-card .search-filter-wrapper {
    flex-grow: 1; /* ยืดเต็มพื้นที่ */
    display: flex;
    flex-direction: column; /* จัด บน(ค้นหา) | ล่าง(ปุ่มกรอง) */
    gap: 15px; /* ระยะห่างระหว่างแถวค้นหา กับ แถวปุ่มกรอง */
    min-width: 0; 
}

/* === NEW: Search Bar (ใน Header Card) === */
/* === REVISED: Search Bar (ใน Header Card) === */
.document-header-card .search-bar-inner {
    display: flex;
}

/* นี่คือ <form> ที่เราจะให้เป็น flex container */
.document-header-card .search-bar-inner form {
    display: flex; 
    flex-grow: 1; 
    gap: 10px; /* ระยะห่างระหว่าง (กลุ่ม input) กับ (ปุ่ม) */
    align-items: center; /* จัดกลางแนวตั้ง */
}

/* * นี่คือส่วนที่สำคัญที่สุด (search-input-group)
 * เราจะย้ายเส้นขอบและพื้นหลังมาไว้ที่นี่
 */
/* === 4. แถวค้นหา (แถวบนขวา) === */
.document-header-card .search-bar-inner .search-input-group {
    flex-grow: 1; /* ยืดเต็มที่ */
    display: flex; 
    align-items: center;
    border: 1px solid #ced4da; /* กรอบล้อมไอคอน+input */
    border-radius: 8px;
    background: #fff;
    transition: all 0.2s ease;
}

/* ไอคอนแว่นขยาย */
.document-header-card .search-bar-inner .search-input-group .fa-search {
    color: #6c757d;
    width: 20px;
    height: 20px;
    margin-left: 15px; 
    margin-right: 10px;
    flex-shrink: 0;
}

/* ช่อง input */
.document-header-card .search-bar-inner input[type="text"] {
    flex-grow: 1;
    padding: 12px 0; 
    font-size: 15px;
    font-family: 'Poppins', sans-serif;
    border: none; /* ไม่มีกรอบ */
    background: none; /* โปร่งใส */
}
.document-header-card .search-bar-inner input[type="text"]:focus {
    outline: none; /* ไม่มีกรอบ focus */
    box-shadow: none;
}

/* เมื่อคลิกที่ group ให้กรอบเปลี่ยนสี */
.document-header-card .search-bar-inner .search-input-group:focus-within {
    border-color: #007bff;
    box-shadow: 0 0 0 0.2rem rgba(0,123,255,.25);
}

/* ปุ่ม "ค้นหา" สีฟ้า */
.document-header-card .search-bar-inner button {
    padding: 12px 20px;
    font-size: 15px;
    font-weight: 500;
    border: none;
    background: #007bff;
    color: white;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 5px;
    flex-shrink: 0;
}
.document-header-card .search-bar-inner button:hover {
    background: #0056b3;
}

.document-header-card .search-bar-inner button svg {
    width: 18px;
    height: 18px;
}

/* === NEW: Filter Buttons (ปุ่มกรอง) === */
/* === 5. แถวปุ่มกรอง (แถวล่างขวา) === */
.document-header-card .filter-buttons {
    display: flex;
    flex-wrap: wrap; /* ถ้าปุ่มเยอะ ให้ขึ้นบรรทัดใหม่ */
    gap: 10px; 
}

/* สไตล์ของปุ่มกรอง (Pill) */
.document-header-card .filter-buttons .filter-btn {
    padding: 8px 15px;
    font-size: 14px;
    font-weight: 500;
    border: 1px solid #e0e0e0;
    border-radius: 20px; 
    background-color: #f8f9fa;
    color: #6c757d;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none; 
}
.document-header-card .filter-buttons .filter-btn:hover {
    background-color: #e2e6ea;
    border-color: #dae0e5;
    color: #343a40;
}
/* ปุ่มที่ถูกเลือก (Active) */
.document-header-card .filter-buttons .filter-btn.active {
    background-color: #28a745; 
    border-color: #28a745;
    color: white;
}

/* === 3. Section (การ์ด) - V2 (เหมือนเดิม) === */
.accordion-item {
    background: #ffffff;
    margin-bottom: 25px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04), 0 10px 20px rgba(0,0,0,0.06);
    border: 1px solid #e7eaf3;
    overflow: hidden;
}
.accordion-header {
    background: #fdfdff;
    padding: 20px 25px;
    font-size: 1.25rem;
    font-weight: 600;
    color: #2c3e50;
    border-bottom: 1px solid #f0f2f5;
}
.accordion-content {
    padding: 10px 15px 15px 15px;
}

/* === 4. Document List (รายการเอกสาร) - V2 (เหมือนเดิม) === */
.doc-list { 
    list-style: none; 
    padding-left: 0; 
    margin: 0;
}
.doc-list li {
    display: flex;
    align-items: center;
    padding: 12px 15px;
    margin: 5px 0;
    border-radius: 8px;
    transition: all 0.25s ease-out;
}
.doc-list li:hover {
    background-color: #f6f9ff;
    transform: translateX(5px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.doc-list img {
    width: 20px;
    height: 20px;
    padding: 10px;
    background: #eef6ff;
    border-radius: 50%;
    margin-right: 15px;
    flex-shrink: 0;
}

.doc-list a {
    text-decoration: none;
    font-weight: 500;
    color: #33475b;
    transition: color 0.2s;
}
.doc-list li:hover a {
    color: #007bff;
}

.doc-list .file-size,
.doc-list .download-count {
    font-size: 0.85rem;
    color: #6a7c92;
    margin-left: 15px;
    white-space: nowrap;
}
.doc-list .timestamp {
    font-size: 0.85rem;
    color: #6a7c92;
    margin-left: auto;
    white-space: nowrap;
    padding-left: 20px;
}

/* --- Admin Panel (เหมือนเดิม) --- */
.admin-wrapper { display: flex; }
.admin-sidebar {
    width: 250px;
    background: #2c3e50;
    color: white;
    min-height: 100vh;
    padding: 20px;
}
.admin-sidebar h3 { text-align: center; }
.admin-sidebar ul { list-style: none; padding: 0; }
.admin-sidebar ul li a {
    display: block;
    padding: 10px;
    color: white;
    text-decoration: none;
    border-radius: 5px;
}
.admin-sidebar ul li a:hover { background: #34495e; }

.admin-content {
    flex-grow: 1;
    padding: 20px;
}

/* --- Forms & Tables (Admin) --- */
form {
    background: #fff;
    padding: 20px;
    border-radius: 5px;
    margin-bottom: 20px;
}
form label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
}
form input[type="text"],
form input[type="password"],
form select,
form input[type="file"] {
    width: 100%;
    padding: 8px;
    margin-bottom: 15px;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-sizing: border-box;
}
form button {
    background: #28a745;
    color: white;
    padding: 10px 15px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
}
table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
}
table th, table td {
    border: 1px solid #ddd;
    padding: 8px;
    text-align: left;
}
table th { background: #f2f2f2; }
.btn-edit { color: #007bff; text-decoration: none; }
.btn-delete { color: #dc3545; text-decoration: none; margin-left: 10px; }