@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,600;9..144,700&family=DM+Sans:wght@400;500;600;700&display=swap');

:root {
  --bg: #eef3f6;
  --panel: rgba(255, 255, 255, 0.9);
  --panel-border: rgba(19, 43, 71, 0.15);
  --text: #18324f;
  --muted: #4f647d;
  --accent: #0f9f9a;
  --accent-2: #f39a3b;
  --edge-gap: 14px;
  --bottom-height: 262px;
  --insights-width: 360px;
  --filters-width: 295px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  font-family: 'DM Sans', system-ui, sans-serif;
  color: var(--text);
  background: radial-gradient(circle at 0 0, #dfeef8 0%, #eef3f6 45%, #f4f7fa 100%);
  overflow: hidden;
}

#map {
  position: fixed;
  inset: 0;
}

.map-legend-overlay {
  position: fixed;
  left: calc(var(--edge-gap) + var(--insights-width) + 12px);
  right: calc(var(--edge-gap) + var(--filters-width) + 12px);
  bottom: calc(var(--edge-gap) + var(--bottom-height) + 10px);
  width: auto;
  min-width: 260px;
  border-radius: 12px;
  padding: 10px;
  z-index: 19;
}

.map-legend-overlay h3 {
  margin: 0;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #355575;
}

.panel {
  backdrop-filter: blur(10px);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  box-shadow: 0 14px 34px rgba(18, 39, 63, 0.14);
}

.top-shell {
  position: fixed;
  top: var(--edge-gap);
  left: var(--edge-gap);
  right: var(--edge-gap);
  z-index: 20;
  border-radius: 14px;
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  gap: 14px;
}

.top-shell h1 {
  margin: 0;
  font-family: 'Fraunces', serif;
  font-size: 1.26rem;
  letter-spacing: -0.01em;
}

.top-shell p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.loading-chip {
  min-width: 280px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 7px;
}

.status-line {
  font-size: 0.78rem;
  color: var(--muted);
  text-align: right;
}

.status-bar {
  width: min(320px, 34vw);
  height: 10px;
  border-radius: 999px;
  background: rgba(25, 45, 66, 0.14);
  overflow: hidden;
}

.status-fill {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, #19a7a4, #45c6b7, #f39a3b);
  transition: width 0.35s ease;
}

.insights-panel,
.filters-panel {
  position: fixed;
  top: 98px;
  bottom: calc(var(--edge-gap) + var(--bottom-height) + 10px);
  border-radius: 14px;
  padding: 14px;
  overflow: auto;
  z-index: 18;
}

.insights-panel {
  left: var(--edge-gap);
  width: var(--insights-width);
}

.filters-panel {
  right: var(--edge-gap);
  width: var(--filters-width);
}

.insights-panel section + section {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid rgba(20, 44, 73, 0.12);
}

.insights-panel h2 {
  margin: 0;
  font-size: 1.1rem;
}

.insights-panel h3,
.filters-panel h3 {
  margin: 0 0 10px;
  font-size: 0.83rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #36506d;
}

.metric-grid {
  margin-top: 11px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.metric-card {
  border-radius: 10px;
  border: 1px solid rgba(21, 45, 73, 0.14);
  background: rgba(255, 255, 255, 0.72);
  padding: 8px;
}

.metric-label {
  font-size: 0.71rem;
  color: #5c6f84;
}

.metric-value {
  margin-top: 2px;
  font-weight: 700;
  font-size: 0.98rem;
  color: #0f3050;
}

.insight-text {
  margin: 8px 0 0;
  padding: 8px;
  border-radius: 9px;
  border: 1px solid rgba(26, 74, 114, 0.18);
  background: linear-gradient(135deg, rgba(218, 242, 255, 0.42), rgba(237, 248, 255, 0.66));
  font-size: 0.79rem;
  line-height: 1.4;
  color: #214767;
}

.legend-card {
  border: 1px solid rgba(18, 40, 65, 0.14);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.75);
  padding: 9px;
}

.legend-ramp {
  margin-top: 8px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: center;
}

.legend-ramp span {
  font-size: 0.74rem;
  color: #315170;
  font-weight: 700;
}

.legend-gradient {
  height: 10px;
  border-radius: 999px;
  border: 1px solid rgba(11, 34, 58, 0.24);
  background: linear-gradient(90deg, #d6654f, #f0c45e, #1a9f8c);
}

.legend-list {
  margin-top: 9px;
  display: grid;
  gap: 6px;
  color: #355473;
}

.legend-list div {
  display: flex;
  align-items: center;
  gap: 8px;
}

.legend-dot,
.legend-poly,
.legend-selected {
  display: inline-block;
  width: 13px;
  height: 13px;
  border-radius: 999px;
  flex-shrink: 0;
}

.legend-dot {
  background: #1a9f8c;
  border: 1px solid #ffffff;
}

.legend-poly {
  border-radius: 3px;
  background: rgba(26, 159, 140, 0.38);
  border: 1px solid #435e79;
}

.legend-selected {
  background: #ffffff;
  border: 2px solid #173a5b;
}

.accordion {
  border-radius: 9px;
  border: 1px solid rgba(18, 40, 65, 0.14);
  background: rgba(255, 255, 255, 0.72);
  padding: 9px;
}

.accordion + .accordion {
  margin-top: 8px;
}

.accordion summary {
  cursor: pointer;
  font-size: 0.84rem;
  font-weight: 700;
  color: #1c3a59;
}

.accordion[open] summary {
  margin-bottom: 8px;
}

a {
  color: #1f7db0;
}

.filters-panel label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 10px;
  font-size: 0.78rem;
  letter-spacing: 0.01em;
  text-transform: none;
  color: #55708a;
}

.filters-panel select,
.filters-panel input {
  border: 1px solid rgba(17, 39, 63, 0.18);
  border-radius: 8px;
  padding: 9px;
  font-size: 0.92rem;
  color: #18324f;
  background: rgba(255, 255, 255, 0.94);
}

.checkbox-row {
  flex-direction: row;
  align-items: center;
  text-transform: none;
  letter-spacing: normal;
  font-size: 0.84rem;
  color: #2b4866;
  gap: 8px;
}

.charts-shell {
  position: fixed;
  left: var(--edge-gap);
  right: var(--edge-gap);
  bottom: var(--edge-gap);
  height: var(--bottom-height);
  border-radius: 14px;
  padding: 10px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  z-index: 18;
}

.chart-card h3 {
  margin: 0 0 8px;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #36506d;
}

.chart {
  width: 100%;
  height: 205px;
}

.hover-tip {
  position: fixed;
  z-index: 30;
  transform: translate(-50%, -115%);
  pointer-events: none;
  min-width: 220px;
  max-width: 300px;
  border-radius: 10px;
  padding: 9px;
  font-size: 0.78rem;
  color: #eaf6ff;
  background: rgba(20, 39, 61, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 10px 30px rgba(8, 19, 33, 0.4);
}

.hover-tip .title {
  font-weight: 700;
  font-size: 0.88rem;
}

.hover-tip .line {
  margin-top: 4px;
  color: #bdd5e8;
}

.hover-tip.hidden {
  display: none;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.8rem;
  line-height: 1.45;
}

ul,
ol {
  margin: 0;
  padding-left: 18px;
}

li + li {
  margin-top: 4px;
}

@media (max-width: 1200px) {
  :root {
    --bottom-height: 250px;
    --insights-width: 320px;
    --filters-width: 265px;
  }
}

@media (max-width: 980px) {
  body {
    overflow: auto;
  }

  .map-legend-overlay {
    display: none;
  }

  .top-shell,
  .insights-panel,
  .filters-panel,
  .charts-shell {
    position: static;
    width: auto;
    height: auto;
    margin: 10px;
    max-height: none;
  }

  .top-shell {
    flex-direction: column;
  }

  .loading-chip {
    align-items: flex-start;
    min-width: 0;
  }

  .status-line {
    text-align: left;
  }

  .status-bar {
    width: 100%;
  }

  #map {
    position: relative;
    width: calc(100% - 20px);
    height: 55vh;
    margin: 10px;
    border-radius: 14px;
    overflow: hidden;
  }

  .charts-shell {
    grid-template-columns: 1fr;
  }

  .chart {
    height: 230px;
  }
}

@media (max-width: 680px) {
  .top-shell,
  .insights-panel,
  .filters-panel,
  .charts-shell {
    margin: 8px;
    padding: 10px;
  }

  #map {
    width: calc(100% - 16px);
    margin: 8px;
    height: 46vh;
  }

  .metric-grid {
    grid-template-columns: 1fr;
  }
}
