﻿* {
  box-sizing: border-box;
  user-select: none;
}

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, sans-serif;
  background-color: #f4f6fa;
  color: #1f2937;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 18px;
  background: #1f2937;
  color: #f9fafb;
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.3);
  z-index: 5;
}

.topbar .brand {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.4px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.topbar button,
.topbar .file-input {
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font: inherit;
  cursor: pointer;
  background: #2563eb;
  color: #f9fafb;
  transition: background 0.15s ease, transform 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.topbar button.secondary {
  background: #374151;
}

.topbar button:hover,
.topbar .file-input:hover {
  background: #1d4ed8;
}

.topbar button.secondary:hover {
  background: #4b5563;
}

.topbar button:active,
.topbar .file-input:active {
  transform: translateY(1px);
}

.topbar button:disabled {
  opacity: 0.5;
  cursor: default;
  transform: none;
}

.file-input {
  position: relative;
  overflow: hidden;
}

.file-input input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.save-status {
  min-width: 160px;
  text-align: right;
  font-size: 13px;
  color: rgba(229, 231, 235, 0.9);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.save-status.visible {
  opacity: 1;
}

.app-shell {
  flex: 1;
  display: flex;
  min-height: 0;
}

.palette {
  width: 200px;
  padding: 16px;
  background: #111827;
  color: #f9fafb;
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 2;
  flex-shrink: 0;
}

.palette h1 {
  margin: 0 0 12px;
  font-size: 18px;
  font-weight: 600;
}

.palette-item {
  padding: 10px 14px;
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 6px;
  cursor: grab;
  transition: background 0.2s ease, transform 0.2s ease;
}

.palette-item:active {
  cursor: grabbing;
  transform: scale(0.97);
}

.palette-item:hover {
  background: #2563eb;
  border-color: #2563eb;
}

.workspace {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
  min-width: 0;
}

.canvas {
  flex: 1;
  position: relative;
  background: repeating-linear-gradient(45deg, #f3f4f6, #f3f4f6 24px, #e5e7eb 24px, #e5e7eb 48px);
}

.canvas-hint {
  position: absolute;
  top: 16px;
  left: 16px;
  padding: 6px 10px;
  background: rgba(17, 24, 39, 0.78);
  color: #f9fafb;
  border-radius: 4px;
  font-size: 13px;
  pointer-events: none;
  opacity: 0.8;
}

.connection-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.connection-line {
  stroke: #2563eb;
  stroke-width: 3;
  stroke-linecap: round;
  pointer-events: stroke;
}

.node {
  position: absolute;
  padding: 0;
  cursor: move;
  min-width: 88px;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: transparent;
  z-index: 3;
  transition: box-shadow 0.15s ease, transform 0.15s ease;
  box-sizing: border-box;
}

.node .resize-handle {
  position: absolute;
  bottom: 6px;
  right: 6px;
  width: 16px;
  height: 16px;
  border-radius: 4px;
  background: rgba(37, 99, 235, 0.85);
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.35);
  cursor: se-resize;
  z-index: 4;
}

.node .resize-handle::after {
  content: '';
  position: absolute;
  inset: 4px;
  border-right: 2px solid rgba(249, 250, 251, 0.9);
  border-bottom: 2px solid rgba(249, 250, 251, 0.9);
}

.node.editing .resize-handle {
  display: none;
}

.node:focus-within,
.node.dragging {
  box-shadow: 0 10px 24px rgba(37, 99, 235, 0.25);
}

.node.pending {
  outline: 2px dashed #2563eb;
  outline-offset: 4px;
}

.node.editing {
  cursor: text;
  box-shadow: 0 14px 32px rgba(37, 99, 235, 0.28);
}

.node button.node-content,
.node .node-content {
  width: 100%;
  height: 100%;
  padding: 10px 18px;
  border-radius: 8px;
  border: 1px solid #9ca3af;
  background: #ffffff;
  color: inherit;
  font: inherit;
  cursor: inherit;
}

.node button.node-content {
  background: linear-gradient(180deg, #60a5fa, #2563eb);
  border-color: #1d4ed8;
  color: #f9fafb;
  font-weight: 600;
}

.node .node-label {
  background: rgba(255, 255, 255, 0.92);
  border-style: dashed;
  text-align: left;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
  min-width: 120px;
  padding: 12px 16px;
  overflow: auto;
}

.collapse-toggle {
  position: absolute;
  top: 6px;
  left: -14px;
  display: none;
  z-index: 4;
}

.node.collapsible .collapse-toggle {
  display: inline-flex;
}

.node.editing .collapse-toggle {
  display: none;
}

.collapse-toggle-btn {
  width: 12px;
  height: 12px;
  padding: 0;
  border: 1px solid rgba(37, 99, 235, 0.7);
  border-radius: 4px;
  background: rgba(17, 24, 39, 0.85);
  color: #f9fafb;
  font: inherit;
  font-size: 10px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease, opacity 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.collapse-toggle-btn:hover:not(:disabled) {
  background: rgba(37, 99, 235, 0.92);
}

.collapse-toggle-btn:active:not(:disabled) {
  transform: translateY(1px);
}

.collapse-toggle-btn:disabled {
  opacity: 0.45;
  cursor: default;
  transform: none;
}

.node.collapsed .node-label {
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  max-height: calc(1.45em * 2 + 12px);
}

.node.editing .node-label {
  background: rgba(37, 99, 235, 0.08);
  border-style: solid;
  border-color: #2563eb;
  user-select: text;
  max-height: none;
  -webkit-line-clamp: initial;
  display: block;
  overflow: auto;
}

.node .node-label[contenteditable='true'] {
  outline: none;
  cursor: text;
}

.context-menu {
  position: fixed;
  min-width: 200px;
  background: #111827;
  color: #f9fafb;
  border-radius: 6px;
  box-shadow: 0 20px 32px rgba(15, 23, 42, 0.35);
  z-index: 999;
  animation: menu-pop 0.12s ease-out;
}

.context-menu.hidden {
  display: none;
}

.context-menu ul {
  list-style: none;
  margin: 0;
  padding: 6px 0;
}

.context-menu li {
  padding: 8px 14px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.15s ease;
}

.context-menu li:hover {
  background: rgba(37, 99, 235, 0.55);
}

.context-menu li.disabled {
  opacity: 0.4;
  cursor: default;
}

@keyframes menu-pop {
  from {
    opacity: 0;
    transform: translateY(-4px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}
