/* ==========================================================================
   NELIX VISUALS  —  nx-visuals.css

   Layout shells that carry diagrams: the generic figure frame (.nx-viz), the
   asymmetric copy + diagram split (.nxd-pair / .nx-blueprint), process rails,
   ecosystem maps and page-hero media.

   Colour comes from the `--nxd-*` bridge declared in nx-diagrams.css, which in
   turn resolves to the contract tokens in docs/REDESIGN_CONTRACT.md. Nothing
   here defines a palette. Load order: nx-diagrams.css before this file.
   ========================================================================== */

/* ------------------------------------------------------------------- frame */

.nx-viz {
  position: relative;
  margin: 0;
  min-width: 0;
  border: 1px solid var(--nxd-line);
  border-radius: var(--nxd-radius);
  background:
    radial-gradient(120% 85% at 50% 0%, var(--nxd-glow-10), transparent 58%),
    linear-gradient(178deg, var(--nxd-navy), var(--nxd-abyss));
  overflow: hidden;
}

/* Generic sizing for legacy canvases only. An nxd diagram sizes its own SVGs
   and swaps between a wide and a spine variant by `display`, so a blanket
   `display: block` here would show both at once. */
.nx-viz__canvas,
.nx-viz svg:not(.nxd__svg) {
  display: block;
  width: 100%;
  height: auto;
}

/* Direct child only — nested .nxd__cap must not inherit the host plate's
   uppercase band (that was stacking a second caption under the diagram). */
.nx-viz > figcaption,
.nx-viz__cap {
  margin: 0;
  padding: 0.75rem 1rem;
  border-block-start: 1px solid var(--nxd-line);
  font-family: var(--nxd-font);
  font-size: var(--nx-fs-eyebrow, 0.6875rem);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--nxd-faint);
}

.nx-viz--flush {
  border: 0;
  border-radius: 0;
  background: transparent;
}

.nx-viz--hero {
  aspect-ratio: 1 / 1;
  max-height: min(560px, 72vh);
  background:
    radial-gradient(ellipse 70% 55% at 50% 42%, var(--nxd-glow-18), transparent 62%),
    radial-gradient(circle at 18% 78%, var(--nxd-glow-06), transparent 42%),
    radial-gradient(circle at 82% 18%, var(--nxd-glow-06), transparent 38%),
    linear-gradient(165deg, var(--nxd-navy), var(--nxd-void) 70%);
  box-shadow: inset 0 0 0 1px var(--nxd-line), var(--nx-shadow-lift, 0 32px 64px -24px rgba(0, 0, 0, 0.8));
  isolation: isolate;
}

.nx-viz--hero .nx-viz__canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.nx-viz--hero svg:not(.nxd__svg) {
  position: relative;
  z-index: 1;
  height: 100%;
  object-fit: contain;
}

/* Generic SVG typography for legacy diagrams only. Diagrams built on the nxd
   system carry their own type classes and must not be overridden here. */
.nx-viz svg:not(.nxd__svg) text,
.nx-viz__label {
  font-family: var(--nxd-font);
  font-size: 10px;
  letter-spacing: 0.08em;
  fill: var(--nxd-muted);
}

.nx-viz svg:not(.nxd__svg) .nx-viz__title {
  font-size: 13px;
  letter-spacing: -0.02em;
  fill: var(--nxd-text);
}

/* --------------------------------------------------------- diagram + copy

   The contract asks for asymmetric 7/5 splits rather than 50/50. `.nxd-pair`
   is the shell the page streams should reach for when placing a diagram beside
   its two to four sentences of copy. `.nx-blueprint` is the older name and is
   kept as an equivalent. */

.nxd-pair,
.nx-blueprint {
  display: grid;
  gap: clamp(1.75rem, 4vw, 3.25rem);
  align-items: center;
  min-width: 0;
}

@media (min-width: 960px) {
  .nxd-pair,
  .nx-blueprint {
    grid-template-columns: minmax(0, 7fr) minmax(0, 5fr);
  }

  .nxd-pair--flip,
  .nx-blueprint--flip {
    grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
  }

  /* diagram first in the source, copy first visually — or the reverse */
  .nxd-pair--flip > .nxd,
  .nxd-pair--flip > .nx-viz,
  .nx-blueprint--flip > .nx-viz {
    order: -1;
  }
}

.nxd-pair__copy,
.nx-blueprint__copy {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  min-width: 0;
}

.nxd-pair__copy p,
.nx-blueprint__copy .nx-body,
.nx-blueprint__copy .nx-lede {
  max-width: 54ch;
}

/* A diagram given the full measure, centred, with breathing room. */
.nxd-solo {
  max-width: var(--nx-container, 84rem);
  margin-inline: auto;
  min-width: 0;
}

/* Two diagrams side by side. Never three — they stop being readable. */
.nxd-duo {
  display: grid;
  gap: clamp(1.25rem, 3vw, 2.5rem);
  min-width: 0;
}

@media (min-width: 1100px) {
  .nxd-duo {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* -------------------------------------------------------- process rail */

.nx-process {
  display: grid;
  gap: 1px;
  background: var(--nxd-line);
  border: 1px solid var(--nxd-line);
  border-radius: var(--nxd-radius);
  overflow: hidden;
}

@media (min-width: 800px) {
  .nx-process {
    grid-template-columns: repeat(var(--nx-process-cols, 4), minmax(0, 1fr));
  }
}

.nx-process__step {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1.5rem;
  background: var(--nxd-navy);
  min-width: 0;
  transition: background var(--nxd-dur-fast) var(--nxd-ease-out);
}

.nx-process__step:hover { background: var(--nxd-lift); }

.nx-process__num {
  font-family: var(--nxd-font);
  font-size: var(--nx-fs-eyebrow, 0.6875rem);
  letter-spacing: var(--nx-tracking-eyebrow, 0.16em);
  text-transform: uppercase;
  color: var(--nxd-azure);
}

.nx-process__name {
  margin: 0;
  font-size: var(--nx-fs-h3, 1.25rem);
  font-weight: 500;
  letter-spacing: -0.02em;
  color: var(--nxd-text);
}

.nx-process__desc {
  margin: 0;
  font-size: var(--nx-fs-caption, 0.8125rem);
  line-height: 1.6;
  color: var(--nxd-muted);
}

/* Hand-off marker between steps: a rounded corner bend, not a chevron. */
@media (min-width: 800px) {
  .nx-process__step:not(:last-child)::after {
    content: "";
    position: absolute;
    top: 1.7rem;
    right: -0.3rem;
    width: 0.6rem;
    height: 0.6rem;
    border-top: 1px solid var(--nxd-line-accent);
    border-right: 1px solid var(--nxd-line-accent);
    border-start-end-radius: 2px;
    transform: rotate(45deg);
    z-index: 1;
    pointer-events: none;
  }
}

/* ------------------------------------------------------- ecosystem map */

.nx-eco {
  display: grid;
  gap: 1rem;
  padding: 1.5rem;
  border: 1px solid var(--nxd-line);
  border-radius: var(--nxd-radius);
  background:
    linear-gradient(var(--nxd-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--nxd-grid) 1px, transparent 1px),
    var(--nxd-navy);
  background-size: 28px 28px, 28px 28px, auto;
}

.nx-eco__row { display: grid; gap: 0.75rem; }

@media (min-width: 720px) {
  .nx-eco__row { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
}

.nx-eco__node {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 1rem;
  border: 1px solid var(--nxd-line);
  border-radius: 4px;
  background: var(--nxd-abyss);
  text-decoration: none;
  color: inherit;
  transition:
    border-color var(--nxd-dur-fast) var(--nxd-ease-out),
    background var(--nxd-dur-fast) var(--nxd-ease-out),
    transform var(--nxd-dur-fast) var(--nxd-ease-out);
}

a.nx-eco__node:hover {
  border-color: var(--nxd-line-accent);
  background: var(--nxd-ink);
  transform: translateY(-2px);
}

.nx-eco__kicker {
  font-family: var(--nxd-font);
  font-size: var(--nx-fs-eyebrow, 0.6875rem);
  letter-spacing: var(--nx-tracking-eyebrow, 0.16em);
  text-transform: uppercase;
  color: var(--nxd-azure);
}

.nx-eco__name {
  margin: 0;
  font-size: 1rem;
  font-weight: 500;
  color: var(--nxd-text);
}

.nx-eco__note {
  margin: 0;
  font-size: var(--nx-fs-caption, 0.8125rem);
  color: var(--nxd-muted);
}

.nx-eco__bridge {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding-block: 0.5rem;
  font-family: var(--nxd-font);
  font-size: var(--nx-fs-eyebrow, 0.6875rem);
  letter-spacing: var(--nx-tracking-eyebrow, 0.16em);
  text-transform: uppercase;
  color: var(--nxd-faint);
}

.nx-eco__bridge::before,
.nx-eco__bridge::after {
  content: "";
  height: 1px;
  flex: 1;
  background: linear-gradient(90deg, transparent, var(--nxd-line-accent), transparent);
}

/* ---------------------------------------------------- feature illustrate */

.nx-featill {
  display: grid;
  gap: 1px;
  background: var(--nxd-line);
  border: 1px solid var(--nxd-line);
  border-radius: var(--nxd-radius);
  overflow: hidden;
}

@media (min-width: 900px) {
  .nx-featill { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.nx-featill__item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 1rem;
  padding: 1.5rem;
  background: var(--nxd-navy);
  align-items: start;
}

.nx-featill__mark {
  width: 2.25rem;
  height: 2.25rem;
  display: grid;
  place-items: center;
  border: 1px solid var(--nxd-line-accent);
  border-radius: 4px;
  background: var(--nxd-ink);
  color: var(--nxd-azure);
  font-family: var(--nxd-font);
  font-size: var(--nx-fs-eyebrow, 0.6875rem);
  font-variant-numeric: tabular-nums;
}

.nx-featill__title {
  margin: 0 0 0.5rem;
  font-size: 1rem;
  font-weight: 500;
  color: var(--nxd-text);
}

.nx-featill__body {
  margin: 0;
  font-size: var(--nx-fs-caption, 0.8125rem);
  line-height: 1.6;
  color: var(--nxd-muted);
}

/* --------------------------------------------------------- app chips */

.nx-apps {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.nx-app {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.85rem;
  border: 1px solid var(--nxd-line);
  border-radius: 4px;
  background: var(--nxd-navy);
  font-size: var(--nx-fs-caption, 0.8125rem);
  color: var(--nxd-body);
}

.nx-app::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 1px;
  background: var(--nxd-azure);
  box-shadow: 0 0 0 3px var(--nxd-glow-10);
}

/* ------------------------------------------------------- page hero media */

.nx-pagehero {
  display: grid;
  gap: 2.5rem;
  align-items: end;
}

@media (min-width: 1024px) {
  .nx-pagehero { grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr); }
}

.nx-pagehero__media { min-width: 0; }

/* ----------------------------------------------------------- animations
   Ambient motion for legacy .nx-viz diagrams. New work uses the .nxd-spark /
   .nxd-breathe primitives in nx-diagrams.css. */

.nx-viz .nx-pulse {
  stroke-dasharray: 8 120;
  animation: nx-viz-pulse 6.4s linear infinite;
}

.nx-viz .nx-spin {
  transform-origin: center;
  animation: nx-viz-spin 48s linear infinite;
}

.nx-viz .nx-spin-rev {
  transform-origin: center;
  animation: nx-viz-spin 64s linear infinite reverse;
}

.nx-viz .nx-breathe {
  animation: nx-viz-breathe 7.5s var(--nxd-ease) infinite;
}

.nx-viz .nx-dashflow {
  stroke-dasharray: 4 10;
  animation: nx-viz-dash 22s linear infinite;
}

@keyframes nx-viz-pulse { to { stroke-dashoffset: -128; } }
@keyframes nx-viz-spin { to { transform: rotate(360deg); } }
@keyframes nx-viz-breathe { 0%, 100% { opacity: 0.55; } 50% { opacity: 1; } }
@keyframes nx-viz-dash { to { stroke-dashoffset: -280; } }

.nx-netline {
  stroke: var(--nxd-line-accent);
  stroke-width: 1;
  fill: none;
}

.nx-netline--live {
  stroke: var(--nxd-azure);
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-dasharray: 6 80;
  animation: nx-viz-pulse 5.2s linear infinite;
}

@media (prefers-reduced-motion: reduce) {
  .nx-viz .nx-pulse,
  .nx-viz .nx-spin,
  .nx-viz .nx-spin-rev,
  .nx-viz .nx-breathe,
  .nx-viz .nx-dashflow,
  .nx-netline--live,
  a.nx-eco__node,
  .nx-process__step {
    animation: none !important;
    transition: none !important;
    transform: none !important;
  }

  .nx-viz .nx-pulse,
  .nx-netline--live {
    stroke-dasharray: none;
  }

  .nx-viz .nx-breathe { opacity: 1; }
}
