/* Import ReactFlow styles */
@import url("https://cdn.jsdelivr.net/npm/@xyflow/react@12.6.2/dist/style.css");

/* CSS Reset & Base */
*, *::before, *::after {
  box-sizing: border-box;
}

* {
  margin: 0;
}

/* Design System */
:root {
  /* Colors */
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-elevated: #334155;
  --bg-card: #475569;
  
  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  
  --accent-blue: #3b82f6;
  --accent-purple: #8b5cf6;
  --accent-green: #10b981;
  --accent-orange: #f59e0b;
  --accent-red: #ef4444;
  --accent-pink: #ec4899;
  
  --border: #475569;
  --border-light: #64748b;
  
  /* Effects */
  --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.3);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.4);
  --radius: 8px;
  --radius-lg: 12px;
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Base Styles */
html {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
}

body {
  background: linear-gradient(135deg, var(--bg-primary) 0%, #020617 100%);
  min-height: 100vh;
}

button {
  color: inherit;
  border: none;
  background: none;
  cursor: pointer;
  font-family: inherit;
}

/* Layout */
.editor-wrapper {
  width: 100vw;
  height: 100vh;
  background: var(--bg-primary);
}

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

.react-flow__background-pattern {
  color: var(--border);
  opacity: 0.5;
}

/* Node Base Styles */
.node-base {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  transition: var(--transition);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-weight: 500;
  box-shadow: var(--shadow);
}

.node-base:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
  border-color: var(--border-light);
}

.selected .node-base {
  border-color: var(--accent-blue);
  box-shadow: var(--shadow-lg), 0 0 0 2px rgba(59, 130, 246, 0.2);
}

/* Placeholder Nodes */
.placeholder-node {
  background: var(--bg-secondary);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 16px;
  color: var(--text-secondary);
  font-size: 13px;
  min-width: 120px;
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  transition: var(--transition);
}

.placeholder-node:hover {
  border-color: var(--accent-blue);
  color: var(--text-primary);
  background: var(--bg-elevated);
}

/* Trigger Nodes */
.trigger-node {
  background: linear-gradient(135deg, var(--accent-red), #dc2626);
  color: white;
  border-radius: 20px;
  min-width: 180px;
  height: 60px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.trigger-content {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
}

.trigger-icon {
  font-size: 18px;
}

.trigger-text {
  font-size: 13px;
  font-weight: 600;
}

/* Agent Nodes */
.agent-node {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  min-width: 140px;
  height: 80px;
  font-size: 14px;
  transition: var(--transition);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 16px;
}

.agent-node:hover {
  transform: translateY(-2px);
  border-color: var(--accent-blue);
}

/* LLM Nodes */
.llm-node {
  width: 60px;
  height: 60px;
  background: linear-gradient(135deg, var(--accent-purple), #7c3aed);
  border-radius: 50%;
  color: white;
  font-size: 12px;
  font-weight: 600;
  border: 2px solid rgba(255, 255, 255, 0.2);
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.llm-node:hover {
  transform: scale(1.05);
}

/* LLM handle */
.llm-node [data-handleid="agent"] {
  width: 18px;
  height: 18px;
  background: rgba(255, 255, 255, 0.9);
  border: 2px solid var(--accent-purple);
  border-radius: 50%;
  cursor: crosshair;
  box-shadow: 0 2px 6px rgba(139, 92, 246, 0.3);
}

.llm-node [data-handleid="agent"]:hover {
  background: white;
  box-shadow: 0 4px 10px rgba(139, 92, 246, 0.5);
}

/* MCP Nodes */
.mcp-node {
  width: 70px;
  height: 50px;
  background: linear-gradient(135deg, var(--accent-green), #059669);
  border-radius: 25px;
  color: white;
  font-size: 11px;
  font-weight: 600;
  border: 2px solid rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 8px;
}

.mcp-node:hover {
  transform: translateY(-1px);
}

/* MCP handle */
.mcp-node [data-handleid="agent"] {
  width: 16px;
  height: 16px;
  background: rgba(255, 255, 255, 0.9);
  border: 2px solid var(--accent-green);
  border-radius: 50%;
  cursor: crosshair;
  box-shadow: 0 2px 6px rgba(16, 185, 129, 0.3);
}

.mcp-node [data-handleid="agent"]:hover {
  background: white;
  box-shadow: 0 4px 10px rgba(16, 185, 129, 0.5);
}

/* Handles */
.our-handle {
  font-size: 10px;
  color: var(--text-secondary);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 4px;
  transition: var(--transition);
}

/* Enhanced handle styling for better UX */
.react-flow__handle {
  transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

/* Agent incoming handle */
.agent-node [data-handleid="incoming"] {
  width: 24px;
  height: 24px;
  background: rgba(59, 130, 246, 0.9);
  border: 2px solid white;
  border-radius: 50%;
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
  cursor: crosshair;
  position: absolute;
  left: -12px;
  top: 50%;
  transform: translateY(-50%);
}

.agent-node [data-handleid="incoming"]:hover {
  background: #2563eb;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.5);
}

/* Agent outgoing handle */
.agent-node [data-handleid="outgoing"] {
  width: 24px;
  height: 24px;
  background: rgba(255, 255, 255, 0.2);
  border: 2px solid white;
  border-radius: 50%;
  cursor: crosshair;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.15s ease, box-shadow 0.15s ease;
  right: -12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.agent-node [data-handleid="outgoing"]:hover {
  background: rgba(255, 255, 255, 0.35);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.agent-node [data-handleid="outgoing"]::after {
  content: '';
  width: 0;
  height: 0;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  border-left: 6px solid white;
  pointer-events: none;
}

/* Trigger outgoing handle */
.trigger-node [data-handleid="outgoing"] {
  width: 24px;
  height: 24px;
  background: rgba(255, 255, 255, 0.2);
  border: 2px solid white;
  border-radius: 50%;
  cursor: crosshair;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.15s ease, box-shadow 0.15s ease;
  right: -12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.trigger-node [data-handleid="outgoing"]:hover {
  background: rgba(255, 255, 255, 0.35);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.trigger-node [data-handleid="outgoing"]::after {
  content: '';
  width: 0;
  height: 0;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  border-left: 6px solid white;
  pointer-events: none;
}

/* Panels */
.react-flow__panel {
  background: rgba(30, 41, 59, 0.95);
  backdrop-filter: blur(10px);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  padding: 16px;
  color: var(--text-primary);
}

.react-flow__panel h3 {
  margin: 0 0 12px 0;
  font-size: 16px;
  font-weight: 600;
}

/* Buttons */
.btn {
  background: var(--accent-blue);
  border-radius: var(--radius);
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  color: white;
  border: none;
  cursor: pointer;
  transition: var(--transition);
  display: block;
  width: 100%;
  margin: 4px 0;
}

.btn:hover {
  background: #2563eb;
  transform: translateY(-1px);
}

.btn-danger {
  background: var(--accent-red);
}

.btn-danger:hover {
  background: #dc2626;
}

.trigger-palette {
  min-width: 200px;
}

.trigger-palette button {
  background: var(--accent-red);
}

.trigger-palette button:hover {
  background: #dc2626;
}

/* Node Selection UI */
.agent-selection, .mcp-selection {
  max-width: 400px;
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  padding: 20px;
  border: 1px solid var(--border);
}

.agent-selection h4, .mcp-selection h4 {
  margin: 0 0 16px 0;
  font-size: 16px;
  font-weight: 600;
}

.agent-buttons {
  display: grid;
  gap: 12px;
}

.agent-option, .mcp-option {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: var(--transition);
  text-align: left;
  width: 100%;
  margin-bottom: 8px;
}

.agent-option:hover, .mcp-option:hover {
  border-color: var(--accent-blue);
  background: var(--bg-card);
  transform: translateY(-1px);
}

.agent-option strong, .mcp-option strong {
  font-size: 14px;
  margin-bottom: 6px;
  display: block;
}

.agent-option small, .mcp-option small {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.4;
}

/* Agent option accent colors */
.agent-option.basic { border-left: 4px solid var(--text-muted); }
.agent-option.orchestrator { border-left: 4px solid var(--accent-blue); }
.agent-option.inspector { border-left: 4px solid var(--accent-green); }
.agent-option.crawler { border-left: 4px solid var(--accent-orange); }
.agent-option.greeter { border-left: 4px solid var(--accent-pink); }
.agent-option.collector { border-left: 4px solid var(--accent-purple); }
.agent-option.license { border-left: 4px solid var(--accent-orange); }
.agent-option.report { border-left: 4px solid var(--accent-green); }

.mcp-dropdown {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.mcp-category h5 {
  margin: 0 0 12px 0;
  font-size: 13px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
  font-weight: 600;
}

/* Node Toolbar */
.react-flow__node-toolbar {
  background: rgba(30, 41, 59, 0.95);
  backdrop-filter: blur(10px);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  padding: 16px;
  max-width: 450px;
  min-width: 350px;
}

.react-flow__node-toolbar > div {
  margin-bottom: 16px;
}

.react-flow__node-toolbar > div:last-child {
  margin-bottom: 0;
}

/* Form Elements */
.react-flow__node-toolbar label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 4px;
  display: block;
}

.react-flow__node-toolbar input[type="text"],
.react-flow__node-toolbar textarea {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  color: var(--text-primary);
  font-size: 13px;
  width: 100%;
  margin: 4px 0 0 0;
  transition: var(--transition);
  font-family: inherit;
}

/* Special styling for agent name input */
.react-flow__node-toolbar input[name="agentName"] {
  background: linear-gradient(135deg, var(--bg-card), var(--bg-elevated));
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  box-shadow: var(--shadow);
  transition: var(--transition);
}

.react-flow__node-toolbar input[name="agentName"]:focus {
  outline: none;
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2), var(--shadow);
  background: var(--bg-card);
  transform: translateY(-1px);
}

.react-flow__node-toolbar input[name="agentName"]::placeholder {
  color: var(--text-muted);
  font-weight: 400;
}

.react-flow__node-toolbar textarea {
  min-height: 80px;
  resize: vertical;
  padding: 12px;
  line-height: 1.4;
  /* Fix scrolling on canvas */
  overflow-y: auto;
  overscroll-behavior: contain;
}

.react-flow__node-toolbar input[type="text"]:focus,
.react-flow__node-toolbar textarea:focus {
  outline: none;
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.react-flow__node-toolbar button {
  background: var(--accent-red);
  border-radius: var(--radius);
  padding: 6px 12px;
  font-size: 12px;
  color: white;
  margin: 4px 4px 4px 0;
  display: inline-block;
  width: auto;
}

.react-flow__node-toolbar button:hover {
  background: #dc2626;
}

/* Checkboxes */
.checkbox-container {
  display: flex;
  align-items: center;
  margin: 12px 0;
  cursor: pointer;
}

input[type="checkbox"] {
  appearance: none;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-radius: 3px;
  background: var(--bg-elevated);
  cursor: pointer;
  position: relative;
  margin-right: 8px;
  flex-shrink: 0;
  transition: var(--transition);
}

input[type="checkbox"]:hover {
  border-color: var(--accent-blue);
}

input[type="checkbox"]:checked {
  background: var(--accent-blue);
  border-color: var(--accent-blue);
}

input[type="checkbox"]:checked::after {
  content: '✓';
  position: absolute;
  top: -2px;
  left: 1px;
  color: white;
  font-size: 12px;
  font-weight: bold;
}

.checkbox-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}

/* Routes List */
.routes-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.route-item {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.route-item input {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px 8px;
  color: var(--text-primary);
  font-size: 12px;
  flex: 1;
  min-width: 120px;
  margin: 0;
}

.route-item button {
  background: var(--accent-red);
  border-radius: 4px;
  padding: 4px 6px;
  font-size: 14px;
  margin: 0;
  flex-shrink: 0;
  width: auto;
}

/* Edges */
.react-flow__edge-path {
  stroke-width: 3;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border-light);
}