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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  color: #2c3e50;
  overflow: hidden;
}

/* ── Top bar (mobile) ────────────────────────────────────────────────────── */
.topbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  height: 48px;
  padding: 0 12px;
  background: #fff;
  border-bottom: 1px solid #dde3ea;
  position: relative;
  z-index: 1000;
  flex-shrink: 0;
}
.topbar-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border: none;
  background: #f0f2f5;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
  min-height: 44px;
}
.topbar-title {
  font-size: 15px;
  font-weight: 600;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}
.topbar-counter {
  font-size: 12px;
  color: #7f8c8d;
}

/* ── App layout ──────────────────────────────────────────────────────────── */
.app-layout {
  display: flex;
  height: 100vh;
  width: 100%;
  overflow: hidden;
}

/* ── Filter panel ────────────────────────────────────────────────────────── */
.filter-panel {
  width: 280px;
  flex-shrink: 0;
  background: #fff;
  border-right: 1px solid #dde3ea;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 500;
}
.filter-panel-inner {
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow-y: auto;
  height: 100%;
  padding: 0 0 16px;
}

.filter-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 12px;
  border-bottom: 1px solid #f0f2f5;
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 1;
}
.filter-header h2 {
  font-size: 15px;
  font-weight: 600;
}
.icon-btn {
  width: 32px;
  height: 32px;
  border: none;
  background: #f0f2f5;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { background: #e2e6ea; }

.filter-group {
  padding: 10px 16px 0;
}
.filter-group label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 600;
  color: #7f8c8d;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 5px;
}
.filter-group input[type="text"],
.filter-group select {
  width: 100%;
  height: 36px;
  padding: 0 10px;
  border: 1px solid #dde3ea;
  border-radius: 6px;
  font-size: 14px;
  color: #2c3e50;
  background: #fff;
  appearance: none;
  -webkit-appearance: none;
}
.filter-group input[type="text"]:focus,
.filter-group select:focus {
  outline: none;
  border-color: #3498db;
  box-shadow: 0 0 0 3px rgba(52,152,219,.15);
}
.filter-group select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%237f8c8d'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}

/* Range slider */
.range-label {
  font-size: 11px;
  font-weight: 500;
  color: #3498db;
  text-transform: none;
  letter-spacing: 0;
}
.range-wrap {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
  padding: 4px 0;
}
.range-wrap input[type="range"] {
  width: 100%;
  height: 4px;
  appearance: none;
  -webkit-appearance: none;
  background: #dde3ea;
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}
.range-wrap input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #3498db;
  border: 2px solid #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
  cursor: grab;
}
.range-wrap input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #3498db;
  border: 2px solid #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
  cursor: grab;
}
.range-values {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: #7f8c8d;
  padding: 2px 0 0;
}

.filter-actions {
  padding: 14px 16px 0;
  display: flex;
  align-items: center;
  gap: 12px;
}
.btn-reset {
  padding: 0 14px;
  height: 36px;
  border: 1px solid #dde3ea;
  border-radius: 6px;
  background: #fff;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
.btn-reset:hover { background: #f0f2f5; }
.counter {
  font-size: 12px;
  color: #7f8c8d;
  line-height: 1.3;
}

/* ── Map ─────────────────────────────────────────────────────────────────── */
#map {
  flex: 1;
  min-width: 0;
}

/* ── Info panel ──────────────────────────────────────────────────────────── */
.info-panel {
  width: 0;
  flex-shrink: 0;
  background: #fff;
  border-left: 1px solid #dde3ea;
  overflow: hidden;
  transition: width 0.25s ease;
  z-index: 500;
}
.info-panel.open {
  width: 340px;
}
.info-panel-inner {
  width: 340px;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.info-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding: 16px 16px 12px;
  border-bottom: 1px solid #f0f2f5;
  flex-shrink: 0;
}
.info-header h2 {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
  flex: 1;
  word-break: break-word;
}
.info-body {
  overflow-y: auto;
  flex: 1;
  padding: 12px 16px;
}
.info-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.info-table th,
.info-table td {
  padding: 7px 0;
  border-bottom: 1px solid #f0f2f5;
  vertical-align: top;
  text-align: left;
}
.info-table th {
  width: 40%;
  color: #7f8c8d;
  font-weight: 500;
  padding-right: 10px;
  white-space: nowrap;
}
.info-table td { color: #2c3e50; word-break: break-word; }
.info-table tr:last-child th,
.info-table tr:last-child td { border-bottom: none; }

/* ── Legend ──────────────────────────────────────────────────────────────── */
.leaflet-legend {
  background: rgba(255,255,255,.95);
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
  padding: 10px 12px;
  max-width: 200px;
}
.legend-content strong {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #7f8c8d;
}
#legend-list {
  list-style: none;
  margin: 6px 0 8px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
#legend-list li {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
}
.legend-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.leaflet-legend hr {
  border: none;
  border-top: 1px solid #f0f2f5;
  margin: 8px 0;
}
.legend-size {
  font-size: 11px;
  color: #7f8c8d;
  margin-top: 4px;
}
.legend-size svg { display: block; width: 100%; }

/* ── Bar chart ───────────────────────────────────────────────────────────── */
.chart-wrap {
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid #f0f2f5;
}
.chart-label {
  font-size: 11px;
  color: #7f8c8d;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}
.chart-wrap svg {
  display: block;
  width: 100%;
  height: auto;
}

/* ── No-results overlay ──────────────────────────────────────────────────── */
.no-results-overlay {
  background: rgba(255,255,255,.95);
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
  padding: 10px 14px;
  font-size: 13px;
  color: #e74c3c;
  pointer-events: none;
}

/* ── Mobile (≤ 768px) ────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .topbar { display: flex; }

  .app-layout {
    height: calc(100vh - 48px);
    position: relative;
  }

  #map { width: 100%; }

  /* Filter panel: bottom drawer */
  .filter-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 65%;
    border-right: none;
    border-top: 1px solid #dde3ea;
    border-radius: 16px 16px 0 0;
    transform: translateY(100%);
    transition: transform 0.3s ease;
    z-index: 900;
    box-shadow: 0 -4px 20px rgba(0,0,0,.15);
  }
  .filter-panel.open {
    transform: translateY(0);
  }
  .filter-panel-inner {
    padding-bottom: 32px;
  }
  .filter-header {
    padding-top: 20px;
  }
  .filter-header::before {
    content: '';
    display: block;
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 36px;
    height: 4px;
    background: #dde3ea;
    border-radius: 2px;
  }

  /* Info panel: bottom sheet */
  .info-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100% !important;
    height: 55%;
    border-left: none;
    border-top: 1px solid #dde3ea;
    border-radius: 16px 16px 0 0;
    transform: translateY(100%);
    transition: transform 0.3s ease;
    z-index: 900;
    box-shadow: 0 -4px 20px rgba(0,0,0,.15);
  }
  .info-panel.open {
    transform: translateY(0);
  }
  .info-panel-inner {
    width: 100%;
  }
  .info-header {
    padding-top: 20px;
    position: relative;
  }
  .info-header::before {
    content: '';
    display: block;
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 36px;
    height: 4px;
    background: #dde3ea;
    border-radius: 2px;
  }

  /* Touch targets */
  .icon-btn { width: 44px; height: 44px; }
  .btn-reset { height: 44px; }
  .filter-group input[type="text"],
  .filter-group select {
    height: 44px;
    font-size: 16px;
  }
  .filter-group label { font-size: 13px; }
  .range-wrap input[type="range"]::-webkit-slider-thumb {
    width: 22px;
    height: 22px;
  }
  .range-wrap input[type="range"]::-moz-range-thumb {
    width: 22px;
    height: 22px;
  }

  .leaflet-legend { max-width: 160px; }
  #legend-list li { font-size: 11px; }
}
