:root {
  --bg: #0d1117;
  --panel: #161b22;
  --panel-hover: #1c2230;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #f58e2c;
  --accent-soft: rgba(245, 142, 44, 0.18);
  --green: #3fb950;
  --green-soft: rgba(63, 185, 80, 0.18);
  --info: #7dd3fc;
  --info-soft: rgba(125, 211, 252, 0.15);
  --border: #30363d;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}

body {
  display: flex;
  flex-direction: column;
}

header {
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.header-left h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
}

.header-left h1 span {
  color: var(--muted);
  font-weight: 400;
}

.subtitle {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.help-btn {
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid rgba(245, 142, 44, 0.4);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s;
}

.help-btn:hover {
  background: rgba(245, 142, 44, 0.3);
}

main {
  flex: 1;
  display: grid;
  grid-template-columns: 380px 1fr;
  min-height: 0;
  position: relative;
}

#sidebar {
  overflow-y: auto;
  border-right: 1px solid var(--border);
  padding: 0 20px 18px;
  background: var(--panel);
  font-size: 13px;
  line-height: 1.55;
}

.tabs {
  display: flex;
  position: sticky;
  top: 0;
  height: 50px;
  align-items: stretch;
  background: var(--panel);
  z-index: 5;
  margin: 0 -20px;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
}

.tab {
  flex: 1;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  padding: 0 8px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  font-weight: 600;
  transition: color 0.15s, border-color 0.15s;
}

.tab:hover { color: var(--text); }

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab-content { display: none; }
.tab-content.active { display: block; padding-top: 18px; }

#sidebar h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin: 24px 0 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

#sidebar section:first-child h2 {
  margin-top: 0;
}

.callout {
  background: var(--accent-soft);
  border-left: 3px solid var(--accent);
  padding: 12px 14px;
  border-radius: 4px;
  margin: 6px 0 18px;
}

.callout h2 {
  margin-top: 0 !important;
  border-bottom: none !important;
  color: var(--accent) !important;
  padding-bottom: 0 !important;
}

.callout p { margin: 6px 0 0; }

.muted-small {
  color: var(--muted);
  font-size: 12px;
}

.link {
  color: var(--accent);
  text-decoration: none;
}
.link:hover { text-decoration: underline; }

.signal-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.signal-list li {
  display: flex;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.signal-list li:last-child { border-bottom: none; }
.signal-list .emoji {
  font-size: 18px;
  flex-shrink: 0;
}
.signal-list strong {
  display: block;
  margin-bottom: 2px;
}
.signal-list p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.stat {
  background: var(--panel-hover);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
}
.stat-value {
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
}
.stat-label {
  color: var(--muted);
  font-size: 11px;
  margin-top: 4px;
}

.bar-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.bar-list li {
  margin: 0 0 8px;
}
.bar-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 4px;
}
.bar-row .name { color: var(--text); font-size: 13px; }
.bar-row .count { color: var(--muted); font-size: 12px; }
.bar-track {
  width: 100%;
  height: 6px;
  background: var(--panel-hover);
  border-radius: 4px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  background: var(--accent);
  transition: width 0.2s;
}

.kv {
  list-style: none;
  padding: 0;
  margin: 0;
}
.kv li {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.kv li:last-child { border-bottom: none; }
.kv li span { color: var(--muted); }
.kv li strong { color: var(--text); font-weight: 500; }

.filter-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 6px 0;
}

.filter-row label.checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 13px;
}

.filter-row input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.filter-actions {
  flex-direction: row;
  gap: 8px;
}

.filter-btn-secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
  transition: background 0.15s, border-color 0.15s;
}
.filter-btn-secondary:hover {
  background: var(--panel-hover);
  border-color: var(--accent);
}

#map-wrap {
  position: relative;
  height: 100%;
  min-height: 400px;
}
#map {
  height: 100%;
  width: 100%;
}

#legend {
  position: absolute;
  left: 12px;
  bottom: 12px;
  background: rgba(13, 17, 23, 0.92);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 4;
}
.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}
.dot-i { background: #3fb950; }
.dot-a { background: #f58e2c; }
.cluster-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  background: rgba(245, 142, 44, 0.8);
  color: #fff;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 600;
}

.drawer {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 280px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  z-index: 6;
}
.drawer.hidden { display: none; }
.drawer h3 {
  margin: 0 0 12px;
  font-size: 15px;
  font-weight: 600;
}
.drawer-close {
  position: absolute;
  top: 8px;
  right: 8px;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 16px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
}
.drawer-close:hover { background: var(--panel-hover); color: var(--text); }
.drawer p { margin: 12px 0 0; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal.hidden { display: none; }
.modal-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 24px;
  max-width: 420px;
  width: calc(100% - 24px);
  position: relative;
}
.modal-card h3 { margin: 0 0 12px; }
.modal-card ol { padding-left: 18px; margin: 0; line-height: 1.6; font-size: 13px; }
.modal-card li { margin-bottom: 6px; }

@media (max-width: 720px) {
  main {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  #sidebar {
    max-height: 35vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .drawer {
    width: calc(100% - 24px);
  }
}
