/* =================================
    CSS VARIABLES (Light & Dark Mode)
    ================================= */
:root {
    /* General/Body */
    --body-background: #f8f8f8; /* From index.css */
    --main-text-color: #333; /* From index.css */
    --subtle-text-color: #6e6e73; /* From index.css */
    --heading-color: #303d4e; /* From index.css (Used for H2/H1) */
    --border-color: #eee; /* From index.css */

    /* Cards/Panels */
    --card-background: white; /* From index.css */
    --card-shadow: 0 6px 15px rgba(0, 0, 0, 0.1); /* Adjusted from index.css for KPI depth */

    /* KPI Colors (Keeping specific colors, but making them variables) */
    --kpi-completed-border: #2ecc71;
    --kpi-completed-value: #27ae60;
    --kpi-outstanding-border: #e74c3c;
    --kpi-outstanding-value: #c0392b;
    --kpi-percentage-border: #3498db;
    --kpi-percentage-value: #2980b9;
    --kpi-info-border: #9b59b6;
    --kpi-info-value: #8e44ad;
    
    /* Progress Bar */
    --progress-background: #ecf0f1;
    --progress-fill: #3498db;

    /* Table */
    --table-header-background: #34495e;
    --table-header-text: white;
    --table-text: #555;
    --table-alt-row: #f9f9f9;
    --table-hover: #e8f4f8;
}

/* Dark Mode - System Preference */
@media (prefers-color-scheme: dark) {
    :root {
        --body-background: #1a1a1a;
        --main-text-color: #e0e0e0;
        --subtle-text-color: #999999;
        --heading-color: #d3cac3;
        --border-color: #444;
        --card-background: #2a2a2a;
        --card-shadow: 0 6px 15px rgba(0, 0, 0, 0.4);

        /* Dark Mode KPI Colors (Slightly adjusted for contrast) */
        --kpi-completed-border: #48c484;
        --kpi-completed-value: #40b374;
        --kpi-outstanding-border: #ff6b6b;
        --kpi-outstanding-value: #ff4757;
        --kpi-percentage-border: #5ac8fa;
        --kpi-percentage-value: #5ac8fa;
        --kpi-info-border: #bb86fc;
        --kpi-info-value: #a370f7;

        /* Dark Mode Progress Bar */
        --progress-background: #333;
        --progress-fill: #5ac8fa;

        /* Dark Mode Table */
        --table-header-background: #4a6480;
        --table-header-text: #e0e0e0;
        --table-text: #b0b0b0;
        --table-alt-row: #333333;
        --table-hover: #3e4e60;
    }
}

/* Dark Mode - Manual Toggle (Matching index.css structure) */
body[data-theme='dark'] {
    /* Reusing the same dark mode variable set */
    --body-background: #1a1a1a;
    --main-text-color: #e0e0e0;
    --subtle-text-color: #999999;
    --heading-color: #d3cac3;
    --border-color: #444;
    --card-background: #2a2a2a;
    --card-shadow: 0 6px 15px rgba(0, 0, 0, 0.4);

    --kpi-completed-border: #48c484;
    --kpi-completed-value: #40b374;
    --kpi-outstanding-border: #ff6b6b;
    --kpi-outstanding-value: #ff4757;
    --kpi-percentage-border: #5ac8fa;
    --kpi-percentage-value: #5ac8fa;
    --kpi-info-border: #bb86fc;
    --kpi-info-value: #a370f7;

    --progress-background: #333;
    --progress-fill: #5ac8fa;

    --table-header-background: #4a6480;
    --table-header-text: #e0e0e0;
    --table-text: #b0b0b0;
    --table-alt-row: #333333;
    --table-hover: #3e4e60;
}


/* ====================================================================== */
/* --- GENERAL STYLES AND LAYOUT (Applied Fixes and Variable Usage) --- */
/* ====================================================================== */

/* --- CRITICAL GLOBAL FIX --- */
html, body {
    height: 100%; 
}

/* --- Global Styles and Typography --- */
body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--body-background); 
    margin: 0;
    padding: 0;
    color: var(--main-text-color);
    transition: background-color 0.3s ease, color 0.3s ease;
}

.dashboard-container {
    max-width: 1400px;
    margin: 20px auto 0;
    padding: 0 20px;
}

h1 {
    color: var(--heading-color);
    text-align: center;
    margin-top: 140px;
    margin-bottom: 40px;
    font-size: 2.2em;
    border-bottom: 3px solid var(--heading-color);
    padding-bottom: 10px;
    transition: color 0.3s ease, border-color 0.3s ease;
}

/* --- Dashboard Sections --- */
.dashboard-section {
    margin-bottom: 50px;
}

.section-header {
    margin-bottom: 30px;
}

.section-title {
    color: var(--heading-color);
    font-size: 1.8em;
    margin: 0 0 10px 0;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--border-color);
    transition: color 0.3s ease, border-color 0.3s ease;
}

.section-description {
    color: var(--subtle-text-color);
    font-size: 1em;
    margin: 10px 0 0 0;
    line-height: 1.6;
}

.chart-subtitle {
    color: var(--subtle-text-color);
    font-size: 0.95em;
    margin: -5px 0 15px 0;
    font-style: italic;
}

/* --- 1. KPI Grid Layout and Cards --- */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr); 
    gap: 20px;
    margin-bottom: 30px;
    /* FIX: Apply 140px offset here */
    margin-top: 20px;
}

.kpi-card {
    background: var(--card-background);
    padding: 25px;
    border-radius: 12px;
    box-shadow: var(--card-shadow);
    border-left: 6px solid;
    text-align: center;
    /* FIX: Removed transition: transform 0.2s; to stop bounce */
    transition: background-color 0.3s ease, box-shadow 0.3s ease;
}

.kpi-card:hover {
    /* FIX: Removed transform: translateY(-3px); to stop bounce */
}

.kpi-label {
    display: block;
    font-size: 1em;
    color: var(--subtle-text-color);
    margin-bottom: 2px; /* Reduced from 10px to pull the number up */
    font-weight: 600;
    text-transform: uppercase;
}

.kpi-value {
    font-size: 3em;
    font-weight: 800;
    margin: 0;
    line-height: 1.1; /* Added to reduce the vertical space the text occupies */
}

/* KPI Color Classes using Variables */
.completed-card { border-left-color: var(--kpi-completed-border); } 
.completed-card .kpi-value { color: var(--kpi-completed-value); }

.outstanding-card { border-left-color: var(--kpi-outstanding-border); } 
.outstanding-card .kpi-value { color: var(--kpi-outstanding-value); }

.percentage-card { border-left-color: var(--kpi-percentage-border); } 
.percentage-card .kpi-value { color: var(--kpi-percentage-value); }

.info-card { border-left-color: var(--kpi-info-border); } 
.info-card .kpi-value { color: var(--kpi-info-value); }

.progress-bar-container {
    background-color: var(--progress-background);
    border-radius: 5px;
    height: 10px;
    margin-top: 15px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background-color: var(--progress-fill);
    transition: width 0.5s ease-in-out, background-color 0.3s ease;
}

/* --- 2. Main Content Grid (Chart Panel) --- */
.main-content-grid {
    /* Removed fixed grid-template-columns to allow the inline PHP style 
       to define the single column for full-width chart */
    gap: 30px;
}

.chart-panel, .table-panel {
    background: var(--card-background);
    padding: 25px;
    border-radius: 12px;
    box-shadow: var(--card-shadow);
    transition: background-color 0.3s ease, box-shadow 0.3s ease;
}

.chart-panel h2, .table-panel h2 {
    color: var(--heading-color);
    font-size: 1.5em;
    margin-top: 0;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--border-color);
    transition: color 0.3s ease, border-color 0.3s ease;
}

/* FIX FOR THE CHART GROWING ISSUE */
/* dashboard.css */
.chart-panel {
    height: auto;      /* This allows the card to shrink to fit your 400px chart */
    position: relative;
    padding-bottom: 25px; 
}

.chart-wrapper {
    height: calc(100% - 60px); 
    position: relative; 
}

.chart-wrapper canvas {
    display: block;
    width: 100% !important; 
    height: 100% !important; 
}
/* END FIX */


/* --- 3. Outstanding Games Table --- */
.table-scroll {
    max-height: 500px; 
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 8px;
}

#outstanding-table {
    width: 100%;
    border-collapse: collapse;
}

#outstanding-table thead th {
    background-color: var(--table-header-background); 
    color: var(--table-header-text);
    padding: 15px;
    text-align: left;
    position: sticky;
    top: 0;
    z-index: 10;
    cursor: pointer;
    transition: background-color 0.3s ease, color 0.3s ease;
}

#outstanding-table tbody td {
    padding: 12px 15px;
    border-bottom: 1px solid var(--border-color);
    color: var(--table-text);
}

#outstanding-table tbody tr:nth-child(even) {
    background-color: var(--table-alt-row);
}

#outstanding-table tbody tr:hover {
    background-color: var(--table-hover);
}