:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #1c2430;
  --muted: #5d6b7b;
  --line: #e4e9ef;
  --brand: #0f6b57;
  --brand-2: #148f74;
  --warn: #b45309;
  --bad: #b42318;
  --ok: #067647;
  --shadow: 0 10px 30px rgba(16, 24, 40, 0.08);
  --radius: 16px;
}

* { box-sizing: border-box; }
html, body {
  height: 100%;
  height: 100dvh;
  margin: 0;
  overflow: hidden;
}
body {
  font-family: Inter, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

.app {
  display: grid;
  grid-template-columns: 300px 1fr 0px;
  height: 100%;
  height: 100dvh;
  transition: grid-template-columns 0.2s ease;
}

.app.list-collapsed {
  grid-template-columns: 0 1fr 0px;
}

.app.photos-open {
  grid-template-columns: 300px 1fr minmax(320px, 420px);
}

.app.list-collapsed.photos-open {
  grid-template-columns: 0 1fr minmax(320px, 420px);
}

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

.app.list-collapsed .sidebar {
  border-right: 0;
  pointer-events: none;
}

.brand {
  padding: 18px 18px 12px;
  border-bottom: 1px solid var(--line);
}
.brand h1 {
  margin: 0 0 4px;
  font-size: 20px;
  letter-spacing: -0.02em;
}
.brand p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.contact-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: #f7fbf9;
}
.contact-bar a {
  text-decoration: none;
  background: var(--brand);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 9px;
  border-radius: 8px;
}
.contact-bar a:hover { background: var(--brand-2); }
.contact-bar span {
  color: var(--ink);
  font-size: 12px;
  font-weight: 600;
  margin-left: 2px;
}

.toolbar {
  padding: 12px 14px;
  display: grid;
  gap: 8px;
  border-bottom: 1px solid var(--line);
}
.toolbar input, .toolbar select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  background: #fff;
}
.filters {
  display: grid;
  gap: 8px;
}
.meta {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  padding: 0 2px;
}
.meta #count { margin-right: auto; }
.reload-data {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font: 600 12px Inter, "Segoe UI", sans-serif;
  padding: 4px 8px;
  border-radius: 8px;
  cursor: pointer;
}
.reload-data:hover { border-color: #b7ddd3; }
.reload-data:disabled { opacity: 0.6; cursor: wait; }

.list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
  padding: 10px;
  display: grid;
  gap: 8px;
  align-content: start;
}

.card {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  cursor: pointer;
  background: #fff;
}
.card:hover, .card.active { border-color: #b7ddd3; box-shadow: var(--shadow); }
.card h3 { margin: 0 0 6px; font-size: 15px; }
.card .price { color: var(--brand); font-weight: 700; }
.card .row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 12px;
  margin-top: 6px;
}
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.badge.available { background: #ecfdf3; color: var(--ok); }
.badge.rented { background: #fef3f2; color: var(--bad); }
.badge.hold { background: #fff7ed; color: var(--warn); }

.map-wrap { position: relative; min-width: 0; }
#map { height: 100%; width: 100%; }

.sidebar-toggle {
  position: absolute;
  z-index: 1000;
  left: 12px;
  top: 12px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font: 600 13px Inter, "Segoe UI", sans-serif;
  padding: 8px 12px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.sidebar-toggle:hover { border-color: #b7ddd3; }

.legend {
  position: absolute;
  z-index: 500;
  right: 12px;
  bottom: 12px;
  background: rgba(255,255,255,.94);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 12px;
  box-shadow: var(--shadow);
}
.legend b { display: block; margin-bottom: 6px; }

.tile-error {
  position: absolute;
  z-index: 1100;
  left: 12px;
  right: 12px;
  bottom: 28px;
  background: #fff7ed;
  color: #9a3412;
  border: 1px solid #fdba74;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow);
  pointer-events: none;
}

.leaflet-gl-layer.maplibre-map {
  z-index: 0;
}

.house-marker {
  background: none;
  border: none;
}
.house-marker svg { display: block; filter: drop-shadow(0 2px 4px rgba(16, 24, 40, 0.28)); }

.photos {
  background: var(--panel);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}
.app:not(.photos-open) .photos {
  border-left: 0;
  pointer-events: none;
}
.photos-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--line);
}
.photos-head h2 {
  margin: 0 0 4px;
  font-size: 18px;
  letter-spacing: -0.02em;
}
.photos-head .price { color: var(--brand); font-weight: 700; }
.photos-close {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  font-size: 24px;
  line-height: 1;
  color: var(--ink);
  cursor: pointer;
}
.photos-close:hover { border-color: #b7ddd3; }
.photos {
  min-height: 0;
}
.photos-gallery {
  flex: 1;
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
  padding: 12px;
  display: grid;
  gap: 10px;
  align-content: start;
}
.photos-gallery img {
  width: 100%;
  max-height: 56vh;
  object-fit: cover;
  border-radius: 12px;
  background: #eef2f6;
}

@media (max-width: 860px) {
  .app,
  .app.photos-open,
  .app.list-collapsed,
  .app.list-collapsed.photos-open {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 52dvh) minmax(0, 1fr);
    transition: grid-template-rows 0.2s ease;
  }
  .app.list-collapsed,
  .app.list-collapsed.photos-open {
    grid-template-rows: 0 minmax(0, 1fr);
  }
  .brand { padding: 10px 12px 8px; }
  .brand h1 { font-size: 18px; }
  .brand p { display: none; }
  .contact-bar { padding: 8px 12px; }
  .toolbar { padding: 8px 12px; gap: 6px; }
  .sidebar {
    grid-column: 1;
    grid-row: 1;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-y;
  }
  .list {
    overflow: visible;
    flex: none;
    touch-action: pan-y;
  }
  .app.list-collapsed .sidebar { border-bottom: 0; }
  .map-wrap { grid-column: 1; grid-row: 2; min-height: 0; }
  .photos {
    grid-column: 1;
    grid-row: 1 / span 2;
    z-index: 2000;
    border-left: 0;
    transform: translateX(100%);
    transition: transform 0.2s ease;
    pointer-events: none;
  }
  .app.photos-open .photos {
    transform: translateX(0);
    pointer-events: auto;
  }
}
