/* Soft card surfaces, one lighting direction, and a continuous matrix terrain. */
#data-connections .ingestion-agent { --matrix-overlap: 220px; }
#data-connections .ingestion-agent-step { padding-bottom: calc(var(--matrix-overlap) + 24px); }
#data-connections .ecosystem-matrix {
  --matrix-green-top-a: #20493d;
  --matrix-green-top-b: #12352f;
  --matrix-green-top-c: #09232b;
  --matrix-green-left-a: #173a32;
  --matrix-green-left-b: #102d2c;
  --matrix-green-left-c: #071e27;
  --matrix-green-right-a: #102f2d;
  --matrix-green-right-b: #0a2429;
  --matrix-green-right-c: #051922;
  --matrix-red-top-a: #45212b;
  --matrix-red-top-b: #2c2029;
  --matrix-red-top-c: #14232c;
  --matrix-red-left-a: #351a25;
  --matrix-red-left-b: #241c27;
  --matrix-red-left-c: #101c26;
  --matrix-red-right-a: #291822;
  --matrix-red-right-b: #1c1a24;
  --matrix-red-right-c: #0b1722;
  --matrix-neutral-top-a: #1b3742;
  --matrix-neutral-top-b: #112b36;
  --matrix-neutral-top-c: #091d29;
  --matrix-neutral-left-a: #152e39;
  --matrix-neutral-left-b: #0d2430;
  --matrix-neutral-left-c: #071a26;
  --matrix-neutral-right-a: #102632;
  --matrix-neutral-right-b: #0a1e2a;
  --matrix-neutral-right-c: #051522;
  --matrix-green-edge: var(--border-accent,rgba(68,160,101,.46));
  --matrix-red-edge: var(--connection-red,var(--brand-red,#ff0000));
  --matrix-neutral-edge: var(--border-subtle,rgba(158,198,207,.18));
  position: relative;
  z-index: 2;
  width: min(680px, calc(100% - 24px));
  margin: calc(-1 * var(--matrix-overlap)) auto 0;
  pointer-events: none;
}
#data-connections .ecosystem-matrix svg { display: block; width: 100%; height: auto; overflow: visible; }
#data-connections .matrix-column { --cell-edge: var(--matrix-green-edge); --cell-left: url(#ecosystem-matrix-green-left); --cell-right: url(#ecosystem-matrix-green-right); }
#data-connections .matrix-column--low { --cell-edge: var(--matrix-red-edge); --cell-left: url(#ecosystem-matrix-red-left); --cell-right: url(#ecosystem-matrix-red-right); }
#data-connections .matrix-column--neutral { --cell-edge: var(--matrix-neutral-edge); --cell-left: url(#ecosystem-matrix-neutral-left); --cell-right: url(#ecosystem-matrix-neutral-right); }
#data-connections .matrix-face { stroke: none; }
#data-connections .matrix-edges { fill: none; stroke: var(--cell-edge); stroke-opacity: 1; stroke-width: 1px; vector-effect: non-scaling-stroke; stroke-linejoin: round; stroke-linecap: round; }
#data-connections .matrix-face--left { fill: var(--cell-left); }
#data-connections .matrix-face--right { fill: var(--cell-right); }
:root[data-theme="light"] #data-connections .ecosystem-matrix {
  --matrix-green-top-a: #f6fbf8;
  --matrix-green-top-b: #e4f1e8;
  --matrix-green-top-c: #d2e5d9;
  --matrix-green-left-a: #eaf4ed;
  --matrix-green-left-b: #d6e7dc;
  --matrix-green-left-c: #c3dacc;
  --matrix-green-right-a: #dfede4;
  --matrix-green-right-b: #cddfd3;
  --matrix-green-right-c: #b7d0c1;
  --matrix-red-top-a: #fff6f3;
  --matrix-red-top-b: #f6e6e4;
  --matrix-red-top-c: #e5e9eb;
  --matrix-red-left-a: #f8eae5;
  --matrix-red-left-b: #eadbd9;
  --matrix-red-left-c: #d5dee3;
  --matrix-red-right-a: #efdedb;
  --matrix-red-right-b: #dfd3d5;
  --matrix-red-right-c: #c6d4dc;
  --matrix-neutral-top-a: #f6fafb;
  --matrix-neutral-top-b: #e5eef2;
  --matrix-neutral-top-c: #d2dfe7;
  --matrix-neutral-left-a: #eaf2f5;
  --matrix-neutral-left-b: #d5e3ea;
  --matrix-neutral-left-c: #c2d3df;
  --matrix-neutral-right-a: #dfebf0;
  --matrix-neutral-right-b: #cbdce5;
  --matrix-neutral-right-c: #b5cbd8;
}
@media (max-width: 700px) {
  #data-connections .ingestion-agent { --matrix-overlap: clamp(84px,31vw,220px); }
  #data-connections .ecosystem-matrix { width: calc(100% - 16px); }
}
/* Rows follow isometric depth: the back apex appears first, the front edge last. */
@keyframes ecosystem-matrix-row-in {
  from { opacity: 0; translate: 0 -8px; }
  to { opacity: 1; translate: 0 0; }
}
@media (prefers-reduced-motion: no-preference) {
  #data-connections .ingestion-agent-step:is([data-ingestion-state="pending"],[data-ingestion-state="running"]) + .ecosystem-matrix .matrix-column { opacity: 0; }
  #data-connections .ingestion-agent-step[data-ingestion-state="done"] + .ecosystem-matrix .matrix-column {
    animation: ecosystem-matrix-row-in .4s cubic-bezier(.22,.68,.26,1) both;
    animation-delay: calc(var(--matrix-row) * 65ms);
  }
}
@media print {
  #data-connections .ecosystem-matrix .matrix-column { opacity: 1 !important; translate: none !important; animation: none !important; }
}

/* A finding grows from the lowest cell only after the terrain has finished. */
#data-connections .ingestion-agent { --matrix-insight-reserve: 0px; }
#data-connections .ingestion-agent-step {
  padding-bottom: calc(var(--matrix-overlap) + 24px + var(--matrix-insight-reserve));
}
#data-connections .ecosystem-matrix {
  --matrix-pin-x: 45.454545%;
  --matrix-pin-y: 75.506667%;
  --matrix-stem-height: calc(40px + var(--matrix-card-half, 90px));
}
#data-connections .matrix-issue-dot {
  position: absolute;
  z-index: 5;
  left: var(--matrix-pin-x);
  top: var(--matrix-pin-y);
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--connection-red, #ff0000);
  translate: -50% -50%;
}
#data-connections .matrix-issue-stem {
  position: absolute;
  z-index: 4;
  left: var(--matrix-pin-x);
  bottom: calc(100% - var(--matrix-pin-y));
  width: 1px;
  height: var(--matrix-stem-height);
  background: var(--connection-red, #ff0000);
  translate: -50% 0;
  transform-origin: center bottom;
}
#data-connections .matrix-issue-card {
  position: absolute;
  z-index: 6;
  left: 50%;
  bottom: calc(100% - var(--matrix-pin-y) + var(--matrix-stem-height));
  width: min(348px, calc(100% - 16px));
  margin: 0;
  padding: 18px 20px;
  border: 1px solid var(--connection-red, #ff0000);
  border-radius: 12px;
  background-color: var(--bg, #020f16);
  background-image: var(--chaos-card-background);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  color: var(--text-primary, #e6eff0);
  text-align: left;
  translate: -50% 50%;
}
#data-connections .matrix-issue-source {
  display: block;
  margin: 0 0 10px;
  color: var(--danger-text, #ff746c);
  font: 700 10px/1.4 var(--font-body);
  letter-spacing: .1em;
  text-transform: uppercase;
}
#data-connections .matrix-issue-problem {
  margin: 0;
  font: 600 17px/1.35 var(--font-body);
  letter-spacing: -.02em;
}
#data-connections .matrix-issue-action {
  margin: 12px 0 0;
  color: var(--text-secondary, #b6c8cd);
  font: 400 15px/1.45 var(--font-body);
  letter-spacing: -.01em;
}
:root[data-theme="light"] #data-connections .matrix-issue-card {
  background-image: linear-gradient(145deg, #fff5f3, #f8fafa);
}
@media (max-width: 700px) {
  #data-connections .ingestion-agent { --matrix-insight-reserve: 120px; }
  #data-connections .ecosystem-matrix { --matrix-stem-height: calc(28px + var(--matrix-card-half, 90px)); }
  #data-connections .matrix-issue-card { padding: 16px; }
  #data-connections .matrix-issue-problem { font-size: 16px; }
  #data-connections .matrix-issue-action { margin-top: 10px; font-size: 14px; }
}
@media (max-width: 540px) {
  #data-connections .ecosystem-matrix { --matrix-stem-height: calc(var(--matrix-pin-y) + 16px + var(--matrix-card-half, 90px)); }
}
@keyframes matrix-issue-dot-in {
  from { opacity: 0; transform: scale(.35); }
  to { opacity: 1; transform: scale(1); }
}
@keyframes matrix-issue-stem-in {
  from { opacity: 1; transform: scaleY(0); }
  to { opacity: 1; transform: scaleY(1); }
}
#data-connections .matrix-issue-end-dot {
  position: absolute;
  z-index: 7;
  left: var(--matrix-pin-x);
  top: calc(var(--matrix-pin-y) - var(--matrix-stem-height));
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--connection-red, #ff0000);
  translate: -50% -50%;
  opacity: 0;
}
@keyframes matrix-issue-end-dot-in {
  from { opacity: 0; transform: scale(0); }
  to { opacity: 1; transform: scale(1); }
}
@keyframes matrix-issue-end-dot-out {
  from { opacity: 1; }
  to { opacity: 0; }
}
/* The same 8px seed → 36% inset → rounded card shape as data connections. */
@keyframes matrix-issue-card-in {
  0% { opacity: 0; clip-path: inset(var(--matrix-seed-inset, calc(50% - 4px)) round 50%); }
  24% { opacity: 1; clip-path: inset(var(--matrix-mid-inset, 36%) round 50%); }
  100% { opacity: 1; clip-path: inset(0 round 12px); }
}
@media (prefers-reduced-motion: no-preference) {
  #data-connections .ingestion-agent-step:is([data-ingestion-state="pending"], [data-ingestion-state="running"]) + .ecosystem-matrix :is(.matrix-issue-dot, .matrix-issue-stem, .matrix-issue-card, .matrix-issue-end-dot),
  #data-connections .ecosystem-matrix[data-issue-state="waiting"] :is(.matrix-issue-dot, .matrix-issue-stem, .matrix-issue-card, .matrix-issue-end-dot) { opacity: 0; }
  #data-connections .ecosystem-matrix[data-issue-state="shown"] .matrix-issue-dot { animation: matrix-issue-dot-in .18s ease-out both; }
  #data-connections .ecosystem-matrix[data-issue-state="shown"] .matrix-issue-stem { animation: matrix-issue-stem-in .4s cubic-bezier(.22,.68,.26,1) .16s both; }
  #data-connections .ecosystem-matrix[data-issue-state="shown"] .matrix-issue-end-dot { animation: matrix-issue-end-dot-in .19s cubic-bezier(.22,.68,.26,1) .56s both, matrix-issue-end-dot-out .18s ease-in .75s forwards; }
  #data-connections .ecosystem-matrix[data-issue-state="shown"] .matrix-issue-card { animation: matrix-issue-card-in .46s cubic-bezier(.22,.68,.26,1) .75s both; }
}
@media print {
  #data-connections .ecosystem-matrix .matrix-issue-end-dot { display: none !important; }
  #data-connections .ecosystem-matrix :is(.matrix-issue-dot, .matrix-issue-stem, .matrix-issue-card, .matrix-issue-end-dot) {
    opacity: 1 !important;
    animation: none !important;
    transform: none !important;
    clip-path: none !important;
  }
}

/* Keep the insight in place while the phone terrain overlaps its lower edge.
   The existing measured reserve shortens the backing by the same amount. */
@media screen and (max-width: 540px) {
  #data-connections .ecosystem-matrix {
    --matrix-mobile-lift: clamp(48px, 14vw, 64px);
    --matrix-stem-height: calc(var(--matrix-pin-y) + 16px - var(--matrix-mobile-lift) + var(--matrix-card-half, 90px));
  }
}
