:root {
  --bg: #f4f0e5;
  --panel: #fffdfa;
  --ink: #1f2a30;
  --muted: #5b6b73;
  --accent: #0f766e;
  --accent-soft: #d9f1ee;
  --line: #d4cec0;
  --warn: #d97706;
  --high: #b91c1c;
  --low: #15803d;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "IBM Plex Sans", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 10%, #fceec6 0%, #f4f0e5 35%),
    linear-gradient(135deg, #f8f6ef 0%, #ebe7db 100%);
  min-height: 100vh;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 253, 250, 0.88);
  backdrop-filter: blur(8px);
}

.topbar h1 {
  margin: 0;
  font-family: "Space Grotesk", sans-serif;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(160px, 1fr));
  gap: 10px;
}

.controls label {
  display: flex;
  flex-direction: column;
  font-size: 12px;
  color: var(--muted);
  gap: 4px;
}

select {
  border: 1px solid #b8b09d;
  border-radius: 10px;
  padding: 9px 10px;
  background: #fff;
  color: var(--ink);
  font-size: 14px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 460px;
  height: calc(100vh - 88px);
}

.map-panel {
  position: relative;
  border-right: 1px solid var(--line);
}

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

.legend {
  position: absolute;
  left: 16px;
  bottom: 16px;
  background: rgba(255, 253, 250, 0.94);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  min-width: 220px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
  font-size: 12px;
}

.legend-bar {
  margin-top: 6px;
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(to right, #e9f7ef, #f8cb7b, #d65f49);
}

.legend-scale {
  margin-top: 4px;
  display: flex;
  justify-content: space-between;
  color: var(--muted);
}

.sidebar {
  padding: 10px 12px;
  overflow-y: auto;
}

.empty {
  border: 1px dashed var(--line);
  border-radius: 14px;
  padding: 18px;
  background: rgba(255, 255, 255, 0.65);
}

.empty h2 {
  margin: 0 0 8px;
  font-family: "Space Grotesk", sans-serif;
}

.hidden {
  display: none;
}

.summary-card,
.chart-card,
.stage-matrix,
.explain {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  margin-bottom: 10px;
}

.summary-card h2 {
  margin: 0;
  font-family: "Space Grotesk", sans-serif;
  font-size: 21px;
}

.summary-card p {
  margin: 6px 0 0;
}

.headline {
  font-weight: 600;
  color: #1f3b35;
  background: var(--accent-soft);
  border: 1px solid #b8dfd9;
  border-radius: 10px;
  padding: 8px 10px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.kpi-grid article {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
}

.kpi-grid h3 {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.2px;
  color: var(--muted);
  text-transform: uppercase;
}

.kpi-grid p {
  margin: 6px 0;
  font-weight: 700;
  font-family: "Space Grotesk", sans-serif;
  font-size: 21px;
}

.kpi-grid small {
  color: var(--muted);
}

.stage-matrix h3,
.chart-card h3 {
  margin: 0 0 8px;
  font-family: "Space Grotesk", sans-serif;
}

.stage-matrix summary {
  cursor: pointer;
  font-family: "Space Grotesk", sans-serif;
  font-weight: 600;
  margin-bottom: 8px;
}

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

.stage-matrix th,
.stage-matrix td {
  padding: 8px 6px;
  border-bottom: 1px solid #ece6da;
  text-align: left;
}

.stage-matrix tr:last-child td {
  border-bottom: none;
}

.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.badge.low {
  background: #e8f7ec;
  color: var(--low);
}

.badge.moderate {
  background: #fff3df;
  color: var(--warn);
}

.badge.high {
  background: #fde8e8;
  color: var(--high);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.card-head select {
  width: 150px;
  font-size: 12px;
  padding: 6px 8px;
}

canvas {
  width: 100%;
  height: 260px !important;
  min-height: 260px;
  max-height: 260px;
}

.dist-note {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.explain summary {
  cursor: pointer;
  font-weight: 600;
  font-family: "Space Grotesk", sans-serif;
}

.explain ul {
  margin: 8px 0 0;
  padding-left: 18px;
  color: var(--muted);
}

@media (max-width: 1120px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: 54vh 46vh;
    height: auto;
  }

  .map-panel {
    border-right: none;
    border-bottom: 1px solid var(--line);
  }

  #map {
    min-height: 52vh;
  }

  .controls {
    grid-template-columns: 1fr;
    width: 100%;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }
}
