/* Control Room 3D renderer — full-bleed dark canvas + overlay chrome. */

:root {
  --fg: #e8ecf5;
  --fg-muted: #9aa6c0;
  --panel-bg: rgba(13, 19, 35, 0.92);
  --panel-border: #2a3754;
  --accent: #5b9dff;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: #05070f;
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

#scene-mount {
  position: fixed;
  inset: 0;
}

#scene-mount canvas {
  display: block;
}

/* ----------------------------------------------------------------- *
 * CSS2D tag layer — the DOM overlay the CSS2DRenderer draws into.
 * It covers the canvas but lets orbit drags pass through; only the
 * individual tags (.node-tag) re-enable pointer events.
 * ----------------------------------------------------------------- */

#tag-layer {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

#overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

#status-banner {
  pointer-events: auto;
  margin-top: 2.5rem;
  padding: 1rem 1.75rem;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  font-size: 1.05rem;
  color: var(--fg);
  max-width: 80vw;
  text-align: center;
  backdrop-filter: blur(6px);
}

/* ----------------------------------------------------------------- *
 * Node tag — the per-entity HTML attached to a 3D point via a
 * CSS2DObject. Structure (matches the JS that builds it):
 *
 *   .node-tag                         ← the CSS2DObject root (centered)
 *     button.node-circle              ← slot 1: avatar / glyph / initials
 *       img.node-avatar | span.node-glyph | span.node-initials
 *       i.node-dot                    ← slot 2: status dot (top-left)
 *     span.node-label                 ← slot 3: name across the bottom
 *     aside.node-popover              ← slot 4: detail popover (hover/pin)
 *
 * Per-kind hue + per-state dot colour are set from JS as CSS custom
 * properties (--kind-color, the .state-* class) so all *styling* stays
 * here and the JS only sets data.
 * ----------------------------------------------------------------- */

.node-tag {
  position: absolute;
  /* The whole tag is non-interactive EXCEPT its circle + popover, so
     orbit drags between tags reach the canvas underneath. */
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: max-content;
  --kind-color: #9aa6c0;
  --circle-size: 44px;
  /* Activity glow 0..1, set by JS on this ROOT so it inherits down to the
     circle's halo box-shadow. DRIVEN BY: the node's recent-signal warmth
     (+ the bounded heartbeat on the org). The whole entity's glow is this
     one CSS channel — there is no 3D halo mesh. */
  --activity: 0;
}

.node-tag.is-org {
  --circle-size: 72px; /* org reads bigger — directive 1 */
}

/* Slot 1 — the circle IS the node (avatar / logo / glyph / initials). */
.node-circle {
  position: relative;
  width: var(--circle-size);
  height: var(--circle-size);
  border-radius: 50%;
  padding: 0;
  border: 2px solid var(--kind-color);
  background: #0c1730;
  color: var(--fg);
  cursor: pointer;
  pointer-events: auto; /* re-enabled over the no-pointer-events layer */
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  /* Activity HALO — a soft glow around the circle whose spread + strength
     scale with the inherited --activity (0..1). Bounded by the calc() caps
     so even a fully-warm node / peak heartbeat stays a gentle halo, never a
     flare. This is the activity glow the directive asks to live on the tag. */
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.55),
    0 0 calc(6px + 22px * var(--activity)) calc(1px + 5px * var(--activity))
      color-mix(in srgb, var(--kind-color) 85%, transparent);
  transition: transform 0.12s ease;
}

.node-circle:hover {
  transform: scale(1.08);
}

.node-circle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Offline nodes read dim (state still encoded by the dot too). */
.node-tag.state-offline .node-circle {
  opacity: 0.5;
  filter: grayscale(0.5);
}

.node-avatar {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.node-glyph {
  font-size: calc(var(--circle-size) * 0.5);
  line-height: 1;
}

.node-initials {
  font-size: calc(var(--circle-size) * 0.36);
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--kind-color);
}

/* Slot 2 — status dot, top-left of the circle. */
.node-dot {
  position: absolute;
  top: 1px;
  left: 1px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid #0c1730;
  background: #6b7689; /* offline (grey) default */
}

.node-tag.state-idle .node-dot {
  background: #3ddc84; /* green — idle / available */
}

.node-tag.state-busy .node-dot {
  background: #ffb24d; /* amber — busy */
  animation: dot-pulse 1.3s ease-in-out infinite;
}

.node-tag.state-offline .node-dot {
  background: #6b7689; /* grey — offline */
}

@keyframes dot-pulse {
  /* Gentle pulse means "busy right now" (directive 1, slot 2). */
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(255, 178, 77, 0.55);
  }
  50% {
    box-shadow: 0 0 0 5px rgba(255, 178, 77, 0);
  }
}

/* Slot 3 — name label across the bottom. */
.node-label {
  margin-top: 5px;
  max-width: calc(var(--circle-size) * 3.4);
  padding: 1px 7px;
  border-radius: 7px;
  background: rgba(7, 11, 22, 0.72);
  color: var(--fg);
  font-size: 0.78rem;
  line-height: 1.25;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  backdrop-filter: blur(2px);
}

.node-tag.is-org .node-label {
  font-size: 0.95rem;
  font-weight: 600;
}

/* Slot 4 — detail popover. Anchored under the circle; tracks the node
   because it lives inside the CSS2DObject. Hidden until hover/pin. */
.node-popover {
  position: absolute;
  top: calc(var(--circle-size) + 4px);
  left: 50%;
  transform: translateX(-50%) translateY(-4px);
  min-width: 160px;
  max-width: 240px;
  margin: 0;
  padding: 0.6rem 0.75rem;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  backdrop-filter: blur(8px);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  pointer-events: auto;
  opacity: 0;
  visibility: hidden;
  transition:
    opacity 0.14s ease,
    transform 0.14s ease;
  z-index: 5;
}

/* Reveal on hover of the tag, OR when pinned (click). */
.node-tag:hover .node-popover,
.node-tag.is-pinned .node-popover {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

.node-popover-title {
  margin: 0 0 0.4rem;
  font-size: 0.92rem;
  font-weight: 600;
  word-break: break-word;
}

.node-popover dl {
  margin: 0;
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.25rem 0.6rem;
}

.node-popover dt {
  color: var(--fg-muted);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.node-popover dd {
  margin: 0;
  font-size: 0.82rem;
  word-break: break-word;
}

.node-popover-pin {
  margin-top: 0.45rem;
  font-size: 0.68rem;
  color: var(--fg-muted);
}

/* Pinned tags float above their neighbours and show a close affordance. */
.node-tag.is-pinned {
  z-index: 6;
}

.node-popover-close {
  position: absolute;
  top: 0.2rem;
  right: 0.35rem;
  font-size: 1.1rem;
  line-height: 1;
  background: none;
  border: none;
  color: var(--fg-muted);
  cursor: pointer;
  display: none;
}

.node-tag.is-pinned .node-popover-close {
  display: block;
}

.node-popover-close:hover {
  color: var(--fg);
}

/* Compact (widget) sizing — smaller tags; hide labels when very small
   so the constellation stays legible. JS toggles .layer-compact and
   .layer-tiny on #tag-layer from the viewport size + zoom. */
.layer-compact .node-tag {
  --circle-size: 34px;
}

.layer-compact .node-tag.is-org {
  --circle-size: 54px;
}

.layer-tiny .node-label {
  display: none;
}

.hidden {
  display: none !important;
}
