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

:root {
  --bg:      #0d0f14;
  --surface: #151820;
  --border:  #252933;
  --accent:  #e84141;
  --accent2: #ff7b00;
  --text:    #e8eaf0;
  --muted:   #8891a4;
  --font:    'Inter', 'Segoe UI', system-ui, sans-serif;
  --sidebar: 310px;
  --header:  56px;
}

html, body { height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 13px; }

/* ── HEADER ────────────────────────────────────────────────── */
#app-header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: var(--header);
  background: rgba(13,15,20,0.95);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 24px;
  padding: 0 20px;
}

#title-block h1 {
  font-size: 18px; font-weight: 700; letter-spacing: -0.3px;
  color: var(--accent);
}
#title-block p { font-size: 11px; color: var(--muted); margin-top: 1px; }

#stats-bar { display: flex; gap: 12px; margin-left: auto; }

.stat-pill {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 5px 12px; text-align: center;
  min-width: 80px;
}
.stat-num  { display: block; font-size: 16px; font-weight: 700; color: var(--accent2); line-height: 1.1; }
.stat-label{ display: block; font-size: 10px; color: var(--muted); margin-top: 1px; text-transform: uppercase; letter-spacing: 0.4px; }

/* ── MAIN LAYOUT ───────────────────────────────────────────── */
#main-layout {
  display: flex;
  height: 100vh;
  padding-top: var(--header);
}

/* ── SIDEBAR ───────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar);
  min-width: var(--sidebar);
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 0;
}

#sidebar::-webkit-scrollbar { width: 5px; }
#sidebar::-webkit-scrollbar-track { background: var(--surface); }
#sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.panel {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.panel h2 {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.8px; color: var(--muted); margin-bottom: 12px;
}

/* ── FILTERS ───────────────────────────────────────────────── */
.filter-group {
  display: flex; flex-direction: column; gap: 5px;
  font-size: 11px; color: var(--muted); text-transform: uppercase;
  letter-spacing: 0.5px; margin-bottom: 12px;
}

.filter-group select {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 7px 10px; font-size: 12px; font-family: var(--font);
  cursor: pointer; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%238891a4'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
}
.filter-group select:focus { outline: none; border-color: var(--accent); }

#reset-btn {
  width: 100%; padding: 8px;
  background: transparent; color: var(--muted);
  border: 1px solid var(--border); border-radius: 6px;
  font-size: 12px; cursor: pointer; font-family: var(--font);
  transition: all 0.15s;
}
#reset-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ── BAR CHARTS ────────────────────────────────────────────── */
.bar-chart { display: flex; flex-direction: column; gap: 5px; }

.bar-row {
  display: flex; align-items: center; gap: 7px; font-size: 11px;
}
.bar-label {
  width: 100px; min-width: 100px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  text-align: right;
}
.bar-track {
  flex: 1; height: 10px;
  background: var(--border); border-radius: 3px; overflow: hidden;
}
.bar-fill {
  height: 100%; border-radius: 3px;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  transition: width 0.4s ease;
}
.bar-val { width: 40px; color: var(--text); text-align: right; font-size: 10px; }

/* ── MAP ───────────────────────────────────────────────────── */
#map-container { flex: 1; position: relative; }
#map { width: 100%; height: 100%; }

/* ── LOADING OVERLAY ───────────────────────────────────────── */
#loading-overlay {
  position: absolute; inset: 0; z-index: 50;
  background: rgba(13,15,20,0.88);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
}

.loader-box { text-align: center; }

.spinner {
  width: 44px; height: 44px; border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
  margin: 0 auto 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }

#loading-text  { font-size: 14px; font-weight: 500; color: var(--text); }
.loading-sub   { font-size: 11px; color: var(--muted); margin-top: 6px; }

/* ── LEGEND ────────────────────────────────────────────────── */
#legend {
  position: absolute; bottom: 28px; right: 16px; z-index: 10;
  background: rgba(13,15,20,0.88); backdrop-filter: blur(6px);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px; min-width: 140px;
}
.legend-title { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.6px; margin-bottom: 8px; }
.legend-gradient {
  height: 8px; border-radius: 4px;
  background: linear-gradient(90deg,
    rgba(0,0,255,0)   0%,
    rgba(0,128,255,1) 25%,
    rgba(0,255,100,1) 50%,
    rgba(255,200,0,1) 75%,
    rgba(255,0,0,1)   100%
  );
}
.legend-labels { display: flex; justify-content: space-between; font-size: 10px; color: var(--muted); margin-top: 4px; }
.legend-note   { font-size: 10px; color: var(--muted); margin-top: 8px; line-height: 1.4; }

/* ── MAPLIBRE POPUP OVERRIDE ───────────────────────────────── */
.maplibregl-popup-content {
  background: var(--surface) !important;
  color: var(--text) !important;
  border: 1px solid var(--border) !important;
  border-radius: 10px !important;
  padding: 14px 16px !important;
  font-family: var(--font) !important;
  font-size: 12px !important;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5) !important;
  min-width: 200px;
}
.maplibregl-popup-tip { display: none !important; }

.popup-title {
  font-size: 13px; font-weight: 600; color: var(--accent);
  margin-bottom: 8px; padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.popup-row { display: flex; justify-content: space-between; gap: 12px; margin: 4px 0; }
.popup-key { color: var(--muted); }
.popup-val { font-weight: 500; text-align: right; }

.maplibregl-ctrl-attrib { font-size: 10px !important; }

/* ── RESPONSIVE ────────────────────────────────────────────── */
@media (max-width: 768px) {
  #sidebar { display: none; }
  #stats-bar .stat-pill:nth-child(n+3) { display: none; }
  #title-block p { display: none; }
}
