body {
    font-family: Arial, sans-serif;
    margin: 20px;
    background-color: #f4f4f4;
    color: #333;
}

header {
    background-color: #333;
    color: #fff;
    padding: 10px 20px;
    text-align: center;
    border-radius: 5px;
    margin-bottom: 20px;
}

header h1 {
    margin: 0;
}

nav {
    margin-top: 10px;
}

nav a {
    color: #fff;
    text-decoration: none;
    margin: 0 10px;
}

main {
    background-color: #f0f0f0;
    padding: 20px;
    border-radius: 5px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

form {
    max-width: 800px;
    margin: 20px auto;
    padding: 20px;
    border: 1px solid #ddd;
    border-radius: 5px;
    background-color: #f9f9f9;
}

input[type="text"],
input[type="password"],
input[type="submit"] {
    width: 100%;
    padding: 10px;
    margin-bottom: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    box-sizing: border-box; /* Ensures padding doesn't affect overall width */
}

input[type="submit"] {
    background-color: #5cb85c;
    color: white;
    border: none;
    cursor: pointer;
}

input[type="submit"]:hover {
    background-color: #4cae4c;
}

.flashes {
    list-style-type: none;
    padding: 0;
    margin: 20px 0;
    text-align: center; /* จัดให้อยู่กลาง */
}

.flashes li {
    padding: 12px 20px; /* เพิ่ม padding */
    margin-bottom: 10px;
    border-radius: 5px;
    font-weight: bold; /* ทำตัวหนา */
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); /* เพิ่มเงาเล็กน้อย */
}

.flashes .success {
    background-color: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb; /* เพิ่ม border */
}

.flashes .danger {
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb; /* เพิ่ม border */
}

.flashes .info {
    background-color: #d1ecf1;
    color: #0c5460;
    border: 1px solid #bee5eb; /* เพิ่ม border */
}

footer {
    text-align: center;
    margin-top: 20px;
    color: #666;
}

/* === General Layout & Cards === */
.card {
    background-color: #f9f9f9;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

/* === Form Styles === */
.form-row {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    align-items: flex-end;
}

.form-group {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 150px;
    align-items: flex-start; /* ✅ เพิ่มบรรทัดนี้เพื่อจัดทุกอย่างชิดซ้าย */
    
}

.form-group label {
    margin-bottom: 5px;
    font-weight: bold;
    
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="date"],
textarea,
select {
    width: 100%;
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-sizing: border-box;
}

/* ฟอร์มข้อมูลลูกค้า สร้าง 2 คอลัมน์ ขนาดเท่ากัน */
.customer-info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr; /* สร้าง 2 คอลัมน์ ขนาดเท่ากัน */
    gap: 1rem 1.5rem; /* ระยะห่างระหว่าง แถว และ คอลัมน์ */
}

.customer-info-grid .form-group {
    margin-bottom: 0; /* ไม่ต้องใช้ margin-bottom แบบเดิม */
}

.grid-span-2 {
    grid-column: 1 / -1; /* สั่งให้ element นี้ขยายเต็มความกว้าง (2 คอลัมน์) */
}



/* === Table Styles === */
table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
}

th, td {
    border: 1px solid #ddd;
    padding: 10px;
    text-align: left;
}

th {
    background-color: #f2f2f2;
    font-weight: bold;
}

tbody tr:nth-child(even) {
    background-color: #f9f9f9;
}

/* === Button Styles === */
.button {
    background-color: #28a745;
    border: none;
    outline: none; /* เพิ่มบรรทัดนี้ */
    box-shadow: none; /* เพิ่มบรรทัดนี้ */
    color: white;
    padding: 10px 15px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 14px;
    margin: 4px 2px;
    cursor: pointer;
    border-radius: 5px;
    transition: background-color 0.2s;
}

.button:hover {
    background-color: #218838;
}

/* เพิ่มการลบ outline ในสถานะ active และ focus */
.button:focus,
.button:active {
    outline: none;
    box-shadow: none;
}

/* Button Variations */
.button-primary { background-color: #007bff; }
.button-primary:hover { background-color: #0069d9; }
.button-secondary { background-color: #6c757d; }
.button-secondary:hover { background-color: #5a6268; }
.button-danger { background-color: #dc3545;}
.button-danger:hover { background-color: #c82333; }
.button-success { background-color: #28a745; }
.button-success:hover { background-color: #218838; }
.button-small { padding: 5px 10px; font-size: 12px; }

/* === Override for Full-Page Forms === */
form.form-full-page {
    max-width: none; /* ลบข้อจำกัดความกว้างสูงสุดออก */
    margin: 0;       /* ไม่ต้องจัดกึ่งกลาง */
    padding: 0;      /* ไม่ต้องมี padding เพิ่มเติม */
    border: none;    /* ไม่ต้องมีเส้นขอบ */
    background-color: transparent; /* ทำให้พื้นหลังโปร่งใส */
}

/* === Sales Grid Layout === */
/* กำหนดความกว้างสูงสุดของ Container */
.form-container {
    max-width: 95%;
    margin: 0 auto;
}

.sales-grid {
    display: grid;
    /* สร้าง Grid 2 คอลัมน์ ขนาดเท่ากัน */
    grid-template-columns: 1fr 1fr; 
    gap: 1.5rem; /* ระยะห่างระหว่าง Card */
}

/* คลาสพิเศษสำหรับ Card ที่ต้องการให้เต็มความกว้าง */
.card-full-width {
    grid-column: 1 / -1; /* สั่งให้ Card นี้ขยายตั้งแต่เส้น Grid ที่ 1 จนถึงเส้นสุดท้าย */
}

/* ทำให้ Layout กลับเป็น 1 คอลัมน์บนจอมือถือ */
@media (max-width: 768px) {
    .sales-grid {
        grid-template-columns: 1fr;
    }
}

.grid-2-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2.5rem;
}


/* ===== Summary Section Layout (ใช้ CSS Grid) ===== */


/* --- CSS พื้นฐานอื่นๆ (เพื่อให้เห็นภาพ) --- */
.form-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; }
.card { background-color: #fff; border: 1px solid #e9ecef; border-radius: 0.375rem; }
.card-body { padding: 1.5rem; }
h3 { margin-top: 0; }

/* =============================================== */
/* === ปรับแก้หน้าตาเพิ่มเติม (UI Adjustments) === */
/* =============================================== */

/* 1. ปรับสีปุ่มลบในตารางสินค้า */
.delete-btn {
    background-color: #e74c3c; /* สีแดงที่ดูสบายตาขึ้น (Flat UI Red) */
    color: white;
    border: none;
    padding: 5px 10px;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s; /* เพิ่ม Animation ตอนชี้เมาส์ */
}

.delete-btn:hover {
    background-color: #c0392b; /* สีแดงเข้มขึ้นเมื่อเมาส์ชี้ */
}


/* 2. ปรับขนาดความกว้างของช่องค้นหาสินค้า */
#product-search {
    max-width: 500px; /* กำหนดความกว้างสูงสุด (ปรับค่าได้ตามต้องการ) */
}


/* 3. ปรับขนาดความกว้างของช่องภาษีมูลค่าเพิ่ม */
#vat-percent-input {
    width: 80px;      /* กำหนดความกว้าง (ปรับค่าได้ตามต้องการ) */
    flex-grow: 0;     /* ป้องกันไม่ให้ช่องขยายตัวตามพื้นที่ที่เหลือ */
    flex-shrink: 0;   /* ป้องกันไม่ให้ช่องหดตัวเมื่อพื้นที่น้อย */
    text-align: right;
}

/* === Align text to the right for summary number inputs === */


/* === Add a checkbox to copy customer address === */
.form-group-inline {
    display: flex;         /* 1. สั่งให้สิ่งที่อยู่ข้างใน (checkbox, label) เรียงกันในแนวนอน */
    align-items: center;   /* 2. จัดให้อยู่กึ่งกลางในแนวตั้ง */
    margin-bottom: 1rem;   /* 3. เพิ่มระยะห่างจากบรรทัดล่าง (เหมือน form-group เดิม) */
}

/* === Style for the checkbox and label === */
.form-group-inline input[type="checkbox"] {
    margin-right: 0.5rem; /* ระยะห่างระหว่าง checkbox กับ label */
    cursor: pointer;      /* เปลี่ยนเคอร์เซอร์เมื่อชี้ที่ checkbox */
}
.form-group-inline label {
    font-size: 14px;      /* ขนาดตัวอักษรของ label */
    margin: 0;            /* ลบระยะห่างบนและล่างของ label */
    font-weight: normal;  /* ทำให้ตัวอักษรไม่หนา */
}
.form-group-inline input[type="checkbox"] {
    width: 20px;          /* กำหนดขนาดของ checkbox */
    height: 20px;         /* กำหนดขนาดของ checkbox */
    cursor: pointer;      /* เปลี่ยนเคอร์เซอร์เมื่อชี้ที่ checkbox */
}

/* --- Styling for Form Actions Bar --- */
.form-actions {
    display: flex;
    justify-content: space-between; /* จัดให้สองฝั่งอยู่ห่างกัน */
    align-items: center;
    padding: 1.5rem;
    background-color: #f8f9fa;
    border-top: 1px solid #dee2e6;
    border-radius: 0 0 0.375rem 0.375rem; /* ทำให้ขอบล่างโค้งมน */
    margin-top: 1.5rem;
}

.submit-buttons {
    display: flex;
    gap: 0.5rem; /* ระยะห่างระหว่างปุ่ม */
}

.back-link {
    color: #6c757d;
    text-decoration: none;
}
.back-link:hover {
    text-decoration: underline;
}

/* Center the login form */
.login-container {
    max-width: 400px;
    margin: 40px auto; /* เพิ่มระยะห่างด้านบนและจัดให้อยู่กลางแนวนอน */
    padding: 30px;
    border: 1px solid #ddd;
    border-radius: 8px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    background-color: #ffffff;
    text-align: center; /* ทำให้ข้อความและปุ่มข้างในอยู่ตรงกลาง */
}

.login-container .form-group {
    text-align: left; /* ทำให้ label ชิดซ้ายเหมือนเดิมเพื่อความสวยงาม */
}

.login-container .button {
    width: 100%;
    padding: 10px;
}

/* ===== Sales List Page Filters ===== */
.filter-box {
    width: 100%;
    box-sizing: border-box;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1.5rem;
    padding: 1rem;
    background-color: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    margin-bottom: 1rem;
}

.filter-column-left {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    flex-grow: 1;
}

.filter-column-right {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    align-items: flex-end;
}

.form-group.search-filter {
    flex-grow: 1;
}

.form-group.search-filter input {
    flex-grow: 1;
}

.form-group label {
    white-space: nowrap;
    font-weight: 500;
}

.status-filter-group {
    margin-bottom: 1rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding: 0 0.5rem;
}

.list-header p {
    margin: 0;
    color: #6c757d;
    font-size: 0.9em;
}

.per-page-selector {
    max-width: 120px;
}

/* ===== Override for Sales List Filter Form ===== */
form.filter-form {
    max-width: none;     /* ยกเลิกการจำกัดความกว้าง */
    margin: 0;           /* ยกเลิกการจัดกึ่งกลาง */
    padding: 0;          /* ยกเลิก padding ของ form เอง */
    border: none;        /* ยกเลิกเส้นขอบ */
    background-color: transparent; /* ทำให้พื้นหลังโปร่งใส */
    box-shadow: none;    /* ยกเลิกเงา (ถ้ามี) */
}

/* == สำหรับปุ่มใน form ที่มีกรอบครอบสีขาว ให้ใช้ class="form-inline-button"*/
.form-inline-button {
    display: inline-block; /* ทำให้ฟอร์มเรียงตัวในบรรทัดเดียวกับองค์ประกอบอื่น */
    max-width: none;
    margin: 4px 2px; /* เพิ่มระยะห่างด้านซ้ายเล็กน้อย */
    padding: 0;
    border: none;
    background: none;
    box-shadow: none;
}

/* ===== New Summary Section Layout (Flexbox) ===== */
.summary-section-new {
    border-top: 1px solid #eee;
    padding-top: 1rem;
    display: flex;
    flex-direction: column; /* จัดเรียงแต่ละแถวในแนวตั้ง */
    gap: 1rem; /* ระยะห่างระหว่างแถว */
}

.summary-row-new {
    display: flex;
    justify-content: space-between; /* ผลัก Label และ Value ไปคนละฝั่ง */
    align-items: center;
}

/* ทำให้ Label มีความกว้างคงที่และชิดขวา */
.summary-row-new .summary-label-new {
    flex-basis: 40%; /* กำหนดความกว้างของ Label (ปรับได้) */
    text-align: right;
    color: #555;
    padding-right: 1rem;
}

/* ทำให้ Value ชิดขวา */
.summary-row-new .summary-value-new {
    flex-basis: 50%; /* กำหนดความกว้างของ Value (ปรับได้) */
    text-align: right;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 0.5rem;
}

.summary-row-new .form-control {
    max-width: 120px;
    text-align: right;
}

/* สไตล์สำหรับแถบ "ยอดรวมสุทธิ" */
.summary-row-new.grand-total {
    background-color: #f0f0f0;
    padding: 0.75rem 1rem;
    margin: 0.5rem -1rem -0.5rem -1rem; /* ใช้ margin ติดลบเพื่อขยายพื้นหลังให้ชิดขอบ */
    border-radius: 4px;
    font-size: 1.2em;
    font-weight: bold;
}
/* ===== Status Badge Styles ===== */
.status-badge { padding: 3px 8px; border-radius: 12px; color: white; font-size: 0.8em; }
.status-draft { background-color: #ffc107; color: #333; }
.status-pending { background-color: #6c757d; }
.status-approved { background-color: #007bff; }
.status-ordered { background-color: #007bff; }
.status-received { background-color: #28a745; }
.status-cancelled { background-color: #dc3545; }
.status-paid { background-color: #17a2b8; }
.status-rejected { background-color: #6c757d; }


/* === START: เพิ่มสไตล์สำหรับรูปภาพสินค้าในตาราง === */

/* สไตล์สำหรับรูปภาพสินค้าจริง */
.product-thumbnail {
    width: 60px;
    height: 60px;
    object-fit: cover; /* ทำให้รูปภาพพอดีกับกรอบโดยไม่เสียสัดส่วน */
    border-radius: 4px;
    border: 1px solid #eee;
}

/* สไตล์สำหรับกรอบรูปภาพเปล่า (Placeholder) */
.image-placeholder {
    width: 60px;
    height: 60px;
    background-color: #f0f0f0;
    border: 1px dashed #ccc;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #aaa;
    font-size: 24px; /* ขนาดของไอคอนรูปภาพ */
}
/* === END: สิ้นสุดสไตล์สำหรับรูปภาพสินค้า === */


/* ===== Table Scroll Wrapper ===== */
.table-scroll-wrapper-css {
    width: 100%;
    border: 1px solid #ddd;
    border-radius: 4px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.table-scroll-wrapper-css table {
    width: 100%;
    border-collapse: collapse;
}
.table-scroll-wrapper-css th, .table-scroll-wrapper-css td {
    padding: 12px;
    border-bottom: 1px solid #ddd;
    text-align: left;
}
.table-scroll-wrapper-css th {
    background-color: #f9f9f9;
    position: sticky;
    top: 0;
    z-index: 1;
}
.form-inline-button {
    display: inline;
}
.form-inline-button button {
    margin-left: 5px;
}
/* ===== End Table Scroll Wrapper ===== */