/* Shared GTM diagram system. Used by /gtm-systems and the homepage preview. */

.nav-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--white-dim);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  padding: 8px 12px;
  cursor: pointer;
}

.nav-toggle:hover,
.nav.is-open .nav-toggle { color: var(--green); border-color: var(--green); }

@media (max-width: 860px) {
  .nav-toggle { display: inline-flex; }
  .nav.is-open .nav-links {
    display: flex;
    flex-direction: column;
    gap: 0;
    position: absolute;
    top: calc(100% - 10px);
    right: 16px;
    min-width: 220px;
    padding: 8px 0;
    background: var(--surface);
    border: 1px solid var(--border);
    z-index: 2;
  }
  .nav.is-open .nav-link {
    padding: 12px 16px;
  }
}

.cap-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--green);
}

.cap-link:hover { color: var(--white); }

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

.status-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  margin-top: 16px;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--white-dim);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 1.5px solid var(--green);
  flex: none;
}

.status-live .status-dot { background: var(--green); }
.status-manual .status-dot { background: transparent; }
.status-dev .status-dot {
  background: transparent;
  border-style: dashed;
  border-radius: 1px;
}

.status-legend {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 28px 32px;
  margin: 8px 0 56px;
}

.status-legend li {
  min-width: 0;
  border-top: 1px solid var(--border);
  padding-top: 16px;
  color: var(--gray);
  font-size: 14px;
  line-height: 1.6;
}

.status-legend .status { margin-bottom: 10px; }

.stage-map { position: relative; }

.stage-list {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 18px 20px;
  position: relative;
  z-index: 1;
}

.stage-item { min-width: 0; }

.stage-btn {
  display: block;
  width: 100%;
  padding: 0 8px 12px 0;
  border: 0;
  background: transparent;
  color: var(--white);
  text-align: left;
  cursor: pointer;
}

.stage-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  display: block;
  margin-bottom: 14px;
  box-shadow: 0 0 0 5px var(--black);
  position: relative;
  z-index: 1;
}

.stage-item.is-planned .stage-dot {
  background: transparent;
  border: 1.5px dashed var(--green);
}

.stage-kicker {
  display: block;
  margin-bottom: 8px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--green);
}

.stage-item.is-planned .stage-kicker { color: var(--white-dim); }

.stage-name {
  display: block;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(18px, 1.8vw, 26px);
  letter-spacing: -0.04em;
  line-height: 0.95;
  text-transform: uppercase;
}

.stage-tease {
  display: block;
  margin-top: 10px;
  color: var(--gray);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 300;
  line-height: 1.5;
  letter-spacing: 0;
  text-transform: none;
}

.stage-btn[aria-expanded="true"] .stage-name { color: var(--green); }

.stage-panel {
  margin: 4px 12px 0 0;
  padding-top: 12px;
  border-top: 1px solid var(--green);
  color: var(--white-dim);
  font-size: 14px;
  line-height: 1.65;
}

.stage-item.is-planned .stage-panel { border-top-style: dashed; }

.js .node-detail,
.js .stage-panel { display: none; }

.js .node-detail.is-open,
.js .stage-panel.is-open { display: block; }

.system { padding: 64px 0; border-top: 1px solid var(--border); }
.system:first-of-type { border-top: 0; padding-top: 8px; }

.system-name {
  display: block;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(22px, 2.2vw, 32px);
  letter-spacing: -0.045em;
  line-height: 0.92;
  text-transform: uppercase;
}

.system-index {
  display: block;
  margin-bottom: 10px;
  font-size: clamp(28px, 3vw, 42px);
  line-height: 0.8;
  letter-spacing: -0.06em;
  color: rgba(237, 235, 230, 0.14);
  -webkit-text-stroke: 1px rgba(237, 235, 230, 0.5);
}

.system-problem {
  margin-top: 18px;
  max-width: 62ch;
  color: var(--gray);
  font-size: 16px;
  line-height: 1.65;
}

.flow { margin-top: 36px; }

.flow-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 18px 28px;
  margin-bottom: 18px;
}

.flow-note {
  max-width: 68ch;
  color: var(--gray);
  font-size: 14px;
  line-height: 1.6;
}

.replay {
  flex: none;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--white-dim);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  padding: 10px 14px;
  cursor: pointer;
}

.replay:hover,
.replay[aria-pressed="true"] { border-color: var(--green); color: var(--green); }

.flow-canvas {
  position: relative;
  padding-left: 8px;
}

.flow.has-loop .flow-canvas { padding: 26px 8px 30px 28px; }

.flow-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
  z-index: 0;
}

.flow-grid {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 48px 28px;
  min-width: 0;
}

.flow-grid[data-cols="3"] {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 36px 28px;
}

.flow-cell { min-width: 0; max-width: 100%; }
.flow-cell[data-col="1"] { grid-column: 1; }
.flow-cell[data-col="2"] { grid-column: 2; }
.flow-cell[data-col="3"] { grid-column: 3; }
.flow-cell[data-col="4"] { grid-column: 4; }
.flow-cell[data-row="1"] { grid-row: 1; }
.flow-cell[data-row="2"] { grid-row: 2; }
.flow-cell[data-row="3"] { grid-row: 3; }
.flow-cell[data-row="4"] { grid-row: 4; }
.flow-cell[data-row="5"] { grid-row: 5; }
.flow-cell[data-row="6"] { grid-row: 6; }
.flow-cell[data-row="7"] { grid-row: 7; }
.flow-cell[data-row="8"] { grid-row: 8; }
.flow-cell[data-row="9"] { grid-row: 9; }
.flow-cell[data-span="3"] { grid-column: 1 / -1; }

.flow-cell[data-span="3"] > .node {
  max-width: 520px;
  margin-left: auto;
  margin-right: auto;
}

.node {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  width: 100%;
  min-height: 96px;
  padding: 14px 16px 16px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--white);
  text-align: left;
  cursor: pointer;
  position: relative;
  z-index: 1;
  transition: border-color 0.25s ease, background 0.25s ease;
}

.node:hover,
.node:focus-visible,
.node[aria-expanded="true"],
.node.is-hot {
  border-color: var(--green);
  background: var(--surface-2);
}

.node-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--white-dim);
}

.node-idx { color: var(--green); }

.node-label {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
  line-height: 1.2;
  letter-spacing: -0.02em;
  overflow-wrap: break-word;
}

.node-via {
  display: block;
  margin-top: 2px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--green);
}

.node-human { border-color: rgba(0, 230, 97, 0.6); }
.node-human .node-kind { color: var(--green); }

.node-decision .node-kind::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 6px;
  border: 1px solid var(--green);
  transform: rotate(45deg);
  vertical-align: 0;
}

.node-exception {
  background: transparent;
  border-style: dashed;
  border-color: #8f8a81;
  min-height: 0;
}

.node-priority { border-color: var(--green); box-shadow: inset 3px 0 0 var(--green); }

.node-planned {
  background: transparent;
  border-style: dashed;
  border-color: rgba(0, 230, 97, 0.65);
  min-height: 0;
}

.node-hub {
  border-color: var(--green);
  box-shadow: inset 0 0 0 1px rgba(0, 230, 97, 0.28);
  min-height: 120px;
}

.node-end { border-color: rgba(237, 235, 230, 0.35); }

.node-detail {
  width: 100%;
  margin-top: 4px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  color: var(--gray);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 300;
  line-height: 1.6;
  letter-spacing: 0;
  text-transform: none;
}

.branch {
  margin-top: 8px;
  margin-left: 16px;
  padding-left: 12px;
  border-left: 1px dashed #8f8a81;
}

.branch[data-kind="priority"] {
  border-left-style: solid;
  border-left-color: var(--green);
}

.branch[data-kind="planned"] {
  border-left-color: rgba(0, 230, 97, 0.7);
}

.via {
  margin: 10px 0 6px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--white-dim);
}

.loop-tag {
  margin-top: 10px;
  color: var(--white-dim);
  font-size: 12px;
  line-height: 1.5;
}

.loop-tag span {
  display: block;
  margin-bottom: 4px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--green);
}

.guardrails {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px 22px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  max-width: 920px;
  margin-left: auto;
  margin-right: auto;
}

.guardrails li {
  min-width: 0;
  color: var(--white-dim);
  font-size: 13px;
  line-height: 1.45;
}

.guardrails span {
  display: block;
  margin-bottom: 6px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--green);
}

.edge {
  fill: none;
  stroke: rgba(0, 230, 97, 0.55);
  stroke-width: 1.35;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.edge-main,
.edge-spoke,
.edge-loop {
  stroke-dasharray: 4 8;
  animation: edgeFlow 16s linear infinite;
}

.edge-planned {
  stroke: rgba(0, 230, 97, 0.45);
  stroke-dasharray: 2 7;
}

.edge-exception { stroke: #8f8a81; stroke-dasharray: 2 6; }

.edge.is-lit,
.edge.is-hot {
  stroke: var(--green);
  stroke-width: 2;
}

@keyframes edgeFlow {
  to { stroke-dashoffset: -240; }
}

.why { margin-top: 32px; max-width: 46rem; }

.why .section-label { margin-bottom: 12px; }

.why p {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(16px, 1.5vw, 20px);
  line-height: 1.2;
  letter-spacing: -0.03em;
  color: var(--white);
}

.planned-section {
  border-top: 1px dashed rgba(0, 230, 97, 0.4);
  border-bottom: 1px dashed rgba(0, 230, 97, 0.4);
  background: repeating-linear-gradient(
    -45deg,
    transparent,
    transparent 11px,
    rgba(0, 230, 97, 0.018) 11px,
    rgba(0, 230, 97, 0.018) 12px
  );
}

.planned-banner {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 22px;
  padding-bottom: 12px;
  border-bottom: 1px dashed rgba(0, 230, 97, 0.45);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--green);
}

.metrics {
  list-style: none;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 48px 72px;
}

.metric-value {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(28px, 3vw, 40px);
  letter-spacing: -0.05em;
  line-height: 0.88;
  text-transform: uppercase;
}

.metric-label {
  margin-top: 12px;
  max-width: 36ch;
  color: var(--gray);
  font-size: 15px;
  line-height: 1.55;
}

.metric-note {
  margin-top: 48px;
  max-width: 68ch;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  color: var(--white-dim);
  font-size: 15px;
  line-height: 1.65;
}

.selected-systems { border-top: 1px solid var(--border); }

.selected-systems,
.sysprev-item,
.sysprev-name,
.flow,
.flow-canvas,
.stage-map,
.metrics,
.guardrails,
.status-legend {
  min-width: 0;
  max-width: 100%;
}

.sysprev-lead {
  margin-top: 18px;
  max-width: 62ch;
  color: var(--gray);
  font-size: 16px;
  font-weight: 300;
  line-height: 1.7;
}

.sysprev-item {
  padding: 42px 0;
  border-top: 1px solid var(--border-light);
}

.sysprev-kicker {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 10px 18px;
  align-items: center;
  margin-bottom: 8px;
}

.sysprev-name {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(20px, 2vw, 26px);
  letter-spacing: -0.04em;
  text-transform: uppercase;
  line-height: 0.95;
}

.sysprev-problem {
  max-width: 62ch;
  margin: 12px 0 8px;
  color: var(--gray);
  font-size: 15px;
}

.sysprev-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 18px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--green);
}

.sysprev-link:hover { color: var(--white); }

.sysprev-all {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 14px;
  color: var(--white);
}

.sysprev-all:hover { color: var(--green); }

.flow-compact { margin-top: 20px; }
.flow-compact .node { min-height: 0; padding: 12px 12px 14px; }
.flow-compact .node-label { font-size: 14px; }
.flow-compact .flow-grid { gap: 36px 18px; }

.text-link {
  color: var(--green);
  border-bottom: 1px solid rgba(0, 230, 97, 0.35);
}

.text-link:hover { color: var(--white); }

@media (max-width: 959px) {
  .status-legend,
  .stage-list,
  .guardrails,
  .metrics { grid-template-columns: 1fr 1fr; }

  .stage-list { grid-template-columns: 1fr; gap: 8px; }

  .stage-btn {
    display: grid;
    grid-template-columns: 16px 1fr;
    column-gap: 14px;
    align-items: start;
    padding: 14px 0;
    border-top: 1px solid var(--border);
  }

  .stage-item.is-planned .stage-btn { border-top-style: dashed; }
  .stage-dot { grid-row: 1 / span 4; margin: 6px 0 0; }
  .stage-panel { grid-column: 2; margin: 0; }

  .flow-canvas { padding: 4px 0 4px 22px; }
  .flow.has-loop .flow-canvas { padding: 22px 0 26px 22px; }

  .flow-grid,
  .flow-grid[data-cols="3"] {
    display: flex;
    flex-direction: column;
    gap: 0;
  }

  .flow-cell {
    width: 100%;
    grid-column: auto;
    grid-row: auto;
  }

  .flow-cell + .flow-cell { margin-top: 22px; }

  .flow-cell[data-span="3"] > .node,
  .guardrails { max-width: none; margin-left: 0; margin-right: 0; }

  .flow.is-drawn .flow-cell + .flow-cell { margin-top: 26px; }
}

@media (max-width: 640px) {
  .status-legend,
  .guardrails,
  .metrics { grid-template-columns: 1fr; }
  .flow-toolbar { flex-direction: column; align-items: flex-start; }
  .metrics { gap: 32px; }
  .system-name { font-size: clamp(22px, 6vw, 28px); }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }

  .ticker-track,
  .nav-dot,
  .scroll-line,
  .marquee-row[data-dir="left"] .marquee-track,
  .marquee-row[data-dir="right"] .marquee-track,
  .net-path,
  .edge,
  .edge-main,
  .edge-spoke,
  .edge-loop {
    animation: none !important;
  }

  .edge-main,
  .edge-spoke,
  .edge-loop { stroke-dasharray: none !important; }

  .hero-title,
  .hero-meta,
  .scroll-cue {
    animation: none !important;
    opacity: 1 !important;
    transform: none !important;
  }

  .reveal { transition: none; }

  .node,
  .replay,
  .cta-link,
  .nav-link,
  .stage-btn,
  .cap-link { transition: none; }

  .cta-link::before,
  .nav-link::after { transition: none; }
}

@media (forced-colors: active) {
  .node,
  .replay,
  .stage-btn { border: 1px solid ButtonText; }
  .node[aria-expanded="true"],
  .node:focus-visible { border-color: Highlight; }
  .edge { stroke: ButtonText; }
}
