:root {
  --surface-1:      #fcfcfb;
  --page-plane:     #f9f9f7;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;
  --gridline:       #e1e0d9;
  --baseline:       #c3c2b7;
  --border:         rgba(11, 11, 11, 0.10);

  --series-residential:      #2a78d6; /* blue */
  --series-commercial:       #1baf7a; /* aqua */
  --series-interdepartmental:#eda100; /* yellow */
  --series-other:            #008300; /* green */
  --total-bar:               #5b7a99; /* neutral steel blue, distinct from class series */
}

@media (prefers-color-scheme: dark) {
  :root {
    --surface-1:      #1a1a19;
    --page-plane:     #0d0d0d;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --gridline:       #2c2c2a;
    --baseline:       #383835;
    --border:         rgba(255, 255, 255, 0.10);

    --series-residential:      #3987e5;
    --series-commercial:       #199e70;
    --series-interdepartmental:#c98500;
    --series-other:            #008300;
    --total-bar:               #7fa1c4;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--page-plane);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

body {
  padding: 24px;
  max-width: 1180px;
  margin: 0 auto;
}

header h1 {
  font-size: 22px;
  font-weight: 600;
  margin: 0 0 2px;
}

header p {
  margin: 0 0 20px;
  color: var(--text-secondary);
  font-size: 13px;
}

#status {
  font-size: 13px;
  color: var(--text-muted);
}
#status.error { color: #d03b3b; }

/* Filters row */
.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 20px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 20px;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
}

.filter-group select {
  font: inherit;
  color: var(--text-primary);
  background: var(--page-plane);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
}

.legend-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-left: auto;
}

.legend-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-primary);
  cursor: pointer;
  user-select: none;
}

.legend-toggle .swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex: none;
}

.legend-toggle input { accent-color: currentColor; margin: 0; }
.legend-toggle.off { color: var(--text-muted); }
.legend-toggle.off .swatch { opacity: 0.25; }

/* Stat tiles */
.stat-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.stat-tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
}

.stat-tile .label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.stat-tile .value {
  font-size: 24px;
  font-weight: 600;
  font-variant-numeric: proportional-nums;
}

.stat-tile .sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Chart cards */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 16px 8px;
  margin-bottom: 20px;
}

.card h2 {
  font-size: 14px;
  font-weight: 600;
  margin: 0 0 12px;
}

.chart-scroll {
  overflow-x: auto;
}

svg text {
  fill: var(--text-secondary);
  font-size: 11px;
}

.axis path,
.axis line {
  stroke: var(--gridline);
}

.axis.x-axis path {
  stroke: var(--baseline);
}

.gridline {
  stroke: var(--gridline);
  stroke-width: 1px;
}

.crosshair {
  stroke: var(--baseline);
  stroke-width: 1px;
  pointer-events: none;
}

.series-line {
  fill: none;
  stroke-width: 2px;
}

.series-dot {
  stroke: var(--surface-1);
  stroke-width: 2px;
}

.bar {
  shape-rendering: crispEdges;
}

/* Tooltip */
.tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  opacity: 0;
  transition: opacity 0.1s ease;
  z-index: 10;
}

.tooltip .tt-title {
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.tooltip-row {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.tooltip-row .key {
  width: 10px;
  height: 2px;
  flex: none;
}

.tooltip-row .val {
  font-weight: 600;
  color: var(--text-primary);
  margin-left: auto;
  padding-left: 10px;
  font-variant-numeric: tabular-nums;
}

.tooltip-row .name {
  color: var(--text-secondary);
}

/* Table */
.table-scroll {
  overflow-x: auto;
  max-height: 360px;
  overflow-y: auto;
  border-top: 1px solid var(--gridline);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead th {
  position: sticky;
  top: 0;
  background: var(--surface-1);
  text-align: left;
  padding: 8px 10px;
  color: var(--text-secondary);
  font-weight: 600;
  border-bottom: 1px solid var(--gridline);
}

tbody td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--gridline);
  font-variant-numeric: tabular-nums;
}

tbody td.num { text-align: right; }

footer {
  color: var(--text-muted);
  font-size: 12px;
  margin-top: 24px;
  padding-top: 12px;
  border-top: 1px solid var(--gridline);
}

footer a { color: inherit; }
