/* Flow diagram component. Reads only tokens: --fg, --bg, --muted, --line, --sans.
   Vertical by default; goes horizontal when its container is wide (expanded card, desktop pages). */
.flow { container-type: inline-size; width: 100%; font-family: var(--sans); color: var(--fg); }

.flow-steps {
  list-style: none;
  display: grid;
  gap: 22px;
}
.flow-step {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 0.8fr);
  gap: 22px;
  align-items: center;
}
.flow-node {
  display: grid;
  grid-template-columns: 2em 1fr;
  column-gap: 6px;
  padding: 8px 12px;
  border: 1px solid var(--fg);
  background: var(--bg);
  font-size: 0.8125rem;
  line-height: 1.35;
}
.flow-k { grid-row: span 2; color: var(--muted); font-variant-numeric: tabular-nums; }
.flow-label { font-weight: 600; }
.flow-note { color: var(--muted); }

/* main-line arrow: a line plus a head, both in --fg */
.flow-step:not(:last-child) .flow-node { position: relative; }
.flow-step:not(:last-child) .flow-node::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 100%;
  width: 1px;
  height: 22px;
  background: var(--fg);
}
.flow-step:not(:last-child) .flow-node::before {
  content: "";
  position: absolute;
  left: calc(50% - 4px);
  top: calc(100% + 15px);
  border: 4px solid transparent;
  border-top: 6px solid var(--fg);
  border-bottom: 0;
}

/* side branch: dashed, muted, joined by a dashed stub */
.flow-side {
  grid-column: 2;
  position: relative;
  padding: 6px 10px;
  border: 1px dashed var(--muted);
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.35;
}
.flow-side::before {
  content: "";
  position: absolute;
  right: 100%;
  top: 50%;
  width: 22px;
  border-top: 1px dashed var(--muted);
}
.flow-step:not(:has(.flow-side)) .flow-node { grid-column: 1; }

@container (min-width: 900px) {
  .flow-steps { grid-template-columns: repeat(var(--n, 6), minmax(0, 1fr)); gap: 26px; align-items: start; }
  .flow-step { grid-template-columns: 1fr; grid-template-rows: auto auto; gap: 22px; }
  .flow-side { grid-column: 1; }
  .flow-side::before { right: auto; left: 50%; top: auto; bottom: 100%; width: 0; height: 22px; border-top: 0; border-left: 1px dashed var(--muted); }
  .flow-step:not(:last-child) .flow-node::after { left: 100%; top: 50%; width: 26px; height: 1px; }
  .flow-step:not(:last-child) .flow-node::before { left: calc(100% + 19px); top: calc(50% - 4px); border: 4px solid transparent; border-left: 6px solid var(--fg); border-right: 0; }
}

/* narrow: one spine on the left, branches indented off it */
@container (max-width: 560px) {
  .flow-steps { gap: 18px; isolation: isolate; }
  .flow-step { grid-template-columns: 1fr; gap: 8px; }
  .flow-node { position: relative; z-index: 1; }
  .flow-side { grid-column: 1; margin-left: 44px; }
  .flow-side::before { width: 24px; }
  .flow-step:not(:last-child) .flow-node::after,
  .flow-step:not(:last-child) .flow-node::before { content: none; }
  .flow-step:not(:last-child)::after {
    content: "";
    position: absolute;
    left: 20px;
    top: 0;
    bottom: -18px;
    width: 1px;
    background: var(--fg);
    z-index: 0;
  }
  .flow-step:not(:first-child) .flow-node::before {
    content: "";
    position: absolute;
    left: 16px;
    top: -7px;
    border: 4px solid transparent;
    border-top: 6px solid var(--fg);
    border-bottom: 0;
  }
}
