* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  display: flex;
  height: 100vh;
  overflow: hidden;
  background: #1a1a2e;
  color: #e0e0e0;
}

/* ── Filter Pane ── */
#filter-pane {
  width: 300px;
  min-width: 300px;
  background: #16213e;
  border-right: 1px solid #0f3460;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#filter-header {
  padding: 18px 16px 12px;
  background: #0f3460;
  border-bottom: 1px solid #1a4a7a;
}

#filter-header h1 {
  font-size: 16px;
  font-weight: 600;
  color: #00d4ff;
  letter-spacing: 0.5px;
}

#filter-header p {
  font-size: 11px;
  color: #8899aa;
  margin-top: 30px;
  margin-bottom: 20px;
  line-height: 1.5;
}

#filter-header p a {
  color: #6ab0d4;
  text-decoration: none;
}

#filter-header p a:hover {
  color: #00d4ff;
  text-decoration: underline;
}

#filter-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px;
}

#filter-body::-webkit-scrollbar { width: 6px; }
#filter-body::-webkit-scrollbar-track { background: #16213e; }
#filter-body::-webkit-scrollbar-thumb { background: #0f3460; border-radius: 3px; }

.filter-section {
  margin-bottom: 16px;
}

.filter-section label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: #00d4ff;
  margin-bottom: 6px;
}

.filter-group-header {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: #ffffff;
  background: #0f3460;
  border-left: 3px solid #00d4ff;
  padding: 5px 10px;
  margin: 6px -12px 12px;
}

/* Hierarchical tree picker */
.tree-picker {
  background: #0f3460;
  border: 1px solid #1a4a7a;
  border-radius: 0 0 4px 4px;
  max-height: 240px;
  overflow-y: auto;
}

.tree-toolbar {
  display: flex;
  gap: 4px;
  margin-bottom: 3px;
}

.tree-toolbar button {
  flex: 1;
  background: rgba(15, 52, 96, 0.7);
  border: 1px solid #1a4a7a;
  color: #8899aa;
  border-radius: 3px;
  padding: 3px 4px;
  font-size: 10px;
  cursor: pointer;
  white-space: nowrap;
  line-height: 1.4;
}

.tree-toolbar button:hover {
  background: rgba(0, 212, 255, 0.12);
  color: #00d4ff;
  border-color: #00d4ff;
}

.tree-picker::-webkit-scrollbar { width: 5px; }
.tree-picker::-webkit-scrollbar-track { background: #0f3460; }
.tree-picker::-webkit-scrollbar-thumb { background: #1a4a7a; border-radius: 3px; }

.tree-list, .tree-children {
  list-style: none;
  padding: 0;
  margin: 0;
}

.tree-children.tree-collapsed { display: none; }

.tree-row {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px;
  user-select: none;
}

.tree-row:hover { background: rgba(0, 212, 255, 0.08); }

.tree-level-0 { padding-left: 6px; }
.tree-level-1 { padding-left: 24px; }
.tree-level-2 { padding-left: 42px; }

.tree-toggle {
  font-size: 9px;
  color: #8899aa;
  width: 12px;
  flex-shrink: 0;
  cursor: pointer;
  text-align: center;
}
.tree-toggle:hover { color: #00d4ff; }

.tree-node-label {
  font-size: 12px;
  color: #c8d8e8;
  flex: 1;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tree-level-0 > .tree-row > .tree-node-label {
  font-weight: 700;
  color: #00d4ff;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.tree-level-1 > .tree-row > .tree-node-label {
  font-weight: 600;
  color: #aaddff;
}

.tree-cb {
  accent-color: #00d4ff;
  cursor: pointer;
  flex-shrink: 0;
  width: 13px;
  height: 13px;
}

.filter-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  margin-bottom: 16px;
}

.btn {
  flex: 1;
  padding: 8px;
  border: none;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-primary {
  background: #0078d4;
  color: #fff;
}

.btn-primary:hover { background: #006cbd; }

.btn-secondary {
  background: #1a4a7a;
  color: #e0e0e0;
}

.btn-secondary:hover { background: #255a8a; }

/* Latency range */
.range-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.range-row input[type="number"] {
  width: 70px;
  flex: none;
  background: #0f3460;
  color: #e0e0e0;
  border: 1px solid #1a4a7a;
  border-radius: 4px;
  padding: 6px 8px;
  font-size: 12px;
  outline: none;
  -moz-appearance: textfield;
}

.range-row input[type="number"]::-webkit-inner-spin-button,
.range-row input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; }

.range-row input[type="number"]:focus { border-color: #00d4ff; }

.range-row span { font-size: 11px; color: #8899aa; }

/* Stats bar */
#stats-bar {
  padding: 10px 12px;
  background: #0a1628;
  border-top: 1px solid #0f3460;
  font-size: 11px;
  color: #8899aa;
}

#stats-bar span { color: #00d4ff; font-weight: 600; }

#github-bar {
  margin-top: 6px;
  font-size: 11px;
}

#github-bar a {
  color: #8899aa;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 5px;
}

#github-bar a::before {
  content: '';
  display: inline-block;
  width: 14px;
  height: 14px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='%238899aa' d='M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-size: 14px 14px;
  flex-shrink: 0;
}

#github-bar a:hover {
  color: #c8d8e8;
}

/* ── Map ── */
#map-container {
  flex: 1;
  position: relative;
}

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

/* Leaflet interactive elements use pointer cursor */
.leaflet-interactive { cursor: pointer !important; }

/* Dark background for Leaflet map before tiles load */
.leaflet-container { background: #0d1117; }

/* ── Tooltip ── */
#tooltip, #tooltip-node {
  position: absolute;
  background: rgba(15, 52, 96, 0.95);
  border: 1px solid #00d4ff;
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 12px;
  color: #e0e0e0;
  pointer-events: none;
  display: none;
  z-index: 1100;
  white-space: nowrap;
  backdrop-filter: blur(4px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}

.tt-close {
  pointer-events: auto;
  position: absolute;
  top: 4px;
  right: 5px;
  background: none;
  border: none;
  color: #8899aa;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
}

.tt-close:hover {
  color: #ffffff;
}

#tooltip .tt-title {
  font-weight: 600;
  color: #00d4ff;
  margin-bottom: 4px;
  font-size: 13px;
}

#tooltip-node .tt-title {
  font-weight: 600;
  color: #00d4ff;
  margin-bottom: 4px;
  font-size: 13px;
}

#tooltip .tt-latency {
  color: #ffcc00;
  font-weight: 700;
  font-size: 14px;
}

#tooltip .tt-latency-rev {
  color: #aaddff;
  font-weight: 600;
  font-size: 13px;
  margin-top: 2px;
}

#tooltip .tt-sub, #tooltip-node .tt-sub {
  font-size: 11px;
  color: #8899aa;
  margin-top: 2px;
}

.tt-details {
  margin-top: 7px;
  border-top: 1px solid rgba(0, 212, 255, 0.2);
  padding-top: 6px;
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 10px;
  row-gap: 3px;
  font-size: 11px;
}

.tt-details .tt-dk {
  color: #8899aa;
  white-space: nowrap;
}

.tt-details .tt-dv {
  color: #c8d8e8;
  font-weight: 500;
}

.tt-details .tt-dv-latency {
  font-weight: 700;
}

/* Legend */
#legend {
  position: absolute;
  bottom: 30px;
  right: 12px;
  background: rgba(15, 52, 96, 0.92);
  border: 1px solid #1a4a7a;
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 11px;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

#legend .leg-title {
  font-weight: 600;
  color: #00d4ff;
  font-size: 12px;
  margin: 0 0 7px 0;
}

#btn-table {
  position: absolute;
  bottom: 30px;
  right: 162px;
  background: rgba(15, 52, 96, 0.92);
  border: 1px solid #00d4ff;
  color: #00d4ff;
  border-radius: 6px;
  padding: 7px 14px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  z-index: 1000;
  backdrop-filter: blur(4px);
}
#btn-table:hover { background: rgba(0, 212, 255, 0.2); }

/* Table modal */
#table-modal {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 1200;
  display: flex;
  align-items: center;
  justify-content: center;
}

#table-modal-box {
  background: #0f1b2d;
  border: 1px solid #1a4a7a;
  border-radius: 8px;
  width: min(760px, 90%);
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0,0,0,0.6);
}

#table-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid #1a4a7a;
  background: rgba(15, 52, 96, 0.6);
}

#table-modal-title {
  font-weight: 600;
  color: #00d4ff;
  font-size: 14px;
}

#btn-table-close {
  background: none;
  border: none;
  color: #a0b4cc;
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
  padding: 0 4px;
}
#btn-table-close:hover { color: #fff; }

#table-modal-body {
  overflow: auto;
  padding: 0;
}

#data-table {
  border-collapse: collapse;
  font-size: 11px;
  white-space: nowrap;
}

#data-table thead th.col-source {
  position: sticky;
  left: 0;
  top: 0;
  z-index: 3;
  background: #0a1628;
  color: #00d4ff;
  font-weight: 600;
  padding: 8px 12px;
  border-bottom: 1px solid #1a4a7a;
  border-right: 1px solid #1a4a7a;
  text-align: left;
  vertical-align: bottom;
}

#data-table thead th.col-dest {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #0a1628;
  color: #00d4ff;
  font-weight: 600;
  border-bottom: 1px solid #1a4a7a;
  padding: 4px 6px;
  vertical-align: bottom;
  text-align: left;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  height: 120px;
  min-width: 28px;
}

#data-table tbody td.src-cell {
  position: sticky;
  left: 0;
  background: #0a1628;
  color: #c8d8e8;
  font-weight: 500;
  padding: 5px 12px;
  border-bottom: 1px solid rgba(26, 74, 122, 0.35);
  border-right: 1px solid #1a4a7a;
  white-space: nowrap;
}

#data-table tbody tr:nth-child(even) td.src-cell { background: #091422; }
#data-table tbody tr:nth-child(even) { background: rgba(255,255,255,0.03); }
#data-table tbody tr:hover { background: rgba(0, 212, 255, 0.07); }
#data-table tbody tr:hover td.src-cell { background: rgba(0, 47, 80, 0.95); }

#data-table td.lat-cell {
  padding: 5px 6px;
  border-bottom: 1px solid rgba(26, 74, 122, 0.25);
  font-weight: 600;
  text-align: center;
  min-width: 28px;
}

#data-table td.empty-cell {
  color: rgba(136, 153, 170, 0.3);
  font-weight: 400;
}

.leg-item {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 5px;
}

.leg-line {
  width: 30px;
  height: 3px;
  border-radius: 2px;
}

/* Loading spinner */
#loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(26,26,46,0.7);
  z-index: 1050;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid #1a4a7a;
  border-top-color: #00d4ff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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