/* Flow Canvas - Infinite Board */
.flow-canvas-wrapper {
  position: relative;
  width: 100%;
  height: 700px;
  background: #0f111a;
  /* Darker background */
  background-image:
    radial-gradient(circle at 1px 1px, rgba(255, 255, 255, 0.05) 1px, transparent 0);
  background-size: 20px 20px;
  border-radius: 12px;
  border: 1px solid var(--border-glass);
  overflow: hidden;
  user-select: none;
  cursor: grab;
}

.flow-canvas-wrapper:active {
  cursor: grabbing;
}

/* Transform Layer (Pan/Zoom) */
.flow-transform-layer {
  transform-origin: 0 0;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  /* Let clicks pass to nodes? No, nodes need pointer events */
}

/* Nodes */
.flow-node {
  position: absolute;
  width: 280px;
  background: rgba(30, 30, 40, 0.9);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  color: white;
  cursor: default;
  pointer-events: auto;
  transition: box-shadow 0.2s, border-color 0.2s;
  display: flex;
  flex-direction: column;
  overflow: visible;
}

.flow-node:hover {
  border-color: rgba(255, 255, 255, 0.3);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.6);
}

.flow-node.selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(168, 85, 247, 0.3);
}

.node-header {
  background: rgba(255, 255, 255, 0.05);
  padding: 12px 15px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 12px 12px 0 0;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: grab;
}

.node-header:active {
  cursor: grabbing;
}

.node-icon {
  width: 28px;
  height: 28px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}

.node-title {
  font-weight: 600;
  font-size: 0.9rem;
  flex: 1;
}

.node-body {
  padding: 15px;
  font-size: 0.8rem;
  color: var(--text-muted);
  min-height: 40px;
}

/* Ports / Handles */
.node-ports {
  display: flex;
  flex-direction: column;
  width: 100%;
  padding-bottom: 10px;
}

.node-port-out {
  position: relative;
  padding: 6px 15px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-primary);
  transition: background 0.2s;
}

.node-port-out:hover {
  background: rgba(255, 255, 255, 0.05);
}

/* Output Handle (Right) */
.port-handle {
  width: 12px;
  height: 12px;
  background: #60a5fa;
  border: 2px solid #1e1e28;
  border-radius: 50%;
  position: absolute;
  right: -6px;
  top: 50%;
  transform: translateY(-50%);
  box-shadow: 0 0 0 2px rgba(69, 137, 245, 0.3);
  cursor: crosshair;
  z-index: 10;
}

.port-handle:hover {
  background: #ffffff;
  transform: translateY(-50%) scale(1.2);
}

/* Input Handle (Left) */
.node-handle-in {
  position: absolute;
  left: -6px;
  top: 26px;
  width: 12px;
  height: 12px;
  background: #a855f7;
  border: 2px solid #1e1e28;
  border-radius: 50%;
  z-index: 10;
  box-shadow: 0 0 0 2px rgba(168, 85, 247, 0.3);
}

/* Special Types */
.flow-node.type-system .node-header {
  background: linear-gradient(90deg, rgba(234, 179, 8, 0.1), transparent);
  border-color: rgba(234, 179, 8, 0.2);
}

.flow-node.type-welcome .node-header {
  background: linear-gradient(90deg, rgba(168, 85, 247, 0.1), transparent);
}

/* SVG Connection Layer */
.connections-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  /* Paths will have auto pointer-events */
  z-index: 0;
  /* Below nodes */
}

.connection-path {
  fill: none;
  stroke: #4b5563;
  stroke-width: 2px;
  transition: stroke 0.2s;
  pointer-events: stroke;
  /* Only click the visible stroke */
  cursor: pointer;
}

.connection-path:hover {
  stroke: var(--primary);
  stroke-width: 4px;
}

.connection-path.selected {
  stroke: #ef4444;
  /* Red to indicate selection/danger */
  stroke-width: 3px;
  stroke-dasharray: 5;
  animation: dash 1s linear infinite;
}

.connection-temp {
  fill: none;
  stroke: #60a5fa;
  stroke-width: 2px;
  stroke-dasharray: 5;
  pointer-events: none;
}

@keyframes dash {
  to {
    stroke-dashoffset: -10;
  }
}

/* Floating Controls */
.canvas-controls {
  position: absolute;
  bottom: 20px;
  left: 20px;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(5px);
  border-radius: 8px;
  display: flex;
  gap: 5px;
  padding: 5px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Side Editor Panel */
.flow-side-panel {
  position: absolute;
  top: 20px;
  right: 20px;
  bottom: 20px;
  width: 350px;
  background: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border-glass);
  border-radius: 12px;
  transform: translateX(110%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: -10px 0 30px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  z-index: 100;
}

.flow-side-panel.open {
  transform: translateX(0);
}

.panel-header {
  padding: 20px;
  border-bottom: 1px solid var(--border-glass);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  font-size: 1.1rem;
}

.panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}