/* rSocials Campaign Workflow — n8n-style workflow builder */
folk-campaign-workflow {
	display: block;
	height: 100%;
}

.cw-root {
	display: flex;
	flex-direction: column;
	height: 100%;
	font-family: system-ui, -apple-system, sans-serif;
	color: var(--rs-text-primary, #e2e8f0);
}

/* ── Toolbar ── */
.cw-toolbar {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 10px 20px;
	min-height: 46px;
	border-bottom: 1px solid var(--rs-border, #2d2d44);
	background: var(--rs-bg-surface, #1a1a2e);
	z-index: 10;
	flex-shrink: 0;
}

.cw-toolbar__title {
	font-size: 15px;
	font-weight: 600;
	flex: 1;
	display: flex;
	align-items: center;
	gap: 8px;
}

.cw-toolbar__title input {
	background: transparent;
	border: 1px solid transparent;
	color: var(--rs-text-primary, #e2e8f0);
	font-size: 15px;
	font-weight: 600;
	padding: 2px 6px;
	border-radius: 4px;
	width: 200px;
}

.cw-toolbar__title input:hover,
.cw-toolbar__title input:focus {
	border-color: var(--rs-border-strong, #3d3d5c);
	outline: none;
}

.cw-toolbar__actions {
	display: flex;
	gap: 6px;
	align-items: center;
}

.cw-btn {
	padding: 6px 12px;
	border-radius: 8px;
	border: 1px solid var(--rs-input-border, #3d3d5c);
	background: var(--rs-input-bg, #16162a);
	color: var(--rs-text-primary, #e2e8f0);
	font-size: 12px;
	cursor: pointer;
	transition: border-color 0.15s, background 0.15s;
	white-space: nowrap;
}

.cw-btn:hover {
	border-color: var(--rs-border-strong, #4d4d6c);
}

.cw-btn--back {
	text-decoration: none;
	color: var(--rs-primary-hover, #6366f1);
	border-color: var(--rs-border, rgba(59,130,246,0.27));
	display: inline-flex;
	align-items: center;
	gap: 4px;
}
.cw-btn--back:hover {
	background: var(--rs-bg-active, rgba(59,130,246,0.13));
	border-color: var(--rs-primary, #4f46e5);
}

.cw-btn--run {
	background: var(--rs-bg-active, rgba(59,130,246,0.13));
	border-color: var(--rs-border, rgba(59,130,246,0.33));
	color: var(--rs-primary-hover, #6366f1);
}

.cw-btn--run:hover {
	background: var(--rs-bg-active, rgba(59,130,246,0.2));
	border-color: var(--rs-primary, #4f46e5);
}

.cw-toggle {
	display: flex;
	align-items: center;
	gap: 6px;
	font-size: 12px;
	color: var(--rs-text-muted, #94a3b8);
}

.cw-toggle input[type="checkbox"] {
	accent-color: #10b981;
}

.cw-save-indicator {
	font-size: 11px;
	color: var(--rs-text-muted, #64748b);
}

/* ── Canvas area ── */
.cw-canvas-area {
	flex: 1;
	display: flex;
	overflow: hidden;
	position: relative;
	min-height: 0;
}

/* ── Left sidebar — node palette ── */
.cw-palette {
	width: 200px;
	min-width: 200px;
	border-right: 1px solid var(--rs-border, #2d2d44);
	background: var(--rs-bg-surface, #1a1a2e);
	overflow-y: auto;
	padding: 12px;
	display: flex;
	flex-direction: column;
	gap: 16px;
}

.cw-palette__group-title {
	font-size: 10px;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.05em;
	color: var(--rs-text-muted, #94a3b8);
	margin-bottom: 4px;
}

.cw-palette__card {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 8px 10px;
	border-radius: 8px;
	border: 1px solid var(--rs-border, #2d2d44);
	background: var(--rs-input-bg, #16162a);
	cursor: grab;
	font-size: 12px;
	transition: border-color 0.15s, background 0.15s;
	margin-bottom: 4px;
}

.cw-palette__card:hover {
	border-color: #6366f1;
	background: #6366f111;
}

.cw-palette__card:active {
	cursor: grabbing;
}

.cw-palette__card-icon {
	font-size: 16px;
	width: 24px;
	text-align: center;
	flex-shrink: 0;
}

.cw-palette__card-label {
	font-weight: 500;
	color: var(--rs-text-primary, #e2e8f0);
}

/* ── SVG canvas ── */
.cw-canvas {
	flex: 1;
	position: relative;
	overflow: hidden;
	cursor: grab;
	background: var(--rs-canvas-bg, #0f0f23);
	min-width: 0;
}

.cw-canvas.grabbing {
	cursor: grabbing;
}

.cw-canvas.wiring {
	cursor: crosshair;
}

.cw-canvas svg {
	display: block;
	width: 100%;
	height: 100%;
}

/* ── Right sidebar — config ── */
.cw-config {
	width: 0;
	overflow: hidden;
	border-left: 1px solid var(--rs-border, #2d2d44);
	background: var(--rs-bg-surface, #1a1a2e);
	display: flex;
	flex-direction: column;
	transition: width 0.2s ease;
}

.cw-config.open {
	width: 280px;
	min-width: 280px;
}

.cw-config__header {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 12px 16px;
	border-bottom: 1px solid var(--rs-border, #2d2d44);
	font-weight: 600;
	font-size: 13px;
}

.cw-config__header-close {
	background: none;
	border: none;
	color: var(--rs-text-muted, #94a3b8);
	font-size: 16px;
	cursor: pointer;
	margin-left: auto;
	padding: 2px;
}

.cw-config__body {
	padding: 12px 16px;
	display: flex;
	flex-direction: column;
	gap: 10px;
	overflow-y: auto;
	flex: 1;
}

.cw-config__field {
	display: flex;
	flex-direction: column;
	gap: 4px;
}

.cw-config__field label {
	font-size: 11px;
	font-weight: 500;
	color: var(--rs-text-muted, #94a3b8);
}

.cw-config__field input,
.cw-config__field select,
.cw-config__field textarea {
	width: 100%;
	padding: 6px 8px;
	border-radius: 6px;
	border: 1px solid var(--rs-input-border, #3d3d5c);
	background: var(--rs-input-bg, #16162a);
	color: var(--rs-text-primary, #e2e8f0);
	font-size: 12px;
	font-family: inherit;
	box-sizing: border-box;
}

.cw-config__field textarea {
	resize: vertical;
	min-height: 60px;
}

.cw-config__field input:focus,
.cw-config__field select:focus,
.cw-config__field textarea:focus {
	border-color: #3b82f6;
	outline: none;
}

.cw-config__thread-btn {
	padding: 8px 12px;
	border-radius: 6px;
	border: 1px solid #6366f155;
	background: #6366f122;
	color: #818cf8;
	font-size: 12px;
	cursor: pointer;
	width: 100%;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: background 0.15s, border-color 0.15s;
}

.cw-config__thread-btn:hover {
	background: #6366f133;
	border-color: #6366f1;
}

.cw-config__delete {
	margin-top: 12px;
	padding: 6px 12px;
	border-radius: 6px;
	border: 1px solid #ef444455;
	background: #ef444422;
	color: #f87171;
	font-size: 12px;
	cursor: pointer;
}

.cw-config__delete:hover {
	background: #ef444433;
}

/* ── Execution log in config panel ── */
.cw-exec-log {
	margin-top: 12px;
	border-top: 1px solid var(--rs-border, #2d2d44);
	padding-top: 12px;
}

.cw-exec-log__title {
	font-size: 11px;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.05em;
	color: var(--rs-text-muted, #94a3b8);
	margin-bottom: 8px;
}

.cw-exec-log__entry {
	display: flex;
	align-items: center;
	gap: 6px;
	padding: 4px 0;
	font-size: 11px;
	color: var(--rs-text-muted, #94a3b8);
}

.cw-exec-log__dot {
	width: 6px;
	height: 6px;
	border-radius: 50%;
	flex-shrink: 0;
}

.cw-exec-log__dot.success { background: #22c55e; }
.cw-exec-log__dot.error { background: #ef4444; }
.cw-exec-log__dot.running { background: #3b82f6; animation: cw-pulse 1s infinite; }

@keyframes cw-pulse {
	0%, 100% { opacity: 1; }
	50% { opacity: 0.4; }
}

/* ── Zoom controls ── */
.cw-zoom-controls {
	position: absolute;
	bottom: 14px;
	right: 14px;
	display: flex;
	align-items: center;
	gap: 0;
	background: var(--rs-bg-surface, #1a1a2e);
	border: 1px solid var(--rs-border, #2d2d44);
	border-radius: 8px;
	box-shadow: 0 2px 8px rgba(0,0,0,0.12);
	overflow: hidden;
	z-index: 5;
}

.cw-zoom-btn {
	width: 32px;
	height: 32px;
	border: none;
	border-radius: 0;
	background: transparent;
	color: var(--rs-text-primary, #e2e8f0);
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: background 0.15s;
	padding: 0;
}

.cw-zoom-btn:hover {
	background: var(--rs-bg-surface-raised, #252545);
}

.cw-zoom-btn svg {
	width: 16px;
	height: 16px;
}

.cw-zoom-sep {
	width: 1px;
	height: 18px;
	background: var(--rs-border, #2d2d44);
	margin: 0 2px;
}

.cw-zoom-level {
	font-size: 11px;
	font-weight: 600;
	color: var(--rs-text-secondary, #94a3b8);
	min-width: 40px;
	text-align: center;
	user-select: none;
}

/* ── Node styles in SVG ── */
.cw-node { cursor: pointer; }
.cw-node.selected > foreignObject > div {
	outline: 2px solid #6366f1;
	outline-offset: 2px;
}

.cw-node foreignObject > div {
	border-radius: 10px;
	border: 1px solid var(--rs-border, #2d2d44);
	background: var(--rs-bg-surface, #1a1a2e);
	overflow: hidden;
	font-size: 12px;
	transition: border-color 0.15s;
}

.cw-node:hover foreignObject > div {
	border-color: #4f46e5 !important;
}

/* Category-specific node backgrounds */
.cw-node--trigger foreignObject > div {
	border-color: #3b82f644;
	background: linear-gradient(135deg, #1a1a2e 0%, #1e2a3e 100%);
}
.cw-node--delay foreignObject > div {
	border-color: #a855f744;
	background: linear-gradient(135deg, #1a1a2e 0%, #251e3e 100%);
}
.cw-node--condition foreignObject > div {
	border-color: #f59e0b44;
	background: linear-gradient(135deg, #1a1a2e 0%, #2e2a1e 100%);
}
.cw-node--action foreignObject > div {
	border-color: #10b98144;
	background: linear-gradient(135deg, #1a1a2e 0%, #1e2e24 100%);
}

.cw-node-header {
	display: flex;
	align-items: center;
	gap: 6px;
	padding: 8px 10px;
	border-bottom: 1px solid var(--rs-border, #2d2d44);
	cursor: move;
}

.cw-node-icon {
	font-size: 14px;
}

.cw-node-label {
	font-weight: 600;
	font-size: 12px;
	color: var(--rs-text-primary, #e2e8f0);
	flex: 1;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.cw-node-cat {
	font-size: 9px;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.04em;
	padding: 1px 5px;
	border-radius: 3px;
	flex-shrink: 0;
}
.cw-node-cat--trigger { color: #60a5fa; background: #3b82f622; }
.cw-node-cat--delay { color: #c084fc; background: #a855f722; }
.cw-node-cat--condition { color: #fbbf24; background: #f59e0b22; }
.cw-node-cat--action { color: #34d399; background: #10b98122; }

.cw-node-status {
	width: 8px;
	height: 8px;
	border-radius: 50%;
	flex-shrink: 0;
}

.cw-node-status.idle { background: #4b5563; }
.cw-node-status.running { background: #3b82f6; animation: cw-pulse 1s infinite; }
.cw-node-status.success { background: #22c55e; }
.cw-node-status.error { background: #ef4444; }

.cw-node-ports {
	padding: 6px 10px;
	display: flex;
	justify-content: space-between;
	min-height: 28px;
}

.cw-node-inputs,
.cw-node-outputs {
	display: flex;
	flex-direction: column;
	gap: 4px;
}

.cw-node-outputs {
	align-items: flex-end;
}

.cw-port-label {
	font-size: 10px;
	color: var(--rs-text-muted, #94a3b8);
}

/* ── Port handles in SVG ── */
.cw-port-group { cursor: crosshair; }
.cw-port-dot {
	transition: r 0.15s, filter 0.15s;
}

.cw-port-group:hover .cw-port-dot {
	r: 7;
	filter: drop-shadow(0 0 4px currentColor);
}

/* ── Edge styles ── */
.cw-edge-group { pointer-events: stroke; }

.cw-edge-path {
	fill: none;
	stroke-width: 2;
}

.cw-edge-hit {
	fill: none;
	stroke: transparent;
	stroke-width: 16;
	cursor: pointer;
}

/* ── Wiring temp line ── */
.cw-wiring-temp {
	fill: none;
	stroke: #6366f1;
	stroke-width: 2;
	stroke-dasharray: 6 4;
	opacity: 0.7;
	pointer-events: none;
}

/* ── Workflow selector ── */
.cw-workflow-select {
	padding: 4px 8px;
	border-radius: 6px;
	border: 1px solid var(--rs-input-border, #3d3d5c);
	background: var(--rs-input-bg, #16162a);
	color: var(--rs-text-primary, #e2e8f0);
	font-size: 12px;
}

/* ── Mobile ── */
@media (max-width: 768px) {
	folk-campaign-workflow {
		height: 100%;
	}

	.cw-palette {
		width: 160px;
		min-width: 160px;
		padding: 8px;
	}

	.cw-config.open {
		position: absolute;
		top: 0;
		right: 0;
		width: 100%;
		height: 100%;
		z-index: 20;
		min-width: unset;
	}

	.cw-toolbar {
		flex-wrap: wrap;
		padding: 8px 12px;
	}
}
