/* ==================== SHARED LAYOUT CSS ==================== */
/* ไฟล์นี้ถูกใช้ร่วมกันทุกหน้า — ห้ามมี CSS เหล่านี้ซ้ำในแต่ละ page */

* { margin: 0; padding: 0; box-sizing: border-box; }
*, *::before, *::after { font-family: 'Sarabun', sans-serif; }

body, html {
    margin: 0 !important;
    padding: 0 !important;
    width: 100%;
    overflow-x: hidden;
    background-color: #f1f5f9;
}

:root {
    --sidebar-width: 260px;
    --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

/* ==================== Main Content ==================== */
.main-content {
    margin-left: var(--sidebar-width);
    padding: 0 !important;
    width: calc(100% - var(--sidebar-width));
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

body.sidebar-collapsed .main-content {
    margin-left: 0;
    width: 100%;
}

.content-body {
    padding: 24px;
    flex-grow: 1;
}

/* ==================== Loading Overlay ==================== */
.loading-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(248, 249, 250, 0.88);
    z-index: 9999;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 16px;
    backdrop-filter: blur(3px);
}
.loading-spinner {
    width: 52px; height: 52px;
    border: 5px solid #e2e8f0;
    border-top: 5px solid #6366f1;
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
}
.loading-text { color: #6366f1; font-weight: 600; font-size: 0.9rem; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ==================== Stat Cards (ใช้ทุกหน้า) ==================== */
.stat-card {
    border-radius: 16px;
    padding: 20px 22px;
    color: white;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    transition: transform 0.3s ease;
    position: relative;
    overflow: hidden;
}
.stat-card:hover { transform: translateY(-4px); }
.stat-card .stat-icon {
    position: absolute;
    right: 16px; top: 50%;
    transform: translateY(-50%);
    font-size: 2.8rem;
    opacity: 0.15;
}
.stat-card .stat-value { font-size: 1.8rem; font-weight: 800; line-height: 1.2; }
.stat-card .stat-label { font-size: 0.82rem; font-weight: 600; opacity: 0.9; }

/* Stat card gradients */
.stat-card.primary, .bg-gradient-purple { background: linear-gradient(135deg, #6366f1, #818cf8); }
.stat-card.success, .bg-gradient-green  { background: linear-gradient(135deg, #10b981, #34d399); }
.stat-card.info,    .bg-gradient-cyan   { background: linear-gradient(135deg, #06b6d4, #22d3ee); }
.stat-card.warning, .bg-gradient-amber  { background: linear-gradient(135deg, #f59e0b, #fbbf24); }
.stat-card.danger,  .bg-gradient-rose   { background: linear-gradient(135deg, #f093fb, #f5576c); }

/* 5-col stat row on desktop */
@media (min-width: 992px) {
    .stat-row-5 > div { flex: 0 0 20%; max-width: 20%; }
}

/* ==================== Chart & Filter Cards ==================== */
.chart-card, .filter-card, .filter-section, .table-card {
    background: white;
    border-radius: 16px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.05);
    border: 1px solid rgba(0,0,0,0.04);
}
.chart-card { padding: 24px; min-height: 380px; margin-bottom: 24px; }
.filter-card, .filter-section { padding: 20px 24px; margin-bottom: 24px; }
.table-card { padding: 24px; margin-bottom: 24px; }

.chart-container {
    position: relative;
    width: 100%;
    height: 340px;
    margin-top: 16px;
}

/* Section Title */
.section-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: #1e293b;
    margin-bottom: 18px;
    padding-bottom: 10px;
    border-bottom: 2px solid #e2e8f0;
}
.section-title i { color: #6366f1; margin-right: 8px; }

/* ==================== RESPONSIVE — Mobile (<992px) ==================== */
@media (max-width: 991.98px) {
    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
    }

    .content-body { padding: 16px; }
    .chart-card { padding: 16px; min-height: 300px; }
    .chart-container { height: 280px; }
    .filter-card, .filter-section { padding: 16px; }
    .table-card { padding: 16px; }

    .stat-card { padding: 16px 18px; }
    .stat-card .stat-value { font-size: 1.5rem; }
    .stat-card .stat-icon { font-size: 2.2rem; right: 12px; }
    .stat-card h6, .stat-card .stat-label { font-size: 0.78rem; }
}

/* ==================== RESPONSIVE — Small phone (<576px) ==================== */
@media (max-width: 575.98px) {
    .content-body { padding: 12px; }
    .chart-card { padding: 14px; min-height: 260px; }
    .chart-container { height: 240px; margin-top: 10px; }
    .filter-card, .filter-section { padding: 14px; }
    .table-card { padding: 12px; }
    .section-title { font-size: 0.92rem; }

    .stat-card { padding: 14px 16px; border-radius: 12px; }
    .stat-card .stat-value { font-size: 1.3rem; }
    .stat-card .stat-icon { font-size: 1.8rem; }
    .stat-card h2 { font-size: 1.3rem; font-weight: 800; }
}

/* ==================== Footer ==================== */
.footer-wrapper {
    background: white;
    border-top: 1px solid #e2e8f0;
}
.footer-wrapper .row {
    padding: 12px 0 !important;
}
@media (max-width: 767.98px) {
    .footer-wrapper .badge {
        display: inline-block;
        font-size: 0.65rem;
        white-space: normal;
        word-break: break-word;
        max-width: 100%;
    }
    .footer-wrapper .col-md-6 {
        padding: 4px 12px;
    }
    .footer-wrapper span.text-muted {
        font-size: 0.7rem;
    }
}

/* ==================== DataTable Responsive ==================== */
@media (max-width: 767.98px) {
    .dataTables_wrapper .dataTables_filter,
    .dataTables_wrapper .dataTables_length {
        text-align: center !important;
        margin-bottom: 8px;
    }
    .dataTables_wrapper .dataTables_filter input {
        width: 100% !important;
        max-width: 250px;
    }
    .dataTables_wrapper .dataTables_info,
    .dataTables_wrapper .dataTables_paginate {
        text-align: center !important;
        margin-top: 8px;
        font-size: 0.78rem;
    }
    .dataTables_wrapper .dataTables_paginate .paginate_button {
        padding: 4px 8px !important;
        font-size: 0.75rem;
    }
    table.dataTable tbody td,
    table.dataTable thead th {
        font-size: 0.72rem !important;
        padding: 6px 4px !important;
    }
}
