/* Color Variables & Design Tokens */
:root {
    --bg-dark: #f1f5f9;
    --bg-card: #ffffff;
    --bg-sidebar: #ffffff;
    
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #64748b;
    
    --color-purple: #8b5cf6;
    --color-cyan: #0891b2;
    --color-emerald: #059669;
    --color-orange: #ea580c;
    --color-danger: #ef4444;
    --color-danger-bg: rgba(239, 68, 68, 0.08);
    
    --border-color: #cbd5e1;
    --border-hover: #94a3b8;
    --glow-color: rgba(99, 102, 241, 0.08);
    
    --font-sans: 'Outfit', 'Sarabun', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --transition-speed: 0.25s;
    --card-shadow: 0 4px 20px -2px rgba(148, 163, 184, 0.12);
    --border-radius: 12px;
}

/* Global Reset */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-primary);
    font-family: var(--font-sans);
    line-height: 1.5;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* Main Layout */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* Sidebar Navigation */
.sidebar {
    width: 260px;
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    position: fixed;
    height: 100vh;
    z-index: 100;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 2.5rem;
}

.brand-icon {
    font-size: 1.75rem;
    color: var(--color-cyan);
    filter: drop-shadow(0 0 8px rgba(6, 182, 212, 0.5));
}

.brand-text h2 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.brand-text p {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.sidebar-menu {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex-grow: 1;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    background: none;
    border: none;
    color: var(--text-secondary);
    padding: 0.85rem 1rem;
    font-family: var(--font-sans);
    font-size: 0.95rem;
    font-weight: 500;
    border-radius: var(--border-radius);
    cursor: pointer;
    text-align: left;
    transition: all var(--transition-speed);
}

.menu-item i {
    font-size: 1.1rem;
    width: 20px;
}

.menu-item:hover {
    color: var(--text-primary);
    background-color: rgba(0, 0, 0, 0.04);
}

.menu-item.active {
    color: var(--text-primary);
    background-color: rgba(99, 102, 241, 0.08);
    border: 1px solid rgba(99, 102, 241, 0.2);
    box-shadow: 0 0 15px rgba(99, 102, 241, 0.04) inset;
}

.sidebar-footer {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border-color);
    padding-top: 1rem;
}

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.status-indicator.online {
    background-color: var(--color-emerald);
    box-shadow: 0 0 8px var(--color-emerald);
}

/* Main Content area */
.main-content {
    flex-grow: 1;
    margin-left: 260px;
    padding: 2rem;
    max-width: calc(100% - 260px);
}

/* Header */
.main-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 1.25rem;
}

.header-title h1 {
    font-size: 1.75rem;
    font-weight: 700;
}

.header-title .subtitle {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.2rem;
    font-size: 0.9rem;
    font-weight: 600;
    font-family: var(--font-sans);
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all var(--transition-speed);
}

.btn-primary {
    background: linear-gradient(135deg, #6366f1, #4f46e5);
    color: white;
    border: none;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
    background: linear-gradient(135deg, #4f46e5, #4338ca);
    box-shadow: 0 4px 20px rgba(99, 102, 241, 0.5);
    transform: translateY(-1px);
}

.btn-secondary {
    background-color: #e2e8f0;
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background-color: #cbd5e1;
    border-color: var(--border-hover);
}

.btn-text {
    background: none;
    border: none;
    color: var(--color-cyan);
    font-weight: 500;
}

.btn-text:hover {
    text-decoration: underline;
}

.btn-danger-outline {
    background: none;
    border: 1px solid var(--color-danger);
    color: var(--color-danger);
}

.btn-danger-outline:hover {
    background-color: var(--color-danger-bg);
}

/* Tabs Content Controller */
.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
    animation: fadeIn 0.4s ease-in-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Cards System */
.dashboard-card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    box-shadow: var(--card-shadow);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    position: relative;
    overflow: hidden;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
}

.card-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Filters Card Specific */
.filters-card {
    border-left: 4px solid var(--color-cyan);
}

.filters-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.25rem;
}

@media (min-width: 992px) {
    .date-range-group {
        grid-column: span 2;
    }
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.filter-group label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-control {
    background-color: #ffffff;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.6rem 0.85rem;
    border-radius: 8px;
    font-family: var(--font-sans);
    font-size: 0.9rem;
    width: 100%;
    outline: none;
    transition: all var(--transition-speed);
}

.form-control:focus {
    border-color: #6366f1;
    box-shadow: 0 0 8px rgba(99, 102, 241, 0.2);
}

.date-range-container {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.date-range-container input[type="date"] {
    flex-grow: 1;
}

/* Range Sliders Double */
.slider-header {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
}

.slider-header span {
    color: var(--color-cyan);
    font-weight: 600;
}

.range-slider-container {
    position: relative;
    height: 20px;
    margin-top: 10px;
    display: flex;
    align-items: center;
}

.range-slider-container::before {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    height: 6px;
    background-color: #94a3b8; /* highly visible track line */
    border-radius: 3px;
    z-index: 0;
}

.range-slider-container input[type="range"] {
    position: absolute;
    width: 100%;
    height: 20px;
    background: none;
    pointer-events: none;
    -webkit-appearance: none;
    appearance: none;
    outline: none;
    z-index: 2;
    margin: 0;
}

/* Styling range input tracks */
.range-slider-container input[type="range"]::-webkit-slider-thumb {
    height: 18px;
    width: 18px;
    border-radius: 50%;
    background: #4f46e5; /* dark indigo, very clear */
    cursor: pointer;
    pointer-events: auto;
    -webkit-appearance: none;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    border: 2px solid #ffffff;
    position: relative;
    z-index: 3;
}

/* KPI Cards Grid */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.25rem;
    margin-bottom: 2rem;
}

.kpi-card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 1.25rem;
    display: flex;
    align-items: center;
    gap: 1.25rem;
    box-shadow: var(--card-shadow);
    transition: transform var(--transition-speed);
}

.kpi-card:hover {
    transform: translateY(-2px);
}

.kpi-icon {
    font-size: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 60px;
    height: 60px;
    border-radius: 12px;
}

.kpi-card.purple .kpi-icon { color: var(--color-purple); background-color: rgba(168, 85, 247, 0.12); }
.kpi-card.cyan .kpi-icon { color: var(--color-cyan); background-color: rgba(6, 182, 212, 0.12); }
.kpi-card.emerald .kpi-icon { color: var(--color-emerald); background-color: rgba(16, 185, 129, 0.12); }
.kpi-card.orange .kpi-icon { color: var(--color-orange); background-color: rgba(249, 115, 22, 0.12); }

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

.kpi-details h3 {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.kpi-details .value {
    font-size: 1.6rem;
    font-weight: 700;
    margin: 0.1rem 0;
}

.kpi-details .unit {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.kpi-details .subtext {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Charts Grid */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.span-2 {
    grid-column: span 2;
}

.chart-card {
    min-height: 380px;
}

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

/* Data Tables */
.table-card {
    border-top: 3px solid var(--color-purple);
}

.table-actions {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.table-search-input {
    width: 250px;
    background-color: #ffffff;
}

.table-container {
    width: 100%;
    overflow-x: auto;
    margin-top: 0.5rem;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    text-align: left;
}

.data-table th, .data-table td {
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--border-color);
}

.data-table th {
    font-weight: 600;
    color: var(--text-secondary);
    background-color: rgba(255, 255, 255, 0.02);
    cursor: pointer;
    user-select: none;
}

.data-table th:hover {
    color: var(--text-primary);
}

.data-table tbody tr {
    transition: background-color var(--transition-speed);
}

.data-table tbody tr:hover {
    background-color: rgba(255, 255, 255, 0.03);
}

/* Badges for Furnaces */
.furnace-badge {
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 700;
}

.furnace-badge.mf-1 { background-color: rgba(168, 85, 247, 0.15); color: var(--color-purple); border: 1px solid rgba(168, 85, 247, 0.3); }
.furnace-badge.mf-3-1 { background-color: rgba(6, 182, 212, 0.15); color: var(--color-cyan); border: 1px solid rgba(6, 182, 212, 0.3); }
.furnace-badge.mf-3-2 { background-color: rgba(16, 185, 129, 0.15); color: var(--color-emerald); border: 1px solid rgba(16, 185, 129, 0.3); }
.furnace-badge.mf-4 { background-color: rgba(249, 115, 22, 0.15); color: var(--color-orange); border: 1px solid rgba(249, 115, 22, 0.3); }

/* Table Pagination */
.table-pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

.table-pagination span {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.pagination-buttons {
    display: flex;
    gap: 0.5rem;
}

/* Grid input table (Data Entry Tab) */
.entry-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    gap: 1rem;
}

.import-paste-box {
    flex-grow: 1;
    max-width: 500px;
}

.grid-table-container {
    max-height: 450px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    margin-bottom: 1.5rem;
}

.grid-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.grid-table th {
    background-color: #f1f5f9;
    padding: 0.75rem;
    text-align: left;
    position: sticky;
    top: 0;
    z-index: 10;
    border-bottom: 2px solid var(--border-color);
    color: var(--text-secondary);
}

.grid-table td {
    padding: 0.4rem;
    border-bottom: 1px solid var(--border-color);
    background-color: var(--bg-card);
}

.grid-table input, .grid-table select {
    background-color: #ffffff !important;
    border: 1px solid var(--border-color) !important;
    color: var(--text-primary) !important;
    padding: 0.4rem !important;
    border-radius: 4px !important;
    font-size: 0.85rem !important;
}

.grid-table input:focus, .grid-table select:focus {
    border-color: #6366f1 !important;
}

.row-delete-btn {
    background: none;
    border: none;
    color: var(--color-danger);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 0.2rem;
}

.row-delete-btn:hover {
    color: #ff3333;
}

.entry-submit-container {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 1rem;
}

.alert {
    padding: 0.85rem 1.25rem;
    border-radius: var(--border-radius);
    font-size: 0.9rem;
    width: 100%;
    margin-bottom: 1rem;
}

.alert-danger {
    background-color: var(--color-danger-bg);
    border: 1px solid rgba(239, 68, 68, 0.4);
    color: var(--color-danger);
}

/* Ranking Page Styles */
.ranking-layout {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.ranking-table th {
    background-color: rgba(99, 102, 241, 0.05);
}

.ranking-row-1 { background-color: rgba(245, 158, 11, 0.06); }
.ranking-row-2 { background-color: rgba(148, 163, 184, 0.05); }
.ranking-row-3 { background-color: rgba(180, 83, 9, 0.04); }

.rank-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    font-weight: 700;
    font-size: 0.85rem;
}

.rank-badge.rank-1 { background-color: #f59e0b; color: #000; box-shadow: 0 0 8px #f59e0b; }
.rank-badge.rank-2 { background-color: #cbd5e1; color: #000; }
.rank-badge.rank-3 { background-color: #b45309; color: #fff; }
.rank-badge.rank-other { background-color: rgba(255, 255, 255, 0.1); color: var(--text-primary); }

.driver-tag {
    font-size: 0.8rem;
    color: var(--color-emerald);
    background-color: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.25);
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
}

/* Energy Insights List */
.insights-container {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.insight-row {
    display: flex;
    gap: 1.25rem;
    padding: 1.25rem;
    border-radius: var(--border-radius);
    background-color: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
}

.insight-badge {
    font-size: 0.75rem;
    font-weight: 700;
    padding: 0.25rem 0.6rem;
    border-radius: 20px;
    height: fit-content;
    text-transform: uppercase;
    white-space: nowrap;
}

.insight-badge.success { background-color: rgba(16, 185, 129, 0.15); color: var(--color-emerald); border: 1px solid var(--color-emerald); }
.insight-badge.info { background-color: rgba(6, 182, 212, 0.15); color: var(--color-cyan); border: 1px solid var(--color-cyan); }
.insight-badge.warning { background-color: rgba(239, 68, 68, 0.15); color: var(--color-danger); border: 1px solid var(--color-danger); }

.insight-text h4 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.insight-text p {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* Toast Message */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background-color: #10b981;
    color: white;
    padding: 0.85rem 1.5rem;
    border-radius: 8px;
    box-shadow: 0 10px 25px -5px rgba(16, 185, 129, 0.3);
    z-index: 9999;
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    pointer-events: none;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

.toast-content {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 600;
    font-size: 0.95rem;
}

.toast-icon {
    font-size: 1.25rem;
}

/* Responsive design adjustments */
@media(max-width: 1200px) {
    .charts-grid {
        grid-template-columns: 1fr;
    }
    .span-2 {
        grid-column: span 1;
    }
}
