/* ================================================================
   1. GLOBAL VARIABLES & SETUP
   file: public/assets/css/style.css
   ================================================================ */
:root {
    --primary-blue: #0078d4;
    --primary-dark: #005a9e;
    --success-green: #107c10;
    --warning-orange: #d35400;
    --danger-red: #dc3545;
    --info-cyan: #00acc1;
    --dark-status: #201f1e;
    --bg-gradient: linear-gradient(135deg, #f0f4f8 0%, #d7e2ed 100%);
    --bg-light: #f8f9fa;
    --text-main: #2c3e50;
    --text-muted: #7f8c8d;
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.1);
    --radius-md: 8px;
    --radius-lg: 18px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Segoe UI', 'Prompt', Tahoma, sans-serif;
    background: var(--bg-gradient);
    color: var(--text-main);
    line-height: 1.5;
    min-height: 100vh;
}

/* ================================================================
   2. LAYOUT COMPONENTS
   ================================================================ */
.container {
    max-width: 1600px;
    margin: 20px auto;
    padding: 0 20px 70px 20px; /* เผื่อพื้นที่ให้ Bottom Bar */
}

header {
    background: white;
    padding: 15px 25px;
    box-shadow: var(--shadow-sm);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap; /* รองรับกรณีเมนูยาวในจอเล็ก */
    gap: 10px;
}

header h1 {
    font-size: 1.5rem;
    color: var(--primary-blue);
}

nav ul {
    display: flex;
    list-style: none;
    gap: 10px;
    flex-wrap: wrap;
}

nav ul li a {
    text-decoration: none;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.85rem;
    padding: 6px 10px;
    border-radius: 6px;
    transition: 0.2s;
}

nav ul li a.active, nav ul li a:hover {
    background: var(--bg-light);
    color: var(--primary-blue);
}

/* ================================================================
   3. CARD & FORM COMPONENTS
   ================================================================ */
.filter-card, .main-card {
    background: #fff;
    padding: 20px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    margin-bottom: 20px;
}

.form-row {
    display: flex;
    gap: 15px;
    align-items: flex-end;
    flex-wrap: wrap;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.form-group label {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-muted);
}

input[type="date"], input[type="text"] {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
}

/* ================================================================
   4. BUTTONS & SWITCHES
   ================================================================ */
.btn-primary {
    background: var(--primary-blue);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 6px;
    font-weight: bold;
    cursor: pointer;
    transition: 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-primary:hover { filter: brightness(1.1); transform: translateY(-1px); }
.btn-primary:disabled { background: #ccc; cursor: not-allowed; transform: none; }

.btn-excel {
    background-color: #1d6f42 !important; 
    color: #ffffff !important;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    font-weight: bold;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s ease;
    font-size: 13px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.btn-excel:hover {
    background-color: #155d32 !important; 
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.switch {
    position: relative;
    display: inline-block;
    width: 38px;
    height: 20px;
}

.switch input { opacity: 0; width: 0; height: 0; }

.slider {
    position: absolute; cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #ccc; transition: .4s; border-radius: 20px;
}

.slider:before {
    position: absolute; content: ""; height: 14px; width: 14px;
    left: 3px; bottom: 3px; background-color: white; transition: .4s; border-radius: 50%;
}

input:checked + .slider { background-color: var(--primary-blue); }
#toggleHideApproved:checked + .slider { background-color: var(--danger-red); }
input:checked + .slider:before { transform: translateX(18px); }

/* ================================================================
   5. TABLE ENGINE & STATUS BADGES
   ================================================================ */
.table-container {
    background: #fff;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    overflow-x: auto; /* เปิด Scroll แนวนอนสำหรับมือถือ */
    -webkit-overflow-scrolling: touch;
    max-height: 650px;
    border: 1px solid #eee;
    width: 100%;
}

table { width: 100%; border-collapse: collapse; font-size: 13px; }

th {
    position: sticky; top: 0; z-index: 10;
    background: #f1f3f5; color: var(--text-main);
    padding: 12px; border-bottom: 2px solid #dee2e6;
    text-align: left;
    white-space: nowrap;
}

td { padding: 10px; border: 1px solid #eee; }

.mismatch-row { background-color: #fff3cd !important; }
.missing-row  { background-color: #f8d7da !important; }
.extra-row    { background-color: #d1ecf1 !important; }
.unapproved-row { border-left: 5px solid var(--danger-red) !important; }

.status-badge {
    padding: 3px 6px; border-radius: 4px;
    font-weight: bold; font-size: 10px; text-transform: uppercase;
    background: #eee; color: #333;
}

.auth-badge {
    font-size: 10px; color: #666; background: #f0f0f0;
    padding: 2px 5px; border-radius: 3px; display: block;
    margin-top: 4px; border: 1px solid #ddd;
}

/* ================================================================
   6. LOADING & SPINNER
   ================================================================ */
.loading {
    display: none; 
    text-align: center;
    padding: 40px;
    background: #fff;
    border-radius: var(--radius-md);
    margin: 20px 0;
    box-shadow: var(--shadow-sm);
}

.spinner {
    border: 4px solid #f3f3f3;
    border-top: 4px solid var(--primary-blue);
    border-radius: 50%;
    width: 30px; height: 30px;
    animation: spin 1s linear infinite;
    display: inline-block;
    margin-bottom: 10px;
}

@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

/* ================================================================
   7. BOTTOM STATUS BAR
   ================================================================ */
.bottom-status-bar, .status-bar {
    background: var(--dark-status);
    color: #fff;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: 40px;
    display: flex; justify-content: center; align-items: center;
    gap: 20px; font-size: 11px; z-index: 2000;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.3);
    padding: 0 20px;
}

.status-item { display: flex; align-items: center; gap: 8px; }

.text-online { color: #28a745; font-weight: bold; }
.text-offline { color: #dc3545; font-weight: bold; }
.text-warning { color: #f59e0b; font-weight: bold; }
.text-right { text-align: right !important; }
.text-left { text-align: left !important; }

/* ================================================================
   8. SPECIFIC FOR OE (EXPENSES)
   ================================================================ */
.diff-val {
    color: #d83b01;
    font-weight: bold;
    display: block;
    font-size: 10px;
    margin-top: 2px;
}

.th-kry-oe { background-color: #8e44ad !important; color: white !important; }
.th-ckd-oe { background-color: #d35400 !important; color: white !important; }

.table-oe td, .table-oe th {
    font-size: 12px;
    padding: 8px;
    border-bottom: 1px solid #eee;
}

.table-oe .text-right {
    font-family: 'Consolas', 'Courier New', monospace; 
    font-size: 12px;
    text-align: right; 
    white-space: nowrap; 
}

.expense-group-row {
    background-color: #f8f9fa;
    font-style: italic;
    color: #777;
}

/* ================================================================
   9. FLEXBOX LAYOUT (Filter & Toggles)
   ================================================================ */
.controls-wrapper {
    display: flex;             
    justify-content: space-between; 
    align-items: flex-end;     
    flex-wrap: wrap;           
    gap: 20px;                 
    width: 100%;
}

.toggles-group {
    display: flex;
    gap: 15px;
    align-items: center;
    margin-bottom: 5px;        
}

.toggle-container {
    display: flex;
    align-items: center;
    gap: 10px;
    white-space: nowrap;       
}

.toggle-label-text {
    font-size: 11px;
    font-weight: bold;
}

/* ================================================================
   10. MOBILE RESPONSIVE PATCH
   ================================================================ */
@media (max-width: 768px) {
    .container {
        padding: 10px 10px 60px 10px;
    }

    header {
        justify-content: center;
        text-align: center;
    }

    header h1 {
        font-size: 1.2rem;
        width: 100%;
        margin-bottom: 10px;
    }

    nav ul {
        justify-content: center;
        width: 100%;
    }

    /* ปรับ Form และ Controls ให้ไหลลงมาเป็นแนวตั้งในมือถือ */
    .controls-wrapper {
        flex-direction: column;
        align-items: stretch !important;
    }

    .form-row {
        flex-direction: column;
        align-items: stretch !important;
        gap: 10px;
    }

    .toggles-group {
        flex-direction: column;
        align-items: flex-start;
        margin-top: 10px;
        width: 100%;
    }

    .toggle-container {
        width: 100%;
        justify-content: space-between; /* ดัน Toggle ไปขวาสุดในจอเล็ก */
        padding: 5px 0;
        border-bottom: 1px solid #f0f0f0;
    }

    .btn-primary {
        width: 100%;
        justify-content: center;
    }

    /* บังคับให้ตารางในทุกหน้าเลื่อนซ้าย-ขวาได้ และไม่เบียดจนอ่านไม่ออก */
    table {
        min-width: 800px; 
    }

    .bottom-status-bar {
        height: auto;
        padding: 8px 10px;
        flex-wrap: wrap;
        gap: 10px;
    }
}