/* ================================================================
   Constructor UX — calm palette, card layout, port alignment
   ================================================================ */

/* === Drawflow node: replace acid cyan with clean white card === */
.drawflow .drawflow-node {
  box-sizing: border-box;
  background: #ffffff;
  border: 1.5px solid #d0d5dd;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.09);
  width: 280px;
  min-width: 200px;
  min-height: 100px;
  /* !important перебивает padding:15px из drawflow.min.css при одинаковой специфичности */
  padding: 0 !important;
  color: #333;
  align-items: flex-start;
}

/* Гарантируем, что обёртка контента занимает всю ширину ноды —
   иначе .df-node-card уже ноды и порты висят правее карточки. */
.drawflow .drawflow-node .drawflow_content_node {
  width: 100%;
  display: block;
  margin: 0;
  padding: 0;
}

.drawflow .drawflow-node.selected {
  background: #ffffff;
  border-color: #1a73e8;
  box-shadow: 0 0 0 3px rgba(26, 115, 232, 0.18),
              0 2px 8px rgba(0, 0, 0, 0.09);
}

/* Visual highlight for the current start node */
.drawflow .drawflow-node.is-start-node {
  border-color: #1565c0;
  border-width: 2px;
  box-shadow: 0 0 0 3px rgba(21, 101, 192, 0.22),
              0 2px 8px rgba(0, 0, 0, 0.10);
}

/* === Port containers: switch to absolute so JS can position each port
     individually. Right/left=0, full height → same coordinate origin as
     the node itself, so offsetTop values from btn-answer-row transfer
     directly to output top values.                                    === */
.drawflow .drawflow-node .outputs {
  position: absolute !important;
  right: 0;
  top: 0;
  height: 100%;
  width: 0;
  display: block;
}

.drawflow .drawflow-node .inputs {
  position: absolute !important;
  left: 0;
  top: 0;
  height: 100%;
  width: 0;
  display: block;
}

/* === Output dots: absolute within .outputs, JS sets top per-row === */
.drawflow .drawflow-node .output {
  position: absolute !important;
  right: -8px;
  top: 50%;                     /* default; overridden by syncPortPositions */
  width: 14px;
  height: 14px;
  background: #1a73e8;
  border: 2px solid #ffffff;
  border-radius: 50%;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.28);
  margin-bottom: 0;
  transform: translateY(-50%);
  cursor: crosshair;
  z-index: 1;
}

/* === Input dot: centered on left edge === */
.drawflow .drawflow-node .input {
  position: absolute !important;
  left: -8px;
  top: 50%;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  background: #43a047;
  border: 2px solid #ffffff;
  border-radius: 50%;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.28);
  margin-bottom: 0;
  cursor: crosshair;
  z-index: 1;
}

/* === Connection lines: calm steel blue === */
.drawflow .connection .main-path {
  stroke: #90a4ae;
  stroke-width: 2.5px;
}
.drawflow .connection .main-path:hover  { stroke: #1a73e8; }
.drawflow .connection .main-path.selected { stroke: #1a73e8; }

/* Drawflow canvas background */
#drawflow { background: #f0f2f5; }

/* === Card content === */
.df-node-card {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 14px 12px;
  font-size: 12px;
  font-family: inherit;
  min-width: unset;
}

/* Node header: id label + start/set-start button in one row */
.df-node-card .node-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 6px;
  padding-bottom: 6px;
  border-bottom: 1px solid #e8eaed;
}

.df-node-card .node-id {
  font-size: 11px;
  font-weight: 600;
  color: #5f6368;
  overflow-wrap: anywhere;
  word-break: break-all;
  min-width: 0;
}

.start-badge {
  display: inline-block;
  background: #1565c0;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
  letter-spacing: 0.4px;
  white-space: nowrap;
  flex-shrink: 0;
  margin-bottom: 0;
}

.btn-set-start {
  font-size: 10px;
  padding: 2px 8px;
  background: #607d8b;
  border-radius: 10px;
  white-space: nowrap;
  flex-shrink: 0;
  margin-bottom: 0;
}
.btn-set-start:hover { background: #455a64; }

/* Section dividers inside the card */
.df-node-card .section-label {
  font-size: 10px;
  font-weight: 600;
  color: #9e9e9e;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 6px 0 3px;
}

/* Textarea: auto-grows by content via JS (_initNodeTextarea); overflow:hidden
   hides the scrollbar during height recalculation; no resize handle on the
   textarea itself (card resize ↘ remains separate and is unaffected). */
.df-node-card textarea {
  width: 100% !important;
  box-sizing: border-box !important;
  resize: none;
  border: 1px solid #d0d5dd;
  border-radius: 4px;
  padding: 5px 7px;
  font-size: 12px;
  font-family: inherit;
  line-height: 1.45;
  min-height: 58px;
  overflow-y: hidden;
  overflow-wrap: anywhere;
  word-break: break-word;
  white-space: pre-wrap;
  color: #333;
  background: #f8faff;
}
.df-node-card textarea:focus {
  outline: none;
  border-color: #1a73e8;
  background: #fff;
  box-shadow: 0 0 0 2px rgba(26, 115, 232, 0.14);
}

/* Button answer rows */
.df-node-card .btn-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 4px;
}

/* Each answer row — fixed min-height so port midpoint is predictable */
.df-node-card .btn-answer-row {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 28px;
  width: 100%;
  box-sizing: border-box;
}

.df-node-card .btn-answer-row input {
  flex: 1;
  min-width: 0;
  width: 100%;
  box-sizing: border-box !important;
  border: 1px solid #d0d5dd;
  border-radius: 4px;
  padding: 4px 6px;
  font-size: 11px;
  font-family: inherit;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.df-node-card .btn-answer-row input:focus {
  outline: none;
  border-color: #1a73e8;
  box-shadow: 0 0 0 2px rgba(26, 115, 232, 0.12);
}

.df-node-card .btn-rm-btn {
  flex-shrink: 0;
  background: #e53935;
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 3px 7px;
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
}
.df-node-card .btn-rm-btn:hover { background: #c62828; }

.df-node-card .btn-add-btn {
  width: 100%;
  box-sizing: border-box;
  text-align: center;
  font-size: 11px;
  padding: 4px 8px;
  margin-top: 6px;
  background: #388e3c;
  border-radius: 4px;
}
.df-node-card .btn-add-btn:hover { background: #2e7d32; }

/* === Drag-and-drop reorder handles === */
.df-node-card .drag-handle {
  flex-shrink: 0;
  cursor: grab;
  color: #bdbdbd;
  font-size: 13px;
  line-height: 1;
  padding: 0 3px 0 0;
  user-select: none;
  touch-action: none;
}
.df-node-card .drag-handle:hover { color: #757575; }
.df-node-card .btn-answer-row.row-dragging { opacity: 0.35; }
.df-node-card .btn-answer-row.row-drag-over {
  outline: 2px dashed #1a73e8;
  outline-offset: 1px;
  border-radius: 4px;
}

/* === Toolbar (sticky) === */
#constructor-toolbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: #fff;
  border-bottom: 2px solid #e0e0e0;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.07);
  padding: 8px 12px !important;
  gap: 8px;
  flex-shrink: 0;
}

#inp-script-title {
  flex: 1;
  border: 1px solid #d0d5dd !important;
  border-radius: 4px;
  padding: 6px 10px !important;
  font-size: 13px;
  font-family: inherit;
}

#btn-add-node { background: #388e3c; padding: 6px 14px; font-size: 13px; }
#btn-add-node:hover { background: #2e7d32; }
#btn-save { background: #1a73e8; padding: 6px 18px; font-weight: 600; font-size: 13px; }
#btn-save:hover { background: #1557b0; }
#btn-back { background: #607d8b; padding: 6px 12px; font-size: 13px; }
#btn-back:hover { background: #455a64; }

/* === Hint panel (steps instruction) === */
#constructor-hint {
  background: #fffde7;
  border-bottom: 1px solid #f0c030;
  padding: 7px 14px;
  font-size: 11px;
  color: #5d4037;
  flex-shrink: 0;
  line-height: 1.8;
}

#constructor-hint .hint-step {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #f9a825;
  color: #fff;
  border-radius: 50%;
  width: 16px;
  height: 16px;
  font-size: 10px;
  font-weight: 700;
  margin: 0 2px;
  vertical-align: middle;
}

/* === Node resize handle: positioned absolute within .drawflow-node === */
.df-node-card .resize-handle {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 16px;
  height: 16px;
  cursor: nwse-resize;
  z-index: 2;
  background: linear-gradient(135deg, transparent 50%, #b0bec5 50%);
  border-radius: 0 0 7px 0;
  opacity: 0.55;
}
.df-node-card .resize-handle:hover { opacity: 1; }
