/* ── NetMap — Map, Panels & Popups ── */

/* ── Map Container ── */
#map {
  position: fixed;
  inset: 0;
  z-index: 1;
}

/* Override Leaflet defaults for dark theme */
.leaflet-container {
  background: var(--bg) !important;
  font-family: var(--font-body) !important;
}

.leaflet-control-zoom {
  border: 1px solid var(--border) !important;
  border-radius: var(--radius-sm) !important;
  overflow: hidden;
  box-shadow: var(--shadow) !important;
}

.leaflet-control-zoom a {
  background: var(--card) !important;
  color: var(--text-secondary) !important;
  border-bottom: 1px solid var(--border) !important;
  width: 34px !important;
  height: 34px !important;
  line-height: 34px !important;
  font-size: 16px !important;
}

.leaflet-control-zoom a:hover {
  background: var(--card-hover) !important;
  color: var(--text) !important;
}

.leaflet-control-zoom a:last-child {
  border-bottom: none !important;
}

.leaflet-control-attribution {
  background: rgba(6, 8, 16, 0.7) !important;
  color: var(--text-muted) !important;
  font-size: 10px !important;
  padding: 2px 6px !important;
}

.leaflet-control-attribution a {
  color: var(--text-muted) !important;
}

/* ── Custom Tooltips ── */
.leaflet-tooltip {
  background: var(--card) !important;
  border: 1px solid var(--border-light) !important;
  border-radius: var(--radius-xs) !important;
  color: var(--text) !important;
  font-family: var(--font-body) !important;
  font-size: 0.8rem !important;
  padding: 8px 12px !important;
  box-shadow: var(--shadow) !important;
  white-space: nowrap !important;
}

.leaflet-tooltip::before {
  border-top-color: var(--card) !important;
}

.leaflet-tooltip-top::before {
  border-top-color: var(--card) !important;
}

.leaflet-tooltip-bottom::before {
  border-bottom-color: var(--card) !important;
}

.leaflet-tooltip-left::before {
  border-left-color: var(--card) !important;
}

.leaflet-tooltip-right::before {
  border-right-color: var(--card) !important;
}

.hop-tooltip-num {
  color: var(--primary);
  font-weight: 600;
  margin-right: 4px;
}

.hop-tooltip-city {
  color: var(--text);
}

.hop-tooltip-ip {
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  display: block;
  margin-top: 2px;
}

.hop-tooltip-latency {
  color: var(--packet);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  margin-top: 2px;
  display: block;
}

/* ── Hop Popups ── */
.leaflet-popup-content-wrapper {
  background: var(--card) !important;
  border: 1px solid var(--border-light) !important;
  border-radius: var(--radius) !important;
  box-shadow: var(--shadow-lg) !important;
  color: var(--text) !important;
}

.leaflet-popup-tip {
  background: var(--card) !important;
  border: 1px solid var(--border-light) !important;
}

.leaflet-popup-close-button {
  color: var(--text-muted) !important;
  font-size: 18px !important;
  top: 8px !important;
  right: 10px !important;
}

.leaflet-popup-close-button:hover {
  color: var(--text) !important;
}

.hop-popup {
  font-family: var(--font-body);
  min-width: 220px;
}

.hop-popup-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.hop-popup-badge {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary-dim);
  color: var(--primary);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
}

.hop-popup-title {
  font-weight: 600;
  font-size: 0.95rem;
}

.hop-popup-subtitle {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.hop-popup-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 0;
  font-size: 0.82rem;
}

.hop-popup-label {
  color: var(--text-muted);
}

.hop-popup-value {
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

.hop-popup-value.latency-good { color: var(--hop); }
.hop-popup-value.latency-mid { color: var(--warning); }
.hop-popup-value.latency-bad { color: var(--error); }

/* ── Stats Overlay ── */
#stats-overlay {
  position: fixed;
  top: 72px;
  right: 20px;
  z-index: 400;
  background: rgba(17, 24, 36, 0.92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  min-width: 200px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(-10px);
  transition: opacity var(--transition-slow), transform var(--transition-slow);
}

#stats-overlay.visible {
  opacity: 1;
  transform: translateY(0);
}

.stats-title {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
}

.stat-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text);
}

.stat-value.highlight {
  color: var(--primary);
}

/* ── Bottom Panel ── */
#bottom-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 400;
  background: rgba(12, 16, 24, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  max-height: 320px;
  transition: transform var(--transition-slow), opacity var(--transition-slow);
  transform: translateY(100%);
  opacity: 0;
  display: flex;
  flex-direction: column;
}

#bottom-panel.visible {
  transform: translateY(0);
  opacity: 1;
}

#bottom-panel.collapsed {
  max-height: 42px;
  overflow: hidden;
}

.panel-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  min-height: 42px;
  flex-shrink: 0;
}

.panel-toggle:hover {
  background: rgba(255, 255, 255, 0.02);
}

.panel-summary {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-muted);
  display: flex;
  gap: 16px;
}

.panel-summary-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.panel-summary-item .val {
  color: var(--text-secondary);
}

.panel-toggle-icon {
  color: var(--text-muted);
  transition: transform var(--transition);
  font-size: 0.9rem;
}

#bottom-panel.collapsed .panel-toggle-icon {
  transform: rotate(180deg);
}

.panel-content {
  overflow-y: auto;
  flex: 1;
}

/* ── Hop Table ── */
.hop-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.hop-table thead {
  position: sticky;
  top: 0;
  z-index: 1;
}

.hop-table th {
  background: var(--surface);
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  padding: 8px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.hop-table td {
  padding: 10px 16px;
  border-bottom: 1px solid rgba(26, 35, 50, 0.5);
  white-space: nowrap;
}

.hop-table tbody tr {
  cursor: pointer;
  transition: background var(--transition);
}

.hop-table tbody tr:hover {
  background: rgba(0, 180, 216, 0.04);
}

.hop-table tbody tr.active {
  background: rgba(0, 180, 216, 0.08);
}

.hop-table tbody tr.hop-source td:first-child,
.hop-table tbody tr.hop-dest td:first-child {
  font-weight: 600;
}

.hop-num {
  font-family: var(--font-mono);
  color: var(--primary);
  font-weight: 600;
  font-size: 0.82rem;
}

.hop-ip {
  font-family: var(--font-mono);
  color: var(--text-secondary);
  font-size: 0.8rem;
}

.hop-city {
  color: var(--text);
}

.hop-isp {
  color: var(--text-secondary);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hop-latency {
  font-family: var(--font-mono);
  font-weight: 500;
}

.hop-latency.good { color: var(--hop); }
.hop-latency.mid { color: var(--warning); }
.hop-latency.bad { color: var(--error); }

.hop-distance {
  font-family: var(--font-mono);
  color: var(--text-muted);
  font-size: 0.8rem;
}

.hop-table tfoot td {
  padding: 10px 16px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  font-weight: 500;
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.hop-table tfoot .total-label {
  font-weight: 600;
  color: var(--text);
}

/* ── Right Sidebar ── */
#sidebar {
  position: fixed;
  top: 56px;
  right: 0;
  bottom: 0;
  width: 300px;
  z-index: 450;
  background: rgba(12, 16, 24, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-left: 1px solid var(--border);
  transform: translateX(100%);
  transition: transform var(--transition-slow);
  overflow-y: auto;
  padding: 20px;
}

#sidebar.visible {
  transform: translateX(0);
}

.sidebar-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 30px;
  height: 30px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  background: var(--card);
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}

.sidebar-close:hover {
  color: var(--text);
  border-color: var(--border-light);
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  padding-right: 40px;
}

.sidebar-badge {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary-dim);
  color: var(--primary);
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sidebar-title {
  font-size: 1.1rem;
  font-weight: 600;
}

.sidebar-subtitle {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-muted);
}

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

.sidebar-section-title {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.sidebar-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 0.82rem;
}

.sidebar-label {
  color: var(--text-muted);
}

.sidebar-value {
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  text-align: right;
}

.sidebar-btn {
  width: 100%;
  padding: 10px 16px;
  margin-top: 16px;
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--primary);
  background: var(--primary-dim);
  border: 1px solid rgba(0, 180, 216, 0.2);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
}

.sidebar-btn:hover {
  background: rgba(0, 180, 216, 0.2);
}

/* ── Export Modal ── */
#export-modal {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6, 8, 16, 0.8);
  backdrop-filter: blur(6px);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition), visibility var(--transition);
}

#export-modal.visible {
  opacity: 1;
  visibility: visible;
}

.export-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 640px;
  width: 90%;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}

.export-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.export-title {
  font-size: 1.1rem;
  font-weight: 600;
}

.export-close {
  width: 30px;
  height: 30px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  background: transparent;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

.export-content {
  flex: 1;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  line-height: 1.6;
  color: var(--text-secondary);
  white-space: pre;
  margin-bottom: 16px;
}

.export-actions {
  display: flex;
  gap: 10px;
}

.export-actions .btn-sm {
  flex: 1;
  justify-content: center;
}

/* ── Packet Control ── */
.packet-control {
  position: fixed;
  bottom: 24px;
  right: 20px;
  z-index: 450;
  opacity: 0;
  transition: opacity var(--transition-slow);
}

.packet-control.visible {
  opacity: 1;
}

.packet-control-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--packet);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  box-shadow: var(--shadow);
}

.packet-control-btn:hover {
  border-color: var(--packet);
  background: rgba(245, 158, 11, 0.1);
}

.packet-control-btn svg {
  width: 16px;
  height: 16px;
}

/* ── Responsive ── */
@media (max-width: 1024px) {
  #stats-overlay {
    top: auto;
    bottom: 54px;
    right: 10px;
    min-width: 160px;
    padding: 12px 14px;
  }

  #sidebar {
    width: 100%;
    top: auto;
    bottom: 0;
    max-height: 60vh;
    border-left: none;
    border-top: 1px solid var(--border);
    border-radius: var(--radius) var(--radius) 0 0;
    transform: translateY(100%);
  }

  #sidebar.visible {
    transform: translateY(0);
  }
}

@media (max-width: 768px) {
  .hop-table .col-isp,
  .hop-table .col-distance {
    display: none;
  }

  .hop-table th, .hop-table td {
    padding: 8px 10px;
    font-size: 0.78rem;
  }

  #bottom-panel {
    max-height: 250px;
  }

  .packet-control {
    bottom: 54px;
    right: 10px;
  }

  #stats-overlay {
    display: none;
  }
}
