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

html, body {
  height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  background: #f4f4f4;
  color: #1a1a1a;
}

code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
  background: rgba(255, 255, 255, 0.08);
  padding: 1px 4px;
  border-radius: 3px;
}

#app {
  display: grid;
  grid-template-columns: 260px 1fr 380px;
  grid-template-rows: 100vh;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ──────────────────────────────────────────── */
#sidebar {
  background: #1e2430;
  color: #d0d8e8;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#sidebar h1 {
  font-size: 15px;
  font-weight: 600;
  padding: 16px;
  border-bottom: 1px solid #2e3a4e;
  color: #e8eef8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#sidebar section {
  padding: 14px 16px;
  border-bottom: 1px solid #2e3a4e;
}

#sidebar section h2 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #7a8faa;
  margin-bottom: 10px;
}

.hint {
  font-size: 11px;
  line-height: 1.5;
  color: #7e8da3;
  margin-top: 8px;
}

#layer-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 260px;
  overflow-y: auto;
}

#layer-list:empty {
  display: none;
}

#layer-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 4px 0;
}

#layer-list li input[type="checkbox"] {
  flex-shrink: 0;
  cursor: pointer;
}

#layer-list li label {
  cursor: pointer;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 13px;
  color: #c8d4e4;
}

#year-select {
  width: 100%;
  padding: 6px 8px;
  background: #2e3a4e;
  color: #d0d8e8;
  border: 1px solid #3e4e66;
  border-radius: 4px;
  font-size: 13px;
}

.btn {
  display: inline-block;
  padding: 6px 12px;
  background: #3a7bd5;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  margin-top: 10px;
}

.btn:hover {
  background: #2a6bc5;
}

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
}

/* ── Map ──────────────────────────────────────────────── */
#map-wrapper {
  position: relative;
  overflow: hidden;
}

#map {
  width: 100%;
  height: 100%;
}

#error-banner {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  background: #c0392b;
  color: #fff;
  padding: 8px 16px;
  font-size: 13px;
  z-index: 10;
  display: none;
}

#error-banner.visible {
  display: block;
}

/* ── Right panel ──────────────────────────────────────── */
#right-panel {
  background: #fff;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-left: 1px solid #dde3ec;
  min-width: 0;  /* allow children to shrink below content size */
}

#right-panel section {
  padding: 14px 16px;
  border-bottom: 1px solid #dde3ec;
  min-width: 0;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

#right-panel h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #666;
  margin: 0;
}

.pill {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  color: #1e3a5f;
  background: #e8f0fa;
  padding: 2px 8px;
  border-radius: 10px;
  white-space: nowrap;
}

.muted {
  color: #aaa;
  font-weight: 400;
  font-size: 11px;
}

/* ── Stats ────────────────────────────────────────────── */
#stats-section {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  /* Cap so that runs-section always gets scroll room when 30 districts are listed. */
  max-height: 62vh;
  overflow: hidden;
}

#stats-no-data {
  color: #888;
  font-size: 13px;
  line-height: 1.5;
}

#stats-kpis {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.kpi {
  background: #f4f7fb;
  border: 1px solid #e4ebf3;
  border-radius: 6px;
  padding: 10px 8px;
  text-align: center;
  cursor: help;
  min-width: 0;  /* prevent grid from overflowing */
}

.kpi-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: #5a6a82;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kpi-value {
  display: block;
  font-size: 20px;
  font-weight: 700;
  color: #1e3a5f;
  font-variant-numeric: tabular-nums;
  margin: 2px 0 1px;
}

.kpi-unit {
  display: block;
  font-size: 10px;
  color: #8a99b0;
  text-transform: lowercase;
}

.subsection-title {
  font-size: 12px;
  font-weight: 600;
  color: #555;
  margin-bottom: 6px;
  display: flex;
  align-items: baseline;
  gap: 6px;
}

/* ── Tables ───────────────────────────────────────────── */
.table-scroll {
  overflow-y: auto;
  overflow-x: auto;
}

.table-scroll--bounded {
  max-height: 340px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  /* auto layout: each column takes exactly as much space as its content needs */
  table-layout: auto;
}

.data-table th,
.data-table td {
  padding: 5px 8px;
  text-align: left;
  border-bottom: 1px solid #edf0f5;
  white-space: nowrap;
}

.data-table th {
  color: #777;
  font-weight: 600;
  background: #f9fafb;
  position: sticky;
  top: 0;
  z-index: 1;
}

.data-table th.num,
.data-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* District name: allow shrink with ellipsis; numeric cols size to content. */
.data-table--numeric td:nth-child(1) {
  max-width: 130px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.data-table tbody tr:hover {
  background: #f7f9fc;
}

/* ── Runs ─────────────────────────────────────────────── */
#runs-section {
  flex: 1 1 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#runs-section .table-scroll {
  overflow-y: auto;
  flex: 1 1 0;
}

/* Run ID column: truncate long ids with ellipsis; other cols size to content. */
#runs-table td:nth-child(1) {
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
}

.status-success  { background: #d4edda; color: #155724; }
.status-failed   { background: #f8d7da; color: #721c24; }
.status-running  { background: #cce5ff; color: #004085; }
.status-unknown  { background: #e2e3e5; color: #383d41; }
