/* ============================================================
   Guardian Mesh — Network Map Stylesheet
   Dark theme, canvas-based map, sidebar + detail panel
   ============================================================ */

/* ====== CSS VARIABLES ====== */
:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-card: #1a1a24;
  --bg-card-hover: #22222e;
  --bg-card-selected: #1e2a3a;
  --accent-cyan: #00d4ff;
  --accent-magenta: #ff00aa;
  --accent-green: #00ff88;
  --accent-orange: #ff8800;
  --accent-cyan-dim: rgba(0, 212, 255, 0.15);
  --accent-green-dim: rgba(0, 255, 136, 0.15);
  --accent-orange-dim: rgba(255, 136, 0, 0.15);
  --accent-magenta-dim: rgba(255, 0, 170, 0.15);
  --text-primary: #ffffff;
  --text-secondary: #8888aa;
  --text-muted: #7777a0;
  --border: #2a2a3a;
  --border-light: #3a3a4a;
  --font-body: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
  --sidebar-width: 320px;
  --detail-width: 360px;
  --header-height: 56px;
  --stats-height: 60px;
  --filters-height: 52px;
  --radius: 8px;
  --radius-sm: 6px;
  --transition: 0.2s ease;
}

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

html {
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-body);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  overflow: hidden;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

a {
  color: var(--accent-cyan);
  text-decoration: none;
  transition: color var(--transition);
}

a:hover {
  color: #33dfff;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

/* Focus styles */
*:focus-visible {
  outline: 2px solid var(--accent-cyan);
  outline-offset: 2px;
}

select,
input[type="text"] {
  font-family: inherit;
}

/* ====== SKIP LINK ====== */
.skip-link {
  position: absolute;
  top: -100px;
  left: 16px;
  background: var(--accent-cyan);
  color: var(--bg-primary);
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  z-index: 9999;
  transition: top var(--transition);
}

.skip-link:focus {
  top: 8px;
}

/* ====== HEADER ====== */
.gm-header {
  height: var(--header-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 100;
  padding-left: max(12px, env(safe-area-inset-left));
  padding-right: max(12px, env(safe-area-inset-right));
}

.gm-header-inner {
  display: flex;
  align-items: center;
  height: 100%;
  padding: 0 20px;
  gap: 24px;
}

.gm-logo {
  display: flex;
  align-items: center;
  text-decoration: none;
  flex-shrink: 0;
}

.gm-logo-text {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 600;
  color: var(--accent-cyan);
  letter-spacing: 2px;
}

.gm-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
}

.gm-nav a {
  color: var(--text-secondary);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  transition: color var(--transition), background var(--transition);
}

.gm-nav a:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.05);
}

.gm-nav a.gm-nav-active {
  color: var(--accent-cyan);
  background: var(--accent-cyan-dim);
}

.gm-header-status {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.gm-live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-green);
  box-shadow: 0 0 6px var(--accent-green);
  animation: gm-pulse 2s ease-in-out infinite;
}

@keyframes gm-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.gm-live-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--accent-green);
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* ====== STATS BAR ====== */
.gm-stats-bar {
  height: var(--stats-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  overflow-x: auto;
  overflow-y: hidden;
}

.gm-stats-inner {
  display: flex;
  align-items: center;
  height: 100%;
  padding: 0 20px;
  gap: 0;
  min-width: max-content;
}

.gm-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 18px;
  border-right: 1px solid var(--border);
  min-width: 100px;
}

.gm-stat:last-child {
  border-right: none;
}

.gm-stat-value {
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 600;
  color: var(--accent-cyan);
  line-height: 1.2;
}

.gm-stat-label {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

/* ====== FILTER CONTROLS ====== */
.gm-filters {
  height: var(--filters-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  overflow-x: auto;
  overflow-y: hidden;
}

.gm-filters-inner {
  display: flex;
  align-items: center;
  height: 100%;
  padding: 0 20px;
  gap: 16px;
  min-width: max-content;
}

.gm-filter-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.gm-filter-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

.gm-filter-select {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 5px 10px;
  font-size: 12px;
  outline: none;
  transition: border-color var(--transition);
  cursor: pointer;
  min-width: 100px;
}

.gm-filter-select:focus {
  border-color: var(--accent-cyan);
}

.gm-filter-select option {
  background: var(--bg-card);
  color: var(--text-primary);
}

.gm-filter-checkbox {
  padding: 0 4px;
}

.gm-checkbox-label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  user-select: none;
}

.gm-checkbox-label input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--bg-card);
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  transition: background var(--transition), border-color var(--transition);
}

.gm-checkbox-label input[type="checkbox"]:checked {
  background: var(--accent-cyan);
  border-color: var(--accent-cyan);
}

.gm-checkbox-label input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 5px;
  width: 4px;
  height: 8px;
  border: solid var(--bg-primary);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.gm-checkbox-label input[type="checkbox"]:focus {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 0 2px var(--accent-cyan-dim);
}

.gm-checkbox-label span {
  transition: color var(--transition);
}

.gm-checkbox-label:hover span {
  color: var(--text-primary);
}

/* ====== MAIN LAYOUT ====== */
.gm-main {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

/* ====== MAP CONTAINER ====== */
.gm-map-container {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: var(--bg-primary);
}

.gm-map-container canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* ====== MAP LEGEND ====== */
.gm-map-legend {
  position: absolute;
  bottom: 16px;
  left: 16px;
  background: rgba(18, 18, 26, 0.92);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 10;
}

.gm-legend-title {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 8px;
}

.gm-legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.gm-legend-item:last-child {
  margin-bottom: 0;
}

.gm-legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.gm-legend-guardian {
  background: var(--accent-cyan);
  box-shadow: 0 0 6px var(--accent-cyan);
}

.gm-legend-bootstrap {
  background: var(--accent-magenta);
  box-shadow: 0 0 6px var(--accent-magenta);
}

.gm-legend-relay {
  background: var(--accent-green);
  box-shadow: 0 0 6px var(--accent-green);
}

.gm-legend-offline {
  background: var(--accent-orange);
  box-shadow: 0 0 4px var(--accent-orange);
}

/* ====== LOADING SPINNER ====== */
.gm-loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  z-index: 20;
  transition: opacity 0.3s ease;
}

.gm-loading.hidden {
  opacity: 0;
  pointer-events: none;
}

.gm-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent-cyan);
  border-radius: 50%;
  animation: gm-spin 0.8s linear infinite;
}

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

.gm-loading span {
  font-size: 12px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* ====== ERROR STATE ====== */
.gm-error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  text-align: center;
  color: var(--text-secondary);
}

.gm-error-state svg {
  width: 48px;
  height: 48px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.gm-error-state p {
  font-size: 14px;
  margin-bottom: 16px;
}

/* ====== SIDEBAR ====== */
.gm-sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}

.gm-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.gm-sidebar-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.gm-sidebar-count {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  color: var(--accent-cyan);
  background: var(--accent-cyan-dim);
  padding: 2px 8px;
  border-radius: 10px;
}

.gm-sidebar-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.gm-sidebar-list::-webkit-scrollbar {
  width: 6px;
}

.gm-sidebar-list::-webkit-scrollbar-track {
  background: transparent;
}

.gm-sidebar-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.gm-sidebar-list::-webkit-scrollbar-thumb:hover {
  background: var(--border-light);
}

/* ====== NODE CARD ====== */
.gm-node-card {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--transition);
}

.gm-node-card:hover {
  background: var(--bg-card-hover);
}

.gm-node-card.selected {
  background: var(--bg-card-selected);
  border-left: 3px solid var(--accent-cyan);
  padding-left: 13px;
}

.gm-node-fingerprint {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-primary);
  margin-bottom: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gm-node-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.gm-node-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--text-secondary);
  min-width: 0;
}

.gm-node-region {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gm-node-type {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 1px 6px;
  border-radius: 3px;
  white-space: nowrap;
}

.gm-node-type.guardian {
  color: var(--accent-cyan);
  background: var(--accent-cyan-dim);
}

.gm-node-type.bootstrap {
  color: var(--accent-magenta);
  background: var(--accent-magenta-dim);
}

.gm-node-type.relay {
  color: var(--accent-green);
  background: var(--accent-green-dim);
}

.gm-node-peers {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
}

/* ====== STATUS BADGE ====== */
.gm-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 8px;
  border-radius: 10px;
}

.gm-status-badge.online {
  color: var(--accent-green);
  background: var(--accent-green-dim);
}

.gm-status-badge.offline {
  color: var(--accent-orange);
  background: var(--accent-orange-dim);
}

.gm-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.gm-status-badge.online .gm-status-dot {
  background: var(--accent-green);
}

.gm-status-badge.offline .gm-status-dot {
  background: var(--accent-orange);
}

/* ====== EMPTY STATE ====== */
.gm-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

.gm-empty-state.hidden {
  display: none;
}

.gm-btn-reset {
  margin-top: 12px;
  padding: 6px 16px;
  font-size: 12px;
  font-weight: 500;
  color: var(--accent-cyan);
  background: var(--accent-cyan-dim);
  border: 1px solid rgba(0, 212, 255, 0.3);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
}

.gm-btn-reset:hover {
  background: rgba(0, 212, 255, 0.25);
  border-color: var(--accent-cyan);
}

/* ====== DETAIL PANEL ====== */
.gm-detail-panel {
  position: absolute;
  top: 0;
  right: 0;
  width: var(--detail-width);
  height: 100%;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 50;
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.4);
}

.gm-detail-panel.visible {
  transform: translateX(0);
}

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

.gm-detail-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.gm-detail-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  transition: color var(--transition), background var(--transition);
}

.gm-detail-close:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.08);
}

.gm-detail-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.gm-detail-body::-webkit-scrollbar {
  width: 6px;
}

.gm-detail-body::-webkit-scrollbar-track {
  background: transparent;
}

.gm-detail-body::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.gm-detail-section {
  margin-bottom: 20px;
}

.gm-detail-section:last-child {
  margin-bottom: 0;
}

.gm-detail-section-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.gm-detail-fingerprint {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--accent-cyan);
  word-break: break-all;
  margin-bottom: 12px;
  padding: 10px 12px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  line-height: 1.6;
}

.gm-detail-meta {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.gm-detail-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
}

.gm-detail-meta-label {
  color: var(--text-secondary);
}

.gm-detail-meta-value {
  color: var(--text-primary);
  font-weight: 500;
}

.gm-verified-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent-cyan);
  background: var(--accent-cyan-dim);
  padding: 2px 8px;
  border-radius: 10px;
}

.gm-verified-badge::before {
  content: '';
  display: inline-block;
  width: 12px;
  height: 12px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%2300d4ff'%3E%3Cpath d='M8 0L9.67 2.5L12.5 1.7L12.4 4.7L15.1 6.1L13.4 8.6L14.8 11.2L11.9 11.8L11.2 14.8L8.4 13.6L5.9 15.5L4.8 12.6L1.8 12.8L2.5 9.9L0 8.2L2.2 6.2L1.3 3.3L4.2 3.1L5.3 0.3L8 0z'/%3E%3Ccircle cx='8' cy='8' r='3.5' fill='%230a0a0f'/%3E%3Cpath d='M6.5 8l1 1L9.5 7' stroke='%2300d4ff' stroke-width='1.2' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-size: contain;
  background-repeat: no-repeat;
}

/* ====== DETAIL METRICS GRID ====== */
.gm-detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.gm-metric-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.gm-metric-value {
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 600;
  color: var(--accent-cyan);
  line-height: 1.2;
}

.gm-metric-label {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ====== RESPONSIVE ====== */
@media (max-width: 900px) {
  .gm-main {
    flex-direction: column;
  }

  .gm-sidebar {
    width: 100%;
    max-height: 40vh;
    border-left: none;
    border-top: 1px solid var(--border);
  }

  .gm-detail-panel {
    width: 100%;
    transform: translateY(100%);
    top: auto;
    bottom: 0;
    height: 70vh;
    border-left: none;
    border-top: 1px solid var(--border);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.4);
  }

  .gm-detail-panel.visible {
    transform: translateY(0);
  }

  .gm-map-container {
    min-height: 300px;
  }

  .gm-nav a {
    font-size: 12px;
    padding: 4px 8px;
  }

  .gm-header-inner {
    padding: 0 12px;
    gap: 12px;
  }

  .gm-logo-text {
    font-size: 13px;
    letter-spacing: 1px;
  }

  .gm-stats-inner {
    padding: 0 12px;
  }

  .gm-stat {
    padding: 0 12px;
    min-width: 80px;
  }

  .gm-stat-value {
    font-size: 14px;
  }

  .gm-filters-inner {
    padding: 0 12px;
    gap: 10px;
  }
}

@media (max-width: 600px) {
  .gm-nav {
    display: flex;
    gap: 4px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 0 8px;
  }

  .gm-nav::-webkit-scrollbar { display: none; }

  .gm-nav a {
    font-size: 11px;
    padding: 4px 8px;
    white-space: nowrap;
    min-height: 44px;
    display: flex;
    align-items: center;
  }

  .gm-header-inner {
    justify-content: space-between;
  }

  .gm-detail-panel {
    height: 85vh;
  }

  .gm-detail-grid {
    grid-template-columns: 1fr;
  }
}

/* ====== SCROLLBAR GLOBAL ====== */
.gm-stats-bar::-webkit-scrollbar,
.gm-filters::-webkit-scrollbar {
  height: 4px;
}

.gm-stats-bar::-webkit-scrollbar-track,
.gm-filters::-webkit-scrollbar-track {
  background: transparent;
}

.gm-stats-bar::-webkit-scrollbar-thumb,
.gm-filters::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}
