:root {
  --ink: #0b1320;
  --slate: #2c3a4d;
  --mist: #f3f5f7;
  --sun: #f4c430;
  --leaf: #2f8f4e;
  --ember: #c0392b;
  --coal: #111111;
  --oasis: #2a9d8f;
  --sky: #1f78b4;
  --card: rgba(255, 255, 255, 0.96);
  --shadow: 0 18px 40px rgba(10, 20, 40, 0.16);
  --chrome-bottom: 0px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
  color: var(--ink);
  background: radial-gradient(
    circle at 20% 20%,
    #f8f6f0 0%,
    #e9edf2 40%,
    #dfe6ef 100%
  );
}

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

.app {
  position: relative;
  height: 100%;
  width: 100%;
}

.panel {
  position: absolute;
  top: 18px;
  right: 18px;
  z-index: 1000;
  width: min(360px, 92vw);
  background: var(--card);
  border-radius: 18px;
  padding: 16px 18px 14px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
}

.panel-toggle {
  display: inline-flex;
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 1100;
  border: none;
  border-radius: 999px;
  padding: 10px 14px;
  background: #111827;
  color: #ffffff;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 10px 20px rgba(17, 24, 39, 0.28);
}

.panel h1 {
  font-family: "Fraunces", serif;
  font-weight: 700;
  font-size: 22px;
  margin: 0 0 6px;
}

.panel p {
  margin: 0 0 12px;
  color: var(--slate);
  font-size: 13px;
}

.chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.chip {
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 160ms ease;
}

.chip.primary {
  background: rgba(47, 143, 78, 0.12);
  color: var(--leaf);
  border-color: rgba(47, 143, 78, 0.3);
}

.chip.secondary {
  background: rgba(31, 120, 180, 0.12);
  color: var(--sky);
  border-color: rgba(31, 120, 180, 0.3);
}

.chip.active {
  transform: translateY(-1px);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.08);
}

.field {
  margin-bottom: 10px;
}

label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--slate);
}

input,
select {
  width: 100%;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid #d5dbe3;
  background: #ffffff;
  font-size: 13px;
}

.field-hint {
  margin-top: 4px;
  font-size: 11px;
  color: #6b778a;
}

.multi-select {
  position: relative;
}

.multi-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid #d5dbe3;
  background: #ffffff;
  font-size: 13px;
  cursor: pointer;
}

.multi-caret {
  font-size: 12px;
  color: #6b778a;
}

.multi-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  max-height: 220px;
  overflow: auto;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
  background: #ffffff;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.12);
  padding: 8px;
  display: none;
  z-index: 1200;
}

.multi-actions {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.multi-action-btn {
  flex: 1;
  border: 1px solid #e2e8f0;
  background: #f8fafc;
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}

.multi-action-btn:hover {
  background: #eef2f7;
}

.multi-select.open .multi-menu {
  display: block;
}

.multi-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 6px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
}

.multi-option:hover {
  background: #f4f6f9;
}

.multi-option input {
  width: 14px;
  height: 14px;
}

.reset-btn {
  width: 100%;
  border: none;
  border-radius: 10px;
  padding: 8px 10px;
  background: #111827;
  color: #ffffff;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 140ms ease, box-shadow 140ms ease;
}

.reset-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 16px rgba(17, 24, 39, 0.25);
}

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

.stat {
  background: #ffffff;
  border-radius: 12px;
  padding: 8px 10px;
  border: 1px solid #e5e9ef;
}

.stat span {
  display: block;
  font-size: 11px;
  color: #627085;
}

.stat strong {
  font-size: 16px;
}

.legend {
  position: absolute;
  bottom: 18px;
  left: 18px;
  z-index: 1000;
  background: var(--card);
  border-radius: 14px;
  padding: 10px 12px;
  box-shadow: var(--shadow);
  font-size: 12px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0;
}

.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.dot.primary {
  background: var(--leaf);
  box-shadow: 0 0 10px rgba(47, 143, 78, 0.5);
}

.dot.secondary {
  background: var(--sky);
  box-shadow: 0 0 10px rgba(31, 120, 180, 0.5);
}

.story {
  margin-top: 10px;
  padding: 10px 12px;
  background: linear-gradient(
    135deg,
    rgba(244, 196, 48, 0.15),
    rgba(47, 143, 78, 0.12)
  );
  border-radius: 12px;
  font-size: 12px;
}

.leaflet-popup-content-wrapper {
  border-radius: 14px;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.18);
}

.popup-title {
  font-family: "Fraunces", serif;
  font-weight: 700;
  font-size: 16px;
  margin-bottom: 4px;
}

.popup-row {
  font-size: 12px;
  color: var(--slate);
}

.school-marker {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid #ffffff;
  box-shadow: 0 0 12px rgba(0, 0, 0, 0.25);
}

.marker-primary {
  background: var(--leaf);
}

.marker-secondary {
  background: var(--sky);
}

.cluster-icon {
  background: transparent;
}

.cluster-bubble {
  width: var(--cluster-size, 36px);
  height: var(--cluster-size, 36px);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(
    circle at 30% 30%,
    rgba(244, 196, 48, 0.9),
    rgba(17, 17, 17, 0.9)
  );
  color: #fff;
  font-weight: 700;
  font-size: 12px;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.2);
}

.loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.78);
  z-index: 2000;
  font-weight: 600;
}

@media (min-width: 901px) and (hover: hover) and (pointer: fine) {
  .panel-toggle {
    display: none;
  }
}

@media (max-width: 900px), (hover: none) and (pointer: coarse) {
  .panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: env(safe-area-inset-bottom);
    top: auto;
    width: auto;
    margin: 0;
    border-radius: 18px 18px 0 0;
    max-height: 60vh;
    overflow: auto;
    padding-bottom: calc(14px + env(safe-area-inset-bottom));
    transition: transform 180ms ease;
  }
  body.panel-collapsed .panel {
    transform: translateY(100%);
  }
  .panel-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    top: auto;
    left: 12px;
    right: auto;
    bottom: calc(12px + env(safe-area-inset-bottom) + var(--chrome-bottom));
  }
  .legend {
    left: auto;
    right: 12px;
    top: 12px;
    bottom: auto;
  }
  .app {
    min-height: 100vh;
  }
  #map {
    height: 100vh;
  }
}

@supports (height: 100dvh) {
  @media (max-width: 900px), (hover: none) and (pointer: coarse) {
    .panel {
      max-height: 60dvh;
    }
    #map {
      height: 100dvh;
    }
  }
}
