/* =================================
   1. GLOBAL STYLES
   ================================= */
body {
    font-family: 'Sarabun', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    margin: 0;
    background-color: #f8f9fa;
    color: #343a40;
    font-size: 16px;
    line-height: 1.6;
}
.content {
    max-width: 1400px;
    margin: 20px auto;
    padding: 2.5rem;
    background-color: #ffffff;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
    border-radius: 12px;
}
h1, h2, h3, h4, h5, h6 {
    color: #212529;
    font-weight: 600;
    line-height: 1.3;
}
h1 { font-size: 2.25rem; margin-top: 0; }
h2 { font-size: 1.75rem; border-bottom: 2px solid #e9ecef; padding-bottom: 10px; margin-top: 2rem; }
a { color: #007bff; text-decoration: none; }
a:hover { color: #0056b3; text-decoration: underline; }
hr { border: 0; border-top: 1px solid #dee2e6; }
table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1.5rem;
    font-size: 0.95rem;
}
table th, table td {
    border: 1px solid #dee2e6;
    padding: 12px 15px;
    text-align: left;
    vertical-align: top;
}
table th {
    background-color: #f8f9fa;
    font-weight: 600;
}
table tbody tr:nth-child(even) {
    background-color: #f8f9fa;
}
table tbody tr:hover {
    background-color: #e9ecef;
}

/* =================================
   2. NAVBAR
   ================================= */
.navbar {
    width: 100%;
    background-color: #343a40;
    padding: 0 2rem;
    display: flex;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    box-sizing: border-box;
}
.navbar .brand-logo {
    padding: 10px 0;
    margin-right: 20px;
}
.navbar .brand-logo img {
    height: 40px;
    width: auto;
}
.navbar a {
    color: #f8f9fa;
    padding: 20px 15px;
    text-decoration: none;
    display: block;
    font-weight: 500;
    transition: background-color 0.2s;
}
.navbar a:hover {
    background-color: #495057;
    color: #ffffff;
    text-decoration: none;
}
.navbar a.right {
    margin-left: auto;
}

/* =================================
   3. LOGIN STYLES
   ================================= */
.login-container {
    width: 100%;
    max-width: 440px;
    margin: 5rem auto;
    padding: 2.5rem;
    background-color: #ffffff;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    border-radius: 12px;
}
.login-header {
    text-align: center;
    margin-bottom: 2rem;
}
.login-header img {
    width: 80px;
    margin-bottom: 1rem;
}
.login-header h1 {
    font-size: 1.75rem;
    margin: 0;
}

/* =================================
   4. BUTTONS
   ================================= */
.button-small {
    padding: 5px 10px;
    font-size: 0.85rem;
    border-radius: 5px;
    text-decoration: none;
    color: #fff;
    border: none;
    cursor: pointer;
    margin-right: 5px;
    display: inline-block;
    text-align: center;
    font-weight: 500;
}
.button-primary {
    background-color: #007bff;
}
.button-primary:hover {
    background-color: #0069d9;
}
.button-edit {
    background-color: #ffc107;
    color: #212529;
}
.button-edit:hover {
    background-color: #e0a800;
}
.button-delete {
    background-color: #dc3545;
}
.button-delete:hover {
    background-color: #c82333;
}

/* =================================
   5. CONTENT STYLES (Forms, Banners)
   ================================= */
.form-layout {
    background-color: #fdfdfd;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 2rem;
    margin-bottom: 2rem;
}
.form-layout h2 {
    margin-top: 0;
    margin-bottom: 1.5rem;
    font-size: 1.5rem;
}
.form-row {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
}
.input-group {
    display: flex;
    flex-direction: column;
    margin-bottom: 1.5rem;
    flex: 1; 
    min-width: 300px;
}
.input-group.half-width {
    flex-basis: calc(50% - 10px);
}
.input-group label {
    font-weight: 600;
    margin-bottom: 8px;
    color: #495057;
}
.input-group input[type="text"],
.input-group input[type="password"],
.input-group input[type="number"],
.input-group input[type="date"],
.input-group textarea,
.input-group select {
    padding: 12px 15px;
    font-size: 1rem;
    border: 1px solid #ced4da;
    border-radius: 8px;
    box-sizing: border-box;
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.input-group input:focus,
.input-group textarea:focus,
.input-group select:focus {
    border-color: #80bdff;
    outline: 0;
    box-shadow: 0 0 0 0.2rem rgba(0,123,255,.25);
}
.input-group input[readonly] {
    background-color: #e9ecef;
    color: #495057;
}
.input-group small {
    margin-top: 5px;
    font-size: 0.9rem;
    color: #6c757d;
}
.error-banner, .success-banner {
    padding: 1.25rem;
    margin-bottom: 1.5rem;
    border: 1px solid transparent;
    border-radius: 8px;
    font-weight: 500;
}
.error-banner {
    color: #721c24;
    background-color: #f8d7da;
    border-color: #f5c6cb;
}
.success-banner {
    color: #155724;
    background-color: #d4edda;
    border-color: #c3e6cb;
}
.button-group {
    display: flex;
    flex-wrap: wrap; 
    gap: 12px; 
    margin-top: 1.5rem;
}
button[type="submit"].button-primary {
    font-family: inherit; 
}
.button-primary {
    display: inline-flex; 
    align-items: center;
    justify-content: center;
    gap: 8px; 
    
    background-color: #007bff;
    color: #ffffff;
    padding: 12px 20px; 
    border-radius: 8px; 
    text-decoration: none;
    font-weight: 600; 
    font-size: 1.05rem; 
    border: none;
    cursor: pointer;
    transition: background-color 0.2s, box-shadow 0.2s, transform 0.1s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.07);
}
.button-primary:hover {
    background-color: #0069d9;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    transform: translateY(-1px);
    color: #ffffff;
}
.button-primary:active {
    transform: translateY(0);
}
.button-secondary {
    display: inline-flex; 
    align-items: center;
    justify-content: center;
    gap: 8px;
    
    background-color: #6c757d;
    color: #ffffff;
    padding: 12px 20px;
    border-radius: 8px;
    text-decoration: none;
    font-weight: 600;
    font-size: 1.05rem;
    border: none;
    cursor: pointer;
    transition: background-color 0.2s, box-shadow 0.2s, transform 0.1s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.07);
}
.button-secondary:hover {
    background-color: #5a6268;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    transform: translateY(-1px);
    color: #ffffff;
}
.button-secondary:active {
    transform: translateY(0);
}

/* =================================
   6. ITEM TABLE (Create/Edit Job)
   ================================= */
.item-table {
    font-size: 1rem;
}
.item-table th, .item-table td {
    vertical-align: middle;
    padding: 8px;
}
.item-table input[type="text"],
.item-table input[type="number"] {
    width: 100%;
    padding: 8px;
    font-size: 0.95rem;
    border-radius: 5px;
    box-sizing: border-box; 
}
.item-table input[readonly] {
    background-color: #f8f9fa;
    border-color: #e9ecef;
}
.btn-delete-row {
    background-color: #dc3545;
    color: white;
    border: none;
    padding: 8px 12px;
    border-radius: 5px;
    cursor: pointer;
    font-weight: 600;
    width: 100%;
}
.btn-delete-row:hover {
    background-color: #c82333;
}

/* =================================
   7. TOTAL SUMMARY (Create/Edit Job)
   ================================= */
.total-summary {
    max-width: 450px;
    margin-left: auto;
    font-size: 1.05rem;
}
.summary-row {
    display: flex;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid #e9ecef;
}
.summary-row.vat-toggle {
    justify-content: flex-end;
    font-weight: 600;
}
.summary-row.vat-toggle label {
    cursor: pointer;
}
.summary-row.vat-toggle input {
    margin-right: 8px;
}
.summary-row.total {
    font-size: 1.25rem;
    font-weight: 700;
    color: #212529;
    border-top: 2px solid #343a40;
    border-bottom: none;
    padding-top: 15px;
}
.summary-label {
    font-weight: 600;
    color: #495057;
}
.total-summary input[readonly] {
    font-size: 1.05rem;
    font-weight: 600;
    text-align: right;
    border: none;
    padding: 0;
    width: 120px;
    background: none;
}
.total-summary .total input[readonly] {
    font-size: 1.25rem;
    font-weight: 700;
    color: #212529;
}

/* =================================
   8. AUTOCOMPLETE (jQuery UI)
   ================================= */
.ui-autocomplete {
    max-height: 250px;
    overflow-y: auto;
    overflow-x: hidden;
    background: #fff;
    border: 1px solid #ddd;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    border-radius: 8px;
    z-index: 1000 !important;
}
.ui-menu-item {
    padding: 10px 15px;
    font-size: 0.95rem;
}
.ui-menu-item-wrapper {
    color: #343a40;
}
.ui-state-active, .ui-widget-content .ui-state-active {
    background-color: #007bff;
    color: #fff;
    border: none;
    border-radius: 5px;
}
.ui-state-active .ui-menu-item-wrapper {
    color: #fff;
}

/* =================================
   9. PRINT BAR (View Job)
   ================================= */
.print-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f8f9fa;
    padding: 1rem 1.5rem;
    border-radius: 8px;
    margin-bottom: 2rem;
    border: 1px solid #e9ecef;
}
.print-bar h1 {
    margin: 0;
    font-size: 1.5rem;
    line-height: 1.2;
}
.print-bar .button-primary,
.print-bar .button-edit {
    padding: 10px 18px;
    font-size: 1rem;
}

/* =================================
   10. (แก้ Bug!) INVOICE PAPER (View Job)
   ================================= */
/* (ลบ!) ลบ `position: relative` และ `min-height` ออกจากโหมดปกติ */
#invoice-paper {
    width: 21cm; 
    margin: 0 auto;
    background: #fff;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    padding: 1.5cm;
    box-sizing: border-box;
}
/* (ลบ!) ลบ `padding-bottom` ออกจากโหมดปกติ */
.invoice-body {
}
.invoice-footer-container {
}


.invoice-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    border-bottom: 3px solid #343a40;
    padding-bottom: 20px;
}
.invoice-logo {
    flex: 1;
}
.invoice-logo img {
    max-width: 120px;
    max-height: 80px;
    margin-bottom: 10px;
}
.invoice-logo strong {
    font-size: 1.1rem;
    color: #212529;
}
.invoice-logo small {
    font-size: 0.9rem;
    line-height: 1.5;
    color: #495057;
}
.invoice-title {
    flex: 1;
    text-align: right;
}
.invoice-title h1 {
    margin: 0;
    font-size: 2rem;
    color: #000;
}
.invoice-title h2 {
    margin: 0 0 15px 0;
    font-size: 1.2rem;
    font-weight: 400;
    color: #6c757d;
    border: none;
}
.invoice-details {
    font-size: 1.1rem;
}
.invoice-details p {
    margin: 0;
    font-weight: 600;
}

.invoice-customer-vehicle {
    display: flex;
    justify-content: space-between;
    margin-top: 20px;
    padding-bottom: 20px;
    border-bottom: 1px solid #dee2e6;
}
.customer-box, .vehicle-box {
    flex-basis: calc(50% - 15px);
    font-size: 0.95rem;
    line-height: 1.7;
}
.customer-box strong, .vehicle-box strong {
    font-size: 1.1rem;
    color: #212529;
    border-bottom: 1px solid #e9ecef;
    padding-bottom: 5px;
    display: block;
    margin-bottom: 10px;
}
.customer-box p, .vehicle-box p {
    margin: 0;
}

.invoice-item-table {
    margin-top: 20px;
    font-size: 0.95rem;
}
.invoice-item-table th, .invoice-item-table td {
    padding: 10px;
    vertical-align: top;
}
.invoice-item-table thead th {
    background-color: #343a40;
    color: #fff;
    border-color: #343a40;
}
.invoice-item-table .text-center { text-align: center; }
.invoice-item-table .text-right { text-align: right; }
.invoice-item-table tbody tr:nth-child(even) {
    background-color: #f8f9fa;
}
.invoice-item-table tbody tr td {
    border-bottom: 1px solid #dee2e6;
}
.invoice-item-table tbody tr:last-child td {
    border-bottom: 2px solid #343a40;
}


/* =================================
   10.5 (แก้ Bug!) INVOICE FOOTER (Totals & Signature)
   ================================= */
/* (ลบ!) ลบ `position: absolute` และ `bottom/left/right` */
.invoice-footer-container {
    display: flex;
    justify-content: space-between;
    align-items: flex-end; 
    
    border-top: 2px solid #343a40; 
    padding-top: 20px;
    margin-top: 20px; /* (ปล่อยให้มันลอยตามธรรมชาติ) */
}
.footer-left-col {
    flex: 1.5; 
    padding-right: 20px;
}
.footer-right-col {
    flex: 1;
    max-width: 400px; 
}

.footer-notes {
    font-size: 0.85rem;
    color: #495057;
    margin-bottom: 30px;
}
.invoice-footer {
    display: flex;
    justify-content: space-between;
    font-size: 0.9rem;
    text-align: center;
    padding-top: 10px;
}
.signature-box {
    flex: 1;
}
.signature-box p {
    margin: 5px 0;
}
.footer-totals {
    width: 100%;
}
.footer-totals .summary-row {
    padding: 12px 0;
    font-size: 1rem;
}
.footer-totals .grand-total {
    font-size: 1.2rem;
    font-weight: 700;
}
.footer-totals .summary-label {
    font-weight: 500;
}
.footer-totals .summary-value {
    font-weight: 600;
}
.baht-text-row {
    text-align: right;
    font-weight: 600;
    margin-top: 15px;
    padding: 10px;
    background: #f8f9fa;
    border-radius: 5px;
    font-size: 0.95rem;
}


/* =================================
   11. (อัปเดต!) PRINT STYLES
   ================================= */
@page {
    size: A4;
    margin: 0.7cm; 
}

@media print {
    html, body {
        background-color: #ffffff;
    }
    
    .navbar, .print-bar, .content > h1:first-child, 
    .success-banner, .error-banner,
    .button-group, .button-secondary {
        display: none !important;
    }
    
    .content {
        padding: 0;
        margin: 0;
        box-shadow: none;
        max-width: 100%;
        border-radius: 0;
    }
    
    /* (แก้ Bug!) ลบโค้ดจัดหน้า Flex/Absolute ทั้งหมด */
    #invoice-paper {
        width: 100%;
        min-height: auto;
        height: auto;
        box-shadow: none;
        padding: 0;
        margin: 0;
        /* (ลบ!) position: relative */
    }
    .invoice-body {
        /* (ลบ!) padding-bottom: 250px */
    }
    .invoice-footer-container {
        /* (ลบ!) position: absolute */
        page-break-inside: avoid; /* (ห้ามแตกกลาง Footer) */
        width: 100%;
    }
    
    /* (Request 1: หัวตารางซ้ำหน้า 2 - ยังคงอยู่) */
    .invoice-item-table thead {
        display: table-header-group;
    }
    .invoice-item-table tbody tr {
        page-break-inside: avoid; 
    }
    
    /* (Request 1: บีบแถว - ยังคงอยู่) */
    .invoice-item-table th, .invoice-item-table td {
        padding: 6px 8px; /* (ลด Padding ลง) */
        font-size: 0.9rem; /* (ลด Font) */
    }
    .invoice-logo strong { font-size: 1rem; }
    .invoice-logo small { font-size: 0.85rem; }
    .customer-box, .vehicle-box { font-size: 0.9rem; }
    .footer-notes { font-size: 0.8rem; margin-bottom: 15px; }
    .invoice-footer { font-size: 0.85rem; }
    .footer-totals .summary-row { padding: 8px 0; font-size: 0.95rem; }
    .footer-totals .grand-total { font-size: 1.1rem; }
    .baht-text-row { font-size: 0.9rem; padding: 8px; }
}

/* =================================
   12. STATUS BADGE STYLES
   ================================= */
.status-badge {
    padding: 5px 12px;
    border-radius: 15px;
    font-size: 0.85rem;
    font-weight: 600;
    color: #ffffff;
    text-transform: capitalize;
}
.status-badge.status-quotation {
    background-color: #007bff; /* ฟ้า (เสนอราคา) */
}
.status-badge.status-in_progress {
    background-color: #ffc107; /* เหลือง (กำลังซ่อม) */
    color: #343a40; 
}
.status-badge.status-completed {
    background-color: #28a745; /* เขียว (เสร็จ) */
}
.status-badge.status-cancelled {
    background-color: #dc3545; /* แดง (ยกเลิก) */
}


/* =================================
   13. SEARCH BAR STYLES (สำหรับ Dashboard)
   ================================= */
.search-bar {
    margin-bottom: 1.5rem; 
}
.search-bar form {
    display: flex;
    gap: 10px; 
    align-items: center;
}
.search-bar input[type="text"] {
    flex: 1; 
    padding: 12px 15px;
    font-size: 1rem;
    border: 1px solid #ced4da;
    border-radius: 8px;
    box-sizing: border-box;
}
.search-bar .button-primary,
.search-bar .button-secondary {
    padding: 12px 15px !important;
    font-size: 1rem !important;
    white-space: nowrap; 
}

/* =================================
   14. ITEM TABLE SELECT (สำหรับ ประเภท)
   ================================= */
.item-table select {
    width: 100%;
    padding: 8px;
    font-size: 0.95rem;
    border: 1px solid #ced4da;
    border-radius: 5px;
    background-color: #fff;
    font-family: inherit;
    box-sizing: border-box; 
}