/* === /css/style.css === */

/* :root defines CSS variables for easy theme changes */
:root {
    --primary-color: #4A90E2; /* A modern, friendly blue */
    --primary-hover: #357ABD;
    --background-color: #F8F9FA;
    --surface-color: #FFFFFF;
    --sidebar-bg: #212529;
    --sidebar-text: #adb5bd;
    --sidebar-text-hover: #FFFFFF;
    --text-color: #333333;
    --border-color: #DEE2E6;
    --danger-color: #E94B3C;
    --success-color: #28A745;
    --font-family: 'Poppins', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --border-radius: 8px;
    --box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

/* --- Global & Layout --- */
body {
    font-family: var(--font-family);
    background-color: var(--background-color);
    margin: 0;
    color: var(--text-color);
    display: flex;
    line-height: 1.6;
}

/* --- Sidebar Navigation (Desktop) --- */
.sidebar {
    width: 250px;
    background-color: var(--sidebar-bg);
    color: var(--sidebar-text);
    padding: 20px;
    height: 100vh;
    position: fixed;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
}

.sidebar-header {
    text-align: center;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 1px solid #495057;
}

.sidebar-header h2 {
    color: white;
    margin: 0;
    font-size: 1.5em;
    font-weight: 600;
}

.sidebar-nav {
    list-style: none;
    padding: 0;
    margin: 0;
    flex-grow: 1;
}

.nav-item a {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 15px 10px;
    color: var(--sidebar-text);
    text-decoration: none;
    border-radius: var(--border-radius);
    transition: background-color 0.2s, color 0.2s;
    font-weight: 500;
}

.nav-item a:hover,
.nav-item a.active {
    background-color: var(--primary-color);
    color: var(--sidebar-text-hover);
}

.nav-item .icon { font-size: 1.2em; }

.sidebar-footer {
    text-align: center;
}

/* 💡 ปุ่มเมนู (ซ่อนบน Desktop) */
#menu-toggle {
    display: none; 
    min-width: 40px;
    padding: 8px 10px; 
    font-size: 1.5em; 
    background-color: #495057; 
    color: white;
    line-height: 1; 
    border-radius: 4px;
    transform: none !important;
}
#menu-toggle:hover {
     transform: none;
}


/* --- Main Content Area --- */
.main-content {
    margin-left: 250px;
    padding: 30px 40px;
    width: calc(100% - 250px);
    box-sizing: border-box;
    overflow-y: auto;
}

.container {
    max-width: 1100px;
    margin: 0 auto;
    background: var(--surface-color);
    padding: 30px;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
}

h1 { text-align: left; color: var(--text-color); font-weight: 600; }
h2 { text-align: left; color: var(--text-color); font-weight: 600; }

/* --- Dashboard Specific Styles (Used in HTML) --- */
.dashboard-header { margin-bottom: 30px; }
.dashboard-header h1 { margin: 0; }
.dashboard-header p { color: #6c757d; font-size: 1.1em; }
.summary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 25px; }
.summary-card { background: var(--surface-color); padding: 25px; border-radius: var(--border-radius); border-left: 5px solid var(--primary-color); box-shadow: var(--box-shadow); }
.summary-card .title { font-size: 1em; color: #6c757d; margin-bottom: 10px; }
.summary-card .value { font-size: 2em; font-weight: 600; color: var(--text-color); }
.summary-card.sales { border-color: #28a745; }
.summary-card.winnings { border-color: #dc3545; }
.summary-card.bills { border-color: #ffc107; }

/* --- Forms & Inputs --- */
.form-container { max-width: 480px; }
.form-group { margin-bottom: 25px; }
.form-group label { display: block; margin-bottom: 8px; font-weight: 500; font-size: 1em; }
.form-group input, .form-group select { width: 100%; padding: 15px 18px; border: 1px solid var(--border-color); border-radius: var(--border-radius); box-sizing: border-box; font-size: 1.1em; transition: border-color 0.2s, box-shadow 0.2s; background-color: #fdfdff; }
.form-group input:focus, .form-group select:focus { outline: none; border-color: var(--primary-color); box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.2); }

/* --- Buttons --- */
.btn { display: inline-block; width: auto; min-width: 120px; padding: 15px 18px; border-radius: var(--border-radius); font-size: 1.1em; font-weight: 600; cursor: pointer; text-align: center; border: none; text-decoration: none; transition: background-color 0.2s, transform 0.1s; }
.btn:hover { transform: translateY(-2px); }
.btn-primary { background-color: var(--primary-color); color: white; }
.btn-primary:hover { background-color: var(--primary-hover); }
.btn-secondary { background-color: #6c757d; color: white; }
.btn-danger { background-color: var(--danger-color); color: white; }

/* --- Table Styles --- */
.data-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
    font-size: 0.95em;
}

.data-table th,
.data-table td {
    padding: 12px 15px;
    text-align: left;
    border-bottom: 1px solid var(--border-color); 
}

.data-table thead th {
    background-color: #f8f9fa; 
    color: var(--text-color);
    font-weight: 600;
    border-bottom: 2px solid var(--border-color);
}

.data-table tbody tr {
    transition: background-color 0.2s;
}

.data-table tbody tr:hover {
    background-color: #f1f5f9; 
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

.data-table tfoot td {
    font-weight: 600;
    font-size: 1.1em;
    background-color: #f8f9fa;
    border-top: 2px solid var(--border-color);
}
/* สไตล์สำหรับแถว Summary (tfoot) ในหน้า Report */
.data-table tfoot {
    background-color: #e9ecef; /* สีพื้นหลังอ่อนๆ */
    border-top: 3px solid #007bff; /* เส้นขอบเน้น */
}
.data-table tfoot tr {
    font-weight: bold;
}

/* --- Loading Overlay --- */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(255, 255, 255, 0.7); 
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
}

.loading-overlay.show {
    opacity: 1;
    visibility: visible;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 5px solid #f3f3f3; 
    border-top: 5px solid var(--primary-color); 
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* --- Mobile Responsive Design (768px and below) --- */
@media (max-width: 768px) {
    body { flex-direction: column; }
    
    /* 1. Sidebar กลายเป็นแถบด้านบน */
    .sidebar { 
        width: 100%; 
        height: auto; 
        position: relative; 
        flex-direction: column; 
        padding: 10px 20px; 
    }
    
    /* 2. Header ของ Sidebar จัดเรียงให้ปุ่มเมนูอยู่ด้านข้าง */
    .sidebar-header {
        display: flex;
        justify-content: space-between; 
        align-items: center;
        width: 100%;
        padding-bottom: 10px;
        margin-bottom: 0;
        border-bottom: none;
    }
    .sidebar-header h2 {
        flex-grow: 1; 
        text-align: center;
    }
    /* 💡 ตำแหน่งใหม่ของปุ่มสลับเมนู */
    .sidebar-header #menu-toggle {
        display: block !important; 
        order: -1; 
    }
    
    /* 3. ปุ่ม 'ออกจากระบบ' จัดการด้วย JS */
    .sidebar-footer { 
        display: none; 
        width: 100%;
        padding-top: 15px;
        margin-top: 15px;
        border-top: 1px solid #495057;
    } 

    /* 4. จัดการ Nav Menu (ซ่อนเริ่มต้น) */
    .sidebar-nav {
        display: none; 
        flex-direction: column;
        width: 100%;
        margin-top: 10px;
        padding-top: 10px;
        border-top: 1px solid #495057;
    }

    /* 💡 คลาสที่ใช้ JS สลับการแสดงผล */
    .sidebar-nav.active {
        display: flex; 
    }
    
    /* 5. Main Content ไม่ต้องมี Margin */
    .main-content { 
        /* 💥 CRITICAL FIX: ใช้ !important เพื่อล้าง margin-left ที่มาจาก Desktop */
        margin-left: 0 !important; 
        width: 100%; 
        padding: 20px; 
    }
    
    /* 💥 CRITICAL FIX: ทำให้ Container กว้างเต็มจอและปรับ Margin/Padding */
    .container {
        max-width: 100%; 
        margin: 0 !important; /* ใช้ !important เพื่อล้าง margin: 0 auto; */
        padding: 15px; 
        border-radius: 0;
        box-shadow: none; /* (Optional) ลด Box-shadow บนมือถือ */
    }
    
    /* 💡 เพิ่ม: ปรับให้ปุ่ม Action อยู่ใต้กัน */
    .action-buttons {
        flex-direction: column;
        gap: 8px;
    }
}