/* ============================================================
   REA GeoPortal - Design System & Global Styles
   Premium dark theme with glassmorphism
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500&display=swap');

/* ---- CSS Custom Properties ---- */
:root {
  /* Primary palette */
  --primary-50: #eef7ff;
  --primary-100: #d9edff;
  --primary-200: #bce0ff;
  --primary-300: #8eccff;
  --primary-400: #59b0ff;
  --primary-500: #3b8eff;
  --primary-600: #1e6bf5;
  --primary-700: #1755e1;
  --primary-800: #1946b6;
  --primary-900: #1a3d8f;

  /* Accent / energy colors */
  --accent-yellow: #fbbf24;
  --accent-orange: #f97316;
  --accent-green: #22c55e;
  --accent-teal: #14b8a6;
  --accent-purple: #a855f7;
  --accent-pink: #ec4899;
  --accent-red: #ef4444;

  /* Chart colors */
  --chart-1: #3b8eff;
  --chart-2: #22c55e;
  --chart-3: #fbbf24;
  --chart-4: #a855f7;
  --chart-5: #ec4899;
  --chart-6: #14b8a6;

  /* Base Variables (Default Dark Theme) */
  --bg-primary: #0a0e1a;
  --bg-secondary: #111827;
  --bg-card: #1a2235;
  --bg-card-hover: #1f2a40;
  --bg-glass: rgba(26, 34, 53, 0.75);
  --bg-input: #0f172a;

  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-default: rgba(255, 255, 255, 0.1);
  --border-active: rgba(59, 142, 255, 0.4);

  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --text-accent: #3b8eff;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.6);
  --shadow-glow: 0 0 20px rgba(59, 142, 255, 0.15);

  /* Layout */
  --sidebar-width: 290px;
  --header-height: 64px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  /* Transitions */
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);

  /* Chart & tooltip theming (dark defaults) */
  --chart-text:     #94a3b8;
  --chart-grid:     rgba(255, 255, 255, 0.07);
  --tooltip-bg:     #1a2235;
  --tooltip-border: rgba(255, 255, 255, 0.12);
  --tooltip-title:  #f1f5f9;
  --tooltip-body:   #94a3b8;
}

/* ---- Light Theme ---- */
[data-theme="light"] {
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #f1f5f9;
  --bg-glass: rgba(255, 255, 255, 0.85);
  --bg-input: #f1f5f9;

  --border-subtle: rgba(0, 0, 0, 0.05);
  --border-default: rgba(0, 0, 0, 0.1);
  --border-active: rgba(59, 142, 255, 0.5);

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.12);
  --shadow-glow: 0 0 20px rgba(59, 142, 255, 0.2);

  /* Chart & tooltip theming */
  --chart-text:     #475569;
  --chart-grid:     rgba(0, 0, 0, 0.07);
  --tooltip-bg:     #ffffff;
  --tooltip-border: rgba(0, 0, 0, 0.12);
  --tooltip-title:  #0f172a;
  --tooltip-body:   #475569;
}

/* ---- Ocean Theme ---- */
[data-theme="ocean"] {
  --bg-primary: #08121f;
  --bg-secondary: #0a192f;
  --bg-card: #112240;
  --bg-card-hover: #162f56;
  --bg-glass: rgba(17, 34, 64, 0.8);
  --bg-input: #0a192f;

  --border-subtle: rgba(100, 255, 218, 0.08);
  --border-default: rgba(100, 255, 218, 0.15);
  --border-active: rgba(100, 255, 218, 0.5);

  --text-primary: #ccd6f6;
  --text-secondary: #8892b0;
  --text-muted: #64748b;
  --text-accent: #64ffda;
  
  --primary-400: #64ffda;
  --primary-500: #64ffda;

  /* Chart & tooltip theming */
  --chart-text:     #8892b0;
  --chart-grid:     rgba(100, 255, 218, 0.08);
  --tooltip-bg:     #112240;
  --tooltip-border: rgba(100, 255, 218, 0.2);
  --tooltip-title:  #ccd6f6;
  --tooltip-body:   #8892b0;
}

/* ---- Nature Theme ---- */
[data-theme="nature"] {
  --bg-primary: #121611;
  --bg-secondary: #1a2018;
  --bg-card: #222b1f;
  --bg-card-hover: #2a3526;
  --bg-glass: rgba(34, 43, 31, 0.8);
  --bg-input: #1a2018;

  --border-subtle: rgba(167, 243, 208, 0.05);
  --border-default: rgba(167, 243, 208, 0.1);
  --border-active: rgba(52, 211, 153, 0.4);

  --text-primary: #ecfdf5;
  --text-secondary: #a7f3d0;
  --text-muted: #6ee7b7;
  --text-accent: #10b981;
  
  --primary-400: #10b981;
  --primary-500: #10b981;

  /* Chart & tooltip theming */
  --chart-text:     #a7f3d0;
  --chart-grid:     rgba(167, 243, 208, 0.07);
  --tooltip-bg:     #222b1f;
  --tooltip-border: rgba(167, 243, 208, 0.15);
  --tooltip-title:  #ecfdf5;
  --tooltip-body:   #a7f3d0;
}

/* ---- Reset & Base ---- */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 14px;
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}
::-webkit-scrollbar-thumb {
  background: var(--text-muted);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}

/* ---- Utility ---- */
.glass {
  background: var(--bg-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-subtle);
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  transition: all var(--transition-base);
}
.card:hover {
  border-color: var(--border-active);
  box-shadow: var(--shadow-glow);
}

/* ---- Layout ---- */
#root {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-layout {
  display: flex;
  flex: 1;
  height: calc(100vh - var(--header-height));
}

/* ---- Header ---- */
.header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 0 24px;
  background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-card) 100%);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  z-index: 1000;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.header-logo {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: white;
  box-shadow: 0 0 12px rgba(59, 142, 255, 0.3);
  flex-shrink: 0;
}

.header-logo-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 3px;
}

.header-title {
  font-size: 1.25rem;
  font-weight: 700;
  background: linear-gradient(90deg, var(--text-primary) 0%, var(--primary-400) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 400;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: rgba(34, 197, 94, 0.12);
  border: 1px solid rgba(34, 197, 94, 0.25);
  border-radius: 20px;
  font-size: 0.75rem;
  color: var(--accent-green);
  font-weight: 500;
}

.header-badge .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent-green);
  animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.8); }
}

/* ---- Sidebar ---- */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-subtle);
  padding: 20px 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.sidebar-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sidebar-section-title {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding-left: 4px;
}

.sidebar select,
.sidebar input {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.85rem;
  transition: all var(--transition-fast);
  outline: none;
  cursor: pointer;
}

.sidebar select:hover,
.sidebar input:hover {
  border-color: var(--border-active);
}

.sidebar select:focus,
.sidebar input:focus {
  border-color: var(--primary-500);
  box-shadow: 0 0 0 3px rgba(59, 142, 255, 0.15);
}

.sidebar select option {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

/* Variable buttons */
.variable-buttons {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.variable-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-align: left;
}

.variable-btn:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
  border-color: var(--border-active);
}

.variable-btn.active {
  background: rgba(59, 142, 255, 0.12);
  border-color: var(--primary-500);
  color: var(--primary-400);
  font-weight: 500;
}

.variable-btn .var-icon {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Legend */
.legend {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
}

.legend-title {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.legend-color {
  width: 20px;
  height: 12px;
  border-radius: 3px;
  flex-shrink: 0;
}

/* ---- Main Content ---- */
body {
  overflow: hidden; /* Global scroll disabled to keep sidebar static */
}

.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 20px;
  overflow-y: hidden; /* Prevent global scroll, let content fill height */
  min-height: 0;
}

/* ---- Top Filter Bar ---- */
.top-filter-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--bg-card);
  padding: 12px 20px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}

.top-filter-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
}

.top-filter-row {
  display: flex;
  flex-direction: row;
  gap: 12px;
  width: 100%;
}

.top-filter-select {
  flex: 1;
  padding: 10px 12px;
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.85rem;
  transition: all var(--transition-fast);
  outline: none;
  cursor: pointer;
  min-width: 0;
}

.top-filter-select:hover {
  border-color: var(--border-active);
}

.top-filter-select:focus {
  border-color: var(--primary-500);
  box-shadow: 0 0 0 3px rgba(59, 142, 255, 0.15);
}

.top-filter-select option {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

#energy-filter-container,
#infra-filter-container {
  width: 100%;
}

#energy-filter-container .top-filter-select {
  width: 100%;
  max-width: 300px;
}

/* Flexible Dashboard Layout */
.dashboard-row {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  flex: 1;
  min-height: 0;
}

.widget-map {
  flex: 2 1 600px;
  min-height: 400px;
  display: flex;
  flex-direction: column;
}

.widget-charts {
  flex: 1 1 350px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  overflow-y: auto;
  padding-right: 4px;
  padding-bottom: 20px;
}

.widget-pie, .widget-bar {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 350px;
}

.widget-table {
  width: 100%;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* ---- Map ---- */
.map-tabs {
  display: flex;
  gap: 8px;
  background: var(--bg-primary); /* matches background to look integrated */
  padding: 8px 12px 0 12px;
  border-top: 1px solid var(--border-subtle);
  border-left: 1px solid var(--border-subtle);
  border-right: 1px solid var(--border-subtle);
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  margin-bottom: 0;
}

.map-tab {
  padding: 8px 16px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.map-tab:hover {
  color: var(--text-primary);
}

.map-tab.active {
  color: var(--primary-400);
  border-bottom-color: var(--primary-500);
}

.map-container {
  flex: 1;
  height: 100%;
  border-radius: 0 0 var(--radius-md) var(--radius-md); /* Connects to tabs above */
  overflow: hidden;
  border: 1px solid var(--border-subtle);
  position: relative;
}

.map-container .leaflet-container {
  height: 100%;
  width: 100%;
  background: var(--bg-primary);
}

/* Fix sub-pixel rendering gaps between adjacent GeoJSON polygons.
   Leaflet SVG renderer leaves hairline gaps due to anti-aliasing.
   shape-rendering:crispEdges removes the anti-aliasing that causes gaps.
   stroke-linejoin + stroke-linecap ensure borders overlap cleanly. */
.map-container .leaflet-overlay-pane svg path {
  shape-rendering: crispEdges;
  stroke-linejoin: round;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

.map-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-card);
  z-index: 500;
}

.map-loading .spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border-default);
  border-top-color: var(--primary-500);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Map Legend */
.map-legend {
  position: absolute;
  bottom: 20px;
  right: 20px;
  background: var(--bg-card);
  padding: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  width: 150px;
}
.legend-scale {
  height: 8px;
  border-radius: 4px;
  margin-bottom: 4px;
}
.legend-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* Leaflet popup overrides */
.leaflet-popup-content-wrapper {
  background: var(--bg-card) !important;
  color: var(--text-primary) !important;
  border-radius: var(--radius-sm) !important;
  border: 1px solid var(--border-default) !important;
  box-shadow: var(--shadow-lg) !important;
}

.leaflet-popup-tip {
  background: var(--bg-card) !important;
  border: 1px solid var(--border-default) !important;
}

.leaflet-popup-close-button {
  color: var(--text-muted) !important;
}

/* ---- Leaflet Scale Bar — theme-aware ---- */
.leaflet-control-scale-line {
  background: var(--bg-card) !important;
  border-color: var(--border-default) !important;
  border-top-color: var(--border-default) !important;
  color: var(--text-secondary) !important;
  font-family: 'Inter', sans-serif !important;
  font-size: 0.68rem !important;
  font-weight: 500 !important;
  padding: 2px 6px !important;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm) !important;
  box-shadow: var(--shadow-sm) !important;
  white-space: nowrap !important;
}

/* Layer switcher control — theme-aware */
.leaflet-control-layers {
  background: var(--bg-card) !important;
  border: 1px solid var(--border-subtle) !important;
  border-radius: var(--radius-sm) !important;
  box-shadow: var(--shadow-md) !important;
  color: var(--text-primary) !important;
  font-family: 'Inter', sans-serif !important;
  font-size: 0.78rem !important;
}

/* Ensure smooth hover transitions on map polygons */
.leaflet-interactive {
  transition: fill-opacity 0.2s ease, stroke-width 0.2s ease, stroke-opacity 0.2s ease;
}
.leaflet-interactive:hover {
  stroke-width: 2.5px;
  stroke-opacity: 1 !important;
  fill-opacity: 0.8 !important;
}

/* ============================================================
   Custom Glowing Grid Clusters
   ============================================================ */
.custom-grid-cluster {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.75rem;
  font-weight: 700;
  color: #fff;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: transform 0.2s ease;
}
.custom-grid-cluster:hover {
  transform: scale(1.15);
  z-index: 1000 !important;
}

/* Low Density: Soft Blue */
.cluster-low {
  background: rgba(59, 142, 255, 0.4);
  border: 2px solid rgba(59, 142, 255, 0.8);
  box-shadow: 0 0 15px rgba(59, 142, 255, 0.5);
  animation: pulse-low 3s infinite alternate;
}
/* Medium Density: Electric Yellow/Gold */
.cluster-medium {
  background: rgba(251, 191, 36, 0.5);
  border: 2px solid rgba(251, 191, 36, 0.9);
  box-shadow: 0 0 20px rgba(251, 191, 36, 0.6);
  animation: pulse-medium 2.5s infinite alternate;
}
/* High Density: Intense Orange */
.cluster-high {
  background: rgba(249, 115, 22, 0.6);
  border: 2px solid rgba(249, 115, 22, 1);
  box-shadow: 0 0 25px rgba(249, 115, 22, 0.8);
  animation: pulse-high 2s infinite alternate;
}

/* Animations */
@keyframes pulse-low {
  from { box-shadow: 0 0 10px rgba(59, 142, 255, 0.3); }
  to { box-shadow: 0 0 20px rgba(59, 142, 255, 0.7); }
}
@keyframes pulse-medium {
  from { box-shadow: 0 0 15px rgba(251, 191, 36, 0.4); }
  to { box-shadow: 0 0 25px rgba(251, 191, 36, 0.8); }
}
@keyframes pulse-high {
  from { box-shadow: 0 0 20px rgba(249, 115, 22, 0.5); }
  to { box-shadow: 0 0 35px rgba(249, 115, 22, 1); }
}


.leaflet-control-layers-expanded {
  padding: 8px 12px !important;
}

.leaflet-control-layers label {
  color: var(--text-secondary) !important;
  font-size: 0.78rem !important;
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 3px 0;
}

.popup-content h3 {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--primary-400);
}

.popup-content .popup-council {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.popup-content .popup-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.popup-content .popup-stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px 8px;
  background: var(--bg-input);
  border-radius: 6px;
}

.popup-content .popup-stat .label {
  font-size: 0.65rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.popup-content .popup-stat .value {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
  font-family: 'JetBrains Mono', monospace;
}

/* ---- Stats Cards ---- */
.stats-grid {
  display: flex;
  gap: 12px;
  flex-wrap: nowrap;
  overflow-x: auto;
  padding-bottom: 4px;
}
.stat-card {
  flex: 1;
  min-width: 140px;
  padding: 12px;
}
.stat-card .stat-icon {
  width: 28px;
  height: 28px;
  margin-bottom: 4px;
}
.stat-card .stat-value {
  font-size: 1.25rem;
}
.stat-card .stat-label {
  font-size: 0.7rem;
}

.stat-card {
  padding: 18px;
  border-radius: var(--radius-md);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  transition: all var(--transition-base);
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  border-radius: 3px 3px 0 0;
}

.stat-card:nth-child(1)::before { background: linear-gradient(90deg, var(--chart-1), var(--chart-2)); }
.stat-card:nth-child(2)::before { background: linear-gradient(90deg, var(--chart-2), var(--chart-3)); }
.stat-card:nth-child(3)::before { background: linear-gradient(90deg, var(--chart-3), var(--chart-4)); }
.stat-card:nth-child(4)::before { background: linear-gradient(90deg, var(--chart-4), var(--chart-5)); }
.stat-card:nth-child(5)::before { background: linear-gradient(90deg, var(--chart-5), var(--chart-6)); }
.stat-card:nth-child(6)::before { background: linear-gradient(90deg, var(--chart-6), var(--chart-1)); }

.stat-card:hover {
  border-color: var(--border-active);
  transform: translateY(-2px);
  box-shadow: var(--shadow-glow);
}

.stat-card .stat-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}

.stat-card .stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  font-family: 'JetBrains Mono', monospace;
  color: var(--text-primary);
  line-height: 1.2;
}

.stat-card .stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
  font-weight: 500;
}

/* ---- Charts Section ---- */
.charts-row {
  display: grid;
  grid-template-columns: 1fr 1.5fr;
  gap: 20px;
}

.chart-card {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  padding: 20px;
  border-radius: var(--radius-md);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
}

.chart-card-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.chart-card-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 16px;
}

/* Recharts overrides */
.recharts-text {
  fill: var(--text-secondary) !important;
  font-size: 0.7rem !important;
}

.recharts-cartesian-axis-tick-value {
  fill: var(--text-muted) !important;
  font-size: 0.7rem !important;
}

.recharts-tooltip-wrapper .recharts-default-tooltip {
  background: var(--bg-card) !important;
  border: 1px solid var(--border-default) !important;
  border-radius: var(--radius-sm) !important;
  box-shadow: var(--shadow-md) !important;
}

.recharts-tooltip-label {
  color: var(--text-primary) !important;
  font-weight: 600 !important;
  font-size: 0.8rem !important;
}

.recharts-tooltip-item {
  color: var(--text-secondary) !important;
  font-size: 0.75rem !important;
}

/* Custom pie chart legend */
.pie-legend {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.pie-legend-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  gap: 8px;
  font-size: 0.75rem;
}

.pie-legend-item .legend-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pie-legend-item .legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.pie-legend-item .legend-label {
  color: var(--text-secondary);
}

.pie-legend-item .legend-value {
  font-weight: 600;
  color: var(--text-primary);
  font-family: 'JetBrains Mono', monospace;
}

/* ---- Data Table ---- */
.table-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.table-container {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  border-radius: var(--radius-md);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  overflow: hidden;
}

.table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-subtle);
  flex-wrap: wrap;
  gap: 12px;
}

.table-header-left {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.table-header-left h3 {
  font-size: 0.95rem;
  font-weight: 600;
}

.table-header-left span {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.table-search {
  position: relative;
}

.table-search input {
  padding: 8px 12px 8px 36px;
  background: var(--bg-input);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.8rem;
  width: 240px;
  outline: none;
  transition: all var(--transition-fast);
}

.table-search input:focus {
  border-color: var(--primary-500);
  box-shadow: 0 0 0 3px rgba(59, 142, 255, 0.15);
}

.table-search .search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

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

.data-table thead {
  position: sticky;
  top: 0;
  z-index: 10;
}

.data-table th {
  padding: 8px 12px;
  text-align: left;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-subtle);
  cursor: pointer;
  user-select: none;
  transition: color var(--transition-fast);
  white-space: nowrap;
}

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

.data-table th.sorted {
  color: var(--primary-400);
}

.data-table th .sort-icon {
  margin-left: 4px;
  opacity: 0.5;
}

.data-table td {
  padding: 6px 12px;
  font-size: 0.82rem;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-subtle);
  white-space: nowrap;
}

.data-table td.numeric {
  font-family: 'JetBrains Mono', monospace;
  text-align: right;
  color: var(--text-primary);
}

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

.data-table tbody tr:hover {
  background: var(--bg-card-hover);
}

.data-table tbody tr.selected {
  background: rgba(59, 142, 255, 0.08);
  border-left: 3px solid var(--primary-500);
}

.table-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: auto;
}

/* Pagination */
.table-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 12px 20px;
  border-top: 1px solid var(--border-subtle);
  font-size: 0.78rem;
  color: var(--text-muted);
  background: var(--bg-secondary);
  border-radius: 0 0 var(--radius-md) var(--radius-md);
}

.pagination-buttons {
  display: flex;
  gap: 4px;
}

.pagination-btn {
  padding: 6px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border-default);
  border-radius: 6px;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.78rem;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.pagination-btn:hover:not(:disabled) {
  background: var(--bg-card-hover);
  border-color: var(--border-active);
  color: var(--text-primary);
}

.pagination-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.pagination-btn.active {
  background: var(--primary-600);
  border-color: var(--primary-500);
  color: white;
}

/* ---- Loading State ---- */
.loading-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  gap: 16px;
}

.loading-screen .spinner-lg {
  width: 48px;
  height: 48px;
  border: 3px solid var(--border-default);
  border-top-color: var(--primary-500);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.loading-screen p {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ---- Empty / Error States ---- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  color: var(--text-muted);
  gap: 8px;
}

.empty-state svg {
  opacity: 0.4;
  margin-bottom: 4px;
}

/* ---- Responsive ---- */
@media (max-width: 1200px) {
  .charts-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 900px) {
  .app-layout {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    min-width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    padding: 12px;
    gap: 12px;
    max-height: 200px;
    overflow-y: auto;
  }

  .sidebar-section {
    min-width: 200px;
    flex: 1;
  }

  .map-wrapper {
  flex: 1.2;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.map-container {
    height: 350px;
    min-height: 300px;
  }

  .stats-grid {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  }
}

/* ---- Animations ---- */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.fade-in {
  animation: fadeIn 0.4s ease-out forwards;
}

.fade-in-delay-1 { animation-delay: 0.1s; opacity: 0; }
.fade-in-delay-2 { animation-delay: 0.2s; opacity: 0; }
.fade-in-delay-3 { animation-delay: 0.3s; opacity: 0; }
.fade-in-delay-4 { animation-delay: 0.4s; opacity: 0; }

/* ============================================================
   Layout Reorganization
   ============================================================ */

/* ── Header: 3-column layout ──────────────────────────────── */
.header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
}

.header-center {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.header-right {
  justify-content: flex-end;
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-palette-icon {
  color: var(--text-muted);
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.header-select {
  padding: 6px 10px;
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.75rem;
  outline: none;
  cursor: pointer;
  transition: border-color var(--transition-fast);
}

.header-select:hover {
  border-color: var(--border-active);
}

/* ── Sidebar: section icon ────────────────────────────────── */
.section-icon {
  width: 11px;
  height: 11px;
  vertical-align: middle;
  margin-right: 5px;
  flex-shrink: 0;
}

/* Sidebar fill remaining height */
.sidebar-section--grow {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}

/* ── Sidebar Summary Stats ────────────────────────────────── */
.sidebar-stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

/* 2-column stat card (wards / households) */
.sidebar-stat {
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  transition: border-color var(--transition-fast);
}

.sidebar-stat:hover {
  border-color: var(--border-default);
}

.sidebar-stat--col {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.sidebar-stat-label {
  font-size: 0.67rem;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  display: flex;
  align-items: center;
  gap: 4px;
}

.stat-label-icon {
  width: 10px;
  height: 10px;
  flex-shrink: 0;
}

.sidebar-stat-value {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  font-family: 'JetBrains Mono', monospace;
  line-height: 1;
}

/* Energy breakdown list (full-width rows) */
.sidebar-energy-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar-energy-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  transition: border-color var(--transition-fast);
}

.sidebar-energy-row:hover {
  border-color: var(--border-default);
}

.sidebar-energy-label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.energy-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.sidebar-energy-value {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-primary);
  font-family: 'JetBrains Mono', monospace;
}

/* ── Sidebar Footer ───────────────────────────────────────── */
.sidebar-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-subtle);
  font-size: 0.68rem;
  color: var(--text-muted);
  flex-shrink: 0;
  margin-top: auto;
  position: sticky;
  bottom: -20px;
  margin-left: -16px;
  margin-right: -16px;
  margin-bottom: -20px;
  z-index: 10;
}

/* ── View Tabs ────────────────────────────────────────────── */
.view-tabs {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.view-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  transition: all var(--transition-fast);
}

.view-tab:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
  border-color: var(--border-default);
}

.view-tab.active {
  background: var(--primary-500);
  color: #fff;
  border-color: var(--primary-500);
  box-shadow: 0 0 0 3px rgba(59, 142, 255, 0.2);
}

/* Context badge (shows selected council name) */
.tab-context-badge {
  margin-left: auto;
  font-size: 0.72rem;
  color: var(--text-muted);
  padding: 5px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: 20px;
  white-space: nowrap;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Updated main-content (no stats row, smaller gap) ────── */
.main-content {
  gap: 12px;
}

/* ── Chart body (replaces anonymous inline div) ───────────── */
.chart-body {
  flex: 1;
  min-height: 0;
  position: relative;
}

/* Ensure charts fill their container */
.widget-charts .chart-card {
  min-height: 320px;
  flex: 1;
}

/* ── Legend title (class-based) ───────────────────────────── */
.legend-label-title {
  font-size: 0.72rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-primary);
}


/* ============================================================
   SPLASH SCREEN
   ============================================================ */
.splash-screen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #06091a 0%, #0d1b38 50%, #08121f 100%);
  transition: opacity 0.6s ease, visibility 0.6s ease;
}
.splash-screen.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
.splash-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  animation: splash-fade-in 0.8s ease both;
}
@keyframes splash-fade-in {
  from { opacity: 0; transform: translateY(24px); }
  to   { opacity: 1; transform: translateY(0); }
}
.splash-logo-wrap {
  width: 130px;
  height: 130px;
  background: white;
  border-radius: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.08), 0 0 40px rgba(59,142,255,0.35), 0 20px 60px rgba(0,0,0,0.5);
  animation: splash-glow 2.5s ease-in-out infinite alternate;
  padding: 12px;
}
@keyframes splash-glow {
  from { box-shadow: 0 0 0 1px rgba(255,255,255,0.08), 0 0 30px rgba(59,142,255,0.25), 0 20px 60px rgba(0,0,0,0.5); }
  to   { box-shadow: 0 0 0 1px rgba(255,255,255,0.12), 0 0 55px rgba(59,142,255,0.5),  0 20px 60px rgba(0,0,0,0.5); }
}
.splash-logo {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.splash-brand {
  text-align: center;
}
.splash-title {
  font-size: 2rem;
  font-weight: 800;
  background: linear-gradient(90deg, #ffffff 0%, #3b8eff 60%, #14b8a6 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.02em;
  line-height: 1.2;
}
.splash-subtitle {
  font-size: 0.9rem;
  color: rgba(255,255,255,0.45);
  margin-top: 6px;
  font-weight: 400;
  letter-spacing: 0.03em;
}
.splash-loader {
  width: 220px;
  height: 3px;
  background: rgba(255,255,255,0.1);
  border-radius: 99px;
  overflow: hidden;
}
.splash-bar {
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, #3b8eff, #14b8a6);
  animation: splash-progress 2.2s ease-in-out forwards;
}
@keyframes splash-progress {
  from { width: 0%; }
  60%  { width: 80%; }
  to   { width: 100%; }
}
.splash-tagline {
  font-size: 0.78rem;
  color: rgba(255,255,255,0.28);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 500;
}
