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

:root {
  --bg:        #111827;
  --bg2:       #1f2937;
  --bg3:       #374151;
  --border:    #374151;
  --text:      #f3f4f6;
  --muted:     #9ca3af;
  --accent:    #3b82f6;
  --accent-h:  #60a5fa;
  --danger:    #ef4444;
  --sidebar-w: 310px;

  --score-lo:  #d73027;
  --score-mid: #fee08b;
  --score-hi:  #1a9850;
}

html, body { height: 100%; overflow: hidden; font-family: system-ui, -apple-system, sans-serif; font-size: 13px; }

/* ── Layout ──────────────────────────────────────────────────────────────── */
body        { display: flex; background: var(--bg); color: var(--text); }
#sidebar    { width: var(--sidebar-w); min-width: var(--sidebar-w); display: flex; flex-direction: column; overflow-y: auto; background: var(--bg); border-right: 1px solid var(--border); z-index: 10; }
#map-container { flex: 1; position: relative; }
#map        { width: 100%; height: 100%; }

/* ── Sidebar Header ──────────────────────────────────────────────────────── */
#sidebar-header {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px 12px;
  border-bottom: 1px solid var(--border);
}
#sidebar-header-main {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}
#home-link {
  font-size: 11px;
  color: var(--muted);
  text-decoration: none;
  letter-spacing: 0.02em;
}
#home-link:hover { color: var(--text); }
#sidebar-header h1 { font-size: 15px; font-weight: 700; line-height: 1.3; }
.subtitle { color: var(--muted); font-size: 11px; margin-top: 3px; }

#lod-pill {
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 99px;
  white-space: nowrap;
  margin-top: 2px;
}

/* ── Panels ──────────────────────────────────────────────────────────────── */
.panel {
  border-bottom: 1px solid var(--border);
  padding: 12px 14px;
}
.panel-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.panel-title.collapsible { cursor: pointer; user-select: none; }
.panel-title.collapsible:hover { color: var(--text); }

.chevron { transition: transform 0.2s; font-size: 10px; }
.panel-body.collapsed { display: none; }
.panel-body.collapsed + .chevron,
.panel-title.open .chevron { transform: rotate(-90deg); }

.panel-body { margin-top: 8px; }
.hint { color: var(--muted); font-size: 11px; margin-bottom: 10px; line-height: 1.4; }

/* ── Profile Grid ────────────────────────────────────────────────────────── */
#profile-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 8px;
}
.profile-btn {
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.profile-btn:hover  { background: var(--bg3); }
.profile-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

#profile-desc {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
  min-height: 28px;
}

/* ── Weight Sliders ──────────────────────────────────────────────────────── */
.weight-group { margin-bottom: 12px; }
.weight-group-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 6px;
  margin-top: 4px;
}

.weight-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 5px;
}
.weight-label {
  flex: 1;
  font-size: 11px;
  color: var(--text);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.weight-slider {
  width: 90px;
  accent-color: var(--accent);
  cursor: pointer;
}
.weight-val {
  width: 30px;
  text-align: right;
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ── Filter Controls ─────────────────────────────────────────────────────── */
.filter-row { margin-bottom: 12px; }
.filter-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
  font-size: 11px;
  color: var(--text);
}
.filter-val { color: var(--accent); font-weight: 600; font-variant-numeric: tabular-nums; }
.filter-slider {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
  display: block;
}
.filter-check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  cursor: pointer;
  margin-bottom: 10px;
}
.filter-check-row input { accent-color: var(--accent); width: 14px; height: 14px; cursor: pointer; }

#reset-filters-btn {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 6px;
  border-radius: 5px;
  font-size: 11px;
  cursor: pointer;
  margin-top: 4px;
  transition: color 0.15s, border-color 0.15s;
}
#reset-filters-btn:hover { color: var(--text); border-color: var(--muted); }

/* ── Legend ──────────────────────────────────────────────────────────────── */
#legend-bar { margin-bottom: 6px; }
#legend-gradient {
  height: 10px;
  border-radius: 4px;
  background: linear-gradient(to right, #d73027, #f46d43, #fee08b, #a6d96a, #1a9850);
  margin-bottom: 4px;
}
#legend-ticks {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--muted);
}
#legend-note { font-size: 10px; color: var(--muted); margin-top: 6px; }

/* ── Loading Bar ─────────────────────────────────────────────────────────── */
#loading-bar {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(17,24,39,0.9);
  color: var(--text);
  padding: 7px 16px;
  border-radius: 20px;
  font-size: 12px;
  pointer-events: none;
  border: 1px solid var(--border);
  backdrop-filter: blur(4px);
}
#loading-bar.hidden { display: none; }

/* ── MapLibre Overrides ──────────────────────────────────────────────────── */
.maplibregl-popup-content {
  background: #1f2937 !important;
  color: #f3f4f6 !important;
  border-radius: 8px !important;
  padding: 12px 14px !important;
  max-width: 260px !important;
  font-size: 12px !important;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5) !important;
}
.maplibregl-popup-tip { border-top-color: #1f2937 !important; }

.popup-name  { font-size: 13px; font-weight: 700; margin-bottom: 4px; line-height: 1.3; }
.popup-sub   { color: #9ca3af; font-size: 11px; margin-bottom: 10px; }

.popup-score {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 10px;
}
.popup-score-val {
  font-size: 26px;
  font-weight: 800;
  line-height: 1;
}
.popup-score-pct { font-size: 11px; color: #9ca3af; }

.popup-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 12px;
  margin-bottom: 10px;
}
.popup-metric { display: flex; flex-direction: column; }
.popup-metric-label { font-size: 10px; color: #9ca3af; }
.popup-metric-val   { font-size: 12px; font-weight: 600; }

.popup-bars { border-top: 1px solid #374151; padding-top: 8px; }
.popup-bar-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 3px;
}
.popup-bar-label { font-size: 10px; color: #9ca3af; width: 72px; min-width: 72px; }
.popup-bar-track {
  flex: 1;
  height: 4px;
  background: #374151;
  border-radius: 2px;
  overflow: hidden;
}
.popup-bar-fill { height: 100%; background: #3b82f6; border-radius: 2px; }
.popup-bar-val  { font-size: 10px; color: #9ca3af; width: 28px; text-align: right; }

/* ── Scrollbar styling ───────────────────────────────────────────────────── */
#sidebar::-webkit-scrollbar { width: 4px; }
#sidebar::-webkit-scrollbar-track { background: transparent; }
#sidebar::-webkit-scrollbar-thumb { background: var(--bg3); border-radius: 2px; }

/* ── Sidebar Disclaimer ──────────────────────────────────────────────────── */
#sidebar-disclaimer {
  padding: 10px 14px;
  font-size: 10px;
  color: var(--muted);
  line-height: 1.5;
  border-top: 1px solid var(--border);
}

/* ── Sidebar Footer ──────────────────────────────────────────────────────── */
#sidebar-footer {
  margin-top: auto;
  padding: 10px 14px 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
#sidebar-disclaimer {
  font-size: 10px;
  color: var(--muted);
  line-height: 1.5;
}
#changelog-btn {
  align-self: flex-start;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 10px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
#changelog-btn:hover { color: var(--text); border-color: var(--muted); }

/* ── Data Sources Modal ──────────────────────────────────────────────────── */
.resource-btn--sources       { border-left-color: #0d9488; }
.resource-btn--sources:hover { border-left-color: #2dd4bf; }
.resource-btn--api           { border-left-color: #d97706; }
.resource-btn--api:hover     { border-left-color: #fbbf24; }

#sources-modal {
  position: fixed;
  inset: 0;
  z-index: 600;
  display: flex;
  align-items: center;
  justify-content: center;
}
#sources-modal.hidden { display: none; }
#sources-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.6);
}
#sources-dialog {
  position: relative;
  z-index: 1;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: min(560px, 92vw);
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}
#sources-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
}
#close-sources-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
  padding: 2px 4px;
  line-height: 1;
}
#close-sources-btn:hover { color: var(--text); }
#sources-body {
  padding: 16px;
  overflow-y: auto;
  font-size: 12px;
  line-height: 1.6;
}
#sources-body::-webkit-scrollbar { width: 4px; }
#sources-body::-webkit-scrollbar-thumb { background: var(--bg3); border-radius: 2px; }

.sources-intro { color: var(--muted); font-size: 11px; margin-bottom: 14px; }

.src-section {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 16px 0 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}
.src-section:first-of-type { margin-top: 0; }

.src-entry {
  margin-bottom: 12px;
  padding-left: 10px;
  border-left: 2px solid var(--bg3);
}
.src-name   { font-weight: 600; color: var(--text); margin-bottom: 2px; }
.src-detail { color: var(--muted); font-size: 11px; margin-bottom: 3px; }
.src-link {
  font-size: 10px;
  color: var(--accent);
  text-decoration: none;
}
.src-link:hover { text-decoration: underline; }

/* ── Changelog Modal ─────────────────────────────────────────────────────── */
#changelog-modal {
  position: fixed;
  inset: 0;
  z-index: 600;
  display: flex;
  align-items: center;
  justify-content: center;
}
#changelog-modal.hidden { display: none; }

#changelog-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.6);
}
#changelog-dialog {
  position: relative;
  z-index: 1;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: min(520px, 92vw);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}
#changelog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
}
#close-changelog-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
  padding: 2px 4px;
  line-height: 1;
}
#close-changelog-btn:hover { color: var(--text); }

#changelog-body {
  padding: 16px;
  overflow-y: auto;
  font-size: 12px;
  line-height: 1.6;
}
#changelog-body::-webkit-scrollbar { width: 4px; }
#changelog-body::-webkit-scrollbar-thumb { background: var(--bg3); border-radius: 2px; }

.cl-version {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 4px;
}
.cl-version-tag {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
}
.cl-version-date { font-size: 11px; color: var(--muted); }
.cl-tagline { color: var(--muted); margin-bottom: 14px; font-size: 11px; }

.cl-section {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 14px 0 6px;
}
.cl-section:first-of-type { margin-top: 0; }

.cl-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.cl-list li { padding-left: 12px; position: relative; color: var(--text); }
.cl-list li::before {
  content: '–';
  position: absolute;
  left: 0;
  color: var(--muted);
}

/* ── Resources Panel ─────────────────────────────────────────────────────── */
.resources-body { display: flex; flex-direction: column; gap: 8px; }

.resource-btn {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 10px 12px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--muted);
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  text-align: left;
  transition: background 0.15s, border-left-color 0.15s;
}
.resource-btn:hover           { background: var(--bg3); }
.resource-btn--report         { border-left-color: #8b5cf6; }
.resource-btn--report:hover   { border-left-color: #a78bfa; }
.resource-btn--download       { border-left-color: var(--accent); }
.resource-btn--download:hover { border-left-color: var(--accent-h); }

.resource-text { display: flex; flex-direction: column; gap: 3px; }
.resource-title { font-size: 12px; font-weight: 600; }
.resource-sub   { font-size: 10px; color: var(--muted); }

/* ── Report Modal ────────────────────────────────────────────────────────── */
#report-modal {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  flex-direction: column;
}
#report-modal.hidden { display: none; }

#report-modal-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 14px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
#report-modal-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
#close-report-btn {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 5px 12px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 11px;
  transition: background 0.15s, border-color 0.15s;
}
#close-report-btn:hover { background: var(--danger); border-color: var(--danger); }

#report-iframe { flex: 1; border: none; width: 100%; background: #fff; }
