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

body {
  width: 100vw; height: 100vh; overflow: hidden;
  background: #0d1117;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ── Canvas ── */
#wrap {
  position: fixed; inset: 0;
  overflow: hidden;
  background-image: radial-gradient(circle, #21262d 1px, transparent 0);
  background-size: 28px 28px;
}

#canvas {
  position: absolute; top: 0; left: 0;
  transform-origin: 0 0;
  will-change: transform;
}

#svg-tails {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  overflow: visible;
}

#svg-links {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  overflow: visible;
}

/* ── Nodes ── */
.node {
  position: absolute;
  display: flex; flex-direction: column;
  background: #161b22;
  /*border: 1px solid var(--nb, #30363d);*/
  border: 2px solid var(--nb, #30363d);
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.55);
  min-width: 320px; min-height: 120px;
  user-select: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  z-index: 1;
}

/* ── Frame nodes ── */
.frame-node {
  position: absolute;
  background: var(--fn-bg, rgba(13,31,64,0.55));
  /*border-width: 3px;*/
  border-width: 1px;
  border-style: solid !important;
  border-color: var(--fn-border, rgba(56,139,253,0.38));
  border-radius: 12px;
  min-width: 120px; min-height: 60px;
  user-select: none;
  z-index: 0;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.frame-node.selected {
  border-color: var(--fn-border-sel, #388bfd);
  box-shadow: 0 0 0 2px var(--fn-glow, rgba(56,139,253,0.28));
}
.frame-node.multi-selected {
  border-color: var(--fn-border-sel, #388bfd);
  box-shadow: 0 0 0 2px var(--fn-glow, rgba(56,139,253,0.28));
}
.frame-node.dragging { opacity: 0.6; }

.frame-header {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 10px;
  background: var(--fn-header-bg, rgba(28,33,40,0.55));
  border-bottom: 1px solid var(--fn-border, rgba(56,139,253,0.25));
  border-radius: 10px 10px 0 0;
  cursor: grab; min-height: 34px;
}
.frame-header:active { cursor: grabbing; }
.frame-label {
  font-size: var(--frame-font-size, 12px); font-weight: 600; letter-spacing: 0.3px;
  font-family: var(--frame-font-family, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif);
  color: var(--fn-label, #79c0ff);
  flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.frame-header .node-actions { opacity: 0; transition: opacity 0.15s; }
.frame-node:hover .frame-header .node-actions,
.frame-node.selected .frame-header .node-actions { opacity: 1; }
.frame-header .inp-title {
  border: none; outline: none;
  font-size: var(--frame-font-size, 12px); font-weight: 600; color: var(--fn-label, #79c0ff);
  font-family: var(--frame-font-family, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif);
  background: transparent; width: 0; flex: 1; min-width: 0;
}
.node.selected {
  border-color: var(--nb-sel, #388bfd);
  box-shadow: 0 0 0 3px var(--nb-glow, rgba(56,139,253,0.22)), 0 8px 32px rgba(0,0,0,0.55);
}
.node.multi-selected {
  border-color: var(--nb-sel, #388bfd);
  box-shadow: 0 0 0 3px var(--nb-glow-m, rgba(56,139,253,0.35)), 0 8px 32px rgba(0,0,0,0.55);
}
.node.dragging {
  opacity: 0.5;
}

.node-header {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  background: #1c2128;
  border-bottom: 1px solid #30363d;
  border-radius: 10px 10px 0 0;
  cursor: grab; min-height: 40px;
}
.node-header:active { cursor: grabbing; }

.lang-badge {
  font-size: 10px; font-weight: 600; font-family: monospace;
  letter-spacing: 0.5px; text-transform: uppercase;
  padding: 2px 7px; border-radius: 3px;
  background: rgba(110,118,129,0.2); color: #8b949e; border: 1px solid #484f58;
  white-space: nowrap; flex-shrink: 0;
}

.node-actions {
  display: flex; align-items: center; gap: 4px;
  opacity: 0; transition: opacity 0.15s;
  flex-shrink: 0;
  margin-left: auto;
}
.node:hover .node-actions,
.node.selected .node-actions { opacity: 1; }
.node-actions .lang-badge { opacity: 0.5; transition: opacity 0.15s; }
.node:hover .node-actions .lang-badge,
.node.selected .node-actions .lang-badge { opacity: 1; }

.node-btn {
  padding: 3px 8px; font-size: 11px;
  border-radius: 4px; border: 1px solid #30363d;
  background: #21262d; color: #c9d1d9;
  cursor: pointer; white-space: nowrap;
}
.node-btn:hover { background: #30363d; }
.node-btn.danger { border-color: #da3633; color: #f85149; }
.node-btn.danger:hover { background: #3d1f1e; }

.node-meta {
  flex: 1 1 auto;
  min-width: 0;
  display: flex; flex-direction: column; gap: 2px;
  max-width: 240px;
}
.node-title {
  font-size: 13px; font-weight: 700; color: #e6edf3;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  background: var(--na-bg, rgba(56,139,253,0.15));
  border-left: 3px solid var(--na, #388bfd);
  padding: 1px 6px;
  border-radius: 2px;
}
.node-filepath {
  font-size: 11px; color: #79c0ff; font-family: monospace;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  background: rgba(121,192,255,0.08);
  padding: 1px 6px;
  border-radius: 2px;
}

.node-meta input {
  border: none; outline: none; width: 100%; min-width: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}
.node-meta .inp-title {
  font-size: 13px; font-weight: 700; color: #e6edf3;
  background: var(--na-bg, rgba(56,139,253,0.15));
  border-left: 3px solid var(--na, #388bfd) !important;
  padding: 1px 6px; border-radius: 2px;
}
.node-meta .inp-filepath {
  font-size: 11px; color: #79c0ff; font-family: monospace;
  background: rgba(121,192,255,0.08);
  padding: 1px 6px; border-radius: 2px;
}
.node-meta input::placeholder { color: #484f58; font-weight: 400; }

.node-body {
  flex: 1; overflow: auto; position: relative;
  border-radius: 0 0 10px 10px;
  user-select: text;
}

.node-body pre {
  margin: 0; padding: 14px 16px;
  font-size: var(--node-font-size, 12.5px); line-height: 1.25;
  font-family: var(--node-font-family, 'Source Code Pro', 'Menlo', 'Cascadia Mono', 'Consolas', 'DejaVu Sans Mono', 'Liberation Mono', 'Ubuntu Mono', monospace);
  font-variant-ligatures: none;
  white-space: pre-wrap; word-break: break-word;
  user-select: text;
}
.node-body pre code.hljs {
  background: transparent !important; padding: 0 !important;
  font-family: inherit;
  user-select: text;
}

.node-body textarea {
  width: 100%; height: 100%; display: block;
  background: #0d1117; color: #e6edf3;
  border: none; outline: none;
  padding: 14px 16px;
  font-size: var(--node-font-size, 12.5px); line-height: 1.25; tab-size: 2;
  font-family: var(--node-font-family, 'Source Code Pro', 'Menlo', 'Cascadia Mono', 'Consolas', 'DejaVu Sans Mono', 'Liberation Mono', 'Ubuntu Mono', monospace);
  resize: none; border-radius: 0 0 10px 10px;
}
.node-body textarea::placeholder { color: #3d444d; }

.resize-handle {
  position: absolute; bottom: 0; right: 0;
  width: 20px; height: 20px;
  cursor: se-resize; border-radius: 0 0 10px 0;
  z-index: 12;
}

.resize-edge {
  position: absolute; z-index: 11;
}
.resize-edge-n { top: -3px;    left: 8px;  right: 8px;  height: 6px; cursor: ns-resize; }
.resize-edge-s { bottom: -3px; left: 8px;  right: 24px; height: 6px; cursor: ns-resize; }
.resize-edge-e { right: -3px;  top: 8px;   bottom: 24px; width: 6px; cursor: ew-resize; }
.resize-edge-w { left: -3px;   top: 8px;   bottom: 8px;  width: 6px; cursor: ew-resize; }
.resize-handle::after {
  content: '';
  position: absolute; bottom: 5px; right: 5px;
  width: 7px; height: 7px;
  border-right: 2px solid #484f58; border-bottom: 2px solid #484f58;
  border-radius: 1px;
}

/* link anchors inside highlighted code */
.link-anchor {
  background: rgba(56,139,253,0.18);
  border-bottom: 1.5px solid #388bfd;
  border-radius: 2px; cursor: pointer; padding: 0 1px;
}
.link-anchor:hover { background: rgba(56,139,253,0.35); }

.tail-anchor {
  background: rgba(57,197,207,0.18);
  border-bottom: 1.5px solid #39c5cf;
  border-radius: 2px; padding: 0 1px;
}
.tail-anchor:hover { background: rgba(57,197,207,0.35); }

/* ── Per-node link SVG (inside #canvas, z-ordered with source node) ── */
/* Position and size are set by renderLinks() in canvas coords to fit path content.
   z-index: 1 matches .node so DOM order (SVG inserted after its source node div)
   determines the stacking: SVG appears above its source node, below later nodes. */
.node-link-svg {
  position: absolute;
  pointer-events: none;
  overflow: visible;
  z-index: 1;
}

/* ── SVG links ── */
.link-path {
  fill: none;
  opacity: 0.65;
}
.link-hit {
  fill: none; stroke: transparent; stroke-width: 12;
  cursor: context-menu; pointer-events: stroke;
}
.lk { pointer-events: none; }
.lk:hover .link-path { opacity: 1; }
.link-preview {
  fill: none; stroke: #388bfd; stroke-width: 1.5;
  opacity: 0.35; stroke-dasharray: 6 4;
  pointer-events: none;
}
.link-label {
  fill: #6e7681; font-size: 11px; font-family: monospace;
  pointer-events: none;
}

/* ── Edit menu (⚙ dropdown in edit mode) ── */
.edit-menu-wrap {
  position: relative;
}
.edit-menu {
  display: none;
  position: absolute; top: calc(100% + 4px); right: 0;
  z-index: 400;
  background: #161b22; border: 1px solid #30363d;
  border-radius: 6px; padding: 8px;
  box-shadow: 0 6px 16px rgba(0,0,0,0.5);
  min-width: 160px;
  white-space: nowrap;
}
.btn-edit-menu { font-size: 14px; padding: 2px 7px; letter-spacing: 1px; }
.edit-menu-wrap.open .edit-menu { display: flex; flex-direction: column; gap: 4px; }
.edit-menu .color-swatches { margin-bottom: 4px; }
.edit-menu .node-btn {
  text-align: left; width: 100%;
}
.edit-menu .menu-sep {
  height: 1px; background: #30363d; margin: 4px 0;
}
.font-controls {
  display: flex; gap: 4px; align-items: center; margin-bottom: 4px;
}
.font-controls select,
.font-controls input[type="number"] {
  background: #21262d; color: #c9d1d9;
  border: 1px solid #30363d; border-radius: 4px;
  font-size: 11px; padding: 2px 4px;
  outline: none;
}
.font-controls select { cursor: pointer; }
.font-controls select:hover,
.font-controls input[type="number"]:hover { border-color: #484f58; }
.font-controls input[type="number"]:focus { border-color: #388bfd; }
.font-controls .sel-font-family { flex: 1; min-width: 0; }
.font-controls .inp-font-size { width: 66px; flex-shrink: 0; }
.font-controls input[type="number"]::-webkit-inner-spin-button { opacity: 0.5; }

/* ── Link context menu ── */
#link-ctx {
  position: fixed; z-index: 310;
  background: #161b22; border: 1px solid #30363d;
  border-radius: 6px; padding: 8px;
  box-shadow: 0 6px 16px rgba(0,0,0,0.5);
  display: none; min-width: 200px;
}
.link-ctx-row {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 4px;
}
.link-ctx-label {
  font-size: 11px; color: #8b949e; width: 36px; flex-shrink: 0;
}
#link-ctx-colors, #link-ctx-widths, #link-ctx-dashes {
  display: flex; gap: 4px; flex-wrap: wrap;
}
.lk-color-swatch {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid transparent; cursor: pointer;
  transition: transform 0.1s;
}
.lk-color-swatch:hover { transform: scale(1.2); }
.lk-color-swatch.active { border-color: #e6edf3; }
.lk-width-btn, .lk-dash-btn {
  background: #21262d; border: 1px solid #30363d;
  border-radius: 4px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  padding: 2px 6px; height: 24px;
}
.lk-width-btn:hover, .lk-dash-btn:hover { border-color: #58a6ff; }
.lk-width-btn.active, .lk-dash-btn.active { border-color: #388bfd; background: #1f3a5f; }
.lk-width-btn svg, .lk-dash-btn svg { display: block; }
.link-ctx-sep {
  height: 1px; background: #30363d; margin: 6px 0;
}
#link-ctx button#link-ctx-goto-from,
#link-ctx button#link-ctx-goto-to,
#link-ctx button#link-ctx-reverse,
#link-ctx button#link-ctx-del {
  display: block; width: 100%;
  background: none; border: none;
  padding: 6px 10px; font-size: 13px; text-align: left;
  border-radius: 4px; cursor: pointer; white-space: nowrap;
}
#link-ctx button#link-ctx-goto-from,
#link-ctx button#link-ctx-goto-to,
#link-ctx button#link-ctx-reverse { color: #58a6ff; }
#link-ctx button#link-ctx-goto-from:hover,
#link-ctx button#link-ctx-goto-to:hover,
#link-ctx button#link-ctx-reverse:hover { background: #1f3a5f; color: #79c0ff; }
#link-ctx button#link-ctx-del { color: #e6edf3; }
#link-ctx button#link-ctx-del:hover { background: #da3633; color: #fff; }

/* ── Free lines ── */
body.line-draw-mode,
body.line-draw-mode * { cursor: crosshair !important; }
#btn-add-line.active { background: #1f3a5f; border-color: #388bfd; color: #58a6ff; }
.fl { pointer-events: none; }
.fl-path { fill: none; opacity: 0.85; }
.fl-hit {
  fill: none; stroke: transparent; stroke-width: 14;
  cursor: pointer; pointer-events: stroke;
}
.fl:hover .fl-path { opacity: 1; }
.fl-pt-handle { pointer-events: none; } /* overridden inline when selected */

/* ── Line context menu ── */
#line-ctx {
  position: fixed; z-index: 310;
  background: #161b22; border: 1px solid #30363d;
  border-radius: 6px; padding: 8px;
  box-shadow: 0 6px 16px rgba(0,0,0,0.5);
  display: none; min-width: 210px;
}
#line-ctx-colors, #line-ctx-widths, #line-ctx-dashes { display: flex; gap: 4px; flex-wrap: wrap; }
#line-ctx-shapes { display: flex; gap: 4px; }
.fl-shape-btn {
  background: #21262d; border: 1px solid #30363d;
  border-radius: 4px; cursor: pointer; color: #c9d1d9;
  padding: 3px 10px; font-size: 11px;
}
.fl-shape-btn:hover { border-color: #58a6ff; }
.fl-shape-btn.active { border-color: #388bfd; background: #1f3a5f; color: #58a6ff; }
#line-ctx button#line-ctx-del {
  display: block; width: 100%;
  background: none; border: none; color: #e6edf3;
  padding: 6px 10px; font-size: 13px; text-align: left;
  border-radius: 4px; cursor: pointer; white-space: nowrap;
}
#line-ctx button#line-ctx-del:hover { background: #da3633; color: #fff; }

/* ── Toolbar ── */
#toolbar {
  position: fixed; top: 14px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px;
  padding: 8px 16px;
  background: #161b22; border: 1px solid #30363d; border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
  z-index: 200; white-space: nowrap; user-select: none;
}
#toolbar .logo { color: #388bfd; font-weight: 700; font-size: 14px; }
#toolbar .sep { width: 1px; height: 18px; background: #30363d; flex-shrink: 0; }
.help-dialog { width: 420px; }
.help-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-bottom: 20px; }
.help-table th {
  text-align: left; color: #8b949e; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.4px;
  padding: 12px 0 4px; border-bottom: 1px solid #21262d;
}
.help-table td { padding: 5px 8px 5px 0; color: #e6edf3; vertical-align: middle; }
.help-table td:last-child { color: #8b949e; }
kbd {
  display: inline-block; padding: 1px 5px; font-size: 11px;
  font-family: 'Source Code Pro', 'Menlo', 'Cascadia Mono', 'Consolas', 'DejaVu Sans Mono', 'Liberation Mono', 'Ubuntu Mono', monospace;
  background: #21262d; border: 1px solid #30363d; border-radius: 4px;
  color: #e6edf3; line-height: 1.6;
}

#canvas-title {
  font-size: 14px; font-weight: 700; color: #e6edf3;
  background: transparent; border: none; outline: none;
  min-width: 80px; max-width: 420px; width: auto;
  font-family: inherit;
}
#canvas-title::placeholder { color: #484f58; font-weight: 400; }
#canvas-title:focus { color: #fff; }
.tb-btn {
  padding: 5px 12px; font-size: 12px;
  border: 1px solid #30363d; border-radius: 6px;
  background: #21262d; color: #c9d1d9; cursor: pointer;
}
.tb-btn:hover { background: #30363d; }
.tb-btn.danger { border-color: #da3633; color: #f85149; }
.tb-btn.danger:hover { background: #3d1f1e; }
.tb-btn.active { background: #1f6feb33; border-color: #388bfd; color: #58a6ff; }

/* ── Navigator panel ── */
#navigator-panel {
  position: fixed;
  background: #161b22; border: 1px solid #30363d; border-radius: 8px;
  padding: 6px 0; min-width: 260px; max-height: 400px;
  overflow-y: auto; z-index: 500;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}
.nav-section {
  padding: 6px 12px 2px;
  font-size: 10px; font-weight: 700; color: #484f58;
  text-transform: uppercase; letter-spacing: 0.6px;
}
.nav-item {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr) minmax(0, 2fr) 52px;
  align-items: center; column-gap: 8px;
  padding: 5px 14px; font-size: 12px; color: #c9d1d9;
  cursor: pointer; white-space: nowrap;
}
/* Items without a path column: label spans across path and sub columns */
.nav-item:not(.nav-has-path) .nav-label { grid-column: 2 / 5; }
.nav-item:hover { background: #21262d; color: #e6edf3; }
.nav-item .nav-icon { font-size: 11px; }
.nav-item .nav-label { overflow: hidden; text-overflow: ellipsis; }
.nav-item .nav-path { overflow: hidden; text-overflow: ellipsis; color: #484f58; font-size: 11px; }
.nav-item .nav-sub { color: #484f58; font-size: 11px; text-align: right; overflow: hidden; text-overflow: ellipsis; }
.nav-empty { padding: 4px 14px 6px; font-size: 12px; color: #484f58; font-style: italic; }
.nav-divider { height: 1px; background: #21262d; margin: 4px 0; }
.nav-search-wrap { padding: 6px 10px 6px; border-bottom: 1px solid #21262d; }
.nav-search {
  width: 100%; box-sizing: border-box;
  background: #0d1117; border: 1px solid #30363d; border-radius: 6px;
  color: #c9d1d9; font-size: 12px; padding: 4px 8px;
  outline: none;
}
.nav-search:focus { border-color: #58a6ff; }

.zoom-ctrl {
  display: flex; align-items: center; gap: 2px;
}
.zoom-btn {
  padding: 3px 7px; font-size: 11px;
  border: 1px solid #30363d; border-radius: 6px;
  background: #21262d; color: #c9d1d9; cursor: pointer;
  line-height: 1;
}
.zoom-btn:hover { background: #30363d; }
#btn-zoom-fit { font-size: 16px; padding: 3px 6px; }
#btn-zoom-out, #btn-zoom-in { font-size: 16px; }
.zoom-input {
  width: 48px; text-align: center; font-size: 12px;
  border: 1px solid #30363d; border-radius: 6px;
  background: #21262d; color: #c9d1d9;
  padding: 3px 4px; outline: none; cursor: default;
  font-family: inherit;
}
.zoom-input:focus { border-color: #388bfd; cursor: text; }

/* ── Link tooltip ── */
#link-tip {
  position: fixed; z-index: 300;
  background: #0f1f3d; border: 1px solid #1f4080;
  border-radius: 6px; padding: 4px;
  box-shadow: 0 3px 12px rgba(0,0,0,0.55);
  display: none; white-space: nowrap;
  transform: translateX(-50%);
  pointer-events: auto;
}
#link-tip button {
  display: block; width: 100%;
  background: none; border: none; color: #a8c8f8;
  padding: 6px 14px; font-size: 12px; text-align: left;
  border-radius: 4px; cursor: pointer; white-space: nowrap;
}
#link-tip button:hover { background: #1f6feb; color: #fff; }

/* ── Anchor context menu (right-click on link-anchor span) ── */
#anchor-ctx {
  position: fixed; z-index: 300;
  background: #0f1f3d; border: 1px solid #1f4080;
  border-radius: 6px; padding: 4px;
  box-shadow: 0 3px 12px rgba(0,0,0,0.55);
  display: none; white-space: nowrap;
  pointer-events: auto;
}
#anchor-ctx button {
  display: block; width: 100%;
  background: none; border: none; color: #a8c8f8;
  padding: 6px 14px; font-size: 12px; text-align: left;
  border-radius: 4px; cursor: pointer; white-space: nowrap;
}
#anchor-ctx button:hover { background: #1f6feb; color: #fff; }

#tail-anchor-ctx {
  position: fixed; z-index: 300;
  background: #061a1d; border: 1px solid #144a50;
  border-radius: 6px; padding: 4px;
  box-shadow: 0 3px 12px rgba(0,0,0,0.55);
  display: none; white-space: nowrap;
  pointer-events: auto;
}
#tail-anchor-ctx button {
  display: block; width: 100%;
  background: none; border: none; color: #56d4dd;
  padding: 6px 14px; font-size: 12px; text-align: left;
  border-radius: 4px; cursor: pointer; white-space: nowrap;
}
#tail-anchor-ctx button:hover { background: #39c5cf; color: #0d1117; }

/* ── Status bar ── */
#status {
  position: fixed; bottom: 14px; left: 50%; transform: translateX(-50%);
  background: #161b22; border: 1px solid #30363d; border-radius: 6px;
  padding: 4px 14px; font-size: 11px; color: #6e7681;
  z-index: 200; pointer-events: none; white-space: nowrap;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}
body.link-mode #status {
  background: #1b2f1b; border-color: #3fb950; color: #3fb950;
}

/* ── Link mode ── */
body.link-mode #wrap { cursor: crosshair !important; }
body.link-mode .node { cursor: pointer !important; }
body.link-mode .node:hover {
  border-color: #3fb950 !important;
  box-shadow: 0 0 0 3px rgba(63,185,80,0.22) !important;
}

/* ── Tail attach mode ── */
body.tail-attach-mode #status {
  background: #061a1d; border-color: #39c5cf; color: #39c5cf;
}
body.tail-attach-mode #wrap { cursor: crosshair !important; }
body.tail-attach-mode .bubble-node { cursor: pointer !important; }
body.tail-attach-mode .bubble-node:hover {
  border-color: #39c5cf !important;
  box-shadow: 0 0 0 3px rgba(57,197,207,0.22) !important;
}

/* ── Mode indicator ── */
#mode-indicator {
  font-size: 11px; color: #6e7681;
  padding: 2px 8px; border-radius: 4px;
  border: 1px solid #30363d;
  background: #21262d;
  font-family: monospace; letter-spacing: 0.5px;
}

/* ── Line Numbers ── */
.code-line { display: block; white-space: pre-wrap; word-break: break-word; }
.has-ln { padding-left: 0 !important; }
.ln-num {
  display: inline-block; min-width: 2.8em;
  padding-right: 8px; margin-right: 8px;
  text-align: right; color: #484f58;
  border-right: 1px solid #21262d;
  cursor: pointer; user-select: none;
  font-size: 11px; vertical-align: top;
  transition: color 0.1s;
}
.ln-num:hover { color: #8b949e; }
.ln-num-input {
  display: inline-block; width: 3.2em;
  padding: 0 4px; margin-right: 8px;
  background: #1f6feb; color: #fff;
  border: none; border-radius: 3px;
  font-size: 11px; font-family: 'Source Code Pro', 'Menlo', 'Cascadia Mono', 'Consolas', 'DejaVu Sans Mono', 'Liberation Mono', 'Ubuntu Mono', monospace;
  text-align: right; outline: none; vertical-align: top;
}
.ln-toggle {
  font-size: 10px; color: #6e7681;
  display: flex; align-items: center; gap: 3px;
  cursor: pointer; user-select: none; white-space: nowrap;
}
.ln-toggle input[type=checkbox] { margin: 0; cursor: pointer; accent-color: #388bfd; }
.ln-toggle:hover { color: #8b949e; }

/* ── Inline editable meta (title / filepath) ── */
.node-title.editable-meta,
.node-filepath.editable-meta { cursor: text; }
.node-title.meta-empty  { opacity: 0.28; font-weight: 400; font-style: italic; }
.node-filepath.meta-empty { opacity: 0.28; font-style: italic; }

/* ── Text nodes ── */
.text-node {
  position: absolute;
  display: flex; flex-direction: column;
  background: transparent;
  border: 2px dashed transparent;
  border-radius: 6px;
  min-width: 60px; min-height: 30px;
  user-select: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  z-index: 1;
}
.text-node:hover {
  border-color: rgba(255,255,255,0.18);
}
.text-node.selected {
  border-color: var(--tn-color, #e6edf3);
  box-shadow: 0 0 0 2px var(--tn-glow, rgba(230,237,243,0.15));
}
.text-node.multi-selected {
  border-color: var(--tn-color, #e6edf3);
  box-shadow: 0 0 0 2px var(--tn-glow, rgba(230,237,243,0.15));
}
.text-node.is-editing {
  border-color: var(--tn-color, #e6edf3);
  border-style: solid;
  box-shadow: 0 0 0 2px var(--tn-glow, rgba(230,237,243,0.15));
}
.text-node.dragging { opacity: 0.6; }

.text-node-header {
  display: flex; align-items: center;
  justify-content: flex-end;
  padding: 2px 4px;
  min-height: 26px;
  cursor: grab;
}
.text-node-header:active { cursor: grabbing; }
.text-node-header .node-actions {
  opacity: 0;
  margin-left: auto;
}
.text-node:hover .text-node-header .node-actions,
.text-node.selected .text-node-header .node-actions,
.text-node.is-editing .text-node-header .node-actions { opacity: 1; }

.text-body {
  flex: 1;
  display: flex;
  padding: 4px 8px 8px;
  overflow: hidden;
  cursor: text;
}
.text-content {
  font-size: var(--text-font-size, 20px);
  font-family: var(--text-font-family, system-ui, sans-serif);
  color: var(--tn-color, #e6edf3);
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.35;
  user-select: text;
  flex: 1;
}
.text-content-empty {
  opacity: 0.3;
  font-style: italic;
}
.text-textarea {
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  font-size: var(--text-font-size, 20px);
  font-family: var(--text-font-family, system-ui, sans-serif);
  color: var(--tn-color, #e6edf3);
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.35;
  padding: 0;
}
.edit-menu-section-label {
  font-size: 10px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.5px; color: #8b949e;
  padding: 2px 4px 4px;
}

/* ── Bubble nodes ── */
.bubble-node {
  background: var(--bn-bg, #162116);
  /*border: 2px solid var(--bn-border, #3fb950);*/
  border: 3px solid var(--bn-border, #3fb950);
  border-radius: 14px;
  min-width: 120px; min-height: 60px;
  opacity: 0.8;
  transition: border-top-left-radius 0.15s, border-top-right-radius 0.15s;
}
.bubble-node.selected {
  border-color: var(--bn-border-sel, #56d364);
  box-shadow: 0 0 0 3px var(--bn-glow-sel, rgba(63,185,80,0.28)), 0 8px 32px rgba(0,0,0,0.55);
}
.bubble-node.multi-selected {
  border-color: var(--bn-border-sel, #56d364);
  box-shadow: 0 0 0 3px var(--bn-glow-msel, rgba(63,185,80,0.42)), 0 8px 32px rgba(0,0,0,0.55);
}
.bubble-header {
  position: absolute;
  bottom: calc(100% - 3px); /* overlap the bubble's top border by 3px */
  left: -3px; right: -3px;
  display: flex; align-items: center; justify-content: flex-end;
  padding: 5px 10px; min-height: 34px;
  background: var(--bh-bg, #1b2e1b);
  border: 3px solid var(--bn-border, #3fb950);
  border-bottom: none;
  border-radius: 12px 12px 0 0;
  cursor: grab;
  opacity: 0; pointer-events: none;
  transition: opacity 0.15s;
  z-index: 1;
}
.bubble-header:active { cursor: grabbing; }
.bubble-node:hover .bubble-header,
.bubble-node.is-editing .bubble-header {
  opacity: 1; pointer-events: auto;
}
.bubble-node:hover,
.bubble-node.is-editing {
  border-top-left-radius: 0;
  border-top-right-radius: 0;
}
.bubble-node.drag-released .bubble-header {
  opacity: 0 !important; pointer-events: none !important;
}
.bubble-node:hover .bubble-header .node-actions,
.bubble-node.is-editing .bubble-header .node-actions { opacity: 1; }
.bubble-tail-toggle {
  display: flex; align-items: center; gap: 4px;
  font-size: 11px; color: #8b949e;
  cursor: pointer; user-select: none;
  margin-right: 4px;
}
.bubble-tail-toggle input { cursor: pointer; }
.bubble-body {
  flex: 1; padding: 10px 14px 14px;
  overflow: auto;
  display: flex; flex-direction: column; justify-content: center;
}
.bubble-text {
  font-size: var(--bubble-font-size, 13px); color: #e6edf3; line-height: 1.65;
  font-family: var(--bubble-font-family, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif);
  white-space: pre-wrap; word-break: break-word;
  user-select: text;
}
.bubble-text.empty { color: #484f58; font-style: italic; }
.bubble-textarea {
  width: 100%; height: 100%; min-height: 50px; display: block;
  background: transparent; color: #e6edf3;
  border: none; outline: none; resize: none;
  font-size: var(--bubble-font-size, 13px); line-height: 1.65;
  font-family: var(--bubble-font-family, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif);
}
/* tail inline SVG (inside bubble div, so z-order follows bubble) */
.bubble-tail-svg {
  position: absolute;
  pointer-events: none;
}
.bubble-tail-poly { pointer-events: none; }
.tail-handle { cursor: move; pointer-events: all; }

/* ── Marquee selection ── */
#marquee {
  position: fixed;
  border: 1px solid rgba(56,139,253,0.7);
  background: rgba(56,139,253,0.08);
  border-radius: 2px;
  pointer-events: none;
  display: none;
  z-index: 150;
}

/* ── Color swatches ── */
.color-swatches {
  display: flex; align-items: center; gap: 3px;
  padding-right: 4px;
}
.color-swatch {
  width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer; flex-shrink: 0;
  transition: transform 0.1s, border-color 0.1s;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.5);
}
.color-swatch:hover { transform: scale(1.3); }
.color-swatch.active { border-color: #fff; }

/* ── Global Config Dialog ── */
#global-config-overlay,
#repo-dialog-overlay,
#fetch-dialog-overlay,
#codesnippetd-dialog-overlay,
#help-dialog-overlay,
#group-dialog-overlay {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(0,0,0,0.65);
  display: flex; align-items: center; justify-content: center;
}
.git-dialog {
  background: #161b22; border: 1px solid #30363d; border-radius: 12px;
  padding: 24px 28px; width: 480px; max-width: 92vw;
  box-shadow: 0 12px 40px rgba(0,0,0,0.75);
}
.global-config-dialog {
  width: 680px;
  max-height: 88vh;
  overflow-y: auto;
}
.gc-textarea {
  resize: vertical; min-height: 64px;
  font-family: inherit; line-height: 1.5;
}
.gc-section-label {
  font-size: 11px; font-weight: 600; color: #8b949e;
  text-transform: uppercase; letter-spacing: 0.4px;
  margin: 18px 0 8px;
}
.gc-repos-table {
  width: 100%; border-collapse: collapse;
  font-size: 12px;
  font-family: 'Source Code Pro', 'Menlo', 'Cascadia Mono', 'Consolas', 'DejaVu Sans Mono', 'Liberation Mono', 'Ubuntu Mono', monospace;
  border: 1px solid #30363d; border-radius: 6px; overflow: hidden;
}
.gc-repos-table thead th {
  background: #21262d; color: #8b949e; padding: 6px 10px;
  text-align: left; font-weight: 600; font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.4px;
}
.gc-repos-table tbody tr { border-top: 1px solid #21262d; }
.gc-repos-table tbody td {
  padding: 6px 10px; color: #e6edf3;
  max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.gc-repos-table tbody td.gc-repo-actions {
  white-space: nowrap; max-width: none; width: 1%;
}
.gc-repos-empty {
  font-size: 12px; color: #484f58; padding: 10px 0;
}
.gc-repo-btn {
  background: none; border: 1px solid #30363d; border-radius: 4px;
  color: #8b949e; font-size: 11px; padding: 2px 8px; cursor: pointer;
  margin-left: 4px;
}
.gc-repo-btn:hover { color: #e6edf3; border-color: #8b949e; }
.gc-repo-btn.del:hover { color: #f85149; border-color: #f85149; }
.git-form-select {
  appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%238b949e'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
  padding-right: 28px;
}
.git-dialog-title {
  font-size: 15px; font-weight: 700; color: #e6edf3;
  margin-bottom: 20px; display: flex; align-items: center; gap: 8px;
}
.git-form-row { margin-bottom: 14px; }
.git-form-label {
  display: block; font-size: 11px; font-weight: 600;
  color: #8b949e; margin-bottom: 5px; text-transform: uppercase;
  letter-spacing: 0.4px;
}
.git-form-input {
  width: 100%; padding: 7px 10px;
  background: #0d1117; border: 1px solid #30363d;
  border-radius: 6px; color: #e6edf3; font-size: 13px;
  font-family: 'Source Code Pro', 'Menlo', 'Cascadia Mono', 'Consolas', 'DejaVu Sans Mono', 'Liberation Mono', 'Ubuntu Mono', monospace;
  outline: none; transition: border-color 0.15s;
}
.git-form-input:focus { border-color: #388bfd; }
.git-form-input::placeholder { color: #484f58; font-style: italic; }
.git-form-divider {
  text-align: center; font-size: 11px; color: #484f58;
  margin: 4px 0 14px; position: relative;
}
.git-form-divider::before, .git-form-divider::after {
  content: ''; position: absolute; top: 50%; width: 42%;
  height: 1px; background: #21262d;
}
.git-form-divider::before { left: 0; }
.git-form-divider::after { right: 0; }
.git-form-note {
  font-size: 11px; color: #6e7681; margin-top: 4px; min-height: 16px;
  display: flex; align-items: center; gap: 5px;
}
.git-form-note.warn { color: #f0883e; }
.git-form-note.ok   { color: #3fb950; }
.git-form-note.err  { color: #f85149; }
.git-form-buttons {
  display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px;
}
.git-btn-save {
  padding: 6px 18px; font-size: 12px; border-radius: 6px;
  background: #1f6feb; border: 1px solid #388bfd; color: #fff;
  cursor: pointer; font-weight: 600;
}
.git-btn-save:hover { background: #388bfd; }
.git-btn-save:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Codesnippetd Dialog ── */
.csd-dialog { width: 560px; }
.csd-source-radios { display: flex; flex-direction: column; gap: 6px; }
.csd-source-radio {
  display: flex; align-items: center; gap: 6px;
  font-size: 13px; color: #e6edf3; cursor: pointer;
}
.csd-source-radio input[type="radio"] { cursor: pointer; }
.csd-tabs {
  display: flex;
  border-bottom: 1px solid #30363d;
  margin-bottom: 14px;
}
.csd-tab {
  padding: 7px 18px;
  font-size: 13px;
  font-family: 'Source Code Pro', 'Menlo', 'Cascadia Mono', 'Consolas', 'DejaVu Sans Mono', 'Liberation Mono', 'Ubuntu Mono', monospace;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: #8b949e;
  cursor: pointer;
  margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s;
}
.csd-tab:hover { color: #e6edf3; }
.csd-tab.active { color: #e6edf3; border-bottom-color: #388bfd; }
#csd-table-wrap {
  max-height: 280px; overflow-y: auto;
  border: 1px solid #30363d; border-radius: 6px; margin-bottom: 10px;
}
.csd-table {
  width: 100%; border-collapse: collapse;
  font-size: 12px; font-family: 'Source Code Pro', 'Menlo', 'Cascadia Mono', 'Consolas', 'DejaVu Sans Mono', 'Liberation Mono', 'Ubuntu Mono', monospace;
}
.csd-table thead th {
  background: #21262d; color: #8b949e; padding: 7px 10px;
  text-align: left; font-weight: 600; font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.4px;
  position: sticky; top: 0;
}
.csd-table tbody tr.csd-result-row {
  border-top: 1px solid #21262d; cursor: pointer;
  transition: background 0.1s;
}
.csd-table tbody tr.csd-result-row:hover { background: #1f2937; }
.csd-table tbody td {
  padding: 7px 10px; color: #e6edf3; vertical-align: top;
}
.csd-table tbody td:first-child {
  color: #6e7681; width: 36px; text-align: right;
}
#csd-wasm-table-wrap {
  max-height: 280px; overflow-y: auto;
  border: 1px solid #30363d; border-radius: 6px; margin-top: 10px; margin-bottom: 10px;
}
.csd-wasm-row td { padding: 7px 10px; color: #e6edf3; vertical-align: top; }
.csd-wasm-row td:first-child { color: #6e7681; width: 36px; text-align: right; }
.csd-wasm-row { border-top: 1px solid #21262d; }

/* ── Arrow nodes ── */
.arrow-node {
  position: absolute;
  height: 40px;
  overflow: visible;
  background: transparent;
  border: none;
  user-select: none;
  z-index: 1;
  transform-origin: 0 50%;
  cursor: grab;
}
.arrow-node:active { cursor: grabbing; }
.arrow-node svg.arrow-svg {
  position: absolute;
  left: 0; top: 0;
  width: 100%; height: 100%;
  overflow: visible;
  pointer-events: none;
}
.arrow-shaft-glow { display: none; }
.arrow-node.selected .arrow-shaft-glow,
.arrow-node.multi-selected .arrow-shaft-glow { display: block; }
.arrow-handle {
  position: absolute;
  pointer-events: all;
  z-index: 12;
  transform: translate(-50%, -50%);
}
.arrow-body-handle {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: #388bfd;
  border: 2px solid #0d1117;
  cursor: ew-resize;
}
.arrow-head-handle {
  width: 10px; height: 10px;
  border-radius: 2px;
  background: #e3b341;
  border: 2px solid #0d1117;
  cursor: nwse-resize;
}
.arrow-rotate-handle {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: #3fb950;
  border: 2px solid #0d1117;
  cursor: crosshair;
}
.arrow-stroke-handle {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: #db61a2;
  border: 2px solid #0d1117;
  cursor: ns-resize;
}

/* ── Arrow context menu ── */
#arrow-ctx {
  position: fixed; z-index: 310;
  background: #161b22; border: 1px solid #30363d;
  border-radius: 6px; padding: 8px;
  box-shadow: 0 6px 16px rgba(0,0,0,0.5);
  display: none; min-width: 200px;
}
#arrow-ctx-colors, #arrow-ctx-widths { display: flex; gap: 4px; flex-wrap: wrap; }
.arrow-width-btn {
  background: #21262d; border: 1px solid #30363d;
  border-radius: 4px; cursor: pointer; color: #c9d1d9;
  padding: 4px 8px; font-size: 12px;
}
.arrow-width-btn:hover { border-color: #58a6ff; }
.arrow-width-btn.active { border-color: #388bfd; background: #1f3a5f; color: #58a6ff; }
#arrow-ctx button#arrow-ctx-del {
  display: block; width: 100%;
  background: none; border: none; color: #e6edf3;
  padding: 6px 10px; font-size: 13px; text-align: left;
  border-radius: 4px; cursor: pointer; white-space: nowrap;
}
#arrow-ctx button#arrow-ctx-del:hover { background: #da3633; color: #fff; }
