:root {
	--primary-color: #3b82f6;
	--bg-color: #f8fafc;
	--sidebar-bg: #ffffff;
	--border-color: #e2e8f0;
	--text-color: #1e293b;
	--block-bg: #ffffff;
	--block-border: #000000;
	/* NSD usually has black borders */
	--hover-bg: #f1f5f9;
}

body {
	font-family: 'Inter', sans-serif;
	margin: 0;
	padding: 0;
	background-color: var(--bg-color);
	color: var(--text-color);
	height: 100vh;
	overflow: hidden;
}

.app-container {
	display: flex;
	height: 100%;
}

.sidebar {
	width: 250px;
	background-color: var(--sidebar-bg);
	border-right: 1px solid var(--border-color);
	padding: 20px;
	display: flex;
	flex-direction: column;
	gap: 20px;
}

.toolbox {
	display: flex;
	flex-direction: column;
	gap: 10px;
}

.draggable-item {
	padding: 10px 15px;
	background-color: white;
	border: 1px solid var(--border-color);
	border-radius: 6px;
	cursor: grab;
	transition: all 0.2s;
	box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.draggable-item:hover {
	border-color: var(--primary-color);
	transform: translateY(-1px);
	box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}

.editor-area {
	flex: 1;
	display: flex;
	flex-direction: column;
	padding: 20px;
	gap: 20px;
	overflow: hidden;
}

.canvas {
	flex: 1;
	min-height: 0;
	background-color: white;
	border: 1px solid var(--border-color);
	border-radius: 8px;
	padding: 40px;
	overflow: auto;
	display: flex;
	flex-direction: column;
	align-items: stretch;
	gap: 24px;
}

.output-area {
	height: 150px;
	background-color: #1e293b;
	color: #e2e8f0;
	padding: 15px;
	border-radius: 8px;
	overflow: auto;
}

.btn {
	padding: 10px 20px;
	border-radius: 6px;
	border: none;
	cursor: pointer;
	font-weight: 500;
	width: 100%;
}

.btn.primary {
	background-color: var(--primary-color);
	color: white;
}

.btn.secondary {
	background-color: transparent;
	border: 1px solid var(--border-color);
	color: var(--text-color);
}

/* NSD Block Styles */
.nsd-block {
	border: 1px solid var(--block-border);
	background-color: var(--block-bg);
	min-width: fit-content;
	position: relative;
	box-sizing: border-box;
}

.nsd-container {
	display: flex;
	flex-direction: column;
	min-width: 400px;
	/* Base width for the diagram */
	width: fit-content;
	/* Allow growing */
	border: 1px solid var(--block-border);
	background-color: white;
}

.drop-zone {
	min-height: 20px;
	background-color: rgba(59, 130, 246, 0.1);
	border: 2px dashed var(--primary-color);
	display: flex;
	align-items: center;
	justify-content: center;
	margin: 2px;
	opacity: 0;
	transition: opacity 0.2s;
}

.drop-zone.active {
	opacity: 1;
	height: 40px;
}

.initial-zone {
	width: 100%;
	height: 100%;
	opacity: 1;
	border: 2px dashed #cbd5e1;
	color: #94a3b8;
}

/* Specific Block Types */
.block-command,
.block-exit,
.block-subprogram {
	padding: 10px;
	text-align: center;
	border-bottom: 1px solid var(--block-border);
	background-color: #fff;
}

.block-subprogram {
	border-left: 5px solid var(--block-border);
	border-right: 5px solid var(--block-border);
}

.block-loop {
	display: flex;
	flex-direction: column;
	border-bottom: 1px solid var(--block-border);
}

.block-loop-header {
	padding: 5px;
	background-color: #e2e8f0;
	/* Darker gray for control structure */
	font-size: 0.9em;
	font-weight: 500;
}

/* Head-controlled: Header is first */
.block-loop-header:first-child {
	border-bottom: none;
	/* Removed to allow L-shape merge */
}

/* Foot-controlled: Header is last */
.block-loop-header:last-child {
	border-top: none;
	/* Removed to allow L-shape merge */
}

.block-loop-body {
	display: flex;
	flex-direction: row;
	min-width: fit-content;
	min-height: 30px;
	background-color: #fff;
	box-sizing: border-box;
}

.loop-spacer {
	width: 30px;
	border-right: 1px solid var(--block-border);
	flex-shrink: 0;
	/* Never shrink */
	background-color: #e2e8f0;
}

.loop-content {
	flex: 1 0 auto;
	display: flex;
	flex-direction: column;
	min-width: fit-content;
	background-color: #fff;
}

/* Specific borders for content to separate from header */
.block-for_loop .loop-content,
.block-while_loop .loop-content {
	border-top: 1px solid var(--block-border);
}

.block-repeat_loop .loop-content {
	border-bottom: 1px solid var(--block-border);
}

.block-if {
	display: flex;
	flex-direction: column;
	border-bottom: 1px solid var(--block-border);
	min-width: fit-content;
}

.block-if-header {
	position: relative;
	display: flex;
	flex-direction: column;
	align-items: center;
	min-height: 65px;
	padding-bottom: 24px;
	border-bottom: 1px solid var(--block-border);
}

/* SVG for the triangle lines in IF block */
.if-svg {
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	pointer-events: none;
	/* Let clicks pass through to text */
}

/* Condition text inside IF header */
.if-condition-text {
	position: absolute;
	top: 5px;
	z-index: 1;
	text-align: center;
	white-space: nowrap;
	padding: 4px 8px;
	transform: translateX(-50%);
}

/* Spacer below text — leaves room for the V-tip */
.if-v-spacer {
	flex: 1 1 0;
	min-height: 28px;
	width: 100%;
}

.block-if-body {
	display: flex;
	min-width: fit-content;
}

/* Labels for Ja/Nein branches */
.if-branch-label {
	padding: 5px;
	text-align: center;
	font-size: 0.9em;
	font-weight: 500;
	background-color: #f8fafc;
	border-bottom: 1px solid var(--block-border);
}

.block-if-branch {
	flex: 1 0 auto; /* flex-grow per JS gesetzt, flex-basis auto = Inhaltsbreite wird respektiert */
	border-right: 1px solid var(--block-border);
	min-height: 50px;
	display: flex;
	flex-direction: column;
	min-width: fit-content;
}

.block-if-branch:last-child {
	border-right: none;
}

/* Nested Drop Zones */
.nested-drop-zone {
	height: 10px;
	background-color: transparent;
	transition: height 0.2s, background-color 0.2s;
}

.nested-drop-zone.active {
	height: 30px;
	background-color: rgba(59, 130, 246, 0.2);
	border: 1px dashed var(--primary-color);
}

/* Insertion Drop Zones */
.insertion-drop-zone {
	height: 10px;
	/* Small hit area */
	background-color: transparent;
	transition: all 0.2s ease;
	margin: 2px 0;
	border-radius: 4px;
	position: relative;
}

/* Expand hit area without taking up space */
.insertion-drop-zone::after {
	content: '';
	position: absolute;
	top: -5px;
	left: 0;
	right: 0;
	bottom: -5px;
	z-index: 10;
}

.insertion-drop-zone.active {
	height: 40px;
	/* Expand to look like a node */
	background-color: rgba(59, 130, 246, 0.1);
	border: 2px dashed var(--primary-color);
	margin: 5px 0;
}

.insertion-drop-zone.active::before {
	content: 'Insert Here';
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	color: var(--primary-color);
	font-size: 0.8em;
	font-weight: 500;
}

/* Initial Zone Override */
.insertion-drop-zone.initial-zone {
	height: 200px;
	background-color: #f8fafc;
	border: 2px dashed #cbd5e1;
	opacity: 1;
	display: flex;
	align-items: center;
	justify-content: center;
	color: #94a3b8;
}

.insertion-drop-zone.initial-zone.active {
	background-color: rgba(59, 130, 246, 0.1);
	border-color: var(--primary-color);
}

.insertion-drop-zone.initial-zone.active::before {
	content: 'Drop to Start';
}

.insertion-drop-zone.empty-container-zone {
	flex: 1;
	min-height: 40px;
	background-color: #f8fafc;
	border: 2px dashed #e2e8f0;
	opacity: 1;
	display: flex;
	align-items: center;
	justify-content: center;
	color: #94a3b8;
	margin: 5px;
	border-radius: 4px;
}

.insertion-drop-zone.empty-container-zone.active {
	background-color: rgba(59, 130, 246, 0.1);
	border-color: var(--primary-color);
}

.menu-item:hover {
	background-color: #f1f5f9;
}/* Case Block Styles */
.block-case {
	display: flex;
	flex-direction: column;
	border-bottom: 1px solid var(--block-border);
	min-width: fit-content;
}

.block-case-header {
	position: relative;
	height: 80px;
	border-bottom: 1px solid var(--block-border);
}

.case-svg {
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	pointer-events: none;
}

.block-case-body {
	display: flex;
	min-width: fit-content;
}

.block-case-branch {
	flex: 1 0 auto;
	border-right: 1px solid var(--block-border);
	min-height: 50px;
	display: flex;
	flex-direction: column;
	min-width: fit-content;
	position: relative;
}

.block-case-branch:last-child {
	border-right: none;
}

.case-label {
	position: absolute;
	bottom: 5px;
	width: 100%;
	text-align: center;
	font-size: 0.8em;
	pointer-events: auto;
	/* Allow clicking on label to edit */
	cursor: text;
}

/* Context Menu */
.context-menu {
	position: absolute;
	background-color: white;
	border: 1px solid #ccc;
	box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.2);
	z-index: 10000;
	min-width: 150px;
	border-radius: 4px;
	padding: 5px 0;
}

.context-menu-item {
	padding: 8px 12px;
	cursor: pointer;
	font-size: 14px;
	color: #333;
}

.context-menu-item:hover {
	background-color: #f0f0f0;
}

/* ===== Move Mode ===== */

/* Move Indicator Banner */
#move-indicator {
	display: none;
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	z-index: 9999;
	background: linear-gradient(135deg, #f59e0b, #d97706);
	color: #ffffff;
	padding: 10px 20px;
	text-align: center;
	font-weight: 600;
	font-size: 0.9em;
	box-shadow: 0 2px 12px rgba(245, 158, 11, 0.5);
	letter-spacing: 0.02em;
	animation: slideDown 0.25s ease;
}

@keyframes slideDown {
	from { transform: translateY(-100%); opacity: 0; }
	to   { transform: translateY(0);    opacity: 1; }
}

/* Drop zones light up as click targets in move mode */
body.move-mode .insertion-drop-zone {
	height: 30px;
	background-color: rgba(245, 158, 11, 0.12);
	border: 2px dashed #f59e0b;
	border-radius: 4px;
	margin: 3px 0;
	cursor: crosshair;
	transition: background-color 0.15s, border-color 0.15s, box-shadow 0.15s;
	opacity: 1;
}

body.move-mode .insertion-drop-zone:hover {
	background-color: rgba(245, 158, 11, 0.28);
	border-color: #d97706;
	box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.25);
}

body.move-mode .insertion-drop-zone::before {
	content: '▶ Move here';
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	color: #d97706;
	font-size: 0.75em;
	font-weight: 600;
	pointer-events: none;
	white-space: nowrap;
}

/* Highlight the block being moved */
.nsd-block.move-source {
	outline: 3px solid #f59e0b;
	outline-offset: -2px;
	box-shadow: 0 0 0 6px rgba(245, 158, 11, 0.25);
	opacity: 0.7;
	transition: opacity 0.2s, box-shadow 0.2s;
}

/* Prevent drag while in move mode */
body.move-mode * {
	user-select: none;
}

body.move-mode .nsd-block:not(.move-source) {
	cursor: not-allowed;
}

body.move-mode {
	cursor: crosshair;
}

/* ===== Subprogramm-Blöcke ===== */

.block-subprogram {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	padding: 10px;
}

.subprogram-text {
	flex: 1;
	text-align: center;
}

.subprogram-edit-btn {
	flex-shrink: 0;
	padding: 2px 8px;
	font-size: 0.78em;
	background: #e2e8f0;
	border: 1px solid #94a3b8;
	border-radius: 4px;
	cursor: pointer;
	white-space: nowrap;
}

.subprogram-edit-btn:hover {
	background: #cbd5e1;
}

/* ===== Subprogramm-Navigation ===== */

.nsd-back-btn {
	display: block;
	width: 100%;
	padding: 8px 16px;
	margin-bottom: 12px;
	background: #3b82f6;
	color: white;
	border: none;
	border-radius: 6px;
	font-size: 0.9em;
	font-weight: 600;
	cursor: pointer;
	text-align: left;
}

.nsd-back-btn:hover {
	background: #2563eb;
}

/* ===== Subprogramm-Sektionen (Hauptansicht) ===== */

.nsd-subprogram-section {
	border: 2px solid #3b82f6;
	border-radius: 6px;
	width: 100%;
}

.nsd-subprogram-diagram {
	padding: 20px;
	background: white;
	display: flex;
	justify-content: center;
	align-items: flex-start;
}

.nsd-subprogram-section-header {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 8px 12px;
	background: #f1f5f9;
	border-bottom: 1px solid #94a3b8;
	user-select: none;
}

.nsd-subprogram-section-header:hover {
	background: #e2e8f0;
}

.nsd-subprogram-toggle {
	font-size: 0.75em;
	color: #64748b;
	flex-shrink: 0;
}

.nsd-subprogram-label {
	font-weight: 600;
	font-size: 0.9em;
	color: #334155;
}

.nsd-edit-sub-btn {
	padding: 3px 10px;
	font-size: 0.8em;
	background: #3b82f6;
	color: white;
	border: none;
	border-radius: 4px;
	cursor: pointer;
}

.nsd-edit-sub-btn:hover {
	background: #2563eb;
}

.nsd-subprogram-preview {
	padding: 10px 14px;
	font-size: 0.85em;
	color: #64748b;
	font-style: italic;
}

.nsd-main-section {
	display: flex;
	justify-content: center;
	align-items: flex-start;
}
}