:root {
  color-scheme: light;
  --bg: #f6f3ed;
  --panel: #fffdf8;
  --ink: #1e2422;
  --muted: #66706b;
  --line: #d9d1c4;
  --listed: #1c7c54;
  --contract: #b86d18;
  --sold: #6c7370;
  --accent: #0f5f76;
  --shadow: 0 10px 28px rgba(30, 36, 34, 0.16);
}

* {
  box-sizing: border-box;
}

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

body {
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  height: 100dvh;
  min-height: 620px;
}

.map-region {
  position: relative;
  min-width: 0;
}

.map {
  height: 100%;
  width: 100%;
  background: #dfe7e3;
}

.top-bar {
  background: rgba(255, 253, 248, 0.94);
  border: 1px solid rgba(217, 209, 196, 0.9);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 16px;
  left: max(14px, env(safe-area-inset-left));
  padding: 12px;
  position: absolute;
  right: max(14px, env(safe-area-inset-right));
  top: max(14px, env(safe-area-inset-top));
  z-index: 500;
}

.top-bar-main {
  align-items: center;
  display: grid;
  gap: 14px;
  grid-template-columns: minmax(0, 1fr) auto;
  min-width: 0;
}

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

.title-block h1,
.panel-header h2 {
  font-size: 18px;
  line-height: 1.1;
  margin: 0;
}

.title-block p,
.panel-header p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
  margin: 4px 0 0;
}

.controls {
  align-items: center;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  min-width: 0;
}

.controls[hidden] {
  display: none;
}

.select-control,
.controls button,
.filter-toggle {
  align-items: center;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  display: inline-flex;
  gap: 8px;
  min-height: 40px;
  padding: 0 12px;
}

.select-control {
  color: var(--muted);
  min-width: 0;
}

.select-control select {
  appearance: none;
  background: transparent;
  border: 0;
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  min-width: 68px;
  outline: 0;
  width: 100%;
}

.select-control span {
  flex: 0 0 auto;
  white-space: nowrap;
}

.filter-toggle {
  flex: 0 0 auto;
}

.controls button,
.filter-toggle {
  cursor: pointer;
  justify-content: center;
}

.disabled-control {
  color: #9aa19d;
  background: rgba(255, 255, 255, 0.68);
}

.disabled-control select {
  color: #9aa19d;
}

.controls button:active,
.filter-toggle:active,
.listing-card:active {
  transform: translateY(1px);
}

.legend {
  align-items: center;
  background: rgba(255, 253, 248, 0.94);
  border: 1px solid rgba(217, 209, 196, 0.9);
  border-radius: 8px;
  bottom: 18px;
  box-shadow: var(--shadow);
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  font-size: 12px;
  gap: 10px;
  left: 18px;
  padding: 8px 10px;
  position: absolute;
  z-index: 500;
}

.legend span {
  align-items: center;
  display: inline-flex;
  gap: 5px;
  white-space: nowrap;
}

.legend-dot {
  border-radius: 999px;
  display: inline-block;
  height: 9px;
  width: 9px;
}

.listed {
  background: var(--listed);
}

.contract {
  background: var(--contract);
}

.sold {
  background: var(--sold);
}

.list-panel {
  background: var(--panel);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.panel-header {
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
  padding: 16px;
}

.listing-list {
  display: grid;
  gap: 10px;
  overflow: auto;
  padding: 12px;
}

.listing-card {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: inherit;
  cursor: pointer;
  display: grid;
  gap: 10px;
  grid-template-columns: 92px minmax(0, 1fr);
  padding: 8px;
  text-align: left;
  width: 100%;
}

.listing-card:focus-visible,
.controls button:focus-visible,
.filter-toggle:focus-visible,
.select-control:focus-within {
  outline: 3px solid rgba(15, 95, 118, 0.3);
  outline-offset: 2px;
}

.listing-card img {
  aspect-ratio: 4 / 3;
  border-radius: 6px;
  height: 100%;
  object-fit: cover;
  width: 92px;
}

.listing-copy {
  min-width: 0;
}

.listing-title {
  font-size: 14px;
  font-weight: 700;
  line-height: 1.25;
  margin: 0;
}

.listing-meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  margin: 4px 0 0;
}

.price-row {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.price {
  font-size: 15px;
  font-weight: 800;
}

.status-pill {
  border-radius: 999px;
  color: #ffffff;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  padding: 5px 7px;
}

.approx-pill,
.source-pill,
.value-pill,
.walk-pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  padding: 4px 6px;
}

.source-pill,
.value-pill,
.walk-pill {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.value-pill {
  border-color: rgba(15, 95, 118, 0.28);
  color: var(--accent);
}

.status-pill.listed-status {
  background: var(--listed);
}

.status-pill.contract-status {
  background: var(--contract);
}

.status-pill.sold-status {
  background: var(--sold);
}

.ol-popup {
  background: #ffffff;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(30, 36, 34, 0.22);
  overflow: hidden;
  width: 270px;
}

.ol-zoom {
  bottom: 12px;
  left: auto;
  right: 12px;
  top: auto;
}

.popup-card {
  overflow: hidden;
}

.popup-card img {
  aspect-ratio: 16 / 10;
  display: block;
  object-fit: cover;
  width: 100%;
}

.popup-body {
  padding: 12px;
}

.popup-body h3 {
  font-size: 16px;
  line-height: 1.25;
  margin: 0;
}

.popup-facts {
  color: var(--muted);
  display: grid;
  gap: 4px;
  font-size: 13px;
  line-height: 1.35;
  margin: 8px 0 10px;
}

.popup-link {
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}

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

.price-marker {
  align-items: center;
  border: 2px solid #ffffff;
  border-radius: 999px;
  box-shadow: 0 4px 12px rgba(30, 36, 34, 0.25);
  color: #ffffff;
  display: inline-flex;
  font-size: 12px;
  font-weight: 800;
  height: 30px;
  justify-content: center;
  min-width: 54px;
  padding: 0 8px;
  white-space: nowrap;
}

.google-price-marker {
  cursor: pointer;
  left: 0;
  position: absolute;
  top: 0;
  transform: translate(-50%, -50%);
}

.price-marker.listed-status {
  background: var(--listed);
}

.price-marker.contract-status {
  background: var(--contract);
}

.price-marker.sold-status {
  background: var(--sold);
}

@media (max-width: 820px) {
  .app-shell {
    display: block;
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
  }

  .map-region {
    height: 67dvh;
    min-height: 430px;
  }

  .top-bar {
    align-items: stretch;
    gap: 8px;
    left: 10px;
    max-height: calc(67dvh - 16px);
    max-width: none;
    overflow-y: auto;
    padding: 8px;
    right: auto;
    width: calc(100vw - 20px);
    -webkit-overflow-scrolling: touch;
  }

  .top-bar-main {
    grid-template-columns: minmax(0, 1fr);
  }

  .filter-toggle {
    width: 100%;
  }

  .controls {
    gap: 6px;
    grid-template-columns: minmax(0, 1fr);
    width: 100%;
  }

  .select-control,
  .controls button,
  .filter-toggle {
    min-height: 34px;
    padding: 0 10px;
  }

  .controls button {
    justify-content: center;
    min-width: 0;
  }

  .legend {
    bottom: 10px;
    left: 10px;
    right: 10px;
  }

  .filters-open .legend {
    display: none;
  }

  .list-panel {
    border-left: 0;
    border-top: 1px solid var(--line);
    height: 33dvh;
  }

  .panel-header {
    padding: 10px 12px;
  }

  .panel-header h2 {
    font-size: 15px;
  }

  .listing-list {
    grid-auto-flow: column;
    grid-auto-columns: minmax(260px, 78vw);
    overflow-x: auto;
    overflow-y: hidden;
    padding: 10px 12px calc(12px + env(safe-area-inset-bottom));
  }

  .listing-card {
    grid-template-columns: 86px minmax(0, 1fr);
    min-height: 116px;
  }

  .listing-card img {
    width: 86px;
  }
}
