/* ============================================================
   FLOW DIAGRAM — staggered vertical process flow
   Reusable for all tabs. Desktop-first.
   ============================================================ */

/* ── Legend ─────────────────────────────────────────────────── */
.flow-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 28px;
  padding: 12px 18px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
}
.flow-legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  color: var(--text-muted);
}
.flow-legend-swatch {
  width: 28px; height: 14px;
  border-radius: 4px;
  flex-shrink: 0;
}
.flow-legend-swatch.ready {
  background: rgba(200,168,78,0.18);
  border: 1.5px solid rgba(200,168,78,0.5);
}
.flow-legend-swatch.optional {
  background: rgba(168,85,247,0.08);
  border: 1.5px dashed rgba(168,85,247,0.55);
}
.flow-legend-swatch.empty {
  background: rgba(255,255,255,0.03);
  border: 1.5px solid rgba(255,255,255,0.12);
  opacity: 0.6;
}

/* ── Stage summary block ─────────────────────────────────────── */
.stage-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
  margin-bottom: 32px;
}
.stage-summary-card {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
}
.stage-summary-card h5 {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin-bottom: 8px;
}
.stage-summary-card ul { display: flex; flex-direction: column; gap: 4px; }
.stage-summary-card li {
  font-size: 0.8rem;
  color: var(--text-muted);
  padding-left: 12px;
  position: relative;
}
.stage-summary-card li::before {
  content: '·';
  position: absolute;
  left: 0;
  color: var(--gold);
}
.stage-summary-card.highlight {
  border-color: rgba(200,168,78,0.22);
  background: rgba(200,168,78,0.04);
}
.stage-summary-card.highlight h5 { color: var(--gold); }
.stage-summary-card.not-target   { border-color: rgba(239,68,68,0.15); }
.stage-summary-card.not-target h5 { color: var(--red); }

/* ══════════════════════════════════════════════════════════════
   STAGGERED FLOW DIAGRAM
   Layout model:
     .flow-diagram          — outer wrapper, sets max-width
       .flow-track          — the main vertical column (left-aligned)
         .flow-step-row     — one row: [spine] [node] [branch?]
           .flow-spine      — fixed-width left column with line + arrow
           .flow-node       — the step card
           .flow-branch     — optional side branch (step 5, step 8)
   ══════════════════════════════════════════════════════════════ */

.flow-diagram {
  max-width: 720px;   /* keeps diagram readable, not full-width */
  position: relative;
}

/* ── Track: vertical stack of step rows ──────────────────────── */
.flow-track {
  display: flex;
  flex-direction: column;
  gap: 0;
}

/* ── Source chips row (top of diagram) ───────────────────────── */
.flow-sources {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 4px;
  padding-left: 40px;   /* align with node column */
}
.flow-source-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: 50px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}
.flow-source-chip .src-icon { font-size: 0.9rem; line-height: 1; }

/* Funnel line from sources down to step 1 */
.flow-sources-merge {
  display: flex;
  align-items: center;
  gap: 0;
  padding-left: 40px;
  height: 28px;
  position: relative;
}
.flow-sources-merge::before {
  content: '';
  position: absolute;
  left: 59px;           /* center of spine (40px offset + 19px = spine midpoint) */
  top: 0; bottom: 0;
  width: 2px;
  background: linear-gradient(to bottom, rgba(200,168,78,0.25), rgba(200,168,78,0.4));
}
.flow-sources-merge-label {
  position: relative;
  z-index: 1;
  margin-left: 68px;    /* push label right of the line */
  font-size: 0.63rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: var(--navy);
  padding: 1px 8px;
  border: 1px solid var(--glass-border);
  border-radius: 50px;
}

/* ── Step row ────────────────────────────────────────────────── */
.flow-step-row {
  display: grid;
  /* col 1: spine (fixed 40px) | col 2: node | col 3: branch (auto) */
  grid-template-columns: 40px 1fr auto;
  grid-template-rows: auto auto;   /* row 1: node+branch, row 2: connector */
  align-items: start;
  gap: 0;
}

/* ── Spine column ────────────────────────────────────────────── */
.flow-spine {
  grid-column: 1;
  grid-row: 1 / 3;      /* spans node row AND connector row */
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}

/* Vertical line running through the spine */
.flow-spine::before {
  content: '';
  position: absolute;
  top: 0; bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 2px;
  background: linear-gradient(
    to bottom,
    rgba(200,168,78,0.45) 0%,
    rgba(200,168,78,0.15) 100%
  );
}

/* Last step: line only goes halfway down (no arrow below) */
.flow-step-row:last-child .flow-spine::before {
  bottom: 50%;
}

/* Arrow head at bottom of each spine segment */
.flow-spine-arrow {
  position: absolute;
  bottom: -1px;
  left: 50%;
  transform: translateX(-50%);
  width: 0; height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 7px solid rgba(200,168,78,0.45);
  z-index: 1;
}
.flow-step-row:last-child .flow-spine-arrow { display: none; }

/* Step number bubble on the spine */
.flow-spine-num {
  position: relative;
  z-index: 2;
  margin-top: 14px;     /* vertically center with node top */
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--navy-card);
  border: 2px solid rgba(200,168,78,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Montserrat', sans-serif;
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--gold);
  flex-shrink: 0;
  transition: var(--transition);
}
/* Optional step: purple spine bubble */
.flow-step-row.is-optional .flow-spine-num {
  border-color: rgba(168,85,247,0.45);
  color: var(--purple);
}
/* Connector label sits below the bubble */
.flow-spine-label {
  position: relative;
  z-index: 2;
  margin-top: auto;
  margin-bottom: 4px;
  font-size: 0.6rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  text-align: center;
  padding: 0 2px;
  line-height: 1.3;
  max-width: 36px;
  word-break: break-word;
}

/* ── Node card ───────────────────────────────────────────────── */
.flow-node {
  grid-column: 2;
  grid-row: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin: 8px 0 0 8px;
  text-align: left;
  color: var(--text);
  font-family: 'Inter', sans-serif;
  transition: var(--transition);
  /* stagger: each step indented a bit more than the previous */
  margin-left: calc(8px + var(--step-indent, 0px));
}

/* Stagger levels — set via inline style or modifier classes */
.flow-node.indent-0 { margin-left: 8px; }
.flow-node.indent-1 { margin-left: 24px; }
.flow-node.indent-2 { margin-left: 40px; }
.flow-node.indent-3 { margin-left: 56px; }
.flow-node.indent-4 { margin-left: 72px; }
.flow-node.indent-5 { margin-left: 88px; }

/* ready */
.flow-node[data-state="ready"] {
  cursor: pointer;
  border-color: rgba(200,168,78,0.28);
  background: rgba(200,168,78,0.05);
}
.flow-node[data-state="ready"]:hover {
  background: rgba(200,168,78,0.1);
  border-color: rgba(200,168,78,0.55);
  box-shadow: 0 6px 20px rgba(200,168,78,0.1);
  transform: translateX(3px);
}
.flow-node[data-state="ready"]:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}
.flow-node[data-state="ready"]:hover .flow-spine-num { border-color: var(--gold); }

/* optional */
.flow-node[data-state="optional"] {
  cursor: pointer;
  border-style: dashed;
  border-color: rgba(168,85,247,0.4);
  background: rgba(168,85,247,0.05);
}
.flow-node[data-state="optional"]:hover {
  background: rgba(168,85,247,0.1);
  border-color: rgba(168,85,247,0.65);
  transform: translateX(3px);
}
.flow-node[data-state="optional"]:focus-visible {
  outline: 2px solid var(--purple);
  outline-offset: 2px;
}
/* "умовний" badge */
.flow-node[data-state="optional"]::before {
  content: 'якщо / умовний';
  position: absolute;
  top: -9px; left: 12px;
  background: var(--navy);
  padding: 0 7px;
  font-size: 0.6rem;
  font-weight: 700;
  color: var(--purple);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border: 1px solid rgba(168,85,247,0.35);
  border-radius: 50px;
}

/* empty */
.flow-node[data-state="empty"] {
  cursor: default;
  border-color: rgba(255,255,255,0.07);
  background: rgba(255,255,255,0.02);
  opacity: 0.5;
  pointer-events: none;
}
.flow-node[data-state="empty"]::before {
  content: 'не описано';
  position: absolute;
  top: -9px; left: 12px;
  background: var(--navy);
  padding: 0 7px;
  font-size: 0.6rem;
  font-weight: 700;
  color: var(--text-dim);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border: 1px solid var(--glass-border);
  border-radius: 50px;
}

/* ── Node internals ──────────────────────────────────────────── */
.node-title {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--white);
  line-height: 1.3;
  margin-bottom: 6px;
}
.flow-node[data-state="empty"] .node-title { color: var(--text-dim); }
.flow-node[data-state="optional"] .node-title { color: rgba(255,255,255,0.85); }

.node-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

/* ── Connector row (below each node, inside .flow-step-row) ──── */
.flow-connector-row {
  grid-column: 2 / 4;
  grid-row: 2;
  height: 32px;         /* space for the spine line to travel */
}

/* ── Branch: side node hanging off a main step ───────────────── */
.flow-branch {
  grid-column: 3;
  grid-row: 1;
  display: flex;
  align-items: flex-start;
  padding-top: 8px;
  padding-left: 12px;
  position: relative;
}

/* Dashed horizontal connector from main node to branch */
.flow-branch::before {
  content: '';
  position: absolute;
  left: 0;
  top: 28px;            /* vertically center with branch node top area */
  width: 12px;
  height: 2px;
  border-top: 2px dashed rgba(168,85,247,0.4);
}

/* Branch label above the branch node */
.flow-branch-label {
  position: absolute;
  top: -4px;
  left: 16px;
  font-size: 0.6rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

/* ── Downstream branch (step 8 below step 7) ─────────────────── */
.flow-downstream {
  display: flex;
  align-items: flex-start;
  padding-left: 40px;   /* align with node column */
  margin-top: 0;
  position: relative;
}
/* Elbow connector: vertical drop then horizontal to node */
.flow-downstream::before {
  content: '';
  position: absolute;
  left: 59px;           /* spine midpoint */
  top: 0;
  width: 2px;
  height: 24px;
  background: rgba(200,168,78,0.25);
}
.flow-downstream::after {
  content: '';
  position: absolute;
  left: 59px;
  top: 24px;
  width: 48px;
  height: 2px;
  background: rgba(200,168,78,0.25);
}
.flow-downstream-inner {
  margin-left: 56px;    /* 48px elbow + 8px gap */
  margin-top: 24px;
  position: relative;
}
/* "звітність" label on the elbow */
.flow-downstream-label {
  position: absolute;
  top: -18px;
  left: 0;
  font-size: 0.6rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 680px) {
  .flow-diagram { max-width: 100%; }

  /* Collapse stagger on mobile — all nodes flush */
  .flow-node.indent-0,
  .flow-node.indent-1,
  .flow-node.indent-2,
  .flow-node.indent-3,
  .flow-node.indent-4,
  .flow-node.indent-5 { margin-left: 8px; }

  /* Stack branch below main node */
  .flow-step-row {
    grid-template-columns: 40px 1fr;
    grid-template-rows: auto auto auto;
  }
  .flow-branch {
    grid-column: 2;
    grid-row: 3;
    padding-left: 8px;
    padding-top: 4px;
  }
  .flow-branch::before { display: none; }
  .flow-branch-label   { display: none; }
  .flow-connector-row  { grid-row: 2; }

  /* Downstream: stack vertically */
  .flow-downstream { padding-left: 40px; }
  .flow-downstream::after { display: none; }
  .flow-downstream-inner { margin-left: 8px; margin-top: 8px; }
  .flow-downstream-label { display: none; }

  /* Sources: wrap tightly */
  .flow-sources { padding-left: 40px; gap: 6px; }
  .flow-source-chip { font-size: 0.7rem; padding: 4px 10px; }

  .stage-summary { grid-template-columns: 1fr; }
}

/* ============================================================
   CLEAN STAGED FLOW v2
   Main path = vertical stack with arrows between blocks
   ============================================================ */

.flow-diagram {
  max-width: 1040px;
}

.flow-stage-stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.flow-stage-node {
  width: min(100%, 700px);
  margin: 0;
  padding: 16px 18px;
}

.flow-stage-main {
  width: min(100%, 560px);
}

.flow-stage-branch {
  width: 280px;
}

.flow-stage-secondary {
  width: 320px;
}

.flow-node-top {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.flow-node-badge {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-family: 'Montserrat', sans-serif;
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--gold);
  border: 2px solid rgba(200,168,78,0.36);
  background: rgba(200,168,78,0.08);
}

.flow-node[data-state="optional"] .flow-node-badge {
  color: var(--purple);
  border-color: rgba(168,85,247,0.42);
  background: rgba(168,85,247,0.1);
}

.flow-node[data-state="empty"] .flow-node-badge {
  color: var(--text-dim);
  border-color: rgba(255,255,255,0.14);
  background: rgba(255,255,255,0.04);
}

.node-snippet {
  font-size: 0.84rem;
  line-height: 1.45;
  color: var(--text-muted);
  font-style: italic;
  margin-bottom: 10px;
}

.flow-seq-arrow {
  width: min(100%, 700px);
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(200,168,78,0.8);
  font-size: 1.35rem;
  line-height: 1;
  position: relative;
  min-height: 18px;
}

.flow-seq-arrow::before {
  content: '';
  position: absolute;
  top: -4px;
  bottom: -4px;
  left: 50%;
  width: 2px;
  transform: translateX(-50%);
  background: linear-gradient(to bottom, rgba(200,168,78,0.2), rgba(200,168,78,0.55));
  z-index: 0;
}

.flow-seq-arrow span {
  position: relative;
  z-index: 1;
  background: var(--navy);
  padding: 0 6px;
}

.flow-branch-stage {
  display: flex;
  align-items: center;
  gap: 20px;
}

.flow-branch-side {
  display: flex;
  align-items: center;
  gap: 10px;
  position: relative;
  padding-top: 14px;
}

.flow-branch-side-label {
  position: absolute;
  top: -2px;
  left: 46px;
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}

.flow-branch-side-line {
  width: 38px;
  border-top: 2px dashed rgba(168,85,247,0.55);
  flex-shrink: 0;
}

.flow-report-stage {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding-left: 86px;
  margin-top: 2px;
}

.flow-report-connector {
  position: relative;
  width: 220px;
  height: 42px;
  flex-shrink: 0;
}

.flow-report-connector::before {
  content: '';
  position: absolute;
  left: 8px;
  top: 0;
  width: 2px;
  height: 22px;
  background: rgba(200,168,78,0.3);
}

.flow-report-connector::after {
  content: '';
  position: absolute;
  left: 8px;
  top: 22px;
  width: 210px;
  height: 2px;
  background: rgba(200,168,78,0.3);
}

.flow-report-label {
  position: absolute;
  top: 8px;
  left: 16px;
  transform: none;
  background: var(--navy);
  padding: 0 6px;
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  white-space: nowrap;
}

@media (max-width: 900px) {
  .flow-branch-stage {
    flex-direction: column;
    align-items: stretch;
  }

  .flow-branch-side {
    padding-top: 0;
    margin-left: 34px;
  }

  .flow-branch-side-label {
    position: static;
    margin-right: 4px;
  }

  .flow-stage-main,
  .flow-stage-branch,
  .flow-stage-secondary,
  .flow-stage-node,
  .flow-seq-arrow {
    width: 100%;
  }
}

@media (max-width: 680px) {
  .flow-stage-stack {
    gap: 12px;
  }

  .flow-node-top {
    align-items: flex-start;
  }

  .flow-branch-side {
    flex-direction: column;
    align-items: stretch;
    margin-left: 18px;
    gap: 8px;
  }

  .flow-branch-side-line {
    width: 2px;
    height: 18px;
    border-top: 0;
    border-left: 2px dashed rgba(168,85,247,0.55);
    margin-left: 14px;
  }

  .flow-report-stage {
    padding-left: 18px;
    flex-direction: column;
    gap: 8px;
  }

  .flow-report-connector {
    width: 2px;
    height: 18px;
    margin-left: 14px;
  }

  .flow-report-connector::before {
    left: 0;
    height: 18px;
  }

  .flow-report-connector::after,
  .flow-report-label {
    display: none;
  }
}
