:root {
  --bg-0: #050b12;
  --bg-1: #0a1520;
  --panel-0: #0e1f2d;
  --panel-1: #13293b;
  --line: #23445f;
  --text: #eaf6ff;
  --muted: #97b4ca;
  --accent-blue: #2f91ff;
  --accent-teal: #1ec2b2;
  --good: #27d48d;
  --warn: #ffd166;
  --bad: #ff6978;
  --shadow: 0 20px 40px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: radial-gradient(circle at 20% 10%, #102338 0%, var(--bg-0) 50%), var(--bg-0);
  color: var(--text);
  font-family: "Manrope", "Segoe UI", sans-serif;
}

body {
  overflow: hidden;
}

.app-shell {
  min-height: 100vh;
  height: 100vh;
  display: grid;
  grid-template-columns: 390px 1fr;
  overflow: hidden;
}

.sidebar {
  position: relative;
  min-height: 0;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(95, 152, 191, 0.8) rgba(9, 21, 32, 0.7);
  padding: 22px 20px 26px;
  background: linear-gradient(190deg, rgba(16, 36, 54, 0.98), rgba(9, 22, 33, 0.98));
  border-right: 1px solid rgba(60, 100, 131, 0.4);
  backdrop-filter: blur(4px);
}

.sidebar::-webkit-scrollbar {
  width: 10px;
}

.sidebar::-webkit-scrollbar-track {
  background: rgba(9, 21, 32, 0.7);
}

.sidebar::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, rgba(47, 145, 255, 0.75), rgba(30, 194, 178, 0.78));
  border-radius: 999px;
  border: 2px solid rgba(9, 21, 32, 0.8);
}

.sidebar::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(135deg, rgba(31, 194, 178, 0.08), transparent 38%);
}

.panel-head,
.panel-section,
.loading-state,
.status-message {
  position: relative;
  z-index: 1;
}

.kicker {
  margin: 0 0 8px;
  font-size: 0.75rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #7eb8de;
  font-weight: 700;
}

h1,
h2,
h3 {
  margin: 0;
  font-family: "Space Grotesk", sans-serif;
  letter-spacing: 0.01em;
}

h1 {
  font-size: 1.5rem;
  line-height: 1.15;
}

h2 {
  font-size: 1.04rem;
}

.subtitle {
  margin: 8px 0 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.panel-section {
  margin-top: 14px;
  border: 1px solid rgba(55, 96, 127, 0.45);
  background: linear-gradient(180deg, rgba(15, 34, 49, 0.92), rgba(11, 24, 35, 0.95));
  box-shadow: var(--shadow);
  border-radius: 14px;
  padding: 14px;
}

.controls {
  display: grid;
  gap: 12px;
}

.control-field {
  display: grid;
  gap: 6px;
}

.control-field label,
.switch-control > span:first-child {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

select {
  width: 100%;
  border-radius: 10px;
  border: 1px solid rgba(66, 114, 148, 0.7);
  background: linear-gradient(180deg, rgba(19, 40, 58, 0.95), rgba(13, 29, 44, 0.95));
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  padding: 9px 10px;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

select:focus {
  border-color: var(--accent-teal);
  box-shadow: 0 0 0 3px rgba(30, 194, 178, 0.18);
}

.switch-control {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.switch-control.compact {
  gap: 8px;
  min-width: 110px;
}

.switch-control.compact > span:first-child {
  font-size: 0.76rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.switch {
  position: relative;
  width: 50px;
  height: 28px;
}

.switch input {
  position: absolute;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.switch-slider {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: rgba(114, 145, 169, 0.45);
  border: 1px solid rgba(127, 164, 193, 0.65);
  transition: background 0.2s ease;
}

.switch-slider::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #dff1ff;
  transition: transform 0.2s ease;
}

.switch input:checked + .switch-slider {
  background: linear-gradient(90deg, rgba(47, 145, 255, 0.6), rgba(30, 194, 178, 0.8));
}

.switch input:checked + .switch-slider::after {
  transform: translateX(21px);
}

.loading-state {
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid rgba(47, 145, 255, 0.5);
  background: rgba(16, 42, 62, 0.85);
  color: #c4e7ff;
  border-radius: 10px;
  padding: 9px 11px;
  font-size: 0.85rem;
}

.hidden {
  display: none;
}

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(161, 201, 232, 0.34);
  border-top-color: var(--accent-teal);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.status-message {
  margin: 10px 2px 4px;
  min-height: 1.1em;
  font-size: 0.82rem;
  color: #a9d4f1;
}

.status-message.warn {
  color: var(--warn);
}

.status-message.error {
  color: var(--bad);
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.score-badge {
  min-width: 60px;
  text-align: center;
  border-radius: 999px;
  padding: 7px 10px;
  font-family: "Space Grotesk", sans-serif;
  font-weight: 700;
  font-size: 1rem;
  transition: background-color 0.3s ease, color 0.3s ease;
}

.score-high {
  background: rgba(39, 212, 141, 0.22);
  color: #97ffd0;
  border: 1px solid rgba(39, 212, 141, 0.45);
}

.score-mid {
  background: rgba(255, 209, 102, 0.2);
  color: #ffe59c;
  border: 1px solid rgba(255, 209, 102, 0.5);
}

.score-low {
  background: rgba(255, 105, 120, 0.19);
  color: #ffc0c8;
  border: 1px solid rgba(255, 105, 120, 0.4);
}

.overall-label {
  margin: 10px 0 6px;
  font-size: 1rem;
  font-weight: 600;
}

.overall-meta {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.distribution-list {
  margin-top: 10px;
  display: grid;
  gap: 10px;
}

.distribution-item {
  display: grid;
  gap: 6px;
  padding: 8px 9px;
  border-radius: 10px;
  border: 1px solid rgba(53, 91, 121, 0.48);
  background: rgba(16, 39, 58, 0.68);
}

.distribution-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.distribution-label {
  font-size: 0.82rem;
  color: #d7ecfb;
}

.distribution-value {
  font-size: 0.82rem;
  color: #bee3fa;
  font-weight: 700;
}

.distribution-track {
  height: 8px;
  border-radius: 99px;
  background: rgba(125, 160, 186, 0.18);
  overflow: hidden;
}

.distribution-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, color-mix(in srgb, var(--dist-color) 40%, #a4f0ff), var(--dist-color));
  transition: width 0.5s ease;
}

.legend-list,
.category-list {
  display: grid;
  gap: 9px;
  margin-top: 10px;
}

.legend-item {
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  align-items: center;
  gap: 8px;
  font-size: 0.86rem;
  padding: 7px 9px;
  border-radius: 10px;
  background: rgba(16, 39, 58, 0.68);
  border: 1px solid rgba(53, 91, 121, 0.48);
}

.legend-item input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent-teal);
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--dot);
  box-shadow: 0 0 12px color-mix(in srgb, var(--dot) 65%, transparent);
}

.legend-count {
  color: #b9d6eb;
  font-weight: 700;
}

.category-item {
  border-radius: 12px;
  border: 1px solid rgba(56, 95, 124, 0.45);
  background: rgba(14, 33, 49, 0.82);
  padding: 9px;
}

.category-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  font-size: 0.84rem;
}

.category-name {
  font-weight: 600;
}

.category-score {
  color: #cbebff;
  font-weight: 700;
}

.category-meta {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.78rem;
}

.score-track {
  margin-top: 8px;
  height: 8px;
  border-radius: 99px;
  background: rgba(125, 160, 186, 0.18);
  overflow: hidden;
}

.score-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, color-mix(in srgb, var(--cat-color) 35%, #87e8ff), var(--cat-color));
  transition: width 0.6s ease;
}

.map-pane {
  position: relative;
  min-width: 0;
}

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

.map-hint {
  position: absolute;
  left: 14px;
  bottom: 14px;
  z-index: 700;
  background: rgba(11, 24, 35, 0.8);
  border: 1px solid rgba(68, 108, 136, 0.5);
  color: #c9e6f8;
  border-radius: 999px;
  padding: 8px 13px;
  font-size: 0.8rem;
  backdrop-filter: blur(3px);
}

.map-message {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 750;
  background: rgba(13, 29, 44, 0.93);
  border: 1px solid rgba(255, 209, 102, 0.6);
  color: #ffe9a9;
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.leaflet-control-zoom a,
.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
  background: #10283d;
  color: #ecf6ff;
}

.leaflet-control-zoom a {
  border-bottom-color: #1f405b;
}

.leaflet-control-zoom {
  border: 1px solid #2b4b65;
}

.leaflet-popup-content {
  margin: 10px 12px;
  font-family: "Manrope", sans-serif;
  font-size: 0.82rem;
}

.leaflet-popup-content strong {
  color: #d7f0ff;
}

.leaflet-popup-tip {
  box-shadow: none;
}

.building-popup {
  min-width: 220px;
  display: grid;
  gap: 8px;
}

.building-popup-title {
  margin: 0;
  font-family: "Space Grotesk", sans-serif;
  font-size: 0.92rem;
}

.building-popup-score {
  font-size: 0.82rem;
  color: #bedff7;
}

.building-popup-address {
  color: #9fc8e5;
}

.building-popup-grid {
  display: grid;
  gap: 4px;
}

.building-popup-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.78rem;
  color: #d6ebfa;
}

.building-popup-row span:last-child {
  font-weight: 700;
  color: #f0fbff;
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 340px 1fr;
  }

  .sidebar {
    padding: 18px 16px 20px;
  }
}

@media (max-width: 920px) {
  body {
    overflow: auto;
  }

  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(52vh, 58vh) auto;
    height: auto;
    overflow: visible;
  }

  .map-pane {
    order: 1;
  }

  .sidebar {
    order: 2;
    height: auto;
    min-height: 0;
    overflow: visible;
    border-right: 0;
    border-top: 1px solid rgba(60, 100, 131, 0.4);
  }

  #map {
    height: 58vh;
  }
}
