/* FSM visual editor (admin) */
.fsm-editor-wrap {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 220px);
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg-surface, #fff);
  --fsm-side-px: 420px;
}

.fsm-editor-toolbar {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-color, #e5e7eb);
  background: var(--bg-main, #f9fafb);
}

.fsm-editor-toolbar label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.875rem;
  cursor: pointer;
}

.fsm-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 8px var(--fsm-side-px, 420px);
  flex: 1;
  min-height: 420px;
  min-width: 0;
}

.fsm-editor-resizer {
  cursor: col-resize;
  background: transparent;
  flex-shrink: 0;
  z-index: 3;
}

.fsm-editor-resizer:hover {
  background: rgba(100, 116, 139, 0.35);
}

.fsm-workspace-wrap {
  position: relative;
  overflow: auto;
  background: #f0f2f5;
  background-image: radial-gradient(circle, #d1d5db 1px, transparent 1px);
  background-size: 20px 20px;
  min-height: 320px;
  min-width: 0;
}

.fsm-workspace {
  position: relative;
  width: 2400px;
  height: 1600px;
  z-index: 0;
}

.fsm-workspace .fsm-connections-svg {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
  overflow: visible;
}

.fsm-editor-wrap.fsm-side-max .fsm-workspace-wrap {
  opacity: 0.4;
  pointer-events: none;
}

.fsm-editor-wrap.fsm-side-max .fsm-editor-resizer {
  display: none;
}

.fsm-editor-wrap.fsm-side-max .fsm-side-panel {
  position: fixed;
  left: 0.75rem;
  right: 0.75rem;
  top: 5.25rem;
  bottom: 0.75rem;
  width: auto !important;
  max-width: none !important;
  height: auto !important;
  max-height: none !important;
  z-index: 10040;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.18);
  border-radius: 10px;
  border: 1px solid var(--border-color, #e5e7eb);
}

.fsm-editor-wrap.fsm-side-collapsed .fsm-body {
  grid-template-columns: 1fr !important;
}

.fsm-editor-wrap.fsm-side-collapsed .fsm-editor-resizer,
.fsm-editor-wrap.fsm-side-collapsed .fsm-side-panel {
  display: none !important;
}

.fsm-panel-reopen {
  display: none;
  position: fixed;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  z-index: 10030;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  padding: 0.75rem 0.4rem;
  border-radius: 8px 0 0 8px;
  box-shadow: -2px 2px 12px rgba(0, 0, 0, 0.12);
  max-height: 180px;
}

.fsm-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 10050;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 2rem 1rem;
  overflow: auto;
}

.fsm-modal-panel {
  background: var(--bg-surface, #fff);
  border-radius: 10px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
  max-width: 920px;
  width: 100%;
  padding: 1.25rem 1.5rem;
  margin-bottom: 2rem;
}

.fsm-modal-panel.fsm-help-modal {
  max-width: 720px;
}

.fsm-modal-panel.fsm-apis-modal,
.fsm-modal-panel.fsm-snippets-modal {
  max-width: 960px;
}

.fsm-modal-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color, #e5e7eb);
}

.fsm-modal-scroll {
  max-height: 50vh;
  overflow: auto;
  margin-bottom: 0.5rem;
}

.fsm-intents-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

.fsm-intents-table th,
.fsm-intents-table td {
  border: 1px solid var(--border-color, #e5e7eb);
  padding: 0.35rem 0.5rem;
  vertical-align: middle;
}

.fsm-intent-route-card {
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: 8px;
  padding: 0.65rem 0.75rem;
  margin-bottom: 0.5rem;
  background: #fafafa;
}

.fsm-intent-route-head {
  margin-bottom: 0.35rem;
  font-size: 0.8rem;
}

.fsm-apis-split {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  min-height: 280px;
}

.fsm-apis-nav {
  width: 200px;
  flex-shrink: 0;
}

.fsm-apis-form-host {
  flex: 1;
  min-width: 0;
}

.fsm-node {
  position: absolute;
  min-width: 300px;
  max-width: 480px;
  min-height: 160px;
  background: var(--bg-surface, #fff);
  border: 2px solid var(--border-color, #e5e7eb);
  border-radius: 8px;
  box-shadow: var(--shadow-sm, 0 1px 2px rgba(0, 0, 0, 0.06));
  cursor: default;
  user-select: none;
  z-index: 2;
}

.fsm-node.selected {
  border-color: #111827;
  box-shadow: 0 0 0 3px rgba(17, 24, 39, 0.12);
}

.fsm-node-header {
  padding: 0.5rem 0.65rem;
  font-size: 0.8125rem;
  font-weight: 600;
  background: var(--bg-main, #f9fafb);
  border-radius: 6px 6px 0 0;
  border-bottom: 1px solid var(--border-color, #e5e7eb);
  cursor: grab;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.35rem;
}

.fsm-node-header:active {
  cursor: grabbing;
}

.fsm-node-id {
  font-size: 0.65rem;
  font-weight: 500;
  color: var(--text-muted, #9ca3af);
  font-family: ui-monospace, monospace;
}

.fsm-node-cycle {
  font-size: 0.62rem;
  color: #4f46e5;
  font-weight: 600;
  margin: 0.15rem 0 0.1rem;
  line-height: 1.25;
}

.fsm-node-body {
  padding: 0.5rem 0.65rem 0.65rem;
  font-size: 0.75rem;
  color: var(--text-secondary, #4b5563);
}

.fsm-node-purpose {
  font-size: 0.68rem;
  color: #4b5563;
  line-height: 1.35;
  margin: 0.2rem 0 0.35rem;
  font-style: italic;
}

.fsm-node-pipeline-wrap {
  margin: 0.35rem 0 0.45rem;
  padding: 0.4rem 0.35rem;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
}

.fsm-node-pipeline-label {
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #64748b;
  margin-bottom: 0.35rem;
}

.fsm-node-pipeline {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 0.25rem 0.15rem;
  line-height: 1.2;
}

.fsm-node-flow-arrow {
  color: #94a3b8;
  font-size: 0.65rem;
  font-weight: 600;
  padding: 0.15rem 0.05rem 0;
  flex-shrink: 0;
}

.fsm-node-pill {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  max-width: 140px;
  padding: 0.2rem 0.35rem 0.25rem;
  border-radius: 5px;
  border: 1px solid #e5e7eb;
  background: #fff;
  font-size: 0.62rem;
  line-height: 1.25;
}

.fsm-node-pill-k {
  font-weight: 700;
  color: #0f172a;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  font-size: 0.58rem;
}

.fsm-node-pill-d {
  color: #475569;
  word-break: break-word;
  margin-top: 0.08rem;
  font-size: 0.6rem;
}

.fsm-node-pill--tts {
  border-color: #7dd3fc;
  background: #f0f9ff;
}
.fsm-node-pill--audio {
  border-color: #a5b4fc;
  background: #eef2ff;
}
.fsm-node-pill--stt {
  border-color: #86efac;
  background: #f0fdf4;
}
.fsm-node-pill--api {
  border-color: #fcd34d;
  background: #fffbeb;
}
.fsm-node-pill--script {
  border-color: #c4b5fd;
  background: #f5f3ff;
}
.fsm-node-pill--ia {
  border-color: #fb923c;
  background: #fff7ed;
}
.fsm-node-pill--out {
  border-color: #94a3b8;
  background: #f1f5f9;
}
.fsm-node-pill--skip {
  border-color: #d1d5db;
  background: #f9fafb;
  color: #6b7280;
}

.fsm-node-preview-label {
  font-size: 0.6rem;
  font-weight: 600;
  color: #64748b;
  margin-top: 0.25rem;
}

.fsm-node-preview {
  font-size: 0.68rem;
  color: #6b7280;
  margin-top: 0.15rem;
  line-height: 1.35;
  max-height: 4.2em;
  overflow: hidden;
  word-break: break-word;
}

.fsm-side-panel {
  border-left: 1px solid var(--border-color, #e5e7eb);
  display: flex;
  flex-direction: column;
  background: var(--bg-surface, #fff);
  min-width: 0;
  max-height: none;
}

.fsm-side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border-color, #e5e7eb);
  flex-shrink: 0;
}

.fsm-side-head h4 {
  font-size: 0.875rem;
  font-weight: 600;
  margin: 0;
  flex: 1;
  min-width: 0;
}

.fsm-side-head-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  justify-content: flex-end;
}

.fsm-side-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  min-height: 200px;
}

.fsm-flow-strip {
  flex-shrink: 0;
  border-top: 1px solid var(--border-color, #e5e7eb);
  padding: 0.75rem 1rem;
  background: var(--bg-surface, #fff);
}

.fsm-flow-strip h4 {
  margin: 0 0 0.5rem 0;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted, #9ca3af);
}

.fsm-flow-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  min-height: 2.5rem;
  align-items: center;
}

.fsm-flow-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.65rem;
  background: var(--bg-main, #f3f4f6);
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: 6px;
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: grab;
}

.fsm-flow-chip.sortable-ghost {
  opacity: 0.4;
}

.fsm-flow-chip .fsm-chip-remove {
  cursor: pointer;
  color: var(--danger, #dc2626);
  font-weight: 700;
  padding: 0 0.15rem;
  border: none;
  background: none;
  line-height: 1;
}

.fsm-step-card {
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: 6px;
  padding: 0.65rem;
  margin-bottom: 0.65rem;
  background: var(--bg-main, #f9fafb);
  font-size: 0.8125rem;
}

.fsm-step-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.fsm-muted {
  font-size: 0.75rem;
  color: var(--text-muted, #9ca3af);
  margin-top: 0.35rem;
  line-height: 1.4;
}

/* Panel lateral: fases colapsables (colores alineados con pastillas del lienzo) */
.fsm-phase-section {
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: 10px;
  margin-bottom: 0.65rem;
  background: var(--bg-surface, #fff);
  overflow: hidden;
}
.fsm-phase-summary {
  list-style: none;
  cursor: pointer;
  padding: 0.5rem 0.65rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  align-items: flex-start;
}
.fsm-phase-summary::-webkit-details-marker {
  display: none;
}
.fsm-phase-summary-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  width: 100%;
}
.fsm-phase-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.fsm-phase--preopen .fsm-phase-dot {
  background: #c4b5fd;
}
.fsm-phase--tts .fsm-phase-dot {
  background: #7dd3fc;
}
.fsm-phase--stt .fsm-phase-dot {
  background: #86efac;
}
.fsm-phase--preai .fsm-phase-dot {
  background: #fcd34d;
}
.fsm-phase--ia .fsm-phase-dot {
  background: #fb923c;
}
.fsm-phase--postai .fsm-phase-dot {
  background: #fcd34d;
}
.fsm-phase--route .fsm-phase-dot {
  background: #3053d1;
}
.fsm-phase--outcome .fsm-phase-dot {
  background: #94a3b8;
}
.fsm-phase-title {
  font-size: 0.82rem;
}
.fsm-phase-hint {
  font-size: 0.68rem;
  color: #64748b;
  font-weight: 400;
  line-height: 1.35;
  padding-left: calc(8px + 0.4rem);
}
.fsm-phase-body {
  padding: 0 0.65rem 0.65rem;
  border-top: 1px solid #f1f5f9;
}
.fsm-phase-section[open] > .fsm-phase-summary {
  background: rgba(255, 255, 255, 0.55);
}

/* Fondo tenue por fase (todo el bloque) */
.fsm-phase-section.fsm-phase--preopen {
  background: rgba(196, 181, 253, 0.09);
  border-color: rgba(167, 139, 250, 0.35);
}
.fsm-phase-section.fsm-phase--tts {
  background: rgba(125, 211, 252, 0.1);
  border-color: rgba(56, 189, 248, 0.35);
}
.fsm-phase-section.fsm-phase--stt {
  background: rgba(134, 239, 172, 0.1);
  border-color: rgba(74, 222, 128, 0.35);
}
.fsm-phase-section.fsm-phase--preai {
  background: rgba(252, 211, 77, 0.1);
  border-color: rgba(251, 191, 36, 0.4);
}
.fsm-phase-section.fsm-phase--ia {
  background: rgba(251, 146, 60, 0.1);
  border-color: rgba(249, 115, 22, 0.35);
}
.fsm-phase-section.fsm-phase--postai {
  background: rgba(252, 211, 77, 0.08);
  border-color: rgba(251, 191, 36, 0.32);
}
.fsm-phase-section.fsm-phase--route {
  background: rgba(48, 83, 209, 0.06);
  border-color: rgba(48, 83, 209, 0.28);
}
.fsm-phase-section.fsm-phase--outcome {
  background: rgba(148, 163, 184, 0.12);
  border-color: rgba(100, 116, 139, 0.35);
}

.fsm-phase-global-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  margin: 0.5rem 0 0.75rem;
  padding: 0.45rem 0.55rem;
  background: var(--bg-main, #f3f4f6);
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: 8px;
}
.fsm-phase-global-tools-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted, #64748b);
  margin-right: 0.25rem;
}

.fsm-var-hint-strip {
  font-size: 0.62rem;
  line-height: 1.45;
  color: #475569;
  margin: 0 0 0.5rem;
  padding: 0.35rem 0.45rem;
  background: rgba(255, 255, 255, 0.65);
  border-radius: 6px;
  border: 1px dashed rgba(100, 116, 139, 0.35);
  cursor: help;
}
.fsm-var-hint-strip code {
  font-size: 0.58rem;
  background: rgba(241, 245, 249, 0.95);
  padding: 0.05rem 0.2rem;
  border-radius: 3px;
}
.fsm-var-hint-label {
  font-weight: 700;
  color: #64748b;
  margin-right: 0.25rem;
}

.fsm-var-insert-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0.25rem;
}

@media (max-width: 1024px) {
  .fsm-body {
    grid-template-columns: 1fr;
  }

  .fsm-editor-resizer {
    display: none;
  }

  .fsm-side-panel {
    border-left: none;
    border-top: 1px solid var(--border-color, #e5e7eb);
    max-height: 55vh;
  }
}
