/* Workflow Editor Styles (Phase 5) */

/* ── Editor Layout ────────────────────────────────────────────────────────── */

.workflow-editor {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 60px);
  background: var(--bg);
}

.workflow-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.workflow-content {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Sidebar (Node Palette) ─────────────────────────────────────────────── */

.workflow-sidebar {
  width: 220px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px;
  overflow-y: auto;
}

.sidebar-section {
  margin-bottom: 24px;
}

.sidebar-section h3 {
  margin: 0 0 12px 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text2);
  text-transform: uppercase;
}

.node-palette {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.node-palette-button {
  padding: 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text1);
  transition: all 0.2s;
}

.node-palette-button:hover {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
  transform: translateY(-1px);
}

.node-palette-button .icon {
  font-size: 20px;
}

/* ── Canvas ──────────────────────────────────────────────────────────────── */

.workflow-canvas-container {
  flex: 1;
  position: relative;
  background: var(--bg);
}

/* React Flow Overrides */
.react-flow {
  background: var(--bg);
}

.react-flow__node {
  border-radius: 8px;
}

.react-flow__node.selected {
  box-shadow: 0 0 0 3px rgba(29, 158, 117, 0.3);
}

.react-flow__edge-path {
  stroke: var(--text3);
  stroke-width: 2;
}

.react-flow__edge.selected .react-flow__edge-path {
  stroke: var(--accent);
  stroke-width: 3;
}

.react-flow__handle {
  width: 10px;
  height: 10px;
  border: 2px solid white;
}

.react-flow__handle-connecting {
  background: var(--accent) !important;
}

.react-flow__handle-valid {
  background: #4CAF50 !important;
}

/* ── Custom Nodes ────────────────────────────────────────────────────────── */

.workflow-node {
  min-width: 180px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  font-family: inherit;
  transition: all 0.2s;
}

.workflow-node:hover {
  box-shadow: 0 4px 8px rgba(0,0,0,0.15);
  transform: translateY(-1px);
}

.workflow-node.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(29, 158, 117, 0.2);
}

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

.node-icon {
  font-size: 20px;
  line-height: 1;
}

.node-label {
  font-weight: 600;
  font-size: 14px;
  color: var(--text1);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.node-body {
  font-size: 12px;
  color: var(--text2);
}

/* Start Node */
.workflow-node.start-node {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border-color: #667eea;
  text-align: center;
}

.workflow-node.start-node .node-label,
.workflow-node.start-node .node-body {
  color: white;
}

/* End Node */
.workflow-node.end-node {
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
  color: white;
  border-color: #f093fb;
  text-align: center;
}

.workflow-node.end-node .node-label,
.workflow-node.end-node .node-body {
  color: white;
}

/* Analysis Node */
.workflow-node.analysis-node {
  background: var(--surface2);
  border-color: var(--accent);
}

.workflow-node.analysis-node .prompt-name {
  font-weight: 500;
  color: var(--text1);
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.workflow-node.analysis-node .questions-indicator {
  font-size: 11px;
  color: var(--accent);
  padding: 4px 8px;
  background: rgba(29, 158, 117, 0.1);
  border-radius: 4px;
  display: inline-block;
  margin-top: 4px;
}

/* Logic Node */
.workflow-node.logic-node {
  background: #FFF3CD;
  border-color: #FFC107;
}

.workflow-node.logic-node .condition-summary {
  padding: 6px 8px;
  background: rgba(255, 193, 7, 0.2);
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
}

.workflow-node.logic-node .condition-summary.has-condition {
  color: #856404;
}

.workflow-node.logic-node .condition-summary.no-condition {
  color: #6c757d;
  font-style: italic;
}

/* Join Node */
.workflow-node.join-node {
  background: #D1ECF1;
  border-color: #17A2B8;
}

.workflow-node.join-node .node-body {
  font-size: 11px;
}

.workflow-node.join-node .strategy,
.workflow-node.join-node .skip-handling {
  margin-bottom: 4px;
}

.workflow-node.join-node strong {
  color: #0c5460;
}

/* ── Config Panel ────────────────────────────────────────────────────────── */

.workflow-config-panel {
  width: 520px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  padding: 16px;
  overflow-y: auto;
}

.config-section {
  margin-bottom: 24px;
}

.config-section h3 {
  margin: 0 0 12px 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text1);
}

.config-section label {
  display: block;
  margin-bottom: 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text2);
}

.config-section input,
.config-section select,
.config-section textarea {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  margin-bottom: 8px;
  font-family: inherit;
  font-size: 14px;
  background: var(--bg);
  color: var(--text1);
}

.config-section textarea {
  resize: vertical;
  min-height: 60px;
}

/* ── Question Editor ─────────────────────────────────────────────────────── */

.question-editor {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 12px;
}

.question-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.question-header span {
  font-weight: 600;
  font-size: 14px;
  color: var(--text1);
}

.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 18px;
  padding: 4px;
  opacity: 0.7;
  transition: opacity 0.2s;
}

.btn-icon:hover {
  opacity: 1;
}

/* ── Logic Expression Editor ─────────────────────────────────────────────── */

.logic-root {
  margin-bottom: 16px;
}

.logic-operands {
  margin-top: 12px;
}

.condition-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px;
  margin-bottom: 8px;
}

.condition-simple {
  display: flex;
  gap: 8px;
  align-items: center;
}

.condition-simple select,
.condition-simple input {
  flex: 1;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 12px;
}

.condition-group {
  border-left: 3px solid var(--accent);
  padding-left: 12px;
  margin-bottom: 8px;
}

.group-header {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.logic-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

/* ── Validation Panel ────────────────────────────────────────────────────── */

.validation-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  max-height: 200px;
  overflow-y: auto;
  z-index: 1000;
}

.validation-error {
  color: var(--danger);
  margin-bottom: 4px;
  font-size: 14px;
  cursor: pointer;
}

.validation-error:hover {
  text-decoration: underline;
}

.validation-warning {
  color: #FFC107;
  margin-bottom: 4px;
  font-size: 14px;
  cursor: pointer;
}

.validation-warning:hover {
  text-decoration: underline;
}

.validation-success {
  color: #4CAF50;
  font-size: 14px;
  font-weight: 600;
}

/* ── Responsive ──────────────────────────────────────────────────────────── */

@media (max-width: 1200px) {
  .workflow-sidebar {
    width: 200px;
  }

  .workflow-config-panel {
    width: 450px;
  }
}

@media (max-width: 900px) {
  .workflow-content {
    flex-direction: column;
  }

  .workflow-sidebar,
  .workflow-config-panel {
    width: 100%;
    border: none;
    border-bottom: 1px solid var(--border);
  }
}
