* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: 'Sarabun', 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  color: #1a1a1a;
  background: #f4f5f7;
}

#app {
  display: grid;
  grid-template-columns: 360px 1fr;
  height: 100vh;
}

/* ============ Sidebar ============ */
#sidebar {
  background: #fff;
  border-right: 1px solid #e0e0e0;
  overflow-y: auto;
  padding: 0;
}

.sidebar-header {
  padding: 16px 18px;
  background: #1a1a1a;
  color: #fff;
}
.sidebar-header h1 {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.2px;
}
.sidebar-header .subtitle {
  font-size: 12px;
  color: #b0b0b0;
  margin-top: 3px;
}
.sidebar-header .author {
  font-size: 11px;
  color: #888;
  margin-top: 8px;
}

.section {
  padding: 14px 18px;
  border-bottom: 1px solid #ececec;
}
.section h2 {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  color: #666;
  text-transform: uppercase;
  margin-bottom: 10px;
}

/* Filter chips */
.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 10px;
  border-radius: 20px;
  background: #f0f0f0;
  border: 1.5px solid transparent;
  cursor: pointer;
  font-size: 12px;
  user-select: none;
  transition: all 0.15s;
}
.chip:hover { background: #e8e8e8; }
.chip.active {
  background: #fff;
  border-color: #1a1a1a;
  font-weight: 600;
}
.chip .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

/* Zone list */
.zone-list { list-style: none; }
.zone-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 0;
  cursor: pointer;
  border-radius: 6px;
  padding: 8px;
  margin: 0 -8px;
}
.zone-item:hover { background: #f4f4f4; }
.zone-item input { margin-top: 4px; }
.zone-color-bar {
  width: 4px;
  align-self: stretch;
  border-radius: 2px;
  flex-shrink: 0;
}
.zone-meta { flex: 1; min-width: 0; }
.zone-name { font-weight: 600; font-size: 13px; }
.zone-counts {
  display: flex;
  gap: 8px;
  margin-top: 3px;
  font-size: 11px;
  color: #777;
}
.zone-counts span b { color: #333; }

/* Stats panel */
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}
.stat-card {
  background: #f7f7f7;
  border-radius: 8px;
  padding: 8px 10px;
}
.stat-card .num { font-size: 20px; font-weight: 700; }
.stat-card .label { font-size: 10px; color: #777; text-transform: uppercase; letter-spacing: 0.5px; }
.stat-card.s .num { color: #1E88E5; }
.stat-card.w .num { color: #E53935; }
.stat-card.p .num { color: #F9A825; }

.balance-bar {
  height: 8px;
  border-radius: 4px;
  overflow: hidden;
  display: flex;
  margin-top: 4px;
  background: #eee;
}
.balance-bar .seg { height: 100%; }
.balance-bar .seg.stay { background: #1E88E5; }
.balance-bar .seg.work { background: #E53935; }
.balance-bar .seg.play { background: #FDD835; }
.balance-label {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: #666;
  margin-top: 5px;
}

/* Age bucket */
.age-bucket {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin-top: 8px;
}
.age-pill {
  background: #f4f4f4;
  border-radius: 6px;
  padding: 6px 0;
  text-align: center;
  font-size: 11px;
  cursor: pointer;
  border: 1.5px solid transparent;
}
.age-pill.active {
  background: #fff;
  border-color: #1a1a1a;
  font-weight: 600;
}
.age-pill .count {
  display: block;
  font-size: 16px;
  font-weight: 700;
  margin-top: 2px;
}
.age-pill.weight-high .count { color: #2e7d32; }
.age-pill.weight-mid .count { color: #f9a825; }
.age-pill.weight-low .count { color: #999; }

/* Google Maps links in popup */
.gmap-links {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid #eee;
  align-items: center;
}
.gmap-link {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 4px 8px;
  background: #f0f4ff;
  border: 1px solid #c7d6ff;
  border-radius: 12px;
  font-size: 11px;
  color: #1a1a1a;
  text-decoration: none;
  transition: background 0.15s;
}
.gmap-link:hover { background: #dfe8ff; }
.gmap-coord {
  font-family: monospace;
  font-size: 10.5px;
  color: #999;
  margin-left: auto;
}

/* STAY pin shapes (divIcon) — distinct by property type */
.pin-stay {
  background: #1E88E5;
  color: #fff;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  line-height: 1;
  font-family: 'Sarabun', sans-serif;
  box-sizing: border-box;
}
.pin-stay.type-house { border-radius: 50%; }                    /* บ้านเดี่ยว — วงกลม */
.pin-stay.type-condo { border-radius: 3px; }                    /* คอนโด — สี่เหลี่ยม */
.pin-stay.type-townhouse { border-radius: 9px 9px 3px 3px; }    /* ทาวน์เฮาส์ — บ้านแถวหลังคาโค้ง */
.pin-stay.type-duplex { border-radius: 50% / 35%; background: linear-gradient(90deg,#1E88E5 50%, #1976D2 50%); }  /* บ้านแฝด — แบ่งครึ่ง */

.pin-stay.age-sweet { border-color: #FFD700; }
.pin-stay.age-sweet-strong { border-color: #FFD700; border-width: 3px; box-shadow: 0 0 6px rgba(255,215,0,0.5); }

/* Magnet tier rows */
.tier-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px solid #f0f0f0;
}
.tier-row:last-child { border-bottom: none; }
.tier-badge {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  color: #fff;
  flex-shrink: 0;
}
.tier-row.tier-S .tier-badge { background: #FF6F00; }
.tier-row.tier-A .tier-badge { background: #FB8C00; }
.tier-row.tier-B .tier-badge { background: #FDD835; color: #5a4a00; }
.tier-row.tier-C .tier-badge { background: #d0d0d0; color: #555; }
.tier-meta { flex: 1; min-width: 0; }
.tier-name { font-size: 12px; font-weight: 600; }
.tier-desc { font-size: 10.5px; color: #777; margin-top: 1px; }
.tier-count {
  font-size: 16px;
  font-weight: 700;
  color: #1a1a1a;
}

/* Legend */
.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  padding: 3px 0;
}
.legend-item .dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

/* ============ Map ============ */
#map { height: 100vh; }

.leaflet-popup-content-wrapper {
  border-radius: 8px;
  font-family: 'Sarabun', 'Segoe UI', sans-serif;
}
.leaflet-popup-content {
  margin: 12px 14px;
  width: 280px !important;
  font-size: 12.5px;
  line-height: 1.45;
}
.popup-stay h3 {
  font-size: 14px;
  margin-bottom: 4px;
  color: #0d47a1;
}
.popup-stay .meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 8px;
}
.popup-stay .tag {
  background: #f0f4ff;
  padding: 2px 7px;
  border-radius: 10px;
  font-size: 11px;
  border: 1px solid #d0e0ff;
}
.popup-stay .tag.bucket-sweet {
  background: #fff3cd;
  border-color: #ffe066;
  font-weight: 600;
}
.popup-stay .row { margin-bottom: 6px; }
.popup-stay .row .label {
  font-size: 10.5px;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  font-weight: 600;
}
.popup-stay .row .val { font-size: 12px; }
.popup-stay .arbitrage {
  background: #f8f9fa;
  border-left: 3px solid #1E88E5;
  padding: 6px 8px;
  margin: 6px 0;
  font-size: 11.5px;
  border-radius: 0 4px 4px 0;
}
.popup-stay .price-row {
  display: flex;
  gap: 6px;
  margin: 6px 0;
}
.popup-stay .price-box {
  flex: 1;
  background: #f7f7f7;
  border-radius: 6px;
  padding: 5px 7px;
}
.popup-stay .price-box .l {
  font-size: 10px;
  color: #888;
  text-transform: uppercase;
}
.popup-stay .price-box .v {
  font-size: 12px;
  font-weight: 600;
  color: #1a1a1a;
}
.popup-stay .price-box.arv .v { color: #2e7d32; }

.popup-wp h4 {
  font-size: 13px;
  margin-bottom: 2px;
}
.popup-wp .cat-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}
.popup-wp.work .cat-label { color: #E53935; }
.popup-wp.play .cat-label { color: #F9A825; }

/* Zone panel (when zone polygon clicked) */
.zone-panel {
  position: absolute;
  bottom: 14px;
  left: 380px;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.18);
  padding: 14px 16px;
  width: 380px;
  z-index: 1000;
  max-height: 44vh;
  overflow-y: auto;
  display: none;
}
.zone-panel.show { display: block; }
.zone-panel .close {
  position: absolute;
  top: 8px;
  right: 12px;
  cursor: pointer;
  font-size: 18px;
  color: #999;
  border: none;
  background: none;
}
.zone-panel h3 {
  font-size: 16px;
  margin-bottom: 8px;
  padding-right: 24px;
}
.zone-panel .meta-row {
  font-size: 12px;
  color: #555;
  margin-bottom: 6px;
}
.zone-panel .meta-row b { color: #1a1a1a; }
.zone-panel .thesis {
  background: #f7f7f7;
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 12.5px;
  line-height: 1.5;
  margin: 8px 0;
}
.zone-panel .label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #777;
  font-weight: 600;
  margin-top: 6px;
}
