:root {
  --bg: #0d1117;
  --bg-secondary: #161b22;
  --surface: rgba(255, 255, 255, 0.05);
  --surface-hover: rgba(255, 255, 255, 0.08);
  --text: rgba(255, 255, 255, 0.92);
  --text-muted: rgba(255, 255, 255, 0.6);
  --text-dim: rgba(255, 255, 255, 0.4);
  --border: rgba(255, 255, 255, 0.1);
  --border-focus: rgba(110, 231, 255, 0.5);
  --accent: #6ee7ff;
  --accent-soft: rgba(110, 231, 255, 0.15);
  --success: #7ccb7d;
  --success-soft: rgba(124, 203, 125, 0.15);
  --warning: #e5a158;
  --warning-soft: rgba(229, 161, 88, 0.15);
  --error: #d47c6a;
  --error-soft: rgba(212, 124, 106, 0.15);
  --purple: #a88bc4;
  --purple-soft: rgba(168, 139, 196, 0.15);
  --blue: #7ba3c4;
  --blue-soft: rgba(123, 163, 196, 0.15);
  --orange: #d48a6a;
  --orange-soft: rgba(212, 138, 106, 0.15);
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  overflow: hidden;
}

/* App Layout */
.app {
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

/* Header */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  z-index: 100;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  font-size: 24px;
  opacity: 0.8;
}

.brand-name {
  font-weight: 600;
  font-size: 16px;
}

.brand-sub {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.tabs {
  display: flex;
  gap: 4px;
  background: var(--surface);
  padding: 4px;
  border-radius: var(--radius-md);
}

.tab {
  padding: 8px 16px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.tab:hover {
  color: var(--text);
  background: var(--surface-hover);
}

.tab.active {
  color: var(--text);
  background: var(--accent-soft);
}

.actions {
  display: flex;
  gap: 8px;
}

.btn {
  padding: 8px 16px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn:hover {
  background: var(--surface-hover);
  border-color: rgba(255, 255, 255, 0.2);
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #000;
}

.btn.primary:hover {
  filter: brightness(1.1);
}

/* Main Content */
.main-content {
  display: grid;
  grid-template-columns: 280px 1fr 320px;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-title {
  display: block;
  font-weight: 600;
  margin-bottom: 12px;
}

.search-input {
  width: 100%;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s ease;
}

.search-input:focus {
  border-color: var(--border-focus);
}

.search-input::placeholder {
  color: var(--text-dim);
}

.node-categories {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.node-category {
  margin-bottom: 4px;
}

.category-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  transition: all 0.15s ease;
}

.category-header:hover {
  background: var(--surface);
  color: var(--text);
}

.category-icon {
  font-size: 14px;
}

.category-toggle {
  margin-left: auto;
  font-size: 10px;
  transition: transform 0.2s ease;
}

.category-header.collapsed .category-toggle {
  transform: rotate(-90deg);
}

.category-nodes {
  padding: 4px 0 4px 8px;
}

.category-header.collapsed + .category-nodes {
  display: none;
}

.node-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  margin-bottom: 4px;
  background: var(--surface);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  cursor: grab;
  transition: all 0.15s ease;
}

.node-item:hover {
  background: var(--surface-hover);
  border-color: var(--border);
  transform: translateX(2px);
}

.node-item:active {
  cursor: grabbing;
}

.node-item-icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  font-size: 16px;
  flex-shrink: 0;
}

.node-item-info {
  flex: 1;
  min-width: 0;
}

.node-item-name {
  font-weight: 500;
  font-size: 13px;
  margin-bottom: 2px;
}

.node-item-desc {
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Canvas */
.canvas-container {
  position: relative;
  background:
    radial-gradient(circle at 20% 30%, rgba(110, 231, 255, 0.03) 0%, transparent 50%),
    radial-gradient(circle at 80% 70%, rgba(124, 203, 125, 0.03) 0%, transparent 50%),
    var(--bg);
  overflow: hidden;
}

.canvas-toolbar {
  position: absolute;
  top: 16px;
  left: 16px;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  z-index: 10;
}

.toolbar-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.toolbar-btn:hover {
  background: var(--surface);
  color: var(--text);
}

.zoom-level {
  padding: 0 8px;
  font-size: 12px;
  color: var(--text-muted);
  font-family: var(--mono);
}

.toolbar-divider {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 4px;
}

.canvas {
  width: 100%;
  height: 100%;
  position: relative;
  background-image:
    radial-gradient(circle, var(--border) 1px, transparent 1px);
  background-size: 20px 20px;
  transform-origin: center center;
}

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

.nodes-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.canvas-hint {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 20px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  color: var(--text-muted);
  font-size: 13px;
  pointer-events: none;
  opacity: 0.8;
}

/* Canvas Node */
.canvas-node {
  position: absolute;
  min-width: 220px;
  background: var(--bg-secondary);
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  cursor: move;
  user-select: none;
  transition: box-shadow 0.15s ease, border-color 0.15s ease;
}

.canvas-node:hover {
  box-shadow: var(--shadow-lg);
}

.canvas-node.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow-lg);
}

.canvas-node.dragging {
  opacity: 0.9;
  z-index: 1000;
}

.node-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.node-icon {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  font-size: 14px;
  flex-shrink: 0;
}

.node-title {
  flex: 1;
  font-weight: 600;
  font-size: 13px;
}

.node-status {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
}

.node-status.error {
  background: var(--error);
}

.node-status.warning {
  background: var(--warning);
}

.node-body {
  padding: 12px 14px;
}

.node-field {
  margin-bottom: 10px;
}

.node-field:last-child {
  margin-bottom: 0;
}

.node-field-label {
  display: block;
  font-size: 10px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.node-field-value {
  font-size: 12px;
  color: var(--text-muted);
  padding: 6px 8px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  font-family: var(--mono);
}

.node-ports {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
}

.port {
  position: relative;
  width: 12px;
  height: 12px;
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: 50%;
  cursor: crosshair;
  transition: all 0.15s ease;
}

.port:hover {
  transform: scale(1.3);
  border-color: var(--accent);
  background: var(--accent-soft);
}

.port.input {
  margin-left: -6px;
}

.port.output {
  margin-right: -6px;
}

.port.connected {
  background: var(--accent);
  border-color: var(--accent);
}

/* Connection Lines */
.connection {
  stroke: var(--accent);
  stroke-width: 2;
  fill: none;
  opacity: 0.6;
}

.connection:hover {
  opacity: 1;
  stroke-width: 3;
}

.connection-temp {
  stroke: var(--accent);
  stroke-width: 2;
  stroke-dasharray: 5, 5;
  fill: none;
  opacity: 0.5;
}

/* Properties Panel */
.properties-panel {
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.panel-title {
  font-weight: 600;
}

.panel-close {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.panel-close:hover {
  background: var(--surface);
  color: var(--text);
}

.panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-dim);
}

.property-group {
  margin-bottom: 20px;
}

.property-group-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.property-field {
  margin-bottom: 14px;
}

.property-label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.property-input {
  width: 100%;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  font-family: var(--mono);
  outline: none;
  transition: border-color 0.15s ease;
}

.property-input:focus {
  border-color: var(--border-focus);
}

.property-textarea {
  min-height: 100px;
  resize: vertical;
}

.property-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23888' d='M6 8L2 4h8z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

.property-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.toggle-switch {
  width: 44px;
  height: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  position: relative;
  transition: all 0.2s ease;
}

.toggle-switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  background: var(--text-muted);
  border-radius: 50%;
  transition: all 0.2s ease;
}

.toggle-switch.active {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.toggle-switch.active::after {
  left: 22px;
  background: var(--accent);
}

/* Status Bar */
.statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 20px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-dim);
}

.status-left,
.status-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.status-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

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

::-webkit-scrollbar-track {
  background: transparent;
}

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

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* Animations */
@keyframes nodeAppear {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.canvas-node {
  animation: nodeAppear 0.2s ease;
}

/* Drop Zone Highlight */
.canvas-container.drag-over {
  background:
    radial-gradient(circle at 50% 50%, rgba(110, 231, 255, 0.08) 0%, transparent 60%),
    radial-gradient(circle at 20% 30%, rgba(110, 231, 255, 0.03) 0%, transparent 50%),
    radial-gradient(circle at 80% 70%, rgba(124, 203, 125, 0.03) 0%, transparent 50%),
    var(--bg);
}

.canvas-container.drag-over .canvas-hint {
  opacity: 0;
}
