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

html, body { height: 100%; overflow: hidden; }

body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }

#map { position: absolute; inset: 0; }

/* ── Sidebar ── */
#sidebar {
  position: absolute;
  top: 0; right: 0;
  width: 300px; height: 100%;
  background: white;
  box-shadow: -2px 0 12px rgba(0,0,0,0.1);
  display: flex;
  flex-direction: column;
  z-index: 10;
  transform: translateX(100%);
  transition: transform 0.2s ease;
}
#sidebar.open { transform: translateX(0); }

#sidebar-header {
  padding: 16px;
  border-bottom: 1px solid #eee;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}
#sidebar-header h2 { font-size: 15px; font-weight: 600; color: #111; line-height: 1.3; }
#sidebar-header p  { font-size: 12px; color: #888; margin-top: 2px; }

#close-btn {
  background: none; border: none;
  font-size: 18px; color: #aaa;
  cursor: pointer; padding: 2px 4px;
  line-height: 1;
}
#close-btn:hover { color: #333; }

#sidebar-body { padding: 16px; flex: 1; overflow-y: auto; }

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 8px 0;
  border-bottom: 1px solid #f0f0f0;
  font-size: 13px;
}
.stat-row:last-child { border-bottom: none; }
.stat-label { color: #666; }
.stat-value { font-weight: 600; color: #111; font-variant-numeric: tabular-nums; }
.stat-value.positive { color: #2e7d32; }

.status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  text-transform: capitalize;
}
.status-under_review  { background: #fff3cd; color: #856404; }
.status-approved      { background: #d1ecf1; color: #0c5460; }
.status-construction  { background: #d4edda; color: #155724; }

/* ── Toggle ── */
#toggle-bar {
  position: absolute;
  top: 12px; left: 12px;
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  display: flex;
  overflow: hidden;
  z-index: 10;
}
#toggle-bar button {
  padding: 8px 14px;
  font-size: 12px;
  font-weight: 600;
  border: none;
  background: none;
  cursor: pointer;
  color: #666;
  transition: background 0.15s, color 0.15s;
}
#toggle-bar button.active {
  background: #111;
  color: white;
}

/* ── Popup ── */
.maplibregl-popup-content {
  padding: 12px 14px;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.18);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 12px;
  min-width: 200px;
  max-width: 100%;
  overflow-wrap: break-word;
}
.popup-name {
  font-size: 13px;
  font-weight: 600;
  color: #111;
  margin-bottom: 2px;
}
.popup-addr {
  font-size: 11px;
  color: #888;
  margin-bottom: 10px;
}
.popup-table {
  width: 100%;
  border-collapse: collapse;
}
.popup-table td { padding: 3px 0; }
.pl { color: #666; padding-right: 12px; white-space: nowrap; }
.pv { text-align: right; font-weight: 600; color: #111; font-variant-numeric: tabular-nums; }
.popup-table tr { border-bottom: 1px solid #f0f0f0; }
.popup-table tr:last-child { border-bottom: none; }
.row-sep-above td { border-top: 2px solid #ddd !important; padding-top: 8px; }
.popup-name-row { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 10px; gap: 8px; }
.popup-name-row .popup-name, .popup-name-row .popup-addr { margin-bottom: 0; }
.popup-note {
  margin: 10px 0 0;
  padding: 6px 8px;
  background: #f7f7f7;
  border-radius: 4px;
}
.popup-note-row {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
}
.popup-note-sub {
  display: block;
  margin-top: 4px;
  font-size: 10px;
  color: #999;
  line-height: 1.5;
  overflow-wrap: break-word;
}

.popup-header { display: none; }
.popup-tabs   { display: none; }
.popup-close  { display: none; }

.popup-with-image {
  display: flex;
  gap: 12px;
  align-items: center;
}
.popup-info-col {
  width: 220px;
  flex: 0 0 220px;
  min-width: 0;
}
.popup-image-col {
  flex: 0 0 auto;
}
.popup-photo {
  display: block;
  width: 220px;
  height: 220px;
  object-fit: cover;
  border-radius: 4px;
}

@media (max-width: 500px) {
  .popup-header {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    margin-bottom: 10px;
  }
  .popup-tabs {
    display: flex;
    flex: 1;
    border-bottom: 1px solid #eee;
  }
  .popup-tab {
    flex: 1;
    padding: 5px 8px;
    font-size: 12px;
    font-weight: 500;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    color: #aaa;
    margin-bottom: -1px;
  }
  .popup-tab.active {
    color: #111;
    font-weight: 600;
    border-bottom-color: #111;
  }
  .popup-close {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 22px; height: 22px;
    border: none;
    background: #eee;
    color: #555;
    border-radius: 50%;
    font-size: 11px;
    cursor: pointer;
  }
  .popup-with-image {
    flex-direction: column;
    align-items: stretch;
  }
  .popup-info-col {
    width: 100%;
    flex: none;
  }
  .popup-image-col {
    display: none;
  }
  .popup-with-image.show-photo .popup-image-col {
    display: block;
  }
  .popup-with-image.show-photo .popup-info-col {
    display: none;
  }
  .popup-photo {
    width: 100%;
    max-width: 250px;
    height: auto;
    aspect-ratio: 1 / 1;
  }
}

/* ── Layer toggles ── */
#layer-toggles {
  position: absolute;
  top: 12px; left: 12px;
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
  padding: 10px 14px;
  font-size: 12px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
#layer-toggles strong { font-size: 11px; color: #222; margin-bottom: 2px; }
#layer-toggles label {
  display: flex;
  align-items: center;
  gap: 7px;
  color: #555;
  cursor: pointer;
}
#layer-toggles input[type="checkbox"] { cursor: pointer; accent-color: #111; }

/* ── Bottom bar ── */
#bottom-bar {
  position: absolute;
  bottom: 28px; left: 12px;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  z-index: 10;
}
#bottom-bar:has(#methodology-content.hidden) {
  bottom: 5px;
}

/* ── Methodology ── */
#methodology {
  display: flex;
  align-items: flex-end;
}
#methodology-content {
  position: relative;
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
  padding: 10px 14px;
  padding-right: 34px;
  font-size: 11px;
  color: #555;
  max-width: 360px;
  line-height: 1.6;
}
.panel-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
  border-bottom: 1px solid #eee;
}
.panel-tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  padding: 0 2px 6px;
  font-size: 11px;
  font-weight: 600;
  color: #999;
  cursor: pointer;
}
.panel-tab.active {
  color: #111;
  border-bottom-color: #111;
}
.panel-page.hidden { display: none; }
#methodology-content ul {
  padding-left: 14px;
  margin: 0;
}
#methodology-content li { margin-bottom: 4px; }
#methodology-content li:last-child { margin-bottom: 0; }
#methodology-content.hidden { display: none; }
.methodology-warning {
  margin-top: 8px;
  padding-top: 7px;
  border-top: 1px solid #eee;
  font-size: 10px;
  color: #888;
  font-style: italic;
  line-height: 1.5;
}
#methodology-toggle {
  position: absolute;
  top: 8px; right: 8px;
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 1.5px solid #ccc;
  background: white;
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);
  cursor: pointer;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #555;
  padding: 0;
  line-height: 1;
}
#methodology-toggle:hover { border-color: #888; color: #111; }

@media (max-width: 500px) {
  #methodology-content { max-width: 300px; }
}
#methodology-collapsed {
  border-radius: 8px;
  border: 1.5px solid #ccc;
  background: white;
  box-shadow: 0 2px 6px rgba(0,0,0,0.12);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
  color: #444;
  padding: 8px 14px;
  line-height: 1;
  white-space: nowrap;
}
#methodology-collapsed:hover { border-color: #888; color: #111; }
#methodology-collapsed.hidden { display: none; }

/* ── Legend ── */
#legend {
  position: absolute;
  top: 12px; right: 12px;
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
  padding: 10px 14px;
  font-size: 11px;
  color: #555;
  z-index: 10;
}
#legend strong { display: block; margin-bottom: 6px; font-size: 11px; color: #222; }
.legend-row {
  display: flex;
  gap: 4px;
}
.legend-row + .legend-row { margin-top: 3px; }
.legend-swatch {
  display: inline-block;
  width: 32px; height: 12px;
  border-radius: 2px;
  flex-shrink: 0;
}
.legend-label {
  width: 32px;
  text-align: center;
  font-size: 10px;
  color: #666;
  flex-shrink: 0;
}
