/* Interactive diagrams: pipeline, MELT flow, topology, trace waterfall. */

.diagram {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  padding: var(--sp-5);
  margin: 0;
  border-radius: var(--r-2xl);
  background: var(--surface-diagram);
  border: 1px solid var(--border-diagram);
  min-width: 0;
}

.diagram__head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap; }
.diagram__title { font-size: var(--fs-14); font-weight: 700; color: var(--text-title); }
.diagram__caption { font-size: var(--fs-12); color: var(--text-muted); }

.diagram__detail {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-height: 62px;
  padding: 12px 14px;
  border-radius: var(--r-lg);
  background: var(--surface-row);
  border: 1px solid var(--border-row);
  font-size: var(--fs-12);
  color: var(--text-list);
  line-height: 1.5;
}

.diagram__detail strong { color: var(--text-title); font-size: var(--fs-13); }
.diagram__hint { color: var(--text-dim); }
.diagram-slot { min-height: 8px; }
.figure-block { min-width: 0; }

/* ---- Pipeline ---------------------------------------------------------------------- */
.pipe {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
  counter-reset: none;
}

.pipe__item { min-width: 0; }

.pipe-node {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 56px;
  padding: 10px 12px;
  border-radius: var(--r-lg);
  background: var(--surface-node);
  border: 1px solid var(--border-node);
  text-align: left;
  transition: border-color var(--dur-fast) ease, background var(--dur-fast) ease, transform var(--dur-fast) var(--ease-out);
}

.pipe-node:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--border-node)); transform: translateY(-1px); }
.pipe-node:focus-visible { outline: none; box-shadow: var(--focus-ring); }

.pipe-node__n {
  flex: none;
  display: grid;
  place-items: center;
  min-width: 26px;
  height: 26px;
  border-radius: var(--r-pill);
  background: var(--pill-bg);
  color: var(--pill-text);
  font-size: var(--fs-10);
  font-weight: 700;
}

.pipe-node__label { font-size: var(--fs-12); font-weight: 600; color: var(--text-strong); line-height: 1.3; }
.pipe-node.is-done { border-color: var(--border-row-active); }
.pipe-node.is-done .pipe-node__n { background: var(--accent-soft-bg); color: var(--accent-text); }
.pipe-node.is-active { background: var(--surface-row-active); border-color: var(--accent); }
.pipe-node.is-active .pipe-node__n { background: var(--accent); color: var(--on-accent); }

/* ---- MELT --------------------------------------------------------------------------- */
.melt {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.melt__source,
.melt__stage {
  padding: 14px 16px;
  border-radius: var(--r-lg);
  background: var(--surface-node);
  border: 1px solid var(--border-node);
  font-size: var(--fs-13);
  font-weight: 700;
  color: var(--text-title);
  min-height: 56px;
  text-align: center;
}

.melt__source { background: var(--accent-soft-bg); border-color: var(--border-row-active); color: var(--accent-text); }
.melt__source:focus-visible,
.melt__stage:focus-visible,
.melt__chip:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.melt__signals { display: flex; flex-direction: column; gap: 8px; position: relative; padding-right: 14px; }
.melt__row { position: relative; }
.melt__chip { width: 100%; padding: 7px 14px; border-radius: var(--r-pill); font-size: var(--fs-12); font-weight: 600; color: var(--on-day); }
.melt__chip--metrics { background: var(--day-teal); }
.melt__chip--logs { background: var(--day-sky); }
.melt__chip--events { background: var(--day-amber); }
.melt__chip--traces { background: var(--day-violet); }
.melt__packet { position: absolute; right: -2px; top: 50%; width: 9px; height: 9px; margin-top: -4.5px; border-radius: 50%; opacity: 0; }
.melt__packet--metrics { background: var(--day-teal); }
.melt__packet--logs { background: var(--day-sky); }
.melt__packet--events { background: var(--day-amber); }
.melt__packet--traces { background: var(--day-violet); }
.melt__arrow { color: var(--text-faint); display: grid; place-items: center; }
.melt__stage:hover,
.melt__source:hover { filter: brightness(1.12); }

/* ---- Topology ------------------------------------------------------------------------- */
.topo-holder { min-width: 0; }

.topo {
  position: relative;
  height: 340px;
  border-radius: var(--r-lg);
  background: var(--surface-row);
  border: 1px solid var(--border-row);
  overflow: hidden;
}

.topo__lines { position: absolute; inset: 0; width: 100%; height: 100%; }
.topo__edge { stroke: var(--border-radio); stroke-width: 1.5; opacity: 0.7; }
.topo__edge.is-hot { stroke: var(--rose); stroke-width: 2; opacity: 1; }

.topo__node {
  position: absolute;
  left: var(--x);
  top: var(--y);
  transform: translate(-50%, -50%);
  width: min(98px, 22%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 7px 6px;
  border-radius: var(--r-md);
  background: var(--surface-node);
  border: 1px solid var(--border-node);
  text-align: center;
  transition: border-color var(--dur-fast) ease, background var(--dur-fast) ease;
}

button.topo__node:hover { border-color: color-mix(in srgb, var(--accent) 50%, var(--border-node)); }
button.topo__node:focus-visible { outline: none; box-shadow: var(--focus-ring); z-index: 2; }
.topo__name { font-size: var(--fs-11); font-weight: 700; color: var(--text-title); word-break: break-word; line-height: 1.2; }
.topo__status { font-size: 9px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-dim); }
.topo__node.is-external { border-style: dashed; }
.topo__node[data-state="degraded"] { border-color: var(--amber); background: var(--callout-warn-bg); }
.topo__node[data-state="degraded"] .topo__status { color: var(--amber); }
.topo__node[data-state="failing"] { border-color: var(--rose); background: var(--callout-danger-bg); }
.topo__node[data-state="failing"] .topo__status { color: var(--rose); }
.topo__node[data-state="unknown"] { border-style: dashed; }
.topo__node[data-state="unknown"] .topo__status { color: var(--text-faint); }
.topo__node.is-selected { box-shadow: 0 0 0 2px var(--accent); }
.topo__node.is-hint { outline: 2px dashed var(--amber); outline-offset: 2px; }

/* ---- Waterfall -------------------------------------------------------------------------- */
.wf { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.wf__axis { display: flex; justify-content: space-between; padding-left: min(38%, 280px); font-size: 10px; color: var(--text-dim); }

.wf__row {
  display: grid;
  grid-template-columns: minmax(120px, 38%) minmax(0, 1fr);
  gap: 4px 12px;
  align-items: center;
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--r-md);
  background: var(--surface-row);
  border: 1px solid var(--border-row);
  text-align: left;
  min-width: 0;
}

button.wf__row { cursor: pointer; transition: border-color var(--dur-fast) ease, background var(--dur-fast) ease; }
button.wf__row:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--border-row)); }
button.wf__row:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.wf__row.is-flagged { border-color: var(--accent); background: var(--surface-row-active); }
.wf__label { display: flex; flex-direction: column; padding-left: calc(var(--depth, 0) * 14px); min-width: 0; }
.wf__name { font-size: var(--fs-12); font-weight: 600; color: var(--text-strong); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wf__service { font-size: var(--fs-10); color: var(--text-dim); }
.wf__track { position: relative; height: 22px; border-radius: 6px; background: var(--track-bg); }
.wf__bar { position: absolute; top: 3px; bottom: 3px; left: var(--left); width: var(--width); border-radius: 5px; background: var(--day-sky); }
.wf__row.is-hot .wf__bar { background: var(--rose); }
.wf__ms { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); font-size: 10px; font-weight: 600; color: var(--text-title); text-shadow: 0 0 4px var(--surface-row); }
.wf__note { grid-column: 1 / -1; font-size: var(--fs-11); color: var(--text-muted); line-height: 1.5; }
