:root {
  --bg: #f5f7f8;
  --panel: #ffffff;
  --panel-2: #f8faf9;
  --text: #17211c;
  --muted: #62706a;
  --border: #dbe3df;
  --shadow: 0 18px 50px rgba(24, 40, 32, 0.12);
  --green: #1f7a55;
  --green-dark: #13523a;
  --yellow: #f6cf45;
  --orange: #f28b31;
  --red: #d94b3d;
  --red-dark: #9e1f2f;
  --purple: #5a2380;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family:
    "Inter",
    "Segoe UI",
    Tahoma,
    Arial,
    sans-serif;
}

button,
input,
select {
  font: inherit;
}

/* Critical Leaflet fallback. Some local browser sessions block the CDN stylesheet,
   so keep the map panes, tiles, markers, and controls positioned correctly here. */
.leaflet-container {
  overflow: hidden;
  background: #dfe7e3;
  outline-offset: 1px;
}

.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;
  top: 0;
  left: 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 canvas,
.leaflet-map-pane svg {
  z-index: 100;
}

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

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

.leaflet-interactive {
  cursor: pointer;
}

.leaflet-grab {
  cursor: grab;
}

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

.leaflet-top {
  top: 0;
}

.leaflet-right {
  right: 0;
}

.leaflet-bottom {
  bottom: 0;
}

.leaflet-left {
  left: 0;
}

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

.leaflet-control-zoom {
  margin: 0 14px 14px 0;
  border: 1px solid rgba(50, 70, 60, 0.2);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(20, 35, 28, 0.16);
}

.leaflet-control-zoom a {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border-bottom: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  font-size: 18px;
  font-weight: 800;
  text-decoration: none;
}

.leaflet-control-zoom a:last-child {
  border-bottom: 0;
}

.leaflet-control-attribution {
  margin: 0;
  padding: 3px 6px;
  background: rgba(255, 255, 255, 0.82);
  color: #53615b;
  font-size: 10px;
}

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

.leaflet-popup-content-wrapper {
  overflow: hidden;
  background: #fff;
  box-shadow: 0 12px 28px rgba(20, 35, 28, 0.22);
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(320px, 360px) minmax(0, 1fr) minmax(320px, 360px);
  width: 100vw;
  height: 100vh;
  min-height: 650px;
  max-height: 100vh;
  overflow: hidden;
}

.panel {
  z-index: 10;
  display: flex;
  min-height: 0;
  min-width: 0;
  flex-direction: column;
  background: var(--panel);
  border-color: var(--border);
}

.panel-left {
  border-right: 1px solid var(--border);
  overflow-y: auto;
}

.panel-right {
  border-left: 1px solid var(--border);
  overflow-y: auto;
}

.brand {
  padding: 22px 22px 16px;
  border-bottom: 1px solid var(--border);
}

.brand h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.1;
  font-weight: 760;
  letter-spacing: 0;
}

.brand p,
.topbar span,
.legend p,
.detail-empty p,
.meta,
.risk-note {
  color: var(--muted);
}

.brand p {
  margin: 7px 0 0;
  font-size: 13px;
  line-height: 1.45;
}

.control-group,
.layer-controls,
.legend {
  padding: 14px 18px 0;
}

.control-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 0 18px;
}

.control-grid .control-group {
  padding: 14px 0 0;
}

label,
.legend h2,
.layer-controls h2 {
  display: block;
  margin-bottom: 7px;
  font-size: 12px;
  font-weight: 760;
  color: #33423b;
}

input[type="search"],
select {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  outline: none;
}

input[type="search"]:focus,
select:focus {
  border-color: rgba(31, 122, 85, 0.65);
  box-shadow: 0 0 0 3px rgba(31, 122, 85, 0.12);
}

.toggle-row {
  display: flex;
  gap: 9px;
  align-items: center;
  margin: 13px 18px 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-2);
  font-size: 13px;
  font-weight: 650;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 14px 18px 2px;
}

.stats div {
  padding: 11px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

.stats strong {
  display: block;
  font-size: 21px;
  line-height: 1;
}

.stats span {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 11px;
}

.legend {
  margin-top: 2px;
}

.legend h2,
.layer-controls h2 {
  margin-top: 0;
  margin-bottom: 10px;
  font-size: 13px;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 7px 0;
  color: #2c3933;
  font-size: 12px;
}

.legend-row.heat-sample {
  align-items: center;
  margin-top: 10px;
  color: #4d5c55;
  font-weight: 650;
}

.legend-row.heat-sample span {
  display: inline-block;
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 2px 8px rgba(34, 20, 45, 0.18);
}

.legend-row.heat-sample span:nth-child(1) {
  width: 12px;
  height: 12px;
  background: var(--yellow);
}

.legend-row.heat-sample span:nth-child(2) {
  width: 17px;
  height: 17px;
  background: var(--red);
}

.legend-row.heat-sample span:nth-child(3) {
  width: 22px;
  height: 22px;
  background: var(--purple);
}

.swatch {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.15);
}

.r0 {
  background: #cbd5cf;
}

.r1 {
  background: var(--yellow);
}

.r2 {
  background: var(--orange);
}

.r3 {
  background: var(--red);
}

.r5 {
  background: var(--purple);
}

.legend p {
  margin: 10px 0 0;
  font-size: 12px;
  line-height: 1.45;
}

.layer-controls {
  display: grid;
  gap: 6px;
  padding-bottom: 12px;
}

.layer-controls label {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 0;
  color: var(--text);
  font-size: 12px;
  font-weight: 560;
}

.candidate-list {
  order: 1;
  flex: none;
  min-height: 280px;
  max-height: calc(100vh - 360px);
  overflow-y: auto;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: #f9fbfa;
}

.legend,
.layer-controls {
  order: 2;
}

.candidate-row {
  width: 100%;
  display: grid;
  grid-template-columns: 42px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 12px 14px 12px 18px;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.candidate-row:hover,
.candidate-row.active {
  background: #eef6f1;
}

.rank {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 8px;
  background: #e9efec;
  font-size: 12px;
  font-weight: 780;
}

.row-title {
  min-width: 0;
}

.row-title strong {
  display: block;
  overflow: hidden;
  font-size: 13px;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-title span {
  display: block;
  overflow: hidden;
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.risk-pill {
  min-width: 32px;
  padding: 5px 8px;
  border-radius: 999px;
  color: #fff;
  font-size: 12px;
  font-weight: 780;
  text-align: center;
}

.row-decision {
  display: grid;
  justify-items: end;
  gap: 5px;
}

.tier-chip {
  max-width: 72px;
  padding: 4px 7px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
  text-align: center;
  text-transform: uppercase;
  white-space: nowrap;
}

.tier-go {
  border-color: rgba(31, 122, 85, 0.35);
  background: #e6f5ed;
  color: #13523a;
}

.tier-watch {
  border-color: rgba(212, 165, 20, 0.35);
  background: #fff7da;
  color: #765707;
}

.tier-check {
  border-color: rgba(242, 139, 49, 0.38);
  background: #fff0e2;
  color: #8a430a;
}

.tier-hard-check {
  border-color: rgba(217, 75, 61, 0.35);
  background: #ffe9e6;
  color: #9e1f2f;
}

.tier-avoid {
  border-color: rgba(90, 35, 128, 0.35);
  background: #efe5f6;
  color: #4a1b69;
}

.risk-pill.risk-0 {
  background: #82908a;
}

.risk-pill.risk-1 {
  background: #d4a514;
}

.risk-pill.risk-2 {
  background: var(--orange);
}

.risk-pill.risk-3 {
  background: var(--red);
}

.risk-pill.risk-5 {
  background: var(--purple);
}

.map-stage {
  position: relative;
  min-height: 0;
  min-width: 0;
  height: 100%;
  overflow: hidden;
  background: #dfe7e3;
}

#map {
  position: absolute;
  inset: 0;
}

.topbar {
  position: absolute;
  z-index: 650;
  top: 16px;
  left: 16px;
  right: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 14px;
  border: 1px solid rgba(219, 227, 223, 0.95);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.topbar strong {
  display: block;
  font-size: 14px;
}

.topbar span {
  display: block;
  margin-top: 3px;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.topbar button,
.detail-actions button {
  height: 34px;
  padding: 0 13px;
  border: 0;
  border-radius: 8px;
  background: var(--green);
  color: #fff;
  font-size: 12px;
  font-weight: 760;
  cursor: pointer;
}

.topbar button:hover,
.detail-actions button:hover {
  background: var(--green-dark);
}

.candidate-marker {
  display: grid;
  width: 31px;
  height: 31px;
  place-items: center;
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 6px 18px rgba(18, 30, 24, 0.25);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
}

.candidate-zone-marker {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 3px solid #fff;
  border-radius: 50%;
  box-shadow: 0 8px 22px rgba(18, 30, 24, 0.28);
  color: #fff;
  font-size: 12px;
  font-weight: 850;
}

.candidate-zone-marker strong {
  line-height: 1;
}

.candidate-zone-marker.verified {
  border-color: #d9f3e7;
  box-shadow:
    0 0 0 4px rgba(31, 122, 85, 0.22),
    0 8px 22px rgba(18, 30, 24, 0.28);
}

.candidate-marker.priority::after {
  content: "";
  position: absolute;
  top: -3px;
  right: -3px;
  width: 9px;
  height: 9px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: #18a058;
}

.candidate-zone-marker.priority::after {
  content: "";
  position: absolute;
  top: -4px;
  right: -4px;
  width: 11px;
  height: 11px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: #18a058;
}

.marker-risk-0 {
  background: #82908a;
}

.marker-risk-1 {
  background: #d4a514;
}

.marker-risk-2 {
  background: var(--orange);
}

.marker-risk-3 {
  background: var(--red);
}

.marker-risk-5 {
  background: var(--purple);
}

.reported-flood-icon {
  background: transparent;
  border: 0;
}

.reported-flood-dot {
  position: relative;
  display: grid;
  place-items: center;
  border: 2px solid rgba(255, 255, 255, 0.92);
  border-radius: 50%;
  background: var(--heat-color);
  box-shadow:
    0 0 0 4px color-mix(in srgb, var(--heat-color) 24%, transparent),
    0 8px 18px rgba(48, 24, 70, 0.3);
  color: #fff;
  font-size: 11px;
  font-weight: 850;
  line-height: 1;
}

.reported-flood-dot strong {
  transform: translateY(-0.5px);
}

.detail-empty,
.detail-content {
  padding: 24px;
}

.detail-empty h2,
.detail-content h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1.18;
  letter-spacing: 0;
}

.detail-empty p {
  margin: 10px 0 0;
  font-size: 13px;
  line-height: 1.55;
}

.detail-head {
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}

.detail-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.tag {
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-2);
  color: #34433c;
  font-size: 12px;
  font-weight: 680;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 18px;
}

.metric {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-2);
}

.metric-wide {
  grid-column: 1 / -1;
}

.decision-card {
  border-width: 1px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.metric strong {
  display: block;
  margin-top: 5px;
  font-size: 15px;
  line-height: 1.35;
}

.decision-note {
  margin: 12px 0 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: #33423b;
  font-size: 13px;
  line-height: 1.55;
}

.detail-section {
  margin-top: 20px;
}

.detail-section h3 {
  margin: 0 0 8px;
  font-size: 13px;
}

.detail-section p,
.detail-section li {
  color: #33423b;
  font-size: 13px;
  line-height: 1.55;
}

.detail-section ul {
  padding-left: 18px;
  margin: 8px 0 0;
}

.reference-links,
.listing-links {
  display: grid;
  gap: 8px;
}

.reference-links a,
.listing-links a {
  display: grid;
  gap: 3px;
  padding: 10px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  text-decoration: none;
}

.reference-links a:hover,
.listing-links a:hover {
  border-color: rgba(31, 122, 85, 0.5);
  background: #f1f8f4;
}

.reference-links span,
.listing-links span {
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

.reference-links strong,
.listing-links strong {
  overflow-wrap: anywhere;
  font-size: 12px;
  line-height: 1.35;
}

.listing-links a {
  border-color: rgba(31, 122, 85, 0.28);
  background: #f7fbf8;
}

.reference-note {
  margin: 10px 0 0;
  padding: 10px 11px;
  border-left: 3px solid var(--orange);
  background: #fff7ed;
  color: #74420c;
  font-size: 12px;
  line-height: 1.45;
}

.risk-note {
  margin-top: 14px;
  padding: 12px;
  border-left: 3px solid var(--green);
  background: #eef7f2;
  font-size: 12px;
  line-height: 1.55;
}

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

.leaflet-popup-content {
  min-width: 220px;
  margin: 13px 14px;
  font-family:
    "Inter",
    "Segoe UI",
    Tahoma,
    Arial,
    sans-serif;
}

.leaflet-control-attribution {
  max-width: calc(100vw - 40px);
  white-space: normal;
}

.popup-title {
  margin: 0 0 6px;
  font-size: 14px;
  font-weight: 780;
}

.popup-meta {
  margin: 0;
  color: #586760;
  font-size: 12px;
  line-height: 1.45;
}

.popup-warning {
  margin: 8px 0;
  padding: 8px;
  border-radius: 8px;
  background: #fff7ed;
  color: #74420c;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.35;
  text-align: left;
}

.popup-sources {
  margin: 8px 0 0;
  font-size: 11px;
  line-height: 1.35;
}

.popup-evidence {
  margin: 9px 0 0;
  padding-left: 16px;
  color: #33423b;
  font-size: 11px;
  line-height: 1.4;
  text-align: left;
}

.popup-sources a {
  color: var(--green-dark);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.popup-listings {
  margin: 8px 0 0;
  text-align: left;
  font-size: 12px;
  line-height: 1.5;
}

.popup-listings a {
  color: var(--green-dark);
  font-weight: 760;
  text-decoration: none;
}

.popup-listings a:hover {
  text-decoration: underline;
  text-underline-offset: 2px;
}

@media (max-width: 1120px) {
  body {
    overflow: auto;
  }

  .app-shell {
    grid-template-columns: 320px 1fr;
    grid-template-rows: minmax(620px, 72vh) auto;
    width: 100%;
    height: auto;
    min-height: 100vh;
    max-height: none;
    overflow: visible;
  }

  .panel-right {
    grid-column: 1 / -1;
    border-top: 1px solid var(--border);
    border-left: 0;
  }
}

@media (max-width: 780px) {
  .app-shell {
    display: flex;
    flex-direction: column;
  }

  .panel-left {
    order: 2;
    height: auto;
    min-height: 58vh;
    border-right: 0;
    border-top: 1px solid var(--border);
  }

  .candidate-list {
    flex: none;
    min-height: 280px;
    max-height: 430px;
  }

  .map-stage {
    order: 1;
    height: 62vh;
    min-height: 460px;
  }

  .panel-right {
    order: 3;
  }

  .topbar {
    left: 10px;
    right: 10px;
    flex-direction: column;
    align-items: flex-start;
  }

  .control-grid,
  .stats {
    grid-template-columns: 1fr;
  }
}
