:root {
  color-scheme: light;
  --bg: #f5f7fa;
  --surface: #ffffff;
  --line: #d9dee8;
  --text: #172033;
  --muted: #667085;
  --green: #087f5b;
  --blue: #1d4ed8;
  --amber: #b45309;
  --red: #b42318;
  --shadow: 0 8px 24px rgba(16, 24, 40, 0.14);
  --app-viewport-height: 100vh;
  --app-header-height: 0px;
  --mobile-nav-height: 58px;
  --mobile-nav-total-height: calc(var(--mobile-nav-height) + env(safe-area-inset-bottom));
}

* { box-sizing: border-box; }

html {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

h1 {
  margin: 0 0 5px;
  font-size: 20px;
  line-height: 1.2;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 7px 14px;
  color: var(--muted);
  font-size: 13px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 392px;
  height: calc(100vh - 69px);
  min-height: 620px;
  overflow: hidden;
}

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

#map {
  width: 100%;
  height: 100%;
  background: #e9eef3;
}

.empty {
  position: absolute;
  top: 18px;
  left: 18px;
  max-width: 420px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, .94);
  box-shadow: var(--shadow);
  padding: 13px 14px;
  z-index: 500;
  font-size: 14px;
  line-height: 1.5;
}

.empty strong {
  display: block;
  margin-bottom: 4px;
  font-size: 15px;
}

.hidden { display: none !important; }

.side {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
  border-left: 1px solid var(--line);
  background: var(--surface);
}

.filters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 13px;
  border-bottom: 1px solid var(--line);
}

.filters input[type="search"] {
  grid-column: 1 / -1;
}

.deal-type-filter,
.price-band-filter,
.money-filter,
.area-filter,
.layer-filter {
  grid-column: 1 / -1;
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  background: #fff;
}

.deal-type-filter-head,
.price-band-filter-head,
.money-filter-head,
.area-filter-head,
.layer-filter-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
}

.deal-type-filter-head strong,
.price-band-filter-head strong,
.money-filter-head strong,
.area-filter-head strong,
.layer-filter-head strong {
  color: var(--text);
  font-size: 13px;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 9px;
  width: fit-content;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.toggle-row input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--blue);
}

.deal-type-buttons,
.price-band-buttons {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.deal-type-toggle,
.price-band-toggle {
  min-width: 0;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f9fafb;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
}

.deal-type-toggle.active,
.price-band-toggle.active {
  border-color: var(--blue);
  background: #eef4ff;
  color: var(--blue);
}

.range-track {
  position: relative;
  height: 28px;
}

.range-rail,
.range-selection {
  position: absolute;
  left: 0;
  right: 0;
  top: 13px;
  height: 4px;
  border-radius: 999px;
}

.range-rail { background: #e4e7ec; }

.range-selection {
  background: var(--blue);
  left: var(--range-left, 0%);
  right: var(--range-right, 0%);
}

.range-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 28px;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  pointer-events: none;
  appearance: none;
}

.range-input::-webkit-slider-runnable-track {
  height: 4px;
  background: transparent;
}

.range-input::-webkit-slider-thumb {
  width: 18px;
  height: 18px;
  margin-top: -7px;
  border: 2px solid var(--blue);
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .16);
  pointer-events: auto;
  appearance: none;
}

.range-input::-moz-range-track {
  height: 4px;
  background: transparent;
}

.range-input::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border: 2px solid var(--blue);
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .16);
  pointer-events: auto;
}

select,
input {
  width: 100%;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 0 10px;
  font-size: 14px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 11px 13px;
  border-bottom: 1px solid var(--line);
}

.stat {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  min-width: 0;
}

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

.stat strong {
  display: block;
  font-size: 18px;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.list {
  min-height: 0;
  overflow: auto;
  padding: 10px 13px 14px;
}

.mobile-nav {
  display: none;
}

.item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 8px;
  cursor: pointer;
  background: #fff;
}

.item:hover,
.item.active {
  border-color: #98a2b3;
  background: #f8fafc;
}

.item-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 13px;
}

.complex {
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.price {
  flex: 0 0 auto;
  color: #101828;
  font-weight: 800;
}

.item-meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.leaflet-popup-content {
  min-width: 230px;
  margin: 12px 14px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

.popup-title {
  margin-bottom: 7px;
  font-size: 15px;
  font-weight: 800;
}

.popup-price {
  margin-bottom: 6px;
  color: #101828;
  font-weight: 800;
}

.popup-meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.popup-link {
  display: inline-block;
  margin-top: 8px;
  color: #175cd3;
  text-decoration: none;
}

.popup-link:hover { text-decoration: underline; }

.listing-tooltip {
  border: 1px solid rgba(23, 32, 51, .18);
  border-radius: 8px;
  box-shadow: 0 8px 20px rgba(16, 24, 40, .18);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

.listing-tooltip .leaflet-tooltip-content {
  margin: 0;
}

.tooltip-card {
  min-width: 210px;
  max-width: 270px;
  padding: 9px 10px;
  background: #fff;
}

.tooltip-title {
  margin-bottom: 5px;
  font-size: 13px;
  font-weight: 800;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.tooltip-price {
  margin-bottom: 5px;
  color: #101828;
  font-size: 13px;
  font-weight: 800;
}

.tooltip-meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.station-marker {
  border: 0;
  background: transparent;
}

.station-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 128px;
  padding: 2px 5px 2px 2px;
  border: 1px solid rgba(16, 24, 40, .28);
  border-radius: 999px;
  background: rgba(255, 255, 255, .96);
  box-shadow: 0 2px 5px rgba(16, 24, 40, .18);
  color: #111827;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
  transform: translate(-7px, -50%);
}

.station-dots {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
}

.station-dot {
  flex: 0 0 auto;
  width: 11px;
  height: 11px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--station-color, #111827);
  box-shadow: 0 0 0 1px rgba(16, 24, 40, .4);
}

.station-dot + .station-dot {
  margin-left: -4px;
}

.station-name {
  overflow: hidden;
  text-overflow: ellipsis;
}

.leaflet-container:not(.station-labels-visible) .station-chip {
  gap: 0;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.leaflet-container:not(.station-labels-visible) .station-name {
  display: none;
}

.station-tooltip {
  border: 1px solid rgba(16, 24, 40, .18);
  border-radius: 8px;
  box-shadow: 0 8px 20px rgba(16, 24, 40, .16);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

@media (max-width: 980px) {
  header { display: block; }

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

  .map-pane {
    height: 58vh;
    min-height: 430px;
  }

  .side {
    border-left: 0;
    border-top: 1px solid var(--line);
  }
}

@media (max-width: 720px) {
  html,
  body {
    height: 100%;
    overflow: hidden;
  }

  body {
    min-height: var(--app-viewport-height);
  }

  header {
    gap: 8px;
    padding: 12px 14px 10px;
  }

  h1 {
    margin-bottom: 7px;
    font-size: 18px;
  }

  .meta {
    gap: 5px 12px;
    font-size: 12px;
    line-height: 1.35;
  }

  .layout {
    display: block;
    height: calc(var(--app-viewport-height) - var(--app-header-height) - var(--mobile-nav-total-height));
    min-height: 0;
    overflow: hidden;
  }

  .map-pane {
    height: 100%;
    min-height: 0;
  }

  .side {
    height: 100%;
    min-height: 0;
    border-top: 0;
    overflow: hidden;
  }

  body[data-mobile-panel="map"] .side {
    display: none;
  }

  body[data-mobile-panel="filters"] .map-pane,
  body[data-mobile-panel="list"] .map-pane {
    display: none;
  }

  body[data-mobile-panel="filters"] .side {
    display: block;
  }

  body[data-mobile-panel="filters"] .filters {
    height: 100%;
    overflow: auto;
    align-content: start;
    padding: 12px 12px 18px;
    border-bottom: 0;
  }

  body[data-mobile-panel="filters"] .stats,
  body[data-mobile-panel="filters"] .list {
    display: none;
  }

  body[data-mobile-panel="list"] .side {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
  }

  body[data-mobile-panel="list"] .filters {
    display: none;
  }

  body[data-mobile-panel="list"] .stats {
    padding: 10px 12px;
  }

  body[data-mobile-panel="list"] .list {
    padding: 9px 12px 16px;
  }

  .deal-type-filter,
  .price-band-filter,
  .money-filter,
  .area-filter,
  .layer-filter {
    padding: 10px;
  }

  .deal-type-buttons,
  .price-band-buttons {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .deal-type-toggle,
  .price-band-toggle,
  select,
  input {
    min-height: 44px;
    height: 44px;
  }

  .toggle-row {
    min-height: 34px;
  }

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

  .stat strong {
    font-size: 17px;
  }

  .empty {
    top: 12px;
    left: 12px;
    right: 12px;
    max-width: none;
  }

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

  .mobile-nav {
    position: fixed;
    z-index: 900;
    right: 0;
    bottom: 0;
    left: 0;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    height: var(--mobile-nav-total-height);
    padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    background: rgba(255, 255, 255, .96);
    box-shadow: 0 -8px 24px rgba(16, 24, 40, .12);
  }

  .mobile-panel-toggle {
    min-width: 0;
    height: 42px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--muted);
    font: inherit;
    font-size: 13px;
    font-weight: 800;
  }

  .mobile-panel-toggle.active {
    border-color: var(--blue);
    background: #eef4ff;
    color: var(--blue);
  }
}
