@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;700&family=Orbitron:wght@600;700;900&display=swap');

:root {
  --bg: #020617;
  --bg-elev: #0b1224;
  --panel: rgba(15, 23, 42, 0.82);
  --line: #1e293b;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --cyan: #22d3ee;
  --violet: #a78bfa;
  --amber: #fbbf24;
  --rose: #f87171;
  --green: #34d399;
  --focus: #67e8f9;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(34, 211, 238, 0.12), transparent 55%),
    radial-gradient(900px 500px at 90% 0%, rgba(167, 139, 250, 0.10), transparent 50%),
    linear-gradient(180deg, #020617 0%, #07111f 100%);
  color: var(--text);
  font-family: 'JetBrains Mono', ui-monospace, monospace;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(34, 211, 238, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(34, 211, 238, 0.035) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse at center, black 30%, transparent 80%);
  z-index: 0;
}

.app-shell { position: relative; z-index: 1; min-height: 100dvh; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 20px;
  border-bottom: 1px solid rgba(34, 211, 238, 0.18);
  background: rgba(2, 6, 23, 0.86);
  backdrop-filter: blur(12px);
}

.brand {
  display: flex; align-items: center; gap: 12px;
}
.brand-mark {
  width: 34px; height: 34px; border-radius: 8px;
  border: 1px solid rgba(34, 211, 238, 0.55);
  box-shadow: 0 0 18px rgba(34, 211, 238, 0.35);
  display: grid; place-items: center;
  color: var(--cyan);
}
.brand h1 {
  margin: 0;
  font-family: Orbitron, sans-serif;
  font-size: 15px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.brand p { margin: 2px 0 0; font-size: 11px; color: var(--muted); }

.metrics {
  display: flex; align-items: center; gap: 18px; font-size: 12px; color: var(--muted);
}
.metrics strong { color: #fff; font-weight: 600; }
.conn-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--green); box-shadow: 0 0 8px var(--green);
}

.nav-tabs {
  display: flex; gap: 8px; flex-wrap: wrap;
}
.tab-btn {
  border: 1px solid rgba(148, 163, 184, 0.25);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 7px 14px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: border-color .2s, color .2s, box-shadow .2s, background .2s;
}
.tab-btn:hover { color: #fff; border-color: rgba(34, 211, 238, 0.5); }
.tab-btn.active {
  color: #041016;
  background: linear-gradient(90deg, #22d3ee, #67e8f9);
  border-color: transparent;
  box-shadow: 0 0 18px rgba(34, 211, 238, 0.35);
  font-weight: 700;
}
.tab-btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.view { display: none; }
.view.active { display: block; }

.map-stage {
  position: relative;
  height: calc(100dvh - 74px);
  min-height: 560px;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

#neural-canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
#neural-canvas.is-panning,
#neural-canvas:active { cursor: grabbing; }
#neural-canvas text { user-select: none; pointer-events: none; }
.nmap-node { cursor: pointer; }
.nmap-node:focus { outline: none; }
.nmap-edge { pointer-events: none; }

.map-hud {
  position: absolute; left: 16px; top: 16px; right: 16px;
  display: flex; justify-content: space-between; gap: 12px; pointer-events: none;
}
.map-hud > * { pointer-events: auto; }

.hud-card {
  background: var(--panel);
  border: 1px solid rgba(34, 211, 238, 0.22);
  border-radius: 12px;
  padding: 10px 12px;
  box-shadow: 0 10px 40px rgba(0,0,0,.35);
  backdrop-filter: blur(10px);
}
.hud-card h2 {
  margin: 0;
  font-family: Orbitron, sans-serif;
  font-size: 12px;
  letter-spacing: .14em;
  color: var(--cyan);
}
.hud-card .crumb {
  margin-top: 6px;
  font-size: 11px;
  color: var(--muted);
  display: flex; gap: 6px; flex-wrap: wrap; align-items: center;
}
.crumb button {
  border: 0; background: transparent; color: var(--cyan);
  font: inherit; cursor: pointer; padding: 0;
  text-decoration: underline; text-underline-offset: 3px;
}
.hud-stats {
  display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end;
}
.stat-pill {
  min-width: 88px;
  text-align: center;
  padding: 8px 10px;
}
.stat-pill b {
  display: block;
  font-family: Orbitron, sans-serif;
  font-size: 16px;
  color: #fff;
}
.stat-pill span { font-size: 10px; color: var(--muted); letter-spacing: .08em; }

.map-controls {
  position: absolute; right: 16px; bottom: 16px;
  display: flex; flex-direction: column; gap: 8px;
}
.map-controls button, .toolbar button, .btn {
  border: 1px solid rgba(34, 211, 238, 0.28);
  background: rgba(2, 6, 23, 0.85);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 12px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: transform .15s, border-color .15s, box-shadow .15s;
}
.map-controls button:hover, .toolbar button:hover, .btn:hover:not(:disabled) {
  border-color: var(--cyan);
  box-shadow: 0 0 16px rgba(34, 211, 238, 0.25);
  transform: translateY(-1px);
}
.btn:disabled { opacity: .35; cursor: not-allowed; transform: none !important; }
.btn-green { border-color: rgba(52, 211, 153, .45); color: #bbf7d0; }
.btn-red { border-color: rgba(248, 113, 113, .45); color: #fecaca; }
.btn-amber { border-color: rgba(251, 191, 36, .45); color: #fde68a; }
.btn-blue { border-color: rgba(96, 165, 250, .45); color: #bfdbfe; }
.btn-indigo { border-color: rgba(167, 139, 250, .45); color: #ddd6fe; }
.btn-slate { border-color: rgba(148, 163, 184, .35); color: #cbd5e1; }
.btn-danger { border-color: rgba(248, 113, 113, .55); color: #fecaca; background: rgba(127, 29, 29, .25); }

.tooltip {
  position: absolute;
  z-index: 30;
  max-width: 280px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(34, 211, 238, 0.35);
  background: rgba(2, 6, 23, 0.94);
  box-shadow: 0 0 24px rgba(34, 211, 238, 0.18);
  pointer-events: none;
  font-size: 12px;
  display: none;
}
.tooltip strong { display: block; font-family: Orbitron, sans-serif; letter-spacing: .08em; margin-bottom: 4px; }
.tooltip span { color: var(--muted); }

.modal-backdrop {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(2, 8, 23, 0.72);
  backdrop-filter: blur(6px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-backdrop.open { display: flex; }
.modal {
  width: min(560px, 100%);
  max-height: min(86dvh, 720px);
  overflow: auto;
  border-radius: 16px;
  border: 1px solid rgba(34, 211, 238, 0.35);
  background:
    linear-gradient(180deg, rgba(15, 23, 42, 0.98), rgba(2, 6, 23, 0.98));
  box-shadow: 0 0 40px rgba(34, 211, 238, 0.18), 0 30px 80px rgba(0,0,0,.55);
}
.modal.wide { width: min(920px, 100%); }
.modal-header, .modal-footer {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.15);
}
.modal-footer { border-bottom: 0; border-top: 1px solid rgba(148, 163, 184, 0.15); }
.modal-body { padding: 16px 18px; display: grid; gap: 12px; }
.modal h3 {
  margin: 0;
  font-family: Orbitron, sans-serif;
  font-size: 14px;
  letter-spacing: .08em;
}
.modal .path { font-size: 11px; color: var(--muted); word-break: break-all; }
.modal-close {
  width: 36px; height: 36px; border-radius: 10px;
  border: 1px solid rgba(248, 113, 113, 0.4);
  background: rgba(127, 29, 29, 0.25);
  color: #fecaca;
  cursor: pointer;
  font-size: 18px;
}
.modal-close:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 6px 10px; font-size: 12px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; color: #fff; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

.ops-wrap, .phish-wrap {
  max-width: 1280px;
  margin: 0 auto;
  padding: 20px;
  display: grid;
  gap: 18px;
}
.card {
  background: rgba(15, 23, 42, 0.88);
  border: 1px solid rgba(34, 211, 238, 0.14);
  border-radius: 14px;
  overflow: hidden;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.12);
}
.card-header h2 {
  margin: 0;
  font-family: Orbitron, sans-serif;
  font-size: 12px;
  letter-spacing: .12em;
  color: var(--cyan);
}

table { width: 100%; border-collapse: collapse; }
th {
  text-align: left;
  font-size: 10px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 10px 12px;
}
td {
  padding: 10px 12px;
  font-size: 12px;
  border-top: 1px solid rgba(30, 41, 59, 0.9);
  vertical-align: middle;
}
tbody tr:hover { background: rgba(34, 211, 238, 0.04); }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 10px; border-radius: 999px;
  font-size: 10px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
}
.badge-running { background: #052e16; color: #4ade80; border: 1px solid #166534; }
.badge-stopped { background: #1e293b; color: #94a3b8; border: 1px solid #334155; }
.badge-error { background: #2d0a0a; color: #f87171; border: 1px solid #7f1d1d; }
.badge-restarting { background: #2d1e00; color: #fbbf24; border: 1px solid #78350f; }
.badge-unconfigured { background: #3b0764; color: #e9d5ff; border: 1px solid #6b21a8; }

.dot { width: 7px; height: 7px; border-radius: 50%; }
.dot-running { background: #4ade80; box-shadow: 0 0 6px #4ade80; animation: pulse-dot 2s infinite; }
.dot-stopped { background: #64748b; }
.dot-error { background: #f87171; box-shadow: 0 0 6px #f87171; }
.dot-restarting { background: #fbbf24; box-shadow: 0 0 6px #fbbf24; animation: pulse-dot 1s infinite; }

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: .4; }
}

.bar-track { background: #1e293b; border-radius: 4px; height: 5px; min-width: 64px; }
.bar-fill { height: 5px; border-radius: 4px; transition: width .5s ease; }

#terminal {
  background: #020817;
  font-size: 12.5px;
  line-height: 1.6;
  min-height: 260px;
  max-height: 380px;
  overflow-y: auto;
  padding: 14px;
}
.log-info { color: #94a3b8; }
.log-warn { color: #fbbf24; }
.log-error { color: #f87171; }
.log-success { color: #4ade80; }
.log-dim { color: #475569; }

#config-editor, #script-editor {
  width: 100%;
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  background: #020817;
  color: #e2e8f0;
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 12px;
  outline: none;
  resize: vertical;
  line-height: 1.6;
  min-height: 240px;
}
#script-editor { min-height: 400px; }
#config-editor:focus, #script-editor:focus { border-color: var(--cyan); box-shadow: 0 0 0 1px rgba(34,211,238,.35); }

#toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 100;
  padding: 10px 18px; border-radius: 10px; font-size: 12px; font-weight: 600;
  display: none;
}
#toast.show { display: block; }
#toast.ok { background: #065f46; border: 1px solid #34d399; color: #ecfdf5; }
#toast.err { background: #7f1d1d; border: 1px solid #f87171; color: #fee2e2; }

select, input[type="text"] {
  background: #0f172a;
  border: 1px solid #334155;
  color: #e2e8f0;
  border-radius: 8px;
  padding: 7px 10px;
  font: inherit;
  font-size: 12px;
}

@media (max-width: 900px) {
  .topbar { flex-wrap: wrap; }
  .metrics { width: 100%; justify-content: space-between; }
  .map-hud { flex-direction: column; }
  .kv { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}
