@import url("https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;600;700&family=IBM+Plex+Mono:wght@400;600&display=swap");

:root {
  --bg: #0b141c;
  --panel: rgba(14, 22, 32, 0.92);
  --panel-border: rgba(255, 255, 255, 0.08);
  --text: #e9f1f7;
  --muted: #8da0b2;
  --accent: #5fe3d0;
  --accent-2: #f7c94b;
  --accent-3: #ff7b6b;
  --grid: rgba(88, 124, 150, 0.08);
  --feed-height-base: 160px;
  --feed-height-expanded: 320px;
  --feed-height: 0px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  height: 100vh;
  width: 100vw;
  font-family: "Space Grotesk", sans-serif;
  color: var(--text);
  background: radial-gradient(1200px 700px at 20% 20%, #1a2b3a 0%, transparent 60%),
    radial-gradient(800px 500px at 80% 0%, #102737 0%, transparent 55%),
    var(--bg);
  overflow: hidden;
}

body.feed-visible {
  --feed-height: var(--feed-height-base);
}

body.feed-visible.feed-expanded {
  --feed-height: var(--feed-height-expanded);
}

body.feed-visible.panels-hidden:not(.feed-expanded) {
  --feed-height: 120px;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image: linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 36px 36px;
  opacity: 0.35;
  pointer-events: none;
  z-index: 0;
}

.bg-glow {
  position: fixed;
  inset: -20% -10% auto;
  height: 60vh;
  background: radial-gradient(circle, rgba(90, 216, 200, 0.15), transparent 60%);
  filter: blur(40px);
  z-index: 0;
}

.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 24px 40px 16px;
  backdrop-filter: blur(12px);
  background: linear-gradient(180deg, rgba(11, 20, 28, 0.95) 0%, rgba(11, 20, 28, 0.6) 100%);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.brand {
  display: flex;
  align-items: center;
  gap: 16px;
}

.logo-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: radial-gradient(circle at top, #e8fff8 0%, var(--accent) 40%, #1b675e 100%);
  box-shadow: 0 0 18px rgba(90, 216, 200, 0.8);
}

.title {
  font-weight: 700;
  font-size: 20px;
  letter-spacing: 0.02em;
}

.subtitle {
  font-size: 12px;
  color: var(--muted);
}

.status {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.status-item {
  display: grid;
  gap: 4px;
  font-size: 12px;
}

.label {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-size: 10px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(90, 216, 200, 0.15);
  color: var(--accent);
  font-size: 12px;
  border: 1px solid rgba(90, 216, 200, 0.3);
}

.pill-muted {
  background: rgba(141, 160, 178, 0.15);
  color: var(--muted);
  border-color: rgba(141, 160, 178, 0.4);
}

.pill.live {
  position: relative;
  box-shadow: 0 0 16px rgba(95, 227, 208, 0.45);
  animation: livePulse 1.6s ease-in-out infinite;
}

.ghost-btn {
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: transparent;
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.ghost-btn:hover {
  border-color: rgba(90, 216, 200, 0.6);
  color: var(--accent);
}

.ghost-btn.active {
  border-color: rgba(247, 201, 75, 0.6);
  color: var(--accent-2);
}

.filters {
  position: fixed;
  top: 88px;
  left: 0;
  right: 0;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  padding: 12px 40px 16px;
  background: linear-gradient(180deg, rgba(11, 20, 28, 0.95) 0%, rgba(11, 20, 28, 0.7) 100%);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(12px);
}

.filter-group {
  display: grid;
  gap: 6px;
  font-size: 12px;
  min-width: 140px;
}

.filter-group.search {
  flex: 1;
  min-width: 220px;
}

.filter-group label {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 10px;
}

.filter-group input,
.filter-group select {
  background: rgba(8, 14, 20, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 10px;
  font-family: inherit;
  font-size: 12px;
}

.graph-stage {
  position: relative;
  width: 100%;
  height: 100vh;
  z-index: 1;
}

.graph-overlay {
  position: absolute;
  inset: 150px 32px calc(var(--feed-height) + 44px) 32px;
  display: grid;
  grid-template-columns: minmax(260px, 360px) minmax(280px, 380px);
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "graph metrics"
    "details nodes";
  gap: 16px;
  pointer-events: none;
  animation: rise 0.8s ease forwards;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 30px 60px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(10px);
  position: relative;
  pointer-events: auto;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.panel-floating {
  position: absolute;
  inset: auto;
  grid-area: auto;
  min-width: 240px;
  min-height: 160px;
  z-index: 5;
}

.panel-grip {
  width: 22px;
  height: 22px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: repeating-linear-gradient(
    45deg,
    rgba(255, 255, 255, 0.35),
    rgba(255, 255, 255, 0.35) 2px,
    transparent 2px,
    transparent 4px
  );
  cursor: grab;
  padding: 0;
  touch-action: none;
}

.panel-grip:hover {
  border-color: rgba(90, 216, 200, 0.6);
}

.panel-grip:active {
  cursor: grabbing;
}

.panel-resize {
  position: absolute;
  right: 10px;
  bottom: 10px;
  width: 14px;
  height: 14px;
  cursor: se-resize;
  opacity: 0.55;
  touch-action: none;
}

.panel-resize::before,
.panel-resize::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: 0;
  width: 12px;
  height: 12px;
  border-right: 2px solid rgba(255, 255, 255, 0.4);
  border-bottom: 2px solid rgba(255, 255, 255, 0.4);
}

.panel-resize::after {
  width: 6px;
  height: 6px;
  right: 2px;
  bottom: 2px;
  border-right-color: rgba(255, 255, 255, 0.25);
  border-bottom-color: rgba(255, 255, 255, 0.25);
}

.panel.is-dragging,
.panel.is-resizing {
  box-shadow: 0 32px 70px rgba(0, 0, 0, 0.45);
}

body.panel-dragging {
  user-select: none;
}

.panel.is-hidden {
  opacity: 0;
  transform: translateY(12px) scale(0.98);
  pointer-events: none;
}

.graph-hud {
  grid-area: graph;
  display: grid;
  gap: 12px;
}

.metrics-panel {
  grid-area: metrics;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}

.metric {
  background: rgba(6, 12, 18, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 10px 12px;
  display: grid;
  gap: 6px;
  font-size: 14px;
}

.feed-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 200px;
}

.feed-dock {
  position: fixed;
  left: 32px;
  right: 32px;
  bottom: 24px;
  height: var(--feed-height);
  z-index: 4;
}

.details-panel {
  grid-area: details;
  min-height: 240px;
  max-height: 520px;
}

.nodes-panel {
  grid-area: nodes;
  min-height: 200px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-actions {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.panel-toggle {
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: transparent;
  color: var(--text);
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.panel-toggle:hover {
  border-color: rgba(90, 216, 200, 0.6);
  color: var(--accent);
}

.panel-title {
  font-weight: 600;
  font-size: 16px;
}

.panel-meta {
  font-size: 12px;
  color: var(--muted);
}

.table-wrap {
  overflow: auto;
  max-height: 420px;
}

.table-wrap table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.table-wrap th {
  text-align: left;
  color: var(--muted);
  font-weight: 600;
  padding: 10px 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 10px;
}

.table-wrap td {
  padding: 10px 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  color: var(--text);
}

.table-wrap tr:hover {
  background: rgba(90, 216, 200, 0.08);
  cursor: pointer;
}

.table-wrap tr.active {
  background: linear-gradient(90deg, rgba(247, 201, 75, 0.2), rgba(247, 201, 75, 0.05));
}

.table-wrap tr {
  box-shadow: inset 3px 0 0 var(--row-accent, transparent);
}

.code-block {
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  color: #cfe2f0;
  background: rgba(5, 12, 18, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 14px;
  max-height: 320px;
  overflow: auto;
  white-space: pre-wrap;
}

.node-drawer {
  position: fixed;
  right: 24px;
  top: 140px;
  width: 320px;
  max-height: calc(100vh - 180px);
  overflow: auto;
  background: rgba(10, 18, 26, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 30px 60px rgba(0, 0, 0, 0.35);
  transform: translateX(360px);
  transition: transform 0.25s ease;
  z-index: 5;
}

.node-drawer.open {
  transform: translateX(0);
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.drawer-section {
  margin-top: 16px;
}

.drawer-label {
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}

.drawer-content {
  font-size: 12px;
  color: var(--text);
  background: rgba(6, 12, 18, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 10px;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 7;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(1200px 700px at 20% 20%, rgba(90, 216, 200, 0.12) 0%, transparent 60%),
    rgba(9, 15, 22, 0.72);
  backdrop-filter: blur(6px);
  opacity: 1;
  visibility: visible;
  transition: opacity 0.35s ease, visibility 0.35s ease;
  pointer-events: none;
}

.loading-overlay.is-hidden {
  opacity: 0;
  visibility: hidden;
}

.loading-card {
  display: grid;
  gap: 12px;
  min-width: 220px;
  max-width: 320px;
  padding: 18px 20px;
  text-align: center;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(8, 14, 20, 0.88);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}

.loading-spinner {
  width: 42px;
  height: 42px;
  margin: 0 auto;
  border-radius: 50%;
  border: 3px solid rgba(95, 227, 208, 0.2);
  border-top-color: var(--accent);
  animation: spin 1s linear infinite;
}

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

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

.loading-bar {
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.loading-bar-fill {
  display: block;
  width: 45%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(95, 227, 208, 0.2), rgba(95, 227, 208, 0.9), rgba(247, 201, 75, 0.75));
  animation: loadingSweep 1.2s ease-in-out infinite;
}

.graph-tooltip {
  position: fixed;
  pointer-events: none;
  background: rgba(8, 14, 20, 0.95);
  border: 1px solid rgba(90, 216, 200, 0.3);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 11px;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.15s ease, transform 0.15s ease;
  z-index: 6;
}

.graph-tooltip.visible {
  opacity: 1;
  transform: translateY(0);
}

.panel-controls {
  position: fixed;
  bottom: calc(var(--feed-height) + 24px);
  right: 24px;
  z-index: 6;
}

.panel-controls-toggle {
  position: absolute;
  right: 0;
  bottom: 0;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(10, 18, 26, 0.95);
  color: var(--text);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
  transition: border-color 0.2s ease, color 0.2s ease;
}

.panel-controls-toggle:hover {
  border-color: rgba(90, 216, 200, 0.6);
  color: var(--accent);
}

.panel-controls-body {
  width: 240px;
  margin-bottom: 52px;
  background: rgba(10, 18, 26, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 16px;
  padding: 14px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(12px);
  transition: transform 0.25s ease, opacity 0.25s ease;
}

.panel-controls.is-collapsed .panel-controls-body {
  transform: translateY(20px);
  opacity: 0;
  pointer-events: none;
}

body.drawer-open .panel-controls {
  right: 360px;
}

.panel-controls-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-controls-section {
  display: grid;
  gap: 10px;
}

.panel-controls-list {
  display: grid;
  gap: 8px;
}

.panel-switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(6, 12, 18, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 12px;
  color: var(--text);
}

.panel-switch input {
  accent-color: var(--accent);
}

.panel-switch span {
  flex: 1;
}

.panel-switch.panel-switch-all {
  background: rgba(90, 216, 200, 0.12);
  border-color: rgba(90, 216, 200, 0.3);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: auto;
}

.legend-dock {
  position: fixed;
  left: 32px;
  bottom: calc(var(--feed-height) + 32px);
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(8, 14, 20, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
  z-index: 4;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}

.legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 4px;
  background: var(--accent);
}

#graphCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: 0;
  background: radial-gradient(circle at 10% 20%, rgba(90, 216, 200, 0.12), transparent 45%),
    radial-gradient(circle at 80% 10%, rgba(122, 169, 255, 0.1), transparent 40%),
    rgba(7, 13, 19, 0.88);
  border: none;
  cursor: grab;
}

#graphCanvas:active {
  cursor: grabbing;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes livePulse {
  0% {
    box-shadow: 0 0 0 rgba(95, 227, 208, 0.1);
  }
  50% {
    box-shadow: 0 0 18px rgba(95, 227, 208, 0.45);
  }
  100% {
    box-shadow: 0 0 0 rgba(95, 227, 208, 0.1);
  }
}

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

@keyframes loadingSweep {
  0% {
    transform: translateX(-60%);
  }
  50% {
    transform: translateX(0%);
  }
  100% {
    transform: translateX(140%);
  }
}

@media (max-width: 1024px) {
  :root {
    --feed-height-base: 140px;
    --feed-height-expanded: 240px;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .graph-overlay {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto 1fr;
    grid-template-areas:
      "graph"
      "metrics"
      "nodes"
      "details";
    inset: 190px 20px calc(var(--feed-height) + 32px) 20px;
  }

  .legend-dock {
    left: 20px;
    bottom: calc(var(--feed-height) + 24px);
  }

  .panel-controls {
    bottom: calc(var(--feed-height) + 20px);
    right: 20px;
  }

  .panel-controls-body {
    width: 220px;
  }

  body.drawer-open .panel-controls {
    right: 300px;
  }
}

@media (max-width: 720px) {
  :root {
    --feed-height-base: 120px;
    --feed-height-expanded: 200px;
  }

  .topbar,
  .filters {
    padding: 16px;
  }

  .graph-overlay {
    inset: 210px 16px calc(var(--feed-height) + 24px) 16px;
  }

  .legend-dock {
    left: 16px;
    bottom: calc(var(--feed-height) + 18px);
  }

  .panel-controls {
    bottom: calc(var(--feed-height) + 18px);
    right: 16px;
  }

  .panel-controls-body {
    width: 200px;
  }

  .panel-controls-toggle {
    margin-right: 0;
  }

  body.drawer-open .panel-controls {
    right: 16px;
  }

  .table-wrap th,
  .table-wrap td {
    padding: 8px 6px;
  }
}

body.panels-hidden .graph-overlay .panel,
body.panels-hidden .filters {
  opacity: 0;
  pointer-events: none;
  transform: translateY(-8px);
}

body.panels-hidden.feed-visible .feed-panel {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.feed-panel .table-wrap {
  max-height: calc(var(--feed-height) - 72px);
}

.legend-swatch.legend-route-forward {
  background: #33ff79;
  box-shadow: 0 0 12px rgba(51, 255, 121, 0.8);
}

.legend-swatch.legend-route-return {
  background: #ff3b3b;
  box-shadow: 0 0 12px rgba(255, 59, 59, 0.8);
}

.legend-swatch.legend-rf {
  background: linear-gradient(120deg, rgba(90, 216, 200, 0.9), rgba(122, 169, 255, 0.7));
}

.legend-swatch.legend-broadcast {
  background: rgba(141, 160, 178, 0.4);
  border: 1px dashed rgba(141, 160, 178, 0.7);
}

body.topomap {
  overflow: hidden;
}

.map-stage {
  position: relative;
  width: 100%;
  height: 100vh;
  z-index: 1;
}

#map {
  position: absolute;
  inset: 0;
  background: #0b141c;
}

#mapCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
}

.map-hud {
  position: absolute;
  top: 120px;
  left: 32px;
  z-index: 4;
  pointer-events: none;
}

.map-hud .panel {
  pointer-events: auto;
}

.map-panel {
  min-width: 220px;
}

.camera-panel {
  margin-top: 12px;
  min-width: 260px;
  display: grid;
  gap: 10px;
}

.camera-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
}

.camera-row input[type="range"] {
  width: 140px;
  accent-color: var(--accent);
}

.camera-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.camera-actions .ghost-btn {
  padding: 6px 12px;
  font-size: 11px;
}

.map-legend {
  bottom: 24px;
}

@media (max-width: 1024px) {
  .map-hud {
    top: 150px;
    left: 20px;
  }
}

@media (max-width: 720px) {
  .map-hud {
    top: 170px;
    left: 16px;
  }
  .map-panel {
    min-width: 200px;
  }

  .camera-panel {
    min-width: 200px;
  }

  .camera-row input[type="range"] {
    width: 120px;
  }
}
