.modal.flow-modal {
  width: min(1480px, 98vw);
  height: min(920px, 94vh);
  max-height: 94vh;
  background: #f7f9fc;
}

.flow-modal .modal-body {
  min-height: 0;
  padding: 0;
  overflow: hidden;
}

#flowViewerRoot {
  height: 100%;
  min-height: 420px;
  display: flex;
  flex-direction: column;
}

.flow-viewer-loading,
.flow-viewer-error {
  min-height: 420px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 10px;
  padding: 32px;
  text-align: center;
  color: #334155;
}

.flow-viewer-loading small,
.flow-viewer-error p {
  max-width: 620px;
  color: #64748b;
  line-height: 1.55;
}

.flow-loading-ring {
  width: 32px;
  height: 32px;
  border: 3px solid #dbe4ef;
  border-top-color: #0f766e;
  border-radius: 50%;
  animation: flow-spin 0.8s linear infinite;
}

@keyframes flow-spin { to { transform: rotate(360deg); } }

.flow-error-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: #fee2e2;
  color: #b91c1c;
  font-size: 22px;
  font-weight: 800;
}

.flow-viewer-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 16px;
  border-bottom: 1px solid #dfe7f0;
  background: rgb(255 255 255 / 0.92);
}

.flow-run-header,
.flow-toolbar-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 14px;
  color: #64748b;
  font-size: 11px;
}

.flow-run-header strong { color: #0f172a; }

.flow-count-strip {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 16px;
  border-bottom: 1px solid #dfe7f0;
  background: #f8fafc;
}

.flow-lightweight-note {
  padding: 8px 16px;
  border-bottom: 1px solid #fde68a;
  background: #fffbeb;
  color: #854d0e;
  font-size: 11px;
  line-height: 1.45;
}

.flow-summary-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 9px;
  border: 1px solid #d7e0ea;
  border-radius: 999px;
  background: #f1f5f9;
  color: #475569;
  font-size: 10.5px;
  font-weight: 700;
}

.flow-summary-pill.status-success { border-color: #bbf7d0; background: #ecfdf3; color: #15803d; }
.flow-summary-pill.status-running { border-color: #fde68a; background: #fffbeb; color: #a16207; }
.flow-summary-pill.status-error { border-color: #fecaca; background: #fff1f2; color: #b91c1c; }

.flow-viewer-workspace {
  min-height: 0;
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  overflow: hidden;
  background:
    radial-gradient(circle at 1px 1px, rgb(148 163 184 / 0.2) 1px, transparent 1.5px) 0 0 / 22px 22px,
    linear-gradient(145deg, #f8fafc, #eef4f8);
}

.flow-canvas-scroll {
  min-width: 0;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  box-sizing: border-box;
  overflow: auto;
  padding: 18px;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-color: #a8b5c4 transparent;
  scrollbar-width: thin;
}

.flow-graph-shell { position: relative; }

.flow-graph {
  position: absolute;
  inset: 0 auto auto 0;
  transform-origin: top left;
}

.flow-edges {
  position: absolute;
  inset: 0;
  overflow: visible;
  pointer-events: none;
}

.flow-edge {
  fill: none;
  stroke: #cbd5e1;
  stroke-width: 3;
  opacity: 0.72;
}

.flow-edge.status-success { stroke: #4ade80; }
.flow-edge.status-running { stroke: #f59e0b; stroke-dasharray: 9 7; }
.flow-edge.status-error { stroke: #ef4444; }
.flow-edge.status-skipped { stroke: #cbd5e1; stroke-dasharray: 5 7; }

.flow-arrow { fill: #cbd5e1; }
.flow-arrow.status-success { fill: #22c55e; }
.flow-arrow.status-running { fill: #f59e0b; }
.flow-arrow.status-error { fill: #ef4444; }

.flow-node {
  position: absolute;
  width: 228px;
  height: 88px;
  padding: 11px 13px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  overflow: hidden;
  border: 1px solid #cbd5e1;
  border-left-width: 5px;
  border-radius: 14px;
  background: rgb(255 255 255 / 0.97);
  box-shadow: 0 8px 22px rgb(15 23 42 / 0.09);
  color: #0f172a;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

.flow-node:hover,
.flow-node.selected {
  transform: translateY(-2px);
  box-shadow: 0 13px 30px rgb(15 23 42 / 0.15);
}

.flow-node.selected { outline: 3px solid rgb(15 118 110 / 0.16); }
.flow-node.status-success { border-left-color: #22c55e; }
.flow-node.status-running { border-left-color: #f59e0b; background: #fffbeb; }
.flow-node.status-error { border-left-color: #ef4444; background: #fff7f7; }
.flow-node.status-skipped { border-left-color: #94a3b8; opacity: 0.76; }
.flow-node.technical { border-style: dashed; }

.flow-node-head {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.flow-node-type {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #64748b;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.flow-technical-tag {
  margin-left: auto;
  padding: 2px 6px;
  border-radius: 999px;
  background: #eef2f7;
  color: #64748b;
  font-size: 8.5px;
  font-weight: 700;
}

.flow-node > strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  line-height: 1.3;
}

.flow-node-meta { color: #64748b; font-size: 10.5px; }

.flow-node-detail {
  min-width: 0;
  overflow: auto;
  padding: 20px;
  border-left: 1px solid #dfe7f0;
  background: rgb(255 255 255 / 0.96);
}

.flow-detail-kicker {
  color: #0f766e;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.flow-node-detail h3 {
  margin: 7px 0 10px;
  color: #0f172a;
  font-size: 16px;
  line-height: 1.35;
}

.flow-detail-grid {
  display: grid;
  gap: 0;
  margin: 18px 0;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  overflow: hidden;
}

.flow-detail-grid > div {
  display: grid;
  grid-template-columns: 100px minmax(0, 1fr);
  gap: 10px;
  padding: 9px 11px;
  border-bottom: 1px solid #edf2f7;
  font-size: 11px;
}

.flow-detail-grid > div:last-child { border-bottom: 0; }
.flow-detail-grid dt { color: #64748b; }
.flow-detail-grid dd { margin: 0; color: #0f172a; font-weight: 600; word-break: break-word; }

.flow-detail-note {
  padding: 12px;
  border-radius: 12px;
  background: #f0fdfa;
  color: #47635f;
  font-size: 11px;
  line-height: 1.55;
}

.flow-error-detail {
  padding: 13px;
  border: 1px solid #fecaca;
  border-radius: 12px;
  background: #fff7f7;
  color: #7f1d1d;
  font-size: 11px;
  line-height: 1.55;
}

.flow-error-detail p { margin: 8px 0 0; }
.flow-error-detail details { margin-top: 10px; }
.flow-error-detail summary { cursor: pointer; font-weight: 700; }
.flow-error-detail pre { max-height: 260px; overflow: auto; white-space: pre-wrap; word-break: break-word; font-size: 10px; }

.modal.flow-node-detail-modal {
  width: min(620px, 94vw);
}

.flow-node-detail-modal .modal-body {
  padding: 18px;
}

@media (max-width: 900px) {
  .modal.flow-modal { width: 100vw; height: 100vh; max-height: 100vh; }
  .flow-viewer-toolbar { align-items: flex-start; flex-direction: column; }
  .flow-viewer-workspace { display: block; overflow: hidden; }
  .flow-node-detail { display: none; }
  .flow-run-header { width: 100%; gap: 6px 10px; }
  .flow-run-header span { flex: 1 1 140px; }
  .flow-count-strip { padding: 9px 12px; }
  .flow-canvas-scroll {
    height: 100%;
    max-height: 100%;
    padding: 10px 10px calc(24px + env(safe-area-inset-bottom));
  }
  .flow-node {
    padding: 8px 9px;
    border-radius: 11px;
    border-left-width: 4px;
    gap: 4px;
  }
  .flow-node > strong {
    font-size: 10.5px;
    line-height: 1.25;
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }
  .flow-node-type { font-size: 8.5px; }
  .flow-node-meta { font-size: 9px; }
  .message-actions { gap: 8px 12px; }
  .bubble-footer .compact-note { width: 100%; margin-left: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .flow-loading-ring { animation-duration: 1.6s; }
  .flow-node, .message-action-btn { transition: none; }
}
