:root {
  --bg: #060912;
  --bg-2: #0b1120;
  --panel: rgba(18, 24, 41, 0.85);
  --border: rgba(255, 255, 255, 0.08);
  --text: #e7ebf5;
  --text-dim: #8a93a8;
  --accent: #6d8dff;

  --claude: #e8853a;
  --agent: #4fa8ff;
  --human: #35d08a;
  --vacant: #6b7280;

  --dept-executive: #b98af0;
  --dept-operations: #4fa8ff;
  --dept-marketing: #ff7ab8;
  --dept-engineering: #35d08a;
  --dept-finance: #f2c94c;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  overflow-x: hidden;
}

/* ---------- background ---------- */

.bg-grid {
  position: fixed;
  inset: 0;
  z-index: 0;
  background-image:
    linear-gradient(rgba(109, 141, 255, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(109, 141, 255, 0.06) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: radial-gradient(ellipse 80% 60% at 50% 20%, black 30%, transparent 90%);
  animation: drift 30s linear infinite;
}

@keyframes drift {
  from { background-position: 0 0, 0 0; }
  to { background-position: 42px 84px, 84px 42px; }
}

#bg-pulse {
  position: fixed;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  opacity: 0.55;
}

/* ---------- topbar ---------- */

.topbar {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 22px 36px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: conic-gradient(from 220deg, var(--claude), var(--agent), var(--human), var(--claude));
  box-shadow: 0 0 24px rgba(109, 141, 255, 0.45);
  flex-shrink: 0;
}

.brand h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.tagline {
  margin: 2px 0 0;
  font-size: 0.82rem;
  color: var(--text-dim);
}

.legend {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel);
  backdrop-filter: blur(10px);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.78rem;
  color: var(--text-dim);
}

.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.dot-claude { background: var(--claude); box-shadow: 0 0 8px var(--claude); }
.dot-agent  { background: var(--agent);  box-shadow: 0 0 8px var(--agent); }
.dot-human  { background: var(--human);  box-shadow: 0 0 8px var(--human); }
.dot-vacant { background: var(--vacant); }

/* ---------- chart ---------- */

.chart-wrap {
  position: relative;
  z-index: 2;
  padding: 20px 24px 60px;
  min-height: 70vh;
}

.connectors {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.connectors path {
  fill: none;
  stroke: url(#line-gradient);
  stroke-width: 1.6;
  stroke-opacity: 0.55;
  marker-end: url(#arrowhead);
}

.arrow-fill { fill: #6d8dff; opacity: 0.75; }

.chart {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 64px;
}

.level {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 28px;
  flex-wrap: wrap;
  width: 100%;
}

.node {
  position: relative;
  width: 208px;
  padding: 14px 16px;
  border-radius: 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-top: 3px solid var(--node-dept, var(--accent));
  backdrop-filter: blur(8px);
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
  animation: rise 0.5s ease both;
}

.node:hover, .node:focus-visible {
  transform: translateY(-4px);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35), 0 0 0 1px var(--node-dept, var(--accent));
  outline: none;
}

.node.is-selected {
  box-shadow: 0 0 0 2px var(--node-dept, var(--accent)), 0 12px 30px rgba(0, 0, 0, 0.4);
}

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.node-top {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.node-title {
  font-size: 0.88rem;
  font-weight: 700;
}

.node-name {
  font-size: 0.78rem;
  color: var(--text-dim);
}

.node-owner-tag {
  margin-top: 8px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-dim);
}

/* ---------- detail panel ---------- */

.detail-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(340px, 88vw);
  z-index: 20;
  background: var(--bg-2);
  border-left: 1px solid var(--border);
  padding: 26px 22px;
  box-shadow: -20px 0 40px rgba(0, 0, 0, 0.4);
  animation: slidein 0.25s ease both;
  overflow-y: auto;
}

@keyframes slidein {
  from { transform: translateX(100%); }
  to   { transform: translateX(0); }
}

.detail-close {
  position: fixed;
  top: 22px;
  right: calc(min(340px, 88vw) + 18px);
  z-index: 21;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 1.1rem;
  cursor: pointer;
}

.detail-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.detail-header .dot {
  width: 14px;
  height: 14px;
}

#detail-title {
  margin: 0;
  font-size: 1.05rem;
}

#detail-name {
  margin: 2px 0 0;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.detail-desc {
  font-size: 0.9rem;
  line-height: 1.5;
  color: #cfd5e4;
}

.detail-systems h3 {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-dim);
  margin-bottom: 10px;
}

#detail-systems-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#detail-systems-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
}

/* ---------- connected systems strip ---------- */

.systems-strip {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 22px;
  flex-wrap: wrap;
  padding: 18px 36px 30px;
  border-top: 1px solid var(--border);
  margin-top: 20px;
}

.systems-strip-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-dim);
}

.systems-list {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}

.system-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--text-dim);
}

.system-chip .pulse {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
  animation: blip 2.2s ease-in-out infinite;
}

@keyframes blip {
  0%, 100% { opacity: 0.4; transform: scale(0.85); }
  50% { opacity: 1; transform: scale(1.15); }
}

@media (max-width: 640px) {
  .legend { display: none; }
  .node { width: 42vw; min-width: 150px; }
}
