:root {
  --bg: #0f1720;
  --panel: #16212e;
  --panel-2: #1e2c3c;
  --border: #2a3a4d;
  --text: #e6edf3;
  --muted: #93a4b8;
  --accent: #2f81f7;
  --accent-2: #3fb950;
  --rent: #f0883e;
  --buy: #3fb950;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* Column layout: platform header on top, tool fills the rest. */
body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

#app {
  display: grid;
  grid-template-columns: 340px 1fr;
  flex: 1 1 auto;
  min-height: 0; /* let the map/sidebar scroll within, not overflow the page */
}

#sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.brand h1 {
  margin: 0;
  font-size: 20px;
  letter-spacing: 0.2px;
}
.brand .tagline {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.intro-note {
  margin: 0;
  padding: 10px 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--muted);
}
.intro-note strong {
  color: var(--text);
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.filter-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
}

.tabs {
  display: flex;
  gap: 8px;
}

.tab {
  flex: 1;
  padding: 9px 10px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.15s ease;
}
.tab:hover {
  border-color: var(--accent);
}
.tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

select,
input[type="text"],
input[type="number"] {
  width: 100%;
  padding: 9px 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
}

.price-row {
  flex-direction: row;
  gap: 10px;
}
.price-row > div {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.apply-btn {
  padding: 11px;
  background: var(--accent-2);
  border: none;
  border-radius: 8px;
  color: #05210d;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
}
.apply-btn:hover {
  filter: brightness(1.05);
}

.result-count {
  font-size: 13px;
  color: var(--muted);
}

.results {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

.result-item {
  padding: 10px 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}
.result-item:hover {
  border-color: var(--accent);
}
.result-item .ri-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 2px;
}
.result-item .ri-meta {
  font-size: 12px;
  color: var(--muted);
}
.result-item .ri-sub {
  font-size: 11px;
  color: #7d8ea3;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---- project search box + suggestions ---- */
.search-group {
  position: relative;
}
.search-results {
  list-style: none;
  margin: 6px 0 0;
  padding: 4px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  max-height: 260px;
  overflow-y: auto;
}
.search-item {
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.search-item:hover {
  background: var(--panel);
}
.search-item .si-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.search-item .si-sub {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.search-empty {
  padding: 8px 10px;
  font-size: 12px;
  color: var(--muted);
}
.badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  margin-right: 6px;
}
.badge.residential {
  background: rgba(27, 94, 32, 0.22);
  color: #5bd66a;
}
.badge.plotted {
  background: rgba(180, 83, 9, 0.22);
  color: #e0952e;
}
.badge.mixed {
  background: rgba(106, 27, 154, 0.22);
  color: #c489f0;
}

.footer-note {
  font-size: 11px;
  color: var(--muted);
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

#map-wrap {
  position: relative;
}
#map {
  width: 100%;
  height: 100%;
}

.map-legend {
  background: #ffffff;
  color: #1a1a1a;
  border: 1px solid #c4ccd6;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12px;
  line-height: 1.6;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
}
/* Horizontal legend: title + colour rows laid out in a single wrapping row. */
.map-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 14px;
}
.map-legend .legend-title {
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #444c56;
  margin-bottom: 0;
  width: 100%;
}
.map-legend .legend-row {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  font-weight: 600;
}
.map-legend .legend-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.25);
  flex-shrink: 0;
}

/* "My location" map button — styled to match Leaflet's zoom controls. */
.locate-btn {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #ffffff;
  color: #333;
  border: 2px solid rgba(0, 0, 0, 0.2);
  border-radius: 6px;
  cursor: pointer;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.3);
  padding: 0;
}
.locate-btn:hover {
  background: #f4f4f4;
  color: #2f81f7;
}

.map-message {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px;
  background: var(--bg);
  color: var(--muted);
  font-size: 15px;
  line-height: 1.6;
}
.map-message code {
  background: var(--panel-2);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--text);
}
.hidden {
  display: none;
}

.iw {
  color: #1a1a1a;
  max-width: 280px;
  font-size: 13px;
}

/* Popup scrolling: Leaflet's maxHeight makes .leaflet-popup-content-wrapper
   scroll. Ensure touch scrolling works inside it (momentum + it captures the
   gesture instead of the map dragging underneath). */
.leaflet-popup-content-wrapper {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
}
.leaflet-popup-content {
  margin: 12px 14px;
}

/* On small screens keep the popup within the viewport width. */
@media (max-width: 560px) {
  .leaflet-popup-content {
    width: auto !important;
    margin: 12px;
  }
  .iw {
    max-width: 78vw;
  }
}
.iw .iw-title {
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 2px;
}
.iw .iw-type {
  color: #57606a;
  font-size: 12px;
  margin-bottom: 6px;
}
.iw .iw-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 8px;
}
.iw .iw-status {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 10px;
}
.iw .iw-status.ok {
  background: #dafbe1;
  color: #1a7f37;
}
.iw .iw-status.warn {
  background: #fff1d6;
  color: #9a6700;
}
.iw .iw-status.bad {
  background: #ffe0e0;
  color: #cf222e;
}
.iw .iw-status.neutral {
  background: #eaeef2;
  color: #57606a;
}
.iw .iw-completion {
  background: #fff8e6;
  border: 1px solid #f0d68a;
  border-radius: 6px;
  padding: 5px 8px;
  margin-bottom: 8px;
  font-size: 12px;
}
.iw .iw-row.iw-flag span:last-child {
  color: #cf222e;
  font-weight: 700;
}
.iw .iw-src {
  font-size: 10px;
  font-weight: 600;
  padding: 1px 5px;
  border-radius: 4px;
  background: #eaeef2;
  color: #57606a;
  margin-left: 4px;
  white-space: nowrap;
}
.iw .iw-src.iw-src-web {
  background: #fff1d6;
  color: #9a6700;
}
.iw .iw-note {
  margin-top: 8px;
  font-size: 11px;
  color: #6e7781;
  font-style: italic;
  line-height: 1.35;
}
.iw .iw-links {
  margin-top: 10px;
  border-top: 1px solid #e4e8ee;
  padding-top: 8px;
  font-size: 12px;
}
.iw .iw-details {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.iw .iw-row {
  display: flex;
  gap: 8px;
  line-height: 1.35;
}
.iw .iw-label {
  color: #57606a;
  min-width: 110px;
  flex-shrink: 0;
}
.iw a {
  color: #0969da;
  font-weight: 600;
}

/* The filters toggle button + sidebar close button only exist on mobile. */
#filters-toggle {
  display: none;
}
#sidebar-close {
  display: none;
}

@media (max-width: 720px) {
  /* Map takes the full area; the sidebar slides over it on demand. */
  #app {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    position: relative;
  }

  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 86%;
    max-width: 340px;
    height: 100%;
    max-height: none;
    z-index: 1600;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 2px 0 18px rgba(0, 0, 0, 0.4);
  }
  #sidebar.open {
    transform: translateX(0);
  }
  /* Hide the floating button while the panel is open (× closes it instead). */
  #filters-toggle.hidden {
    display: none;
  }

  /* Floating "Filters & search" button. position:fixed pins it to the viewport
     so it can't be hidden by the map's stacking context or an unexpected #app
     height. z-index above Leaflet controls (~1000) and the sidebar is separate. */
  #filters-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    position: fixed;
    left: 12px;
    bottom: 16px;
    z-index: 1500;
    padding: 12px 18px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 24px;
    font-size: 15px;
    font-weight: 700;
    box-shadow: 0 3px 14px rgba(0, 0, 0, 0.4);
    cursor: pointer;
    font-family: inherit;
  }

  /* Close (×) button inside the sidebar header on mobile. */
  #sidebar-close {
    display: block;
    position: absolute;
    top: 14px;
    right: 14px;
    background: transparent;
    border: none;
    color: var(--text);
    font-size: 26px;
    line-height: 1;
    cursor: pointer;
    padding: 0 6px;
  }
  .brand {
    position: relative;
    padding-right: 34px;
  }
}
