/* Reset & Base */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: #333;
  background: #f5f6f8;
}

/* Header */
#header {
  height: 50px;
  background: #fff;
  border-bottom: 1px solid #e0e0e0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  z-index: 1000;
  position: relative;
}

#header h1 {
  font-size: 18px;
  font-weight: 600;
  color: #1a1a2e;
  letter-spacing: -0.3px;
}

#legend {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 13px;
  color: #666;
}

.legend-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.legend-label {
  font-weight: 600;
  color: #374151;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.legend-divider {
  width: 1px;
  height: 16px;
  background: #d1d5db;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.legend-stripe {
  width: 4px;
  height: 14px;
  border-radius: 2px;
  display: inline-block;
}

/* Layer Toggles */
/* Date Range Slider */
.date-filter-group {
  gap: 8px !important;
}

.date-label {
  font-size: 11px;
  color: #374151;
  font-weight: 500;
  min-width: 52px;
  text-align: center;
  white-space: nowrap;
}

.date-slider {
  position: relative;
  width: 140px;
  height: 24px;
  display: flex;
  align-items: center;
  user-select: none;
  touch-action: none;
}

.date-slider-track {
  position: absolute;
  left: 0;
  right: 0;
  height: 4px;
  background: #d1d5db;
  border-radius: 2px;
  top: 50%;
  transform: translateY(-50%);
}

.date-slider-range {
  position: absolute;
  height: 4px;
  background: #3b82f6;
  border-radius: 2px;
  top: 50%;
  transform: translateY(-50%);
  cursor: grab;
}

.date-slider-range:active {
  cursor: grabbing;
}

.date-slider-handle {
  position: absolute;
  width: 16px;
  height: 16px;
  background: #fff;
  border: 2px solid #3b82f6;
  border-radius: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  cursor: grab;
  z-index: 2;
  transition: box-shadow 0.15s;
  outline: none;
}

.date-slider-handle:hover,
.date-slider-handle:focus {
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.2);
}

.date-slider-handle:active {
  cursor: grabbing;
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.3);
}

.layer-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  font-size: 13px;
  color: #666;
}

.layer-toggle input[type="checkbox"] {
  cursor: pointer;
}

.layer-link {
  font-size: 13px;
  color: #2563eb;
  text-decoration: none;
}

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

/* Main Content Layout */
#content {
  display: flex;
  height: calc(100% - 50px);
}

/* Map */
#map {
  width: 60%;
  height: 100%;
  flex-shrink: 0;
}

/* Detail Panel */
#detail-panel {
  width: 40%;
  height: 100%;
  overflow-y: auto;
  background: #f9fafb;
  border-left: 1px solid #e5e7eb;
  padding: 24px;
}

/* Placeholder */
.placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  color: #9ca3af;
}

.placeholder-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.6;
}

.placeholder h2 {
  font-size: 20px;
  font-weight: 600;
  color: #6b7280;
  margin-bottom: 8px;
}

.placeholder p {
  font-size: 14px;
  max-width: 260px;
  line-height: 1.5;
}

/* Detail Card */
.detail-card {
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
  padding: 24px;
}

.detail-card h2 {
  font-size: 20px;
  font-weight: 700;
  color: #1a1a2e;
  margin-bottom: 4px;
  line-height: 1.3;
}

.detail-card .address {
  font-size: 14px;
  color: #6b7280;
  margin-bottom: 16px;
}

.detail-card .price {
  font-size: 22px;
  font-weight: 700;
  color: #2563eb;
  margin-bottom: 20px;
}

.detail-card hr {
  border: none;
  border-top: 1px solid #e5e7eb;
  margin: 16px 0;
}

.detail-card h3 {
  font-size: 15px;
  font-weight: 600;
  color: #374151;
  margin-bottom: 10px;
  margin-top: 8px;
}

.detail-card p {
  font-size: 14px;
  line-height: 1.6;
  color: #4b5563;
  margin-bottom: 12px;
}

.detail-card a {
  color: #2563eb;
  text-decoration: none;
}

.detail-card a:hover {
  text-decoration: underline;
}

/* Tables */
.detail-card table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 16px;
  font-size: 13px;
}

.detail-card table th,
.detail-card table td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid #f0f0f0;
}

.detail-card table th {
  font-weight: 600;
  color: #6b7280;
  background: #f9fafb;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.detail-card table td {
  color: #374151;
}

.detail-card table tr:last-child td {
  border-bottom: none;
}

.detail-card table tr:hover td {
  background: #f9fafb;
}

/* Lists & Checkboxes */
.detail-card ul,
.detail-card ol {
  padding-left: 20px;
  margin-bottom: 12px;
}

.detail-card li {
  font-size: 14px;
  line-height: 1.7;
  color: #4b5563;
}

.detail-card ul.checklist {
  list-style: none;
  padding-left: 0;
}

.detail-card ul.checklist li {
  position: relative;
  padding-left: 26px;
  margin-bottom: 6px;
}

.detail-card ul.checklist li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 4px;
  width: 16px;
  height: 16px;
  border: 2px solid #d1d5db;
  border-radius: 3px;
  background: #fff;
}

.detail-card ul.checklist li.checked::before {
  background: #2563eb;
  border-color: #2563eb;
}

.detail-card ul.checklist li.checked::after {
  content: "";
  position: absolute;
  left: 3px;
  top: 7px;
  width: 10px;
  height: 5px;
  border-left: 2px solid #fff;
  border-bottom: 2px solid #fff;
  transform: rotate(-45deg);
}

/* Tags / Badges */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
  margin-right: 6px;
  margin-bottom: 6px;
}

.badge-blue {
  background: #eff6ff;
  color: #2563eb;
}

.badge-green {
  background: #ecfdf5;
  color: #059669;
}

.badge-amber {
  background: #fffbeb;
  color: #d97706;
}

.badge-gray {
  background: #f3f4f6;
  color: #6b7280;
}

/* Leaflet Popup Styling */
.leaflet-popup-content-wrapper {
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  padding: 0;
}

.leaflet-popup-content {
  margin: 12px 16px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 13px;
  line-height: 1.5;
  max-width: 320px;
  color: #333;
}

.leaflet-popup-content strong {
  font-size: 14px;
  color: #1a1a2e;
}

.leaflet-popup-tip {
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

/* Rental Markers */
.rental-marker-icon {
  background: none !important;
  border: none !important;
}

.rental-marker {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px 10px;
  border-radius: 14px;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  overflow: hidden;
}

.rental-marker:hover {
  transform: scale(1.08);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
}

.marker-stars {
  font-size: 9px;
  line-height: 1;
  margin-right: 2px;
  opacity: 0.85;
}

.marker-status-stripe {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 6px;
  border-radius: 0 14px 14px 0;
}

/* Active Marker Highlight */
.active-marker {
  transform: scale(1.15);
  box-shadow: 0 0 0 3px #fff, 0 0 0 5px #3b82f6, 0 4px 12px rgba(37, 99, 235, 0.4);
}

.marker-active {
  filter: drop-shadow(0 0 6px rgba(37, 99, 235, 0.6)) drop-shadow(0 0 12px rgba(37, 99, 235, 0.3));
  z-index: 1000 !important;
}

/* Scrollbar for detail panel */
#detail-panel::-webkit-scrollbar {
  width: 6px;
}

#detail-panel::-webkit-scrollbar-track {
  background: transparent;
}

#detail-panel::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 3px;
}

#detail-panel::-webkit-scrollbar-thumb:hover {
  background: #9ca3af;
}

/* Status Badge in Detail Panel */
.detail-status {
  margin: 6px 0 4px;
}

.status-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  letter-spacing: 0.3px;
}

/* Detail Panel - Image Gallery */
.detail-gallery {
  margin-bottom: 16px;
}

.gallery-main {
  width: 100%;
  border-radius: 8px;
  overflow: hidden;
  background: #f3f4f6;
  margin-bottom: 8px;
}

.gallery-main-img {
  width: 100%;
  height: 280px;
  object-fit: contain;
  display: block;
  background: #f3f4f6;
}

.gallery-thumbs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.gallery-thumb {
  width: 64px;
  height: 48px;
  object-fit: contain;
  background: #f3f4f6;
  border-radius: 4px;
  cursor: pointer;
  border: 2px solid transparent;
  opacity: 0.6;
  transition: opacity 0.15s, border-color 0.15s;
  flex-shrink: 0;
}

.gallery-thumb:hover {
  opacity: 0.85;
}

.gallery-thumb.active {
  border-color: #3b82f6;
  opacity: 1;
}

/* Detail Panel - Listing Link */
.detail-listing-link {
  margin-bottom: 12px;
}

.detail-listing-link a {
  display: inline-block;
  padding: 6px 14px;
  background: #2563eb;
  color: #fff;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  transition: background 0.15s;
}

.detail-listing-link a:hover {
  background: #1d4ed8;
}

/* Detail Panel - Rendered Markdown */
.detail-markdown {
  font-size: 14px;
  line-height: 1.65;
  color: #374151;
}

.detail-markdown h1 {
  font-size: 20px;
  font-weight: 700;
  color: #1a1a2e;
  margin: 0 0 12px;
  line-height: 1.3;
}

.detail-markdown h2 {
  font-size: 16px;
  font-weight: 700;
  color: #1f2937;
  margin: 24px 0 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid #e5e7eb;
}

.detail-markdown h3 {
  font-size: 14px;
  font-weight: 600;
  color: #374151;
  margin: 16px 0 6px;
}

.detail-markdown p {
  margin: 0 0 10px;
}

.detail-markdown ul,
.detail-markdown ol {
  padding-left: 20px;
  margin: 0 0 10px;
}

.detail-markdown li {
  margin-bottom: 3px;
}

.detail-markdown table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0 12px;
  font-size: 13px;
}

.detail-markdown th,
.detail-markdown td {
  padding: 6px 10px;
  text-align: left;
  border-bottom: 1px solid #f0f0f0;
}

.detail-markdown th {
  font-weight: 600;
  color: #6b7280;
  background: #f9fafb;
  font-size: 12px;
}

.detail-markdown tr:hover td {
  background: #f9fafb;
}

.detail-markdown a {
  color: #2563eb;
  text-decoration: none;
}

.detail-markdown a:hover {
  text-decoration: underline;
}

.detail-markdown hr {
  border: none;
  border-top: 1px solid #e5e7eb;
  margin: 16px 0;
}

.detail-markdown strong {
  font-weight: 600;
  color: #1f2937;
}

.detail-markdown code {
  background: #f3f4f6;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 12px;
}

/* Images inside rendered markdown — never crop */
.detail-markdown img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  margin: 6px 0;
  display: block;
  background: #f3f4f6;
}

/* Checkbox lists in markdown */
.detail-markdown input[type="checkbox"] {
  margin-right: 6px;
  vertical-align: middle;
}

/* Search Button */
.search-btn {
  background: #f3f4f6;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  padding: 4px 12px;
  font-size: 13px;
  color: #374151;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}

.search-btn:hover {
  background: #e5e7eb;
}

/* Search Overlay */
.search-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 2000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 10vh;
}

.search-overlay.hidden {
  display: none;
}

.search-dialog {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.2);
  width: 560px;
  max-width: 90vw;
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.search-input {
  padding: 14px 18px;
  border: none;
  border-bottom: 1px solid #e5e7eb;
  font-size: 16px;
  font-family: inherit;
  outline: none;
  color: #1f2937;
}

.search-input::placeholder {
  color: #9ca3af;
}

.search-results {
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.search-result-item {
  padding: 12px 18px;
  border-bottom: 1px solid #f3f4f6;
  cursor: pointer;
  transition: background 0.1s;
}

.search-result-item:hover {
  background: #f9fafb;
}

.search-result-title {
  font-size: 14px;
  font-weight: 600;
  color: #1f2937;
  margin-bottom: 4px;
}

.search-result-price {
  font-weight: 500;
  color: #6b7280;
  font-size: 12px;
}

.search-snippet {
  font-size: 13px;
  color: #6b7280;
  line-height: 1.5;
  margin-top: 2px;
}

.search-snippet mark {
  background: #fef08a;
  color: #1f2937;
  border-radius: 2px;
  padding: 0 1px;
}

.search-empty {
  padding: 24px 18px;
  text-align: center;
  color: #9ca3af;
  font-size: 14px;
}

.search-hint {
  padding: 8px 18px;
  font-size: 12px;
  color: #9ca3af;
  border-top: 1px solid #e5e7eb;
  text-align: center;
}

/* Filter Toggle Button (mobile only) */
.filter-toggle {
  display: none;
  background: #f3f4f6;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  padding: 4px 12px;
  font-size: 13px;
  color: #374151;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}

.filter-toggle:hover {
  background: #e5e7eb;
}

.filter-toggle.active {
  background: #2563eb;
  color: #fff;
  border-color: #2563eb;
}

/* Responsive: stack vertically on small screens */
@media (max-width: 768px) {
  #content {
    flex-direction: column;
  }

  #map {
    width: 100%;
    height: 50vh;
  }

  #detail-panel {
    width: 100%;
    height: auto;
    flex: 1;
    border-left: none;
    border-top: 1px solid #e5e7eb;
  }

  #header h1 {
    font-size: 16px;
  }

  .filter-toggle {
    display: inline-block;
  }

  /* Legend becomes a collapsible drawer */
  #legend {
    display: none;
    position: absolute;
    top: 50px;
    left: 0;
    right: 0;
    background: #fff;
    border-bottom: 1px solid #e0e0e0;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    padding: 12px 16px;
    flex-direction: column;
    gap: 10px;
    z-index: 999;
  }

  #legend.open {
    display: flex;
  }

  .legend-group {
    flex-wrap: wrap;
    gap: 8px;
  }

  .legend-divider {
    display: none;
  }

  /* Date slider wider on mobile */
  .date-slider {
    width: 120px;
  }
}
