/* === Reset & Base === */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #1a1a2e;
  color: #eee;
  line-height: 1.5;
}

/* === Header === */
#header {
  height: 48px;
  padding: 0 24px;
  background: #111;
  border-bottom: 1px solid #222;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 1000;
  position: relative;
}
#header h1 { font-size: 18px; font-weight: 600; color: #fff; }
#header h1 span { color: #4ecca3; }
#header p { font-size: 13px; color: #888; }

/* === Map === */
#map {
  width: 100%;
  height: calc(100vh - 48px);
  position: relative;
}

/* === Search Bar === */
.search-container {
  position: absolute;
  top: 12px;
  left: 56px;
  z-index: 1000;
  width: 340px;
}
.search-container input {
  width: 100%;
  padding: 10px 36px 10px 14px;
  background: rgba(22, 33, 62, 0.92);
  border: 1px solid #0f3460;
  border-radius: 8px;
  color: #eee;
  font-size: 14px;
  outline: none;
  backdrop-filter: blur(8px);
}
.search-container input::placeholder { color: #666; }
.search-container input:focus { border-color: #4ecca3; }
.search-clear {
  position: absolute;
  top: 8px;
  right: 10px;
  background: none;
  border: none;
  color: #666;
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
  padding: 2px 4px;
}
.search-clear:hover { color: #eee; }
.search-results {
  margin-top: 4px;
  background: rgba(22, 33, 62, 0.95);
  border: 1px solid #0f3460;
  border-radius: 8px;
  overflow: hidden;
  display: none;
  backdrop-filter: blur(8px);
}
.search-results.visible { display: block; }
.search-result-item {
  padding: 10px 14px;
  font-size: 13px;
  color: #ccc;
  cursor: pointer;
  border-bottom: 1px solid rgba(15, 52, 96, 0.5);
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover {
  background: #0f3460;
  color: #fff;
}

/* === Score Panel === */
.score-panel {
  position: fixed;
  top: 48px;
  right: 0;
  width: 360px;
  height: calc(100vh - 48px);
  background: #16213e;
  border-left: 1px solid #0f3460;
  transform: translateX(100%);
  transition: transform 0.3s ease;
  overflow-y: auto;
  z-index: 900;
}
.score-panel.open { transform: translateX(0); }
.panel-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: none;
  border: none;
  color: #888;
  font-size: 20px;
  cursor: pointer;
  z-index: 1;
  padding: 2px 6px;
}
.panel-close:hover { color: #eee; }

.panel-tabs {
  display: flex;
  gap: 8px;
  padding: 12px 20px 0;
  border-bottom: 1px solid rgba(15, 52, 96, 0.6);
}
.panel-tab {
  border: 1px solid rgba(78, 204, 163, 0.18);
  border-bottom: none;
  border-radius: 8px 8px 0 0;
  background: rgba(15, 52, 96, 0.35);
  color: #8fa7c2;
  padding: 10px 14px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.panel-tab:hover {
  background: rgba(15, 52, 96, 0.6);
  color: #d7e6f6;
}
.panel-tab.active {
  background: #1b3157;
  color: #4ecca3;
  border-color: rgba(78, 204, 163, 0.35);
}
.panel-tab-content { display: none; }
.panel-tab-content.active { display: block; }

/* Panel Sections */
.panel-header {
  padding: 24px 20px 16px;
  border-bottom: 1px solid rgba(15, 52, 96, 0.6);
}
.panel-address {
  font-size: 13px;
  color: #aaa;
  margin-bottom: 12px;
  word-wrap: break-word;
}
.panel-score {
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.panel-score-number {
  font-size: 56px;
  font-weight: 700;
  line-height: 1;
}
.panel-score-label {
  font-size: 14px;
  color: #aaa;
}
.score-green { color: #4ecca3; }
.score-yellow { color: #ffc107; }
.score-red { color: #e74c3c; }

.panel-section {
  padding: 16px 20px;
  border-bottom: 1px solid rgba(15, 52, 96, 0.6);
}
.panel-section-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #888;
  margin-bottom: 12px;
}

/* Breakdown Bars */
.breakdown-item {
  margin-bottom: 10px;
}
.breakdown-label {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  margin-bottom: 4px;
}
.breakdown-label span:first-child { color: #ccc; }
.breakdown-label span:last-child { color: #eee; font-weight: 600; }
.breakdown-bar {
  height: 6px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 3px;
  overflow: hidden;
}
.breakdown-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.5s ease;
}

/* Details */
.detail-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 13px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}
.detail-row:last-child { border-bottom: none; }
.detail-key { color: #888; }
.detail-value { color: #eee; text-align: right; max-width: 55%; }

.legend-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.legend-item {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 12px;
  align-items: start;
}
.legend-swatch {
  height: 16px;
  width: 36px;
  margin-top: 2px;
  position: relative;
}
.legend-swatch.line {
  border-radius: 999px;
}
.legend-swatch.line.blue { background: #3498db; height: 3px; margin-top: 8px; }
.legend-swatch.line.yellow { background: #f1c40f; height: 3px; margin-top: 8px; }
.legend-swatch.line.orange { background: #f39c12; height: 3px; margin-top: 8px; }
.legend-swatch.line.red { background: #e74c3c; height: 4px; margin-top: 7px; }
.legend-swatch.line.dashed-green {
  height: 0;
  margin-top: 8px;
  border-top: 2px dashed #2ecc71;
}
.legend-swatch.dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #4ecca3;
  border: 1px solid rgba(255, 255, 255, 0.3);
  margin-left: 10px;
}
.legend-swatch.ring {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #4ecca3;
  box-shadow: 0 0 0 8px rgba(78, 204, 163, 0.08);
  margin-left: 10px;
}
.legend-swatch.plant {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #f39c12;
  margin-left: 11px;
}
.legend-swatch.reach {
  height: 0;
  margin-top: 8px;
  border-top: 2px dashed #64dd17;
}
.legend-body strong {
  display: block;
  color: #e8f1fb;
  font-size: 13px;
  margin-bottom: 2px;
}
.legend-body span {
  display: block;
  color: #8ca1bb;
  font-size: 12px;
  line-height: 1.5;
}

/* Warnings */
.warning-box {
  padding: 10px 12px;
  margin-bottom: 8px;
  border-radius: 6px;
  font-size: 12px;
  line-height: 1.5;
  background: rgba(231, 76, 60, 0.12);
  border: 1px solid rgba(231, 76, 60, 0.25);
  color: #f0a0a0;
}
.warning-box.info {
  background: rgba(255, 193, 7, 0.1);
  border-color: rgba(255, 193, 7, 0.25);
  color: #e0c060;
}

/* Copy Link */
.panel-actions {
  padding: 16px 20px 24px;
}
.btn-copy-link {
  width: 100%;
  padding: 10px;
  background: #0f3460;
  border: 1px solid rgba(78, 204, 163, 0.3);
  border-radius: 6px;
  color: #4ecca3;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-copy-link:hover { background: #1a4a80; }

/* === Layer Controls === */
.layer-controls {
  position: absolute;
  bottom: 24px;
  right: 12px;
  z-index: 800;
  background: rgba(22, 33, 62, 0.92);
  border: 1px solid #0f3460;
  border-radius: 8px;
  padding: 10px 14px;
  backdrop-filter: blur(8px);
}
.layer-controls label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #ccc;
  cursor: pointer;
  padding: 3px 0;
}
.layer-controls input[type="checkbox"] {
  accent-color: #4ecca3;
}

/* === Loading Overlay === */
.loading-overlay {
  position: fixed;
  top: 48px;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(26, 26, 46, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.loading-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}
.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(78, 204, 163, 0.2);
  border-top-color: #4ecca3;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* === Pulsing Marker === */
.pulse-marker {
  width: 16px;
  height: 16px;
  background: #4ecca3;
  border-radius: 50%;
  box-shadow: 0 0 0 0 rgba(78, 204, 163, 0.5);
  animation: pulse 2s ease-out infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(78, 204, 163, 0.5); }
  70% { box-shadow: 0 0 0 20px rgba(78, 204, 163, 0); }
  100% { box-shadow: 0 0 0 0 rgba(78, 204, 163, 0); }
}

/* === Leaflet Overrides (Dark Popups) === */
.leaflet-popup-content-wrapper {
  background: #16213e;
  color: #eee;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}
.leaflet-popup-tip { background: #16213e; }
.leaflet-popup-content { font-size: 13px; line-height: 1.5; }
.leaflet-popup-content strong { color: #4ecca3; }

/* === Mobile === */
@media (max-width: 768px) {
  .score-panel {
    width: 100%;
    top: 48px;
    height: calc(100vh - 48px);
  }
  .search-container { width: calc(100% - 24px); }
  .layer-controls { bottom: 12px; right: 8px; }
  .panel-score-number { font-size: 44px; }
}
