:root {
    --primary-h: 238;
    --primary-s: 83%;
    --primary-l: 67%;
    --primary: hsl(var(--primary-h), var(--primary-s), var(--primary-l));
    
    --secondary-h: 271;
    --secondary-s: 91%;
    --secondary-l: 65%;
    --secondary: hsl(var(--secondary-h), var(--secondary-s), var(--secondary-l));
    
    --accent-h: 330;
    --accent-s: 81%;
    --accent-l: 60%;
    --accent: hsl(var(--accent-h), var(--accent-s), var(--accent-l));
    
    --bg-dark: #0f172a;
    --card-bg: rgba(30, 41, 59, 0.45);
    --glass-border: rgba(255, 255, 255, 0.08);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --sidebar-w: 240px;
    
    --green: #10b981;
    --orange: #f59e0b;
    --red: #ef4444;
    --teal: #14b8a6;
    --purple: #a855f7;
    --gap: 20px;
}

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

body {
    font-family: 'Outfit', 'Inter', -apple-system, sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    min-height: 100vh;
    overflow-x: hidden;
    line-height: 1.5;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* Loading */
#loading {
    position: fixed; inset: 0; z-index: 9999;
    background: var(--bg-dark);
    display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 20px;
}
.spinner {
    width: 50px; height: 50px;
    border: 3px solid rgba(99,102,241,0.1);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: rotate 1s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}
@keyframes rotate { to { transform: rotate(360deg); } }

/* Layout */
.dashboard-wrapper { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
    width: var(--sidebar-w);
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(20px);
    border-right: 1px solid var(--glass-border);
    padding: 2rem 1.25rem;
    position: fixed; height: 100vh; z-index: 100;
    display: flex; flex-direction: column;
    transition: all 0.3s ease;
}

.logo { 
    display: flex; align-items: center; gap: 0.75rem; margin-bottom: 2.5rem; 
    padding: 0 0.5rem;
}
.logo-icon { font-size: 1.5rem; filter: drop-shadow(0 0 8px var(--primary)); }
.logo-text {
    font-weight: 800; font-size: 1.2rem; letter-spacing: 1px;
    background: linear-gradient(135deg, var(--primary), var(--secondary), var(--accent));
    -webkit-background-clip: text; background-clip: text;
    -webkit-text-fill-color: transparent;
}

nav ul { list-style: none; }
nav li {
    padding: 0.75rem 1rem; margin-bottom: 6px;
    border-radius: 12px; cursor: pointer;
    color: var(--text-muted); font-size: 0.9rem; font-weight: 500;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex; align-items: center; gap: 10px;
}
nav li:hover { 
    background: rgba(255,255,255,0.05); color: var(--text-main); 
    transform: translateX(4px);
}
nav li.active {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    box-shadow: 0 8px 16px -4px rgba(99,102,241,0.4);
}

.sidebar-filters {
    margin-top: auto; padding-top: 1.5rem;
    border-top: 1px solid var(--glass-border);
}
.sidebar-filters label {
    display: block; font-size: 0.75rem; color: var(--text-muted);
    text-transform: uppercase; letter-spacing: 1px; font-weight: 600;
    margin: 1rem 0 0.5rem;
}
.sidebar-filters select {
    width: 100%; padding: 0.6rem 0.75rem;
    background: rgba(255,255,255,0.03); border: 1px solid var(--glass-border);
    border-radius: 10px; color: white; font-size: 0.85rem; outline: none;
    transition: border-color 0.2s;
}
.sidebar-filters select:focus { border-color: var(--primary); }

/* Content */
.content {
    flex: 1; margin-left: var(--sidebar-w);
    padding: 2.5rem 3rem; position: relative;
}

header { margin-bottom: 2.5rem; animation: slideDown 0.6s ease-out; }
@keyframes slideDown { from { transform: translateY(-20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

h1 { font-size: 2.2rem; font-weight: 800; letter-spacing: -0.5px; margin-bottom: 0.5rem; }
#last-updated { color: var(--text-muted); font-size: 0.95rem; display: flex; align-items: center; gap: 8px; }
#last-updated::before { content: ''; width: 8px; height: 8px; background: var(--green); border-radius: 50%; box-shadow: 0 0 8px var(--green); }

.dashboard-section {
    display: flex; flex-direction: column; gap: var(--gap);
    margin-bottom: 4rem; scroll-margin-top: 2rem;
    animation: fadeIn 0.8s ease-out;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* KPI Cards */
.kpi-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--gap); }
.kpi-card {
    background: var(--card-bg); backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border); border-radius: 20px;
    padding: 1.5rem; position: relative; overflow: hidden;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.kpi-card:hover { transform: translateY(-5px); border-color: rgba(255,255,255,0.2); box-shadow: 0 20px 40px -10px rgba(0,0,0,0.5); }
.kpi-card::after {
    content: ''; position: absolute; top: 0; left: 0; width: 4px; height: 100%; background: var(--primary);
}
.kpi-card.green::after { background: var(--green); }
.kpi-card.orange::after { background: var(--orange); }
.kpi-card.purple::after { background: var(--purple); }
.kpi-card.red::after { background: var(--red); }
.kpi-card.teal::after { background: var(--teal); }

.kpi-label { font-size: 0.8rem; color: var(--text-muted); font-weight: 600; display: flex; align-items: center; gap: 6px; }
.kpi-value { font-size: 1.8rem; font-weight: 800; margin: 0.5rem 0; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 0.85rem; color: var(--text-muted); }
.kpi-diff { font-size: 0.85rem; font-weight: 700; margin-top: 0.5rem; }
.kpi-diff.up { color: var(--green); }
.kpi-diff.down { color: var(--red); }

/* Grids */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); }

/* Chart Cards */
.chart-card {
    background: var(--card-bg); backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border); border-radius: 24px;
    padding: 1.75rem; transition: border-color 0.3s;
}
.chart-card:hover { border-color: rgba(255,255,255,0.15); }
.chart-card h3 { font-size: 1.1rem; font-weight: 700; margin-bottom: 0.5rem; color: var(--text-main); }
.chart-desc { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 1.5rem; }

.chart-inner { position: relative; height: 320px; width: 100%; }
.chart-inner.tall { height: 400px; }
.chart-inner.pyramid { height: 500px; }

/* Map */
.map-container { height: 320px; width: 100%; border-radius: 16px; z-index: 1; border: 1px solid var(--glass-border); overflow: hidden; }
.leaflet-container { background-color: #1e293b !important; }

/* Controls */
.header-controls { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; }
#districtFilter, #townSearch {
    background: rgba(255,255,255,0.05); border: 1px solid var(--glass-border);
    border-radius: 12px; padding: 0.6rem 1rem; color: white; font-size: 0.9rem; outline: none;
    transition: all 0.2s; min-width: 200px;
}
#districtFilter:focus, #townSearch:focus { border-color: var(--primary); background: rgba(255,255,255,0.08); }

/* Table */
.table-wrapper {
    background: var(--card-bg); backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border); border-radius: 20px;
    overflow: hidden;
}
table { width: 100%; border-collapse: collapse; }
th {
    background: rgba(15,23,42,0.9); text-align: right; padding: 1.25rem 1rem;
    font-size: 0.8rem; font-weight: 700; text-transform: uppercase; letter-spacing: 1px;
    color: var(--text-muted); border-bottom: 1px solid var(--glass-border);
}
th:first-child { text-align: left; padding-left: 2rem; }
th:last-child { padding-right: 2rem; }
td { padding: 1rem; text-align: right; border-bottom: 1px solid rgba(255,255,255,0.03); font-size: 0.95rem; font-variant-numeric: tabular-nums; }
td:first-child { text-align: left; font-weight: 600; padding-left: 2rem; }
td:last-child { padding-right: 2rem; }
tr:last-child td { border-bottom: none; }
tr:hover { background: rgba(255,255,255,0.02); }
.neg { color: var(--red); font-weight: 600; }
.pos { color: var(--green); font-weight: 600; }

/* Blobs */
.background-blobs { position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: -1; pointer-events: none; }
.blob { position: absolute; filter: blur(120px); opacity: 0.15; border-radius: 50%; }
.blob-1 { width: 600px; height: 600px; background: var(--primary); top: -200px; right: -100px; }
.blob-2 { width: 500px; height: 500px; background: var(--accent); bottom: -100px; left: -100px; }

/* Responsive */
@media (max-width: 1400px) {
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 1024px) {
    .sidebar { transform: translateX(-100%); }
    .content { margin-left: 0; padding: 1.5rem; }
    .grid-2 { grid-template-columns: 1fr; }
    .kpi-grid { grid-template-columns: 1fr; }
    h1 { font-size: 1.75rem; }
}
