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

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: #f5f5f5;
  color: #333;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

header {
  background: #1a1a2e;
  color: #e0e0e0;
  padding: 10px 20px;
  display: flex;
  align-items: baseline;
  gap: 16px;
  flex-shrink: 0;
}
header h1 {
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
}
header .subtitle {
  font-size: 12px;
  color: #aaa;
}

/* Dashboard grid */
.dashboard {
  display: grid;
  grid-template-columns: 260px 1fr 300px;
  flex: 1;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  background: #fff;
  border-right: 1px solid #ddd;
  overflow-y: auto;
  padding: 12px;
}
.sidebar h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #666;
  margin-bottom: 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid #eee;
}
.sidebar section { margin-bottom: 16px; }

/* Layer toggles */
.layer-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  font-size: 13px;
}
.layer-item input[type="checkbox"] {
  accent-color: #4a90d9;
  width: 16px;
  height: 16px;
  cursor: pointer;
}
.layer-item label {
  cursor: pointer;
  flex: 1;
}
.layer-item select {
  font-size: 11px;
  padding: 2px 4px;
  border: 1px solid #ccc;
  border-radius: 3px;
  background: #f9f9f9;
}

/* Legend */
#legend-content { font-size: 12px; }
.legend-gradient {
  margin: 6px 0 12px;
}
.gradient-bar {
  height: 12px;
  border-radius: 2px;
  margin-bottom: 2px;
}
.legend-labels {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: #666;
}
.legend-title {
  font-size: 11px;
  color: #888;
  margin-top: 2px;
}
.legend-categorical {
  margin: 4px 0;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 2px 0;
  font-size: 12px;
}
.legend-swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  flex-shrink: 0;
  border: 1px solid rgba(0,0,0,0.15);
}

/* Detail panel */
#detail-content table {
  width: 100%;
  font-size: 12px;
  border-collapse: collapse;
}
#detail-content td {
  padding: 3px 4px;
  border-bottom: 1px solid #f0f0f0;
}
#detail-content td:first-child {
  color: #888;
  width: 45%;
}
#detail-content td:last-child {
  font-weight: 500;
  text-align: right;
}

/* Map */
#map-container {
  position: relative;
  overflow: hidden;
}
#map { width: 100%; height: 100%; }

/* Tooltip */
.tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(255,255,255,0.95);
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 6px 10px;
  font-size: 12px;
  line-height: 1.4;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
  z-index: 10;
  max-width: 240px;
}
.tooltip strong { color: #1a1a2e; }

/* Charts panel */
.charts-panel {
  background: #fff;
  border-left: 1px solid #ddd;
  overflow-y: auto;
  padding: 12px;
}
.chart-section {
  margin-bottom: 16px;
}
.chart-section h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: #666;
  margin-bottom: 6px;
}
.chart-wrapper {
  position: relative;
  height: 180px;
}
.chart-wrapper.chart-tall {
  height: 320px;
}

/* Stats summary */
#stats-content {
  font-size: 12px;
  line-height: 1.6;
}
#stats-content .stat-row {
  display: flex;
  justify-content: space-between;
  padding: 2px 0;
  border-bottom: 1px solid #f0f0f0;
}
#stats-content .stat-label { color: #888; }
#stats-content .stat-value { font-weight: 600; }
#stats-content .correlation-box {
  margin-top: 8px;
  padding: 8px;
  background: #f0f7ff;
  border-radius: 4px;
  border-left: 3px solid #4a90d9;
}
#stats-content .correlation-value {
  font-size: 20px;
  font-weight: 700;
  color: #1a1a2e;
}
#stats-content .correlation-label {
  font-size: 11px;
  color: #666;
}

.hidden { display: none !important; }

/* Sidebar toggle button — hidden on desktop */
.sidebar-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  background: #1a1a2e;
  color: #fff;
  border: none;
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
  width: 100%;
  gap: 6px;
}
.sidebar-toggle:hover {
  background: #2a2a4e;
}

/* Responsive — tablet */
@media (max-width: 1024px) {
  .dashboard {
    grid-template-columns: 220px 1fr;
    grid-template-rows: 1fr auto;
  }
  .charts-panel {
    grid-column: 1 / -1;
    border-left: none;
    border-top: 1px solid #ddd;
    max-height: 250px;
    display: flex;
    gap: 12px;
    overflow-x: auto;
  }
  .chart-section { min-width: 250px; }
}

/* Responsive — mobile: stack all blocks vertically */
@media (max-width: 768px) {
  body {
    height: auto;
    overflow: auto;
  }

  header {
    flex-direction: column;
    gap: 4px;
    padding: 10px 12px;
  }
  header h1 {
    font-size: 14px;
    white-space: normal;
  }

  .dashboard {
    display: flex;
    flex-direction: column;
    overflow: visible;
  }

  /* Sidebar — collapsed by default on mobile */
  .sidebar {
    border-right: none;
    border-bottom: 1px solid #ddd;
    order: 1;
    display: none;
  }
  .sidebar.open {
    display: block;
  }

  /* Map — full width, fixed height */
  #map-container {
    order: 2;
    height: 50vh;
    min-height: 300px;
  }

  /* Charts — stacked vertically below map */
  .charts-panel {
    order: 3;
    border-left: none;
    border-top: 1px solid #ddd;
    max-height: none;
    overflow-x: visible;
    overflow-y: visible;
    display: block;
  }
  .charts-panel .chart-section {
    min-width: unset;
  }
  .charts-panel .chart-wrapper {
    height: 200px;
  }
  .charts-panel .chart-wrapper.chart-tall {
    height: 280px;
  }

  /* Sidebar toggle visible on mobile */
  .sidebar-toggle {
    display: flex;
    order: 0;
  }
}
