/* ═══════════════════════════════════════════════
   Kode Visual Scripter — scripter.css
   ═══════════════════════════════════════════════ */

/* ── Root layout ── */
.vs-root {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  background: #09090b;
  font-family: 'Inter', sans-serif;
}

/* ── Toolbar ── */
.vs-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  height: 48px;
  background: #111113;
  border-bottom: 1px solid #27272a;
  flex-shrink: 0;
  z-index: 10;
}
.vs-toolbar-left {
  display: flex;
  align-items: center;
  gap: 14px;
  flex: 1;
}
.vs-logo {
  font-size: 15px;
  font-weight: 700;
  color: #e4e4e7;
  white-space: nowrap;
}
.vs-logo .logo-bracket { color: #8b5cf6; }
.vs-hint {
  font-size: 12px;
  color: #52525b;
  display: none;
}
@media (min-width: 1100px) { .vs-hint { display: block; } }

.vs-toolbar-center {
  display: flex;
  align-items: center;
  gap: 4px;
  background: #18181b;
  border: 1px solid #3f3f46;
  border-radius: 8px;
  padding: 0 10px;
  height: 32px;
}
.vs-script-name {
  background: transparent;
  border: none;
  outline: none;
  color: #e4e4e7;
  font-size: 13px;
  font-family: 'JetBrains Mono', monospace;
  width: 120px;
}
.vs-script-name:focus { color: #a78bfa; }
.vs-script-ext {
  color: #52525b;
  font-size: 13px;
  font-family: 'JetBrains Mono', monospace;
}

.vs-toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── Buttons ── */
.vs-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 14px;
  height: 32px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.vs-btn-ghost {
  background: transparent;
  color: #a1a1aa;
  border: 1px solid #3f3f46;
}
.vs-btn-ghost:hover { background: #27272a; color: #e4e4e7; }
.vs-btn-primary {
  background: #7c3aed;
  color: #fff;
}
.vs-btn-primary:hover { background: #6d28d9; }
.vs-sm { height: 26px; padding: 0 10px; font-size: 12px; }

/* ── Body ── */
.vs-body {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* ── Palette ── */
.vs-palette {
  width: 210px;
  flex-shrink: 0;
  background: #111113;
  border-right: 1px solid #27272a;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.vs-palette-search {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid #27272a;
  flex-shrink: 0;
}
.vs-palette-search svg { color: #52525b; flex-shrink: 0; }
.vs-palette-search input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: #e4e4e7;
  font-size: 12px;
}
.vs-palette-search input::placeholder { color: #52525b; }

#vs-palette-groups {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0 16px;
}
#vs-palette-groups::-webkit-scrollbar { width: 4px; }
#vs-palette-groups::-webkit-scrollbar-thumb { background: #3f3f46; border-radius: 2px; }

.vs-palette-group-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #52525b;
  padding: 10px 12px 4px;
}
.vs-palette-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  cursor: grab;
  user-select: none;
  border-radius: 6px;
  margin: 1px 6px;
  transition: background 0.1s;
}
.vs-palette-item:hover { background: #1c1c1f; }
.vs-palette-item:active { cursor: grabbing; }
.vs-palette-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.vs-palette-label {
  font-size: 12.5px;
  color: #a1a1aa;
  line-height: 1;
}
.vs-palette-item:hover .vs-palette-label { color: #e4e4e7; }

/* ── Canvas ── */
.vs-canvas-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #09090b;
  cursor: default;
}
/* Subtle dot grid */
.vs-canvas-wrap::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: radial-gradient(circle, #27272a 1px, transparent 1px);
  background-size: 28px 28px;
  pointer-events: none;
  opacity: 0.6;
}

.vs-canvas-vp {
  position: absolute;
  top: 0; left: 0;
  transform-origin: 0 0;
  will-change: transform;
}

.vs-svg {
  position: absolute;
  top: 0; left: 0;
  pointer-events: none;
  overflow: visible;
}
.vs-svg .vs-conn-hit { cursor: pointer; pointer-events: stroke; }
.vs-svg .vs-conn-path { pointer-events: none; transition: stroke 0.1s; }
.vs-svg .vs-conn-hit:hover + .vs-conn-path { stroke-width: 3; }
.vs-svg g:has(.vs-conn-hit:hover) .vs-conn-path { opacity: 0.8; }

#vs-nodes-layer {
  position: absolute;
  top: 0; left: 0;
}

.vs-canvas-tip {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  color: #3f3f46;
  pointer-events: none;
  white-space: nowrap;
}

.vs-empty-hint {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  gap: 12px;
}
.vs-empty-icon {
  font-size: 40px;
  opacity: 0.15;
}
.vs-empty-hint p {
  color: #52525b;
  font-size: 14px;
  text-align: center;
  line-height: 1.6;
}
.vs-empty-hint span { font-size: 12px; color: #3f3f46; }

/* ── Nodes ── */
.vs-node {
  position: absolute;
  width: 240px;
  user-select: none;
  filter: drop-shadow(0 4px 16px rgba(0,0,0,0.5));
}
.vs-node.vs-node-dragging { opacity: 0.9; filter: drop-shadow(0 8px 24px rgba(0,0,0,0.7)); z-index: 100; }
.vs-node.vs-node-selected .vs-node-card { outline: 2px solid #8b5cf6; }

.vs-node-card {
  background: #18181b;
  border: 1px solid #27272a;
  border-radius: 10px;
  overflow: hidden;
  transition: border-color 0.15s;
}
.vs-node-card:hover { border-color: #3f3f46; }

.vs-node-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px 9px 12px;
  background: var(--node-color, #3b82f6);
  background: linear-gradient(135deg, var(--node-color, #3b82f6), color-mix(in srgb, var(--node-color, #3b82f6) 70%, #000));
  cursor: grab;
}
.vs-node-header:active { cursor: grabbing; }
.vs-node-header-icon {
  font-size: 13px;
  line-height: 1;
  flex-shrink: 0;
}
.vs-node-title {
  font-size: 12.5px;
  font-weight: 600;
  color: #fff;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.vs-node-delete {
  background: transparent;
  border: none;
  cursor: pointer;
  color: rgba(255,255,255,0.5);
  font-size: 18px;
  line-height: 1;
  padding: 0 2px;
  border-radius: 4px;
  transition: color 0.1s, background 0.1s;
  flex-shrink: 0;
}
.vs-node-delete:hover { color: #fff; background: rgba(255,255,255,0.15); }

.vs-node-fields {
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.vs-field {}
.vs-field label {
  display: block;
  font-size: 10.5px;
  color: #71717a;
  margin-bottom: 3px;
  font-weight: 500;
}
.vs-field input[type="text"],
.vs-field select {
  width: 100%;
  background: #09090b;
  border: 1px solid #27272a;
  border-radius: 5px;
  color: #e4e4e7;
  font-size: 12px;
  padding: 5px 8px;
  outline: none;
  font-family: 'JetBrains Mono', monospace;
  box-sizing: border-box;
  transition: border-color 0.15s;
}
.vs-field input[type="text"]:focus,
.vs-field select:focus { border-color: #6d28d9; }
.vs-field input[type="text"]::placeholder { color: #3f3f46; }
.vs-field select { appearance: auto; }
.vs-field-check {
  display: flex;
  align-items: center;
}
.vs-field-check label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  margin: 0;
  color: #a1a1aa;
  font-size: 12px;
}
.vs-field-check input[type="checkbox"] {
  accent-color: #7c3aed;
  width: 14px;
  height: 14px;
  cursor: pointer;
}

.vs-node-outputs {
  display: flex;
  flex-direction: column;
  padding: 0 0 4px 0;
}

/* ── Ports ── */

.vs-node-wrap { position: absolute; }

/* Input port dot — sits inside the node header, sticks out the left edge */
.vs-node-header { position: relative; }

.vs-port-in-anchor {
  /* absolute so it protrudes left of the header */
  position: absolute;
  left: -11px;
  top: 50%;
  transform: translateY(-50%);
  width: 22px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: crosshair;
  z-index: 5;
  border-radius: 6px;
  transition: background 0.12s;
}
.vs-port-in-anchor:hover { background: rgba(99,102,241,0.18); }

/* Output port row — generous click area */
.vs-port-out-anchor {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 7px 10px 7px 12px;
  cursor: crosshair;
  gap: 8px;
  min-height: 32px;
  transition: background 0.12s;
}
.vs-port-out-anchor:hover { background: rgba(255,255,255,0.04); }
.vs-port-out-anchor:hover .vs-port-dot {
  background: var(--port-color, #94a3b8);
  box-shadow: 0 0 8px var(--port-color, #94a3b8);
  transform: scale(1.25);
}

.vs-port-label {
  font-size: 10.5px;
  color: #52525b;
  font-weight: 500;
  transition: color 0.12s;
}
.vs-port-out-anchor:hover .vs-port-label { color: var(--port-color, #94a3b8); }

.vs-port-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2.5px solid var(--port-color, #94a3b8);
  background: #09090b;
  flex-shrink: 0;
  transition: background 0.15s, box-shadow 0.15s, transform 0.1s;
  pointer-events: none;
}
.vs-port-in-anchor .vs-port-dot {
  width: 14px;
  height: 14px;
  border-color: #6366f1;
  border-width: 2.5px;
  --port-color: #6366f1;
}
.vs-port-in-anchor:hover .vs-port-dot {
  background: #6366f1;
  box-shadow: 0 0 8px #6366f1;
  transform: scale(1.3);
}

/* When in connecting mode, show crosshair cursor everywhere */
.vs-canvas-wrap.vs-connecting { cursor: crosshair !important; }
.vs-canvas-wrap.vs-connecting .vs-node-wrap { cursor: crosshair; }
.vs-canvas-wrap.vs-connecting .vs-node-header { cursor: crosshair; }

/* Snap-target highlight — applied via JS when dragging a connection nearby */
.vs-port-in-anchor.vs-port-snap-target .vs-port-dot {
  background: #6366f1;
  box-shadow: 0 0 14px #818cf8, 0 0 4px #818cf8;
  transform: scale(1.5);
  border-color: #a5b4fc;
}
.vs-port-in-anchor.vs-port-snap-target {
  background: rgba(99,102,241,0.2);
}

/* Entry node badge */
.vs-node-entry-badge {
  display: inline-block;
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: rgba(255,255,255,0.12);
  color: rgba(255,255,255,0.7);
  padding: 1px 5px;
  border-radius: 3px;
}

/* ── Output panel ── */
.vs-output {
  width: 300px;
  flex-shrink: 0;
  background: #111113;
  border-left: 1px solid #27272a;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.vs-output-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid #27272a;
  flex-shrink: 0;
  font-size: 13px;
  font-weight: 600;
  color: #a1a1aa;
}
.vs-output-btns { display: flex; gap: 6px; }

.vs-messages {
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex-shrink: 0;
  max-height: 160px;
  overflow-y: auto;
}
.vs-messages:empty { display: none; }
.vs-msg {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  font-size: 11.5px;
  padding: 6px 9px;
  border-radius: 6px;
  line-height: 1.4;
}
.vs-msg svg { flex-shrink: 0; margin-top: 1px; }
.vs-msg-error { background: rgba(239,68,68,0.12); color: #fca5a5; border: 1px solid rgba(239,68,68,0.2); }
.vs-msg-warn  { background: rgba(245,158,11,0.12); color: #fcd34d; border: 1px solid rgba(245,158,11,0.2); }
.vs-msg-ok    { background: rgba(34,197,94,0.12);  color: #86efac;  border: 1px solid rgba(34,197,94,0.2); }

.vs-output-placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: #3f3f46;
  padding: 24px;
  text-align: center;
}
.vs-output-placeholder p { font-size: 13px; color: #52525b; line-height: 1.5; }
.vs-output-placeholder strong { color: #71717a; }

.vs-code-pre {
  flex: 1;
  overflow: auto;
  margin: 0;
  padding: 14px;
  background: transparent;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  line-height: 1.7;
  color: #a78bfa;
  white-space: pre;
}
.vs-code-pre::-webkit-scrollbar { width: 5px; height: 5px; }
.vs-code-pre::-webkit-scrollbar-thumb { background: #3f3f46; border-radius: 3px; }

/* ── Node picker popup ── */
.vs-picker {
  position: fixed;
  z-index: 1000;
  background: #18181b;
  border: 1px solid #3f3f46;
  border-radius: 10px;
  box-shadow: 0 16px 48px rgba(0,0,0,0.6);
  min-width: 200px;
  max-height: 380px;
  overflow-y: auto;
  padding: 6px;
}
.vs-picker::-webkit-scrollbar { width: 4px; }
.vs-picker::-webkit-scrollbar-thumb { background: #3f3f46; border-radius: 2px; }

.vs-picker-search {
  padding: 6px 4px 4px;
  border-bottom: 1px solid #27272a;
  margin-bottom: 4px;
}
.vs-picker-search input {
  width: 100%;
  background: #09090b;
  border: 1px solid #27272a;
  border-radius: 6px;
  color: #e4e4e7;
  font-size: 12px;
  padding: 6px 10px;
  outline: none;
  box-sizing: border-box;
}

.vs-picker-group-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #52525b;
  padding: 6px 10px 2px;
}
.vs-picker-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12.5px;
  color: #a1a1aa;
  transition: background 0.1s, color 0.1s;
}
.vs-picker-item:hover { background: #27272a; color: #e4e4e7; }
.vs-picker-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ── Context menu for connections ── */
.vs-conn-ctx {
  position: fixed;
  z-index: 1000;
  background: #18181b;
  border: 1px solid #3f3f46;
  border-radius: 7px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  padding: 4px;
}
.vs-conn-ctx button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: #fca5a5;
  font-size: 12.5px;
  padding: 6px 12px;
  border-radius: 5px;
  cursor: pointer;
}
.vs-conn-ctx button:hover { background: rgba(239,68,68,0.1); }
