:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #17202a;
  --muted: #667085;
  --line: #d8dee6;
  --soft: #eef2f6;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --warn: #b45309;
  --danger: #b91c1c;
  --shadow: 0 12px 30px rgba(15, 23, 42, 0.12);
  --footer-height: 34px;
}

/* Leaflet layout fallback. The CDN stylesheet can be blocked on file:// previews
   or static hosts with strict network rules; without these positioning rules
   map tiles flow like ordinary images and appear as broken blocks. */
.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-container {
  overflow: hidden;
  touch-action: pan-x pan-y;
  font: 12px/1.5 Helvetica Neue, Arial, Helvetica, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

#map .leaflet-pane,
#map .leaflet-control-container,
#map .leaflet-top,
#map .leaflet-bottom,
#map .leaflet-tile,
#map .leaflet-layer,
#map .leaflet-zoom-animated {
  box-sizing: content-box;
}

.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow {
  user-select: none;
  -webkit-user-drag: none;
}

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

.leaflet-marker-icon {
  pointer-events: auto;
}

.leaflet-tile {
  filter: inherit;
  visibility: hidden;
  border: 0;
  max-width: none !important;
  max-height: none !important;
}

.leaflet-container .leaflet-overlay-pane svg {
  max-width: none !important;
  max-height: none !important;
}

.leaflet-container .leaflet-marker-pane img,
.leaflet-container .leaflet-shadow-pane img,
.leaflet-container .leaflet-tile-pane img,
.leaflet-container img.leaflet-image-layer,
.leaflet-container .leaflet-tile {
  max-width: none !important;
  max-height: none !important;
}

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

.leaflet-zoom-animated {
  transform-origin: 0 0;
}

.leaflet-zoom-anim .leaflet-zoom-animated {
  transition: transform 0.25s cubic-bezier(0, 0, 0.25, 1);
}

.leaflet-zoom-anim .leaflet-tile,
.leaflet-pan-anim .leaflet-tile {
  transition: none;
}

.leaflet-fade-anim .leaflet-tile {
  will-change: opacity;
  transition: opacity 0.2s linear;
}

.leaflet-zoom-anim .leaflet-zoom-hide {
  visibility: hidden;
}

.leaflet-map-pane canvas {
  z-index: 100;
}

.leaflet-map-pane svg {
  z-index: 200;
}

.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: 400;
}

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

.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 {
  float: left;
  clear: both;
}

.leaflet-right .leaflet-control {
  float: right;
}

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

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

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

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

.leaflet-interactive {
  cursor: pointer;
}

.leaflet-grab {
  cursor: grab;
}

.leaflet-dragging .leaflet-grab,
.leaflet-dragging .leaflet-grab .leaflet-interactive {
  cursor: move;
}

.leaflet-popup-pane,
.leaflet-control {
  cursor: auto;
}

.leaflet-control-zoom a {
  background: #fff;
  border-bottom: 1px solid #ccc;
  color: #000;
  display: block;
  font-size: 22px;
  height: 30px;
  line-height: 30px;
  text-align: center;
  text-decoration: none;
  width: 30px;
}

.leaflet-control-zoom {
  border: 2px solid rgba(0, 0, 0, 0.2);
  border-radius: 4px;
  overflow: hidden;
}

.leaflet-control-attribution {
  background: rgba(255, 255, 255, 0.82);
  margin: 0;
  padding: 0 5px;
  color: #333;
}

.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 3px 14px rgba(0, 0, 0, 0.25);
}

.leaflet-popup-content {
  margin: 13px 19px;
  line-height: 1.4;
}

.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 3px 14px rgba(0, 0, 0, 0.25);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, Segoe UI, Arial, sans-serif;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) var(--footer-height);
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) auto auto;
  gap: 18px;
  align-items: center;
  min-height: 72px;
  padding: 12px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 50;
}

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

.brand p,
.panel-head p,
.list-toolbar p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.view-switch {
  display: inline-flex;
  padding: 3px;
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.view-button {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 8px 12px;
  border-radius: 6px;
  min-width: 84px;
}

.view-button.is-active {
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.12);
}

.top-actions {
  display: flex;
  gap: 8px;
}

.primary-action,
.ghost-action {
  border-radius: 7px;
  padding: 9px 12px;
  border: 1px solid transparent;
  min-height: 36px;
}

.primary-action {
  background: var(--accent);
  color: #fff;
}

.primary-action:hover {
  background: var(--accent-dark);
}

.ghost-action {
  background: #fff;
  color: var(--ink);
  border-color: var(--line);
}

.ghost-action:hover {
  background: var(--soft);
}

.ghost-action.compact {
  min-height: 30px;
  padding: 5px 9px;
  font-size: 13px;
}

.layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  min-height: 0;
  overflow: hidden;
}

.build-footer {
  height: var(--footer-height);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 18px;
  border-top: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

.filters-panel {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 16px;
  overflow: auto;
  min-height: 0;
}

.panel-head,
.list-toolbar,
.hidden-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-head h2,
.list-toolbar h2 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0;
}

.filter-block {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.filter-block h3 {
  margin: 0 0 10px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.field {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 13px;
}

.field.pair {
  grid-template-columns: 1fr 86px 86px;
  align-items: center;
}

.field input,
.field select,
.sort-field select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  min-height: 34px;
  padding: 7px 8px;
  color: var(--ink);
  background: #fff;
}

.check-field {
  display: flex;
  gap: 9px;
  align-items: center;
  margin: 10px 0;
  color: var(--ink);
  font-size: 14px;
}

.workspace {
  min-width: 0;
  min-height: 0;
  padding: 16px;
  display: flex;
  flex-direction: column;
  overflow: auto;
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(130px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
  flex: 0 0 auto;
}

.stat-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
}

.stat-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.stat-card strong {
  display: block;
  margin-top: 3px;
  font-size: 19px;
  letter-spacing: 0;
}

.view-pane {
  display: none;
}

.view-pane.is-active {
  display: block;
}

#mapView {
  /* Keep Leaflet panes and boosted marker z-indexes below app-level overlays. */
  position: relative;
  z-index: 0;
  isolation: isolate;
  min-height: 0;
}

#mapView.is-active {
  flex: 1 1 auto;
}

#map {
  position: relative;
  z-index: 0;
  isolation: isolate;
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #dde5ec;
}

.map-legend {
  position: absolute;
  z-index: 700;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid #b8bec5;
  border-radius: 4px;
  padding: 10px 12px;
  font-family: Arial, sans-serif;
  font-size: 12px;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.22);
  pointer-events: auto;
}

.sale-legend {
  right: 24px;
  bottom: 24px;
  width: 250px;
}

.heat-legend {
  left: 24px;
  bottom: 24px;
  width: 250px;
}

.legend-title {
  font-weight: 700;
  margin-bottom: 7px;
}

.legend-grid {
  display: grid;
  grid-template-columns: 16px auto;
  gap: 5px 7px;
  align-items: center;
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid #111827;
  display: inline-block;
}

.legend-note {
  margin-top: 7px;
  color: #5f6368;
}

.heat-scale {
  width: 220px;
  height: 14px;
  background: linear-gradient(90deg, #2b83ba 0%, #1a9850 35%, #ffe066 68%, #d7191c 100%);
  border: 1px solid #777;
}

.heat-scale-labels {
  display: flex;
  justify-content: space-between;
  width: 222px;
  margin-top: 4px;
  color: #334155;
}

.sale-map-icon {
  background: transparent;
  border: 0;
}

.sale-map-dot {
  border: 2px solid #111827;
  border-radius: 50%;
  display: block;
  opacity: 0.94;
  box-sizing: border-box;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.38);
  cursor: pointer;
  pointer-events: auto;
}

#map .leaflet-marker-icon.sale-marker-bucket-1 {
  z-index: 610000 !important;
}

#map .leaflet-marker-icon.sale-marker-bucket-2 {
  z-index: 620000 !important;
}

#map .leaflet-marker-icon.sale-marker-bucket-3 {
  z-index: 630000 !important;
}

#map .leaflet-marker-icon.sale-marker-bucket-4 {
  z-index: 640000 !important;
}

#map .leaflet-marker-icon.sale-marker-bucket-5 {
  z-index: 650000 !important;
}

#map .leaflet-marker-icon.sale-marker-bucket-9 {
  z-index: 690000 !important;
}

.list-toolbar {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 12px;
}

.sort-field {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.listing-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 12px;
}

.list-more {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
  padding: 10px 0 2px;
}

.list-more button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  border-radius: 7px;
  min-height: 34px;
  padding: 7px 12px;
  font-size: 13px;
  cursor: pointer;
}

.list-more button:hover {
  background: var(--soft);
}

.listing-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto 1fr;
}

.listing-card.is-selected {
  outline: 2px solid var(--accent);
}

.card-photo {
  height: 150px;
  background: #dce3ea;
  overflow: hidden;
}

.card-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.card-body {
  padding: 12px;
}

.card-topline {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
}

.card-title {
  margin: 0;
  font-size: 15px;
  line-height: 1.28;
  letter-spacing: 0;
}

.score-pill {
  flex: 0 0 auto;
  min-width: 50px;
  text-align: center;
  border-radius: 999px;
  padding: 4px 8px;
  color: #fff;
  font-weight: 760;
  font-size: 13px;
}

.card-address,
.metric-muted {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.card-address {
  margin: 7px 0 10px;
}

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

.metric {
  background: var(--soft);
  border-radius: 7px;
  padding: 7px 8px;
  min-height: 48px;
}

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

.metric strong {
  display: block;
  margin-top: 2px;
  font-size: 14px;
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.card-actions button,
.card-actions a,
.popup-actions button,
.popup-actions a,
.detail-actions button,
.detail-actions a {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 7px;
  min-height: 32px;
  padding: 6px 9px;
  text-decoration: none;
  font-size: 13px;
}

.card-actions button:hover,
.popup-actions button:hover,
.detail-actions button:hover {
  background: var(--soft);
}

.detail-panel {
  position: fixed;
  inset: 0 0 0 auto;
  width: min(560px, 100vw);
  background: var(--panel);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow);
  transform: translateX(104%);
  transition: transform 0.18s ease;
  z-index: 1200;
}

.detail-panel.is-open {
  transform: translateX(0);
}

.detail-shell {
  height: 100%;
  overflow: auto;
  padding: 18px;
  position: relative;
}

.detail-loading {
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
}

.close-button {
  position: sticky;
  top: 0;
  float: right;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 24px;
  line-height: 1;
  z-index: 2;
}

.detail-title {
  margin: 0 44px 8px 0;
  font-size: 22px;
  line-height: 1.18;
  letter-spacing: 0;
}

.detail-gallery {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 8px;
  margin: 14px 0;
}

.detail-gallery img {
  width: 100%;
  height: 150px;
  object-fit: cover;
  border-radius: 8px;
  background: var(--soft);
}

.detail-gallery img:first-child {
  height: 308px;
  grid-row: span 2;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0;
}

.detail-section {
  border-top: 1px solid var(--line);
  padding-top: 14px;
  margin-top: 14px;
}

.detail-section h3 {
  margin: 0 0 9px;
  font-size: 15px;
}

.detail-facts {
  display: grid;
  gap: 7px;
}

.detail-fact-row {
  display: grid;
  gap: 2px;
}

.detail-fact-row span {
  color: var(--muted);
  font-size: 12px;
}

.detail-fact-row strong {
  font-size: 13px;
  font-weight: 650;
}

.analog-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.analog-list li {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px;
}

.leaflet-popup-content {
  min-width: 250px;
}

.sale-popup .leaflet-popup-content {
  min-width: 390px;
  max-height: min(620px, 72vh);
  overflow: auto;
  padding-right: 2px;
}

.rent-popup .leaflet-popup-content {
  min-width: 330px;
}

.popup-title {
  font-weight: 760;
  margin-bottom: 6px;
}

.popup-title a {
  color: var(--ink);
  text-decoration: none;
}

.popup-title a:hover,
.rent-cell-list a:hover {
  text-decoration: underline;
}

.sale-popup-body {
  font-size: 13px;
  line-height: 1.35;
}

.popup-score-badge {
  display: inline-block;
  border: 1px solid #111827;
  border-radius: 4px;
  font-weight: 700;
  margin-bottom: 7px;
  padding: 2px 7px;
}

.popup-row {
  margin-top: 2px;
}

.popup-muted {
  color: var(--muted);
  margin-top: 3px;
}

.popup-platforms {
  margin-top: 7px;
}

.popup-platforms-title {
  font-weight: 700;
  margin-bottom: 4px;
}

.popup-platform-links {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.popup-platform-links a {
  background: #111827;
  border: 1px solid #111827;
  border-radius: 4px;
  color: #fff;
  font-weight: 700;
  padding: 3px 7px;
  text-decoration: none;
}

.popup-text-block {
  border-top: 1px solid #e5e7eb;
  margin-top: 7px;
  padding-top: 6px;
}

.popup-separator {
  border: 0;
  border-top: 1px solid #ddd;
  margin: 8px 0;
}

.rent-cell-heading {
  font-weight: 700;
  margin-bottom: 6px;
}

.rent-cell-list {
  max-height: 260px;
  overflow: auto;
  padding-right: 4px;
}

.rent-cell-list ol {
  margin: 0;
  padding-left: 18px;
}

.rent-cell-list li {
  margin: 0 0 8px;
}

.rent-item-muted {
  color: #5f6368;
}

.popup-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%) translateY(80px);
  background: #111827;
  color: #fff;
  padding: 10px 14px;
  border-radius: 8px;
  z-index: 110;
  opacity: 0;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.empty-state {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  color: var(--muted);
}

@media (max-width: 980px) {
  body {
    display: block;
    height: auto;
    overflow: auto;
  }

  .topbar {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .layout {
    grid-template-columns: 1fr;
    overflow: visible;
  }

  .filters-panel {
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .workspace {
    display: block;
    overflow: visible;
  }

  .stats-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #map {
    height: 62vh;
    min-height: 420px;
  }

  .build-footer {
    min-height: var(--footer-height);
  }
}

@media (max-width: 620px) {
  .workspace,
  .filters-panel {
    padding: 12px;
  }

  .field.pair {
    grid-template-columns: 1fr 1fr;
  }

  .field.pair span {
    grid-column: 1 / -1;
  }

  .stats-row,
  .listing-cards {
    grid-template-columns: 1fr;
  }

  .detail-gallery {
    grid-template-columns: 1fr;
  }

  .detail-gallery img,
  .detail-gallery img:first-child {
    height: 220px;
    grid-row: auto;
  }
}
