/* Reset และ Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Sarabun', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #f4f7fa;
    min-height: 100vh;
    color: #2c3e50;
    line-height: 1.6;
    overflow-x: clip;
}

/* Sidebar */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 260px;
    height: 100vh;
    background: linear-gradient(135deg, #059669 0%, #10b981 100%);
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
    z-index: 1000;
    overflow-y: auto;
}

.sidebar-header {
    padding: 18px 16px 16px;
    background: rgba(0, 0, 0, 0.18);
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
    position: relative;
    overflow: hidden;
}

.sidebar-header::before {
    content: '';
    position: absolute;
    top: -28px;
    right: -28px;
    width: 90px;
    height: 90px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.07);
    pointer-events: none;
}

.sidebar-header::after {
    content: '';
    position: absolute;
    bottom: -20px;
    right: 24px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.05);
    pointer-events: none;
}

.logo {
    display: flex;
    align-items: center;
    gap: 11px;
    color: white;
    min-width: 0;
}

.logo-icon {
    width: 42px;
    height: 42px;
    background: rgba(255, 255, 255, 0.18);
    border: 1px solid rgba(255, 255, 255, 0.28);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25em;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15), inset 0 1px 0 rgba(255,255,255,0.2);
}

.logo-text {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
}

.logo-text h2 {
    font-size: 1.15em;
    font-weight: 700;
    letter-spacing: 0.2px;
    line-height: 1.15;
    white-space: nowrap;
}

.logo-text span {
    font-size: 0.7em;
    opacity: 0.72;
    letter-spacing: 0.6px;
    font-weight: 400;
    white-space: nowrap;
}

.sidebar-toggle {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.18);
    color: white;
    font-size: 1em;
    cursor: pointer;
    padding: 7px 9px;
    border-radius: 8px;
    transition: all 0.2s ease;
    flex-shrink: 0;
    line-height: 1;
}

.sidebar-toggle:hover {
    background: rgba(255, 255, 255, 0.22);
    border-color: rgba(255, 255, 255, 0.35);
}

.sidebar-nav {
    padding: 20px 0;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 15px 25px;
    color: rgba(255, 255, 255, 0.8);
    text-decoration: none;
    transition: all 0.3s ease;
    font-size: 1.05em;
    font-weight: 500;
    border-left: 3px solid transparent;
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border-left-color: white;
}

.nav-item.active {
    background: rgba(255, 255, 255, 0.15);
    color: white;
    border-left-color: white;
}

.nav-item i {
    font-size: 1.3em;
    width: 24px;
    text-align: center;
}

.sidebar-footer {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 20px;
    background: rgba(0, 0, 0, 0.1);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    color: white;
}

.user-info i {
    font-size: 2.5em;
}

.user-details {
    display: flex;
    flex-direction: column;
}

.user-name {
    font-weight: 600;
    font-size: 0.95em;
}

.user-role {
    font-size: 0.85em;
    opacity: 0.8;
}

/* Main Content */
.main-content {
    margin-left: 260px;
    min-height: 100vh;
    background: #f4f7fa;
    transition: all 0.3s ease;
    width: calc(100% - 260px);
    box-sizing: border-box;
}

/* Top Bar */
.top-bar {
    background: white;
    padding: 20px 30px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.top-bar-left {
    display: flex;
    align-items: center;
    gap: 15px;
}

.mobile-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.5em;
    color: #059669;
    cursor: pointer;
}

.page-title {
    font-size: 1.8em;
    color: #2c3e50;
    font-weight: 600;
}

.top-bar-right {
    display: flex;
    align-items: center;
    gap: 20px;
}

.date-display {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #7f8c8d;
    font-size: 0.95em;
}

.date-display i {
    color: #10b981;
}

/* Content Wrapper */
.content-wrapper {
    padding: 30px;
    width: 100%;
    box-sizing: border-box;
}

/* Page Header */
.page-header {
    background: white;
    padding: 25px 30px;
    border-radius: 10px;
    margin-bottom: 30px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    border-left: 4px solid #10b981;
    width: 100%;
    box-sizing: border-box;
}

.header-content h2 {
    color: #2c3e50;
    font-size: 1.8em;
    font-weight: 700;
    margin-bottom: 5px;
}

.header-content p {
    color: #7f8c8d;
    font-size: 1.05em;
}

/* Tab Content */
.tab-content {
    display: none;
    width: 100%;
}

.tab-content.active {
    display: block;
    width: 100%;
}

/* Cards */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 25px;
    margin-bottom: 30px;
}

.card {
    background: white;
    padding: 25px;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    transition: all 0.3s ease;
    border: 1px solid rgba(0, 0, 0, 0.05);
    box-sizing: border-box;
    width: 100%;
}

.card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
    transform: translateY(-2px);
}

/* Card Heading with Icon */
.card h3 {
    color: #2c3e50;
    margin-bottom: 20px;
    font-size: 1.3em;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
}

.card h3 i {
    color: #10b981;
    font-size: 1.1em;
}

.card h3::before {
    display: none;
}

/* Chart Container */
.chart-container {
    position: relative;
    height: 400px;
    width: 100%;
}

.chart-container-sm {
    position: relative;
    height: 300px;
    width: 100%;
}

.chart-container-md {
    position: relative;
    height: 350px;
    width: 100%;
}

/* Overview Charts Layout */
.overview-charts {
    margin-bottom: 30px;
}

.overview-charts .chart-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 25px;
    margin-bottom: 25px;
}

.overview-charts .chart-col-1 {
    grid-column: span 1;
}

.overview-charts .chart-col-2 {
    grid-column: span 2;
}

.overview-charts .chart-col-full {
    grid-column: span 3;
}

@media (max-width: 1024px) {
    .overview-charts .chart-row {
        grid-template-columns: 1fr;
    }

    .overview-charts .chart-col-1,
    .overview-charts .chart-col-2,
    .overview-charts .chart-col-full {
        grid-column: span 1;
    }
}

/* Stats Cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
    width: 100%;
    box-sizing: border-box;
}

/* Year selection buttons - overview tab */
.year-btn {
    padding: 8px 18px;
    border: 2px solid #10b981;
    border-radius: 20px;
    background: white;
    color: #059669;
    font-family: inherit;
    font-size: 0.95em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s ease;
}

.year-btn:hover {
    background: #ecfdf5;
    transform: translateY(-1px);
    box-shadow: 0 3px 8px rgba(16, 185, 129, 0.2);
}

.year-btn.active {
    background: linear-gradient(135deg, #059669, #10b981);
    color: white;
    border-color: transparent;
    box-shadow: 0 3px 10px rgba(16, 185, 129, 0.4);
}

.stat-card {
    background: white;
    padding: 25px;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    transition: all 0.3s ease;
    border-left: 4px solid #10b981;
}

.stat-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

.stat-card.stat-primary {
    border-left-color: #3498db;
}

.stat-card.stat-success {
    border-left-color: #10b981;
}

.stat-card.stat-warning {
    border-left-color: #f39c12;
}

.stat-card.stat-danger {
    border-left-color: #e74c3c;
}

.stat-card.stat-info {
    border-left-color: #3498db;
}

.stat-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 15px;
}

.stat-title {
    font-size: 0.95em;
    color: #7f8c8d;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-icon {
    width: 50px;
    height: 50px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5em;
}

.stat-primary .stat-icon {
    background: rgba(52, 152, 219, 0.1);
    color: #3498db;
}

.stat-success .stat-icon {
    background: rgba(16, 185, 129, 0.1);
    color: #10b981;
}

.stat-warning .stat-icon {
    background: rgba(243, 156, 18, 0.1);
    color: #f39c12;
}

.stat-danger .stat-icon {
    background: rgba(231, 76, 60, 0.1);
    color: #e74c3c;
}

.stat-info .stat-icon {
    background: rgba(52, 152, 219, 0.1);
    color: #3498db;
}

.stat-value {
    font-size: 2em;
    font-weight: 700;
    color: #2c3e50;
    margin-bottom: 5px;
}

.stat-desc {
    font-size: 0.9em;
    color: #95a5a6;
}

/* Tables */
.table-container {
    background: white;
    border-radius: 10px;
    overflow-x: auto;
    overflow-y: auto;
    max-height: 75vh;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    min-width: max-content;
}

.data-table thead {
    background: transparent;
}

.data-table thead th {
    padding: 12px 14px;
    text-align: left;
    font-weight: 600;
    color: white;
    background: linear-gradient(135deg, #059669 0%, #10b981 100%);
    font-size: 0.9em;
    white-space: nowrap;
    letter-spacing: 0.3px;
    /* sticky header */
    position: sticky;
    top: 0;
    z-index: 2;
}

/* First column: sticky left */
.data-table thead th:first-child,
.data-table tbody td:first-child {
    position: sticky;
    left: 0;
}

.data-table thead th:first-child {
    z-index: 4; /* corner cell: sticks in both axes */
}

.data-table tbody td:first-child {
    z-index: 1;
    background: white;
    box-shadow: 2px 0 6px -2px rgba(0, 0, 0, 0.1);
}

.data-table tbody tr:hover td:first-child {
    background: #f8f9fa;
}

.sortable-th {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
    transition: background 0.2s ease;
}

.sortable-th:hover {
    background: linear-gradient(135deg, #0369a1, #0284c7) !important;
}

.sortable-th.sorted {
    background: linear-gradient(135deg, #1d4ed8, #2563eb) !important;
}

.sort-indicator {
    font-size: 0.75em;
    opacity: 0.55;
    margin-left: 4px;
    display: inline-block;
    transition: opacity 0.2s ease;
}

.sortable-th.sorted .sort-indicator {
    opacity: 1;
}

.data-table tbody tr {
    border-bottom: 1px solid #ecf0f1;
    transition: all 0.2s ease;
}

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

.data-table tbody td {
    padding: 10px 14px;
    color: #2c3e50;
    font-size: 0.9em;
    vertical-align: middle;
    white-space: nowrap;
}

/* Monthly Compare – month checkbox grid */
.mc-months-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.mc-month-label {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border: 2px solid rgba(16, 185, 129, 0.25);
    border-radius: 10px;
    cursor: pointer;
    font-size: 0.9em;
    transition: all 0.2s ease;
    background: #f9fafb;
}

.mc-month-label:hover {
    border-color: #10b981;
    background: #ecfdf5;
}

.mc-month-label input[type="checkbox"] {
    accent-color: #059669;
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.mc-month-label:has(input:checked) {
    border-color: #059669;
    background: #d1fae5;
    color: #065f46;
    font-weight: 600;
}

/* Footer */
.content-footer {
    background: white;
    padding: 20px 30px;
    margin-top: 40px;
    border-radius: 10px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.footer-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
    color: #7f8c8d;
    font-size: 0.9em;
}

.footer-content i {
    color: #10b981;
    margin-right: 8px;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.active {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
    }

    .mobile-toggle {
        display: block;
    }

    .page-title {
        font-size: 1.3em;
    }

    .content-wrapper {
        padding: 15px;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .cards-grid {
        grid-template-columns: 1fr;
    }

    .footer-content {
        flex-direction: column;
        text-align: center;
    }
}

/* Utilities */
.mt-20 {
    margin-top: 20px;
}

.mb-20 {
    margin-bottom: 20px;
}

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

/* Filter Styles */
.filter-select {
    padding: 10px 15px;
    border: 2px solid #e0e6ed;
    border-radius: 8px;
    font-size: 1em;
    min-width: 150px;
    transition: all 0.3s ease;
    background: white;
    color: #2c3e50;
}

.filter-select:focus {
    outline: none;
    border-color: #10b981;
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);
}

/* Loading State */
.loading {
    text-align: center;
    padding: 40px;
    color: #10b981;
}

.loading::after {
    content: '';
    display: inline-block;
    width: 40px;
    height: 40px;
    border: 4px solid #e0e6ed;
    border-top-color: #10b981;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes pulse-warning {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.4);
        transform: scale(1);
    }
    50% {
        box-shadow: 0 0 0 4px rgba(245, 158, 11, 0);
        transform: scale(1.02);
    }
}

/* Badge Styles */
.badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.85em;
    font-weight: 600;
    text-align: center;
}

.badge-info {
    background: #dbeafe;
    color: #1e40af;
}

.badge-warning {
    background: #fef3c7;
    color: #92400e;
}

.badge-success {
    background: #d1fae5;
    color: #065f46;
}

.badge-danger {
    background: #fee2e2;
    color: #991b1b;
}

/* Hourly Analysis Styles */
.filters-bar {
    display: flex;
    gap: 20px;
    padding: 15px 0;
    border-bottom: 2px solid #e5e7eb;
    margin-bottom: 20px;
    flex-wrap: wrap;
    align-items: center;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.filter-group label {
    font-size: 0.9em;
    font-weight: 600;
    color: #374151;
}

.filter-group select {
    padding: 8px 12px;
    border: 2px solid #d1d5db;
    border-radius: 8px;
    font-size: 0.9em;
    background: white;
    min-width: 150px;
    transition: all 0.3s ease;
}

.filter-group select:focus {
    outline: none;
    border-color: #059669;
    box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.1);
}

#hourly-tab {
    width: 100%;
}

.charts-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
    margin-bottom: 30px;
    width: 100%;
}

.charts-grid .chart-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
    width: 100%;
}

/* Table tabs */
.table-tabs {
    display: flex;
    gap: 5px;
    margin-bottom: 15px;
    border-bottom: 2px solid #e5e7eb;
    padding-bottom: 0;
}

.table-tab-btn {
    padding: 10px 20px;
    border: none;
    background: transparent;
    font-family: inherit;
    font-size: 0.9em;
    font-weight: 600;
    color: #6b7280;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.3s ease;
}

.table-tab-btn:hover {
    color: #059669;
    background: #f0fdf4;
}

.table-tab-btn.active {
    color: #059669;
    border-bottom-color: #059669;
    background: #f0fdf4;
}

.table-tab-content {
    display: none;
}

.table-tab-content.active {
    display: block;
}
