/* ═══════════════════════════ MAP PAGE ═══════════════════════════ */

/* ── Sidebar ─────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  height: 100%;
  max-height: 100%;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: transform 0.25s ease, min-width 0.25s ease, width 0.25s ease;
  z-index: 1000;
  overflow: hidden;
}

#sidebar.collapsed {
  transform: translateX(calc(-1 * var(--sidebar-w)));
  min-width: 0;
  width: 0;
  border-right: none;
}

#sidebar-reopen {
  display: none;
  position: fixed;
  top: calc(var(--nav-h) + 12px);
  left: 14px;
  z-index: 1100;
  background: var(--sidebar-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  padding: 8px 10px;
  cursor: pointer;
  line-height: 0;
  transition: all 0.15s;
  box-shadow: var(--shadow-md);
}
#sidebar-reopen:hover { background: var(--surface); color: var(--accent); border-color: var(--accent-ring); }
#sidebar.collapsed ~ #sidebar-reopen,
body.sidebar-collapsed #sidebar-reopen { display: flex; }

/* Header */
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg-elevated);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-subtitle {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

#sidebar-toggle {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s;
}
#sidebar-toggle:hover { background: var(--surface); color: var(--text); border-color: var(--border-strong); }

/* Scrollable area */
.sidebar-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.sidebar-scroll::-webkit-scrollbar { width: 6px; }
.sidebar-scroll::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 3px; }

/* ── Search ──────────────────────────────────────────────── */
.search-wrap {
  display: flex;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0 12px;
  gap: 8px;
  transition: all 0.15s;
}
.search-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
.search-icon { color: var(--text-muted); flex-shrink: 0; }

#search {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 13px;
  padding: 10px 0;
  font-family: inherit;
}
#search::placeholder { color: var(--text-dim); }

#clear-search {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
  padding: 2px 4px;
  border-radius: 3px;
}
#clear-search:hover { color: var(--text); background: var(--surface-hover); }

/* ── Stats row ───────────────────────────────────────────── */
.stats-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  gap: 6px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  transition: border-color 0.15s;
}
.stat-card:hover { border-color: var(--border-strong); }
.stat-val {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.stat-lbl {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 500;
}
.stat-card.online .stat-val { color: var(--st-online); }
.stat-card.recent .stat-val { color: var(--st-recent); }

/* ── Refresh bar ─────────────────────────────────────────── */
.refresh-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
}

#refresh-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  padding: 5px 10px;
  font-size: 11px;
  font-weight: 500;
  transition: all 0.15s;
}
#refresh-btn:hover {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent-ring);
}
#refresh-btn.loading svg { animation: spin 0.8s linear infinite; }

/* ── Filter groups ───────────────────────────────────────── */
.filter-group {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  overflow: hidden;
}

.group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: var(--surface);
  border: none;
  border-bottom: 1px solid var(--border-strong);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 8px 12px;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}
.group-header:hover { color: var(--text); background: var(--surface-hover); }
.group-header.collapsed { border-bottom: none; }

.chevron {
  transition: transform 0.2s;
  flex-shrink: 0;
}
.group-header.collapsed .chevron { transform: rotate(-90deg); }

.group-body {
  padding-top: 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.group-body.hidden { display: none; }

/* Source rows */
.source-row {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  transition: background 0.12s;
  user-select: none;
}
.source-row:hover { background: var(--surface); }
.source-row input[type="checkbox"] { display: none; }

/* Checkbox rows (status, role) */
.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  transition: background 0.12s;
  user-select: none;
  font-size: 13px;
  color: var(--text);
}
.check-row:hover { background: var(--surface); }
.check-row input[type="checkbox"] { accent-color: var(--accent); width: 14px; height: 14px; }

/* ── Legend ──────────────────────────────────────────────── */
.legend-block {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  background: var(--surface);
}
.legend-block h4 {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.legend-grid { display: flex; flex-direction: column; gap: 5px; }
.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--text-muted);
}
.legend-sep {
  font-size: 10px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 4px;
  padding-top: 4px;
  border-top: 1px solid var(--border-light);
}

/* ── Map wrap ────────────────────────────────────────────── */
#map-wrap {
  flex: 1;
  position: relative;
  height: 100%;
  overflow: hidden;
}

#map {
  width: 100%;
  height: 100%;
  background: var(--map-bg);
  overscroll-behavior: none;
}

/* ── Floating controls ───────────────────────────────────── */
.map-controls {
  position: absolute;
  bottom: 24px;
  right: 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--sidebar-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
  z-index: 900;
  box-shadow: var(--shadow-md);
}

.map-controls-sep {
  height: 1px;
  background: var(--border);
  margin: 2px 0;
}

.map-controls button {
  width: 32px;
  height: 32px;
  background: transparent;
  border: none;
  border-radius: var(--radius-xs);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.map-controls button:hover { background: var(--surface); color: var(--accent); }

/* ── Loading overlay ─────────────────────────────────────── */
#loading-overlay {
  position: absolute;
  inset: 0;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  z-index: 2000;
  color: var(--text-muted);
  font-size: 13px;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

/* ── Error toast ─────────────────────────────────────────── */
#error-toast {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(244,63,94,0.15);
  border: 1px solid var(--st-danger);
  color: var(--st-danger);
  padding: 9px 16px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 500;
  z-index: 2000;
  box-shadow: var(--shadow-md);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: opacity 0.3s;
}
#error-toast.hidden { display: none; }

/* ── Detail panel ────────────────────────────────────────── */
#detail-panel {
  width: var(--panel-w);
  min-width: var(--panel-w);
  height: 100%;
  background: var(--panel-bg);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform 0.25s ease, min-width 0.25s ease, width 0.25s ease;
  z-index: 900;
}
#detail-panel.hidden {
  transform: translateX(var(--panel-w));
  min-width: 0;
  width: 0;
  border-left: none;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg-elevated);
}

.node-identity {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-width: 0;
  flex: 1;
}

.short-name-badge {
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  color: var(--accent-contrast);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.03em;
  border-radius: var(--radius-xs);
  padding: 6px 10px;
  flex-shrink: 0;
  font-family: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  box-shadow: var(--shadow-accent);
}

.node-long-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
  word-break: break-word;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.node-hex-id {
  font-size: 11px;
  font-family: ui-monospace, monospace;
  color: var(--text-muted);
  margin-top: 2px;
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

#share-node-btn, #close-panel {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.15s;
}
#share-node-btn:hover, #close-panel:hover { background: var(--surface); color: var(--text); border-color: var(--border-strong); }

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.panel-body::-webkit-scrollbar { width: 6px; }
.panel-body::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 3px; }

.badges-row { display: flex; flex-wrap: wrap; gap: 6px; }

/* Detail row */
.detail-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  font-size: 12px;
}
.detail-label { color: var(--text-muted); }
.detail-val   { color: var(--text); font-weight: 500; font-variant-numeric: tabular-nums; }

/* Detail section */
.detail-section {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}

.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--bg-elevated);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
}
.info-cell {
  padding: 10px 14px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.info-cell:nth-child(2n)  { border-right: none; }
.info-cell:last-child,
.info-cell:nth-last-child(2):nth-child(odd) { border-bottom: none; }
.info-cell span  {
  display: block;
  font-size: 10px;
  color: var(--text-muted);
  margin-bottom: 3px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.info-cell strong {
  font-size: 13px;
  color: var(--text);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

/* Battery */
.battery-widget {
  padding: 12px 14px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}
.battery-label {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 12px;
  color: var(--text-muted);
}
.battery-label strong { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.battery-track {
  height: 6px;
  background: var(--surface-3);
  border-radius: 100px;
  overflow: hidden;
}
.battery-fill {
  height: 100%;
  border-radius: 100px;
  transition: width 0.4s ease, background-color 0.3s;
  background: linear-gradient(90deg, var(--st-online), var(--accent));
  box-shadow: 0 0 8px var(--accent-glow);
}

/* Maps link */
.maps-link {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--accent);
  padding: 9px 14px;
  border-top: 1px solid var(--border);
  transition: background 0.12s;
}
.maps-link:hover { background: var(--surface-hover); text-decoration: none; }

/* Neighbors */
#dp-neighbors { padding: 6px 10px 8px; }
.neighbor-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  transition: background 0.12s;
  cursor: default;
}
.neighbor-item:hover { background: var(--surface-hover); }
.neighbor-id {
  font-family: ui-monospace, monospace;
  font-size: 11px;
  color: var(--accent);
}
.neighbor-snr {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.snr-good  { color: var(--st-online); }
.snr-ok    { color: var(--st-recent); }
.snr-bad   { color: var(--st-danger); }

/* ── Leaflet overrides ───────────────────────────────────── */
.leaflet-control-layers {
  background: var(--sidebar-bg) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius) !important;
  color: var(--text) !important;
  box-shadow: var(--shadow-md) !important;
}
.leaflet-control-layers-toggle {
  background-color: var(--sidebar-bg) !important;
  width: 36px !important;
  height: 36px !important;
}
.leaflet-control-layers label { color: var(--text) !important; font-size: 12px !important; }
.leaflet-control-layers-separator { border-color: var(--border) !important; }
.leaflet-container .leaflet-control-attribution {
  background: color-mix(in srgb, var(--bg) 75%, transparent) !important;
  color: var(--text-dim) !important;
  font-size: 10px !important;
}
.leaflet-container .leaflet-control-attribution a { color: var(--text-muted) !important; }

/* Cluster icons */
.cluster-icon {
  border-radius: 50%;
  border: 2px solid;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: white;
  box-shadow: 0 4px 14px rgba(0,0,0,0.35);
  cursor: pointer;
  transition: transform 0.15s;
  font-variant-numeric: tabular-nums;
}
.cluster-icon:hover { transform: scale(1.1); }

.mesh-marker { background: transparent; border: none; }

/* ── Map responsive ──────────────────────────────────────── */
@media (max-width: 1024px) {
  :root { --sidebar-w: 270px; }
}

@media (max-width: 768px) {
  :root { --panel-w: 100vw; }

  #detail-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 75vh;
    border-left: none;
    border-top: 1px solid var(--border);
    transform: translateY(100%);
    box-shadow: var(--shadow-lg);
  }
  #detail-panel.hidden { transform: translateY(100%); width: 100%; }
  #detail-panel:not(.hidden) { transform: translateY(0); }
}

@media (max-width: 640px) {
  :root { --sidebar-w: 260px; }
}
