:root {
  --green: #158300;
  --light-green: #86b523;
  --yellow: #d7ca39;
  --orange: #f39a25;
  --red: #b51d18;
  --missing: #7d8288;
  --ink: #263247;
  --muted: #657083;
  --panel: #ffffff;
  --strip: #fff0aa;
  --shadow: 0 8px 24px rgba(24, 32, 44, 0.18);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* Critical Leaflet layout rules. The CDN Leaflet CSS can fail inside embedded
   browsers; without these, tiles and marker panes participate in page layout. */
.leaflet-container {
  position: relative;
  overflow: hidden !important;
  background: #dce9ee;
  outline: 0;
  touch-action: none;
}

.leaflet-pane,
.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow,
.leaflet-tile-container,
.leaflet-pane > svg,
.leaflet-pane > canvas,
.leaflet-zoom-box,
.leaflet-image-layer,
.leaflet-layer {
  position: absolute;
  left: 0;
  top: 0;
}

.leaflet-pane {
  z-index: 400;
}

.leaflet-tile-pane {
  z-index: 200;
}

.leaflet-overlay-pane {
  z-index: 400;
}

.leaflet-shadow-pane {
  z-index: 500;
}

.leaflet-marker-pane {
  z-index: 600;
}

.leaflet-tooltip-pane {
  z-index: 650;
}

.leaflet-popup-pane {
  z-index: 700;
}

.leaflet-map-pane {
  z-index: auto;
}

.leaflet-tile {
  width: 256px;
  height: 256px;
  user-select: none;
}

.leaflet-tile-loaded {
  visibility: inherit;
}

.leaflet-marker-icon,
.leaflet-marker-shadow {
  display: block;
}

.leaflet-interactive {
  cursor: pointer;
}

.leaflet-control {
  position: relative;
  z-index: 800;
  pointer-events: auto;
}

.leaflet-left .leaflet-control {
  margin-left: 12px;
}

.leaflet-bottom .leaflet-control {
  margin-bottom: calc(18px + var(--safe-bottom));
}

.leaflet-top,
.leaflet-bottom {
  position: absolute;
  z-index: 800;
  pointer-events: none;
}

.leaflet-top {
  top: 0;
}

.leaflet-right {
  right: 0;
}

.leaflet-bottom {
  bottom: 0;
}

.leaflet-left {
  left: 0;
}

.leaflet-control-zoom {
  border: 1px solid rgba(45, 55, 70, 0.2);
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 3px 10px rgba(24, 32, 44, 0.18);
}

.leaflet-control-zoom a {
  display: block;
  width: 30px;
  height: 30px;
  background: #fff;
  color: #263247;
  line-height: 30px;
  text-align: center;
  text-decoration: none;
  font-size: 18px;
  font-weight: 800;
}

.leaflet-control-zoom a + a {
  border-top: 1px solid rgba(45, 55, 70, 0.14);
}

.leaflet-popup {
  position: absolute;
  text-align: center;
  margin-bottom: 20px;
}

.leaflet-popup-content-wrapper {
  padding: 1px;
  text-align: left;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 5px 18px rgba(24, 32, 44, 0.22);
}

.leaflet-popup-content {
  margin: 13px 16px;
  min-width: 190px;
}

.leaflet-popup-tip-container {
  width: 40px;
  height: 20px;
  position: absolute;
  left: 50%;
  margin-left: -20px;
  overflow: hidden;
  pointer-events: none;
}

.leaflet-popup-tip {
  width: 17px;
  height: 17px;
  padding: 1px;
  margin: -10px auto 0;
  transform: rotate(45deg);
  background: #fff;
  box-shadow: 0 5px 18px rgba(24, 32, 44, 0.18);
}

.leaflet-popup-close-button {
  position: absolute;
  top: 0;
  right: 0;
  padding: 6px 8px 0 0;
  color: #687385;
  text-decoration: none;
  font-size: 18px;
  font-weight: 800;
}

* {
  box-sizing: border-box;
}

html,
body,
.app-shell,
.map-panel,
#map {
  width: 100%;
  height: 100%;
  margin: 0;
}

html,
body {
  height: 100%;
  height: 100dvh;
}

body {
  overflow: hidden;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button {
  font: inherit;
}

.map-panel {
  position: relative;
  background: #e8f3f7;
  overflow: hidden;
}

#map {
  z-index: 0;
}

.top-strip {
  position: absolute;
  z-index: 600;
  top: 0;
  left: 0;
  right: 0;
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 18px 10px 20px;
  background: var(--strip);
  border-bottom: 1px solid rgba(60, 71, 91, 0.14);
  box-shadow: 0 2px 8px rgba(50, 55, 65, 0.08);
}

.top-strip > div {
  min-width: 0;
}

.top-strip h1 {
  margin: 0;
  color: #28324a;
  font-size: clamp(18px, 2vw, 24px);
  font-weight: 800;
  line-height: 1.05;
}

.top-strip p {
  margin: 3px 0 0;
  color: #515b6d;
  font-size: 13px;
  font-weight: 600;
}

.icon-button {
  min-width: 42px;
  min-height: 36px;
  padding: 7px 12px;
  border: 1px solid rgba(44, 55, 75, 0.18);
  border-radius: 6px;
  background: #ffffff;
  color: #243049;
  font-weight: 750;
  box-shadow: 0 2px 8px rgba(35, 43, 55, 0.12);
  cursor: pointer;
}

.callouts {
  position: absolute;
  z-index: 610;
  top: 74px;
  left: 18px;
  display: grid;
  gap: 10px;
  width: min(390px, calc(100vw - 36px));
  pointer-events: none;
}

.callout {
  pointer-events: auto;
  width: fit-content;
  max-width: 100%;
  display: grid;
  grid-template-columns: 15px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 9px 13px;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.94);
  color: #333a46;
  box-shadow: var(--shadow);
  font-size: 14px;
  font-weight: 800;
  text-align: left;
  cursor: pointer;
}

.callout::before,
.legend-dot {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  display: inline-block;
  content: "";
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.75);
}

.callout span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#cheapestCallout::before {
  background: var(--green);
}

#expensiveCallout::before {
  background: var(--red);
}

.legend {
  position: absolute;
  z-index: 610;
  right: 18px;
  bottom: calc(22px + var(--safe-bottom));
  width: min(270px, calc(100vw - 36px));
  padding: 12px 13px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.legend-toggle {
  display: none;
}

.legend-items {
  display: block;
}

.map-status {
  position: absolute;
  z-index: 610;
  left: 58px;
  bottom: calc(22px + var(--safe-bottom));
  max-width: min(320px, calc(100vw - 36px));
  padding: 8px 11px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  color: #4b5563;
  box-shadow: 0 4px 14px rgba(35, 43, 55, 0.12);
  font-size: 12px;
  font-weight: 750;
}

.legend h2 {
  margin: 0 0 10px;
  color: #263247;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.legend-row {
  display: grid;
  grid-template-columns: 16px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  color: #384457;
  font-size: 13px;
  font-weight: 700;
}

.legend-count {
  color: #6b7485;
  font-weight: 650;
}

.legend-row em {
  display: block;
  margin-top: 1px;
  color: #6b7485;
  font-size: 11px;
  font-style: normal;
  font-weight: 750;
}

.insights-panel {
  position: absolute;
  z-index: 620;
  top: 74px;
  right: 18px;
  width: min(380px, calc(100vw - 36px));
  padding: 16px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-header h2 {
  margin: 0;
}

.project-summary {
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(56, 68, 87, 0.12);
}

.project-summary p {
  margin: 0;
  color: #4b5563;
  font-size: 14px;
  line-height: 1.45;
}

.project-summary p + p {
  margin-top: 8px;
}

.project-summary a {
  color: #1f5fae;
  font-weight: 800;
  text-decoration: underline;
  text-underline-offset: 2px;
}

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

.stats-grid div {
  padding: 12px;
  border: 1px solid rgba(56, 68, 87, 0.12);
  border-radius: 8px;
  background: #f8fafc;
}

.stats-grid dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.stats-grid dd {
  margin: 3px 0 0;
  color: var(--ink);
  font-size: 20px;
  font-weight: 850;
}

.price-marker-shell {
  width: 12px;
  height: 12px;
  background: transparent;
  border: 0;
}

.price-marker-dot {
  display: block;
  width: 11px;
  height: 11px;
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(25, 35, 50, 0.28);
}

.leaflet-popup-content-wrapper {
  border-radius: 8px;
}

.popup-title {
  margin: 0 0 6px;
  color: var(--ink);
  font-size: 15px;
  font-weight: 850;
}

.popup-price {
  margin: 0 0 8px;
  color: #1f2937;
  font-size: 20px;
  font-weight: 900;
}

.popup-meta {
  margin: 0;
  color: #4b5563;
  font-size: 13px;
  line-height: 1.35;
}

@media (max-width: 700px), (max-height: 500px) {
  .top-strip {
    align-items: center;
    min-height: 82px;
    padding: 8px 10px;
  }

  .top-strip p {
    display: block;
    max-width: calc(100vw - 96px);
    font-size: 11px;
    line-height: 1.25;
  }

  .callouts {
    top: 92px;
    left: 10px;
  }

  .legend {
    right: 10px;
    bottom: calc(86px + var(--safe-bottom));
    width: min(270px, calc(100vw - 20px));
    padding: 0;
    overflow: hidden;
  }

  .legend h2 {
    display: none;
  }

  .legend-toggle {
    width: 100%;
    min-height: 44px;
    display: grid;
    grid-template-columns: auto 1fr 14px;
    align-items: center;
    gap: 9px;
    padding: 9px 12px;
    border: 0;
    background: transparent;
    color: #263247;
    font-size: 13px;
    font-weight: 800;
    text-align: left;
    cursor: pointer;
  }

  .legend-swatches {
    display: flex;
    justify-content: flex-end;
  }

  .legend-swatches i {
    width: 11px;
    height: 11px;
    margin-left: -2px;
    border: 1px solid rgba(255, 255, 255, 0.9);
    border-radius: 50%;
  }

  .legend-chevron {
    width: 8px;
    height: 8px;
    border-right: 2px solid #657083;
    border-bottom: 2px solid #657083;
    transform: rotate(45deg) translateY(-2px);
    transition: transform 160ms ease;
  }

  .legend-items {
    display: none;
    padding: 0 12px 10px;
  }

  .legend.is-expanded .legend-items {
    display: block;
  }

  .legend.is-expanded .legend-chevron {
    transform: rotate(225deg) translate(-2px, -1px);
  }

  .map-status {
    left: 52px;
    bottom: calc(12px + var(--safe-bottom));
  }

  .leaflet-left .leaflet-control {
    margin-left: 10px;
  }

  .leaflet-bottom .leaflet-control {
    margin-bottom: calc(12px + var(--safe-bottom));
  }

  .insights-panel {
    top: 92px;
    right: 10px;
    max-height: calc(100vh - 108px);
    overflow: auto;
  }
}

@media (min-width: 701px) and (max-height: 500px) {
  .legend {
    bottom: calc(12px + var(--safe-bottom));
  }
}
