html,
body {
  height: 100%;
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  color: #111;
}

/* Prevent padding/borders from causing overflow on small screens */
*,
*::before,
*::after {
  box-sizing: border-box;
}

.layout {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  height: 100%;
}

#map {
  height: 100%;
}

.panel {
  padding: 14px;
  overflow: auto;
  border-left: 1px solid #e5e5e5;
  background: #fafafa;
}

.title {
  font-weight: 750;
  margin: 0 0 6px;
  letter-spacing: -0.01em;
}

.hint {
  color: #555;
  font-size: 13px;
  margin: 6px 0 12px;
}

/* ---- grouped controls ---- */
.section {
  background: #fff;
  border: 1px solid #e8e8e8;
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 12px;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.04);
}

.section h3 {
  font-size: 13px;
  margin: 0 0 10px;
  color: #333;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 12px;
  align-items: end;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

label {
  font-size: 12px;
  color: #333;
  font-weight: 650;
}

select,
input[type="range"],
button {
  font: inherit;
}

select {
  padding: 7px 10px;
  border: 1px solid #dcdcdc;
  border-radius: 10px;
  background: white;
  min-width: 0;
  max-width: 100%;
}

.inline {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid #e5e5e5;
  background: #fff;
  font-size: 13px;
}

.pill-group {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid #e5e5e5;
  background: #fff;
  font-size: 13px;
  max-width: 100%;
}

.pill-group label {
  font-weight: 700;
  margin-right: 6px;
}

.pill-option {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  cursor: pointer;
}

.pill-option input {
  accent-color: #333;
}

/* pill-style select */
.pill-select {
  appearance: none;
  border: none;
  background: transparent;
  font: inherit;
  font-weight: 600;
  padding: 2px 16px 2px 4px;
  cursor: pointer;
  min-width: 0;
  max-width: 100%;
}

/* small caret */
.pill-select-wrapper {
  position: relative;
}

.pill-select-wrapper::after {
  content: "▾";
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 10px;
  pointer-events: none;
  opacity: 0.7;
}

.toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid #e5e5e5;
  background: #fff;
}

.toggle label {
  margin: 0;
  font-size: 13px;
  font-weight: 650;
  color: #222;
}

.sliderRow {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
}

.sliderValue {
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: #333;
  white-space: nowrap;
}

/* ---- charts ---- */
.chartTitle {
  font-size: 15px;
  font-weight: 750;
  margin: 0 0 8px;
}

.chartActions {
  display: flex;
  gap: 10px;
  align-items: center;
  margin: 6px 0 10px;
  flex-wrap: wrap;
}

button {
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid #dcdcdc;
  background: #fff;
  cursor: pointer;
}

button:hover {
  background: #f5f5f5;
}

canvas {
  max-width: 100%;
}

a {
  color: inherit;
}

/* ---- legend control (Leaflet overlay) ---- */
.legend {
  background: rgba(255, 255, 255, 0.9);
  padding: 10px 10px;
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
  font-size: 12px;
  line-height: 1.1;
}

.legend .bar {
  width: 220px;
  height: 12px;
  border-radius: 6px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  margin: 6px 0 6px 0;
}

.legend .labels {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-variant-numeric: tabular-nums;
}

.legend .title {
  font-weight: 650;
  margin-bottom: 2px;
}

.info-icon {
  position: relative;
  display: inline-block;
  margin-left: 6px;
  font-size: 0.9em;
  color: #666;
  cursor: pointer;
}

.info-icon:hover {
  color: #000;
}

.info-icon .tooltip {
  visibility: hidden;
  opacity: 0;
  width: 320px;
  background-color: #222;
  color: #fff;
  text-align: left;
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 0.8em;
  line-height: 1.4;

  position: absolute;
  bottom: 125%;
  left: 50%;
  transform: translateX(-50%);

  z-index: 10;
  transition: opacity 0.2s ease;
}

.info-icon .tooltip::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  margin-left: -6px;
  border-width: 6px;
  border-style: solid;
  border-color: #222 transparent transparent transparent;
}

.info-icon:hover .tooltip,
.info-icon:focus .tooltip {
  visibility: visible;
  opacity: 1;
}

/* ===================== Mobile layout ===================== */

@media (max-width: 900px) {
  /* Stack: map on top, panel below */
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: 55vh auto;
    height: 100vh;
  }

  /* Leaflet must have an explicit height */
  #map {
    height: 55vh;
    min-height: 320px;
  }

  /* Let the page scroll naturally on mobile */
  .panel {
    border-left: none;
    border-top: 1px solid #e5e5e5;
    overflow: visible;
  }

  /* Filters grid becomes one column */
  .grid {
    grid-template-columns: 1fr;
  }

  /* Chart view controls: stack pill groups vertically */
  .inline {
    flex-direction: column;
    align-items: stretch;
  }

  /* Make pill groups behave on narrow screens (avoid overflow) */
  .pill-group {
    width: 100%;
    max-width: 100%;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 12px;
    border-radius: 12px;
  }

  /* Put the pill-group label on its own row */
  .pill-group > label {
    flex: 0 0 100%;
    margin: 0;
  }

  /* Keep radio options readable without forcing overflow */
  .pill-option {
    flex: 0 0 auto;
    white-space: nowrap;
  }

  /* Let the select shrink/grow inside the pill group */
  .pill-select-wrapper {
    flex: 1 1 160px;
    min-width: 0;
  }

  .pill-select {
    width: 100%;
    min-width: 0;
  }

  /* Bigger touch targets + prevent iOS zoom on focus */
  select,
  button {
    font-size: 16px;
  }

  /* Make buttons span nicely */
  .chartActions {
    flex-direction: column;
    align-items: stretch;
  }

  .chartActions button {
    width: 100%;
  }

  /* Leaflet legend: keep it from overflowing tiny screens */
  .legend .bar {
    width: 160px;
  }
}
