/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { width: 100%; height: 100%; overflow: hidden; background: #faf9f6; }
body { font-family: 'Georgia', serif; }

/* ── Canvas ── */
#app {
  width: 100vw; height: 100vh; position: relative; overflow: hidden;
  background: #faf9f6;
  background-image: radial-gradient(circle, #ddd9ce 1px, transparent 1px);
  background-size: 28px 28px;
}

/* ── Nodes ── */
.node {
  position: absolute;
  background: #fffef9;
  border-radius: 4px;
  min-width: 120px;
  max-width: 280px;
  overflow: visible;
  font-size: 13.5px;
  line-height: 1.65;
  color: #2a2820;
  cursor: grab;
  user-select: none;
  z-index: 10;
  display: flex;
  flex-direction: column;

  /* Single unified border — no double-border artefact */
  box-shadow:
    0 0 0 0.5px #c4bfb0,
    0 1px 4px rgba(0,0,0,0.05);
  transition: box-shadow .12s;
}

.node:hover {
  box-shadow:
    0 0 0 0.5px #8a8478,
    0 2px 8px rgba(0,0,0,0.08);
}

.node.selected {
  box-shadow:
    0 0 0 1.5px #5a5248,
    0 0 0 3.5px rgba(90,82,72,0.12),
    0 2px 8px rgba(0,0,0,0.08);
}

.node.edge-target {
  box-shadow:
    0 0 0 2px rgba(64,140,220,0.7),
    0 2px 8px rgba(0,0,0,0.08);
}

/* Clips node content to max-height */
.node-clip {
  display: flex;
  flex-direction: column;
  max-height: 420px;
  overflow: hidden;
  border-radius: 4px;    /* must match .node border-radius exactly */
  flex: 1;
  min-height: 0;
  position: relative;
}

.node-inner {
  padding: 10px 28px 10px 13px;
  position: relative;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.node-tag {
  font-size: 10px;
  color: #9a9080;
  letter-spacing: .06em;
  text-transform: uppercase;
  margin-bottom: 4px;
  font-family: system-ui, sans-serif;
}

.node-content {
  outline: none;
  min-height: 20px;
  word-break: break-word;
}

/* Mixed-provenance node content — two-zone layout */
.node-content-mixed {
  outline: none;
  min-height: 20px;
  word-break: break-word;
  cursor: text;
}

/* Agent zone: sealed markdown block, italic */
.span-agent {
  display: block;
  font-style: italic;
  user-select: text;
  cursor: text;
  pointer-events: all;
  /* Suppress any contenteditable focus ring */
  outline: none;

  & p { margin: 0 0 0.6em; }
  & p:last-child { margin-bottom: 0; }
  & ul, & ol { padding-left: 1.4em; margin: 0.3em 0 0.6em; list-style-position: outside; }
  & li { margin-bottom: 0.2em; }
  & strong { font-weight: 600; font-style: normal; }
  & code {
    font-family: var(--font-mono, monospace);
    font-size: 0.88em;
    background: rgba(0,0,0,0.06);
    padding: 1px 4px;
    border-radius: 2px;
    font-style: normal;
  }
}

/* User zone: editable block below agent content */
.span-user {
  display: block;
  font-style: normal;
  cursor: text;
  outline: none;
  min-height: 1em;
}

/* Keep user zone visible even when empty */
.span-user:empty::before {
  content: '';
  display: inline-block;
}

/* ── LM-authored text is italic ── */
/* Chat assistant messages and agent-authored edge labels.
   Bot/synthesis/comment nodes use .span-agent inside .node-content-mixed instead. */
.node.synthesis-node .synthesis-md,
.node.bot-node .synthesis-md,
.node.comment-node .synthesis-md,
.chat-msg.assistant,
.edge-label-overlay.lm-label .edge-label-text {
  font-style: italic;
}

/* ── Synthesis node ── */
.node.synthesis-node {
  background: #eee9de;
  box-shadow:
    0 0 0 1px #9a9080,
    0 1px 6px rgba(0,0,0,0.07);
  max-width: 320px;

  & .node-clip { max-height: 480px; }
  & .node-inner { font-style: normal; }
}
.node.synthesis-node:hover {
  box-shadow:
    0 0 0 1px #7a7060,
    0 2px 8px rgba(0,0,0,0.1);
}

.synthesis-md {
  font-style: italic;
  line-height: 1.7;
  user-select: text;
  cursor: text;

  & p { margin: 0 0 0.6em; }
  & p:last-child { margin-bottom: 0; }
  & h1, & h2, & h3 {
    font-style: normal;
    font-weight: 500;
    margin: 0.5em 0 0.3em;
    font-size: 1em;
    color: #3a3020;
  }
  & ul, & ol { padding-left: 1.2em; margin: 0.3em 0 0.6em; }
  & li { margin-bottom: 0.2em; }
  & strong { font-weight: 600; font-style: normal; color: #2a2820; }
  & em { font-style: italic; }
  & code {
    font-family: var(--font-mono, monospace);
    font-size: 0.88em;
    background: rgba(0,0,0,0.06);
    padding: 1px 4px;
    border-radius: 2px;
    font-style: normal;
  }
}

/* ── Paragraph pop-out blocks ── */
.md-block {
  position: relative;
  padding-right: 18px;

  &:last-child p,
  &:last-child li { margin-bottom: 0; }

  & .md-popout {
    position: absolute;
    right: 0; top: 1px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 9px;
    color: #c4bfb0;
    opacity: 0;
    transition: opacity .12s, color .1s;
    padding: 1px 2px;
    line-height: 1;
    font-family: system-ui, sans-serif;
  }
  &:hover .md-popout { opacity: 1; }
  & .md-popout:hover { color: #5a5248; }
}

/* ── Processing state ── */
.node.processing-node {
  background: #f0ede4;
  box-shadow: 0 0 0 1px #b8b090 inset, 0 0 0 1px #b8b090;
  min-width: 160px;
  max-width: 280px;
}
/* Dashed border on processing uses outline to avoid double-border */
.node.processing-node {
  box-shadow: none;
  outline: 1px dashed #b8b090;
}

.processing-body {
  padding: 12px 14px;
  font-family: system-ui, sans-serif;
  font-size: 12px;
  color: #7a7060;
  display: flex;
  align-items: center;
  gap: 8px;
}
.processing-spinner {
  width: 12px; height: 12px;
  border: 1.5px solid #d8d4c8;
  border-top-color: #7a6f5a;
  border-radius: 50%;
  animation: spin .8s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Cluster inference spinner ──
   Replaces the 4 score dots while a cluster is actively running inference.
   The arc rotates in place; transform-box:fill-box ensures the origin is
   the arc's own centre (cx/cy), not the SVG viewport origin. */
@keyframes cluster-spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}
.cluster-spinner {
  transform-box: fill-box;
  transform-origin: center;
  animation: cluster-spin 0.9s linear infinite;
  transition: opacity 0.18s ease;
}
/* Score dots inside the cluster hull fade when inferring */
.cluster-dot-fading {
  transition: opacity 0.18s ease;
}

/* ── Node variants ── */
.node.bot-node {
  background: #f6f4ee;
  box-shadow:
    0 0 0 0.5px #afa89a,
    0 1px 4px rgba(0,0,0,0.05);
  outline: 0.5px dashed #afa89a;
  /* dashed via outline so border-radius is preserved */
  box-shadow: none;
}
.node.bot-node:hover { outline-color: #7a7060; }

.node.comment-node {
  background: #f8f6f0;
  box-shadow:
    0 0 0 0.5px #c4bfb0,
    inset 2.5px 0 0 #9a9080;
}

.node.artifact-node {
  background: #f3f0e8;
  box-shadow: 0 0 0 1px #b8b09a, 0 1px 4px rgba(0,0,0,0.05);
  min-width: 220px;
  max-width: 340px;
}

.node.chat-node {
  background: #fffef9;
  min-width: 220px;
  max-width: 300px;
}

.node.instrument-node {
  background: #f5f2ea;
  min-width: 190px;
  max-width: 300px;
  outline: 1px dashed #a09880;
  box-shadow: none;
}

.node.image-node {
  background: #f3f0e8;
  min-width: 120px;
  max-width: 320px;

  & .node-clip { max-height: 340px; }
  & img {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 3px;
    pointer-events: none;
    user-select: none;
  }
}

/* ── Dismiss animation ── */
@keyframes node-dismiss {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to   { opacity: 0; transform: translateY(40px) scale(0.96); }
}
.node.dismissing {
  animation: node-dismiss 0.22s cubic-bezier(.4,0,.6,1) forwards;
  pointer-events: none;
}

/* ── Dismiss button ── */
.node-x {
  position: absolute;
  top: 6px; right: 7px;
  font-size: 14px;
  color: #c8c0b0;
  cursor: pointer;
  background: none;
  border: none;
  line-height: 1;
  opacity: 0;
  transition: opacity .12s;
  font-family: sans-serif;
  padding: 0;
  z-index: 3;
}
.node:hover .node-x { opacity: 1; }

/* ── Node hover bar ── */
.node-hbar {
  height: 0;
  overflow: hidden;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1px;
  opacity: 0;
  transition: opacity .15s, height .1s;
  pointer-events: none;
}
.node:hover .node-hbar {
  height: 22px;
  opacity: 1;
  pointer-events: all;
}
.node-hbar button {
  font-size: 10px;
  color: #7a7060;
  background: rgba(255,253,248,0.97);
  border: 0.5px solid #d0ccc0;
  border-top: none;
  border-radius: 0 0 3px 3px;
  padding: 3px 8px;
  cursor: pointer;
  font-family: system-ui, sans-serif;
  transition: background .1s;
  white-space: nowrap;
}
.node-hbar button:hover { background: #ede9e0; color: #2a2820; }

/* ── Provenance ── */
.prov-btn {
  font-size: 10px;
  color: #9a9080;
  cursor: pointer;
  background: none;
  border: none;
  padding: 2px 0 0;
  text-decoration: underline;
  text-underline-offset: 2px;
  font-family: system-ui, sans-serif;
  display: block;
}
.prov-body {
  display: none;
  font-size: 11px;
  color: #7a7060;
  border-top: 0.5px solid #d8d4c8;
  margin-top: 4px;
  padding-top: 4px;
  font-style: normal;
  font-family: system-ui, sans-serif;
  line-height: 1.5;
}

/* ── Chat node ── */
.chat-header {
  padding: 7px 8px 5px 11px;
  font-size: 10px;
  color: #9a9080;
  letter-spacing: .06em;
  text-transform: uppercase;
  border-bottom: 0.5px solid #e8e4da;
  font-family: system-ui, sans-serif;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.chat-header-actions { display: flex; align-items: center; gap: 4px; }

.header-btn {
  font-size: 10px;
  color: #9a9080;
  background: none;
  border: none;
  cursor: pointer;
  padding: 1px 4px;
  border-radius: 3px;
  font-family: system-ui, sans-serif;
  transition: background .1s;
  line-height: 1.4;
}
.header-btn:hover { background: #ede9e0; color: #2a2820; }

.chat-seed {
  padding: 5px 11px 4px;
  font-size: 11px;
  color: #9a9080;
  font-style: italic;
  font-family: system-ui, sans-serif;
  line-height: 1.4;
  border-bottom: 0.5px solid #e8e4da;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-msgs {
  max-height: 150px;
  overflow-y: auto;
  padding: 7px 11px;
  font-size: 12.5px;
  line-height: 1.55;
  font-family: system-ui, sans-serif;
}

.chat-msg-row {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 4px;
  margin-bottom: 5px;

  &:hover .chat-popout { opacity: 1; }
}

.chat-msg {
  flex: 1;
  color: #2a2820;
  min-width: 0;

  /* Assistant messages are LM-authored: italic */
  &.assistant {
    font-style: italic;
    color: #5a5248;
    padding-left: 9px;
    border-left: 1.5px solid #c4bfb0;
  }
  &.thinking {
    color: #9a9080;
    font-style: italic;
  }
}

.chat-popout {
  flex-shrink: 0;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 10px;
  color: #b0a890;
  opacity: 0;
  transition: opacity .12s;
  padding: 1px 2px;
  line-height: 1;
  font-family: system-ui, sans-serif;
  align-self: flex-start;
  margin-top: 1px;

  &:hover { color: #5a5248; }
}

.chat-irow {
  display: flex;
  gap: 4px;
  padding: 5px 8px;
  border-top: 0.5px solid #e8e4da;

  & input {
    flex: 1;
    border: 0.5px solid #c4bfb0;
    border-radius: 11px;
    padding: 4px 10px;
    font-size: 11.5px;
    font-family: system-ui, sans-serif;
    background: #fffef9;
    color: #2a2820;
    outline: none;

    &:focus { border-color: #7a6f5a; }
  }
}

.chat-send {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: #2a2820;
  color: #faf9f6;
  border: none;
  cursor: pointer;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* ── Instrument node ── */
.inst-header {
  padding: 7px 28px 5px 11px;
  font-size: 10px;
  color: #7a6f5a;
  letter-spacing: .06em;
  text-transform: uppercase;
  border-bottom: 0.5px solid #d8d2c4;
  font-family: system-ui, sans-serif;
  display: flex;
  align-items: center;
  gap: 6px;
}
.inst-body {
  padding: 9px 11px;
  font-family: system-ui, sans-serif;

  & label {
    font-size: 11px;
    color: #7a7060;
    display: block;
    margin-bottom: 3px;
  }
}

.ifield { margin-bottom: 8px; }
.ifield input[type=text] {
  width: 100%;
  border: 0.5px solid #c4bfb0;
  border-radius: 3px;
  padding: 4px 8px;
  font-size: 12px;
  font-family: system-ui, sans-serif;
  background: #fffef9;
  color: #2a2820;
  outline: none;
}
.ifield input[type=range] { width: 100%; accent-color: #7a6f5a; }
.ifield select {
  width: 100%;
  border: 0.5px solid #c4bfb0;
  border-radius: 3px;
  padding: 4px 7px;
  font-size: 12px;
  font-family: system-ui, sans-serif;
  background: #fffef9;
  color: #2a2820;
  outline: none;
}

.iradio-group, .icheckbox-group { display: flex; flex-direction: column; gap: 4px; margin-top: 3px; }
.iradio-opt, .icheckbox-opt { display: flex; align-items: center; gap: 10px; font-size: 12px; color: #2a2820; cursor: pointer; }
.iradio-opt input[type=radio],
.icheckbox-opt input[type=checkbox] { flex-shrink: 0; margin: 0 5px 0 0; }

.radio-other-input {
  flex: 1;
  min-width: 0;
  border: none;
  border-bottom: 0.5px solid #c4bfb0;
  background: transparent;
  font-size: 12px;
  font-family: system-ui, sans-serif;
  color: #2a2820;
  outline: none;
  padding: 0 2px;
  margin-left: 4px;
  transition: border-color .1s;

  &:focus { border-bottom-color: #7a6f5a; }
  &:disabled { color: #b0a890; cursor: default; }
}

.ibtns {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  margin-top: 8px;
  padding-top: 7px;
  border-top: 0.5px solid #e0dcd2;
}
.ibtn {
  font-size: 11.5px;
  color: #4a4030;
  background: #eee9de;
  border: 0.5px solid #c4bfb0;
  border-radius: 3px;
  padding: 4px 11px;
  cursor: pointer;
  font-family: system-ui, sans-serif;
  transition: background .1s;

  &:hover { background: #e0dcd0; }
  &.primary { background: #2a2820; color: #faf9f6; border-color: #2a2820; }
  &.primary:hover { background: #4a4438; }
}

/* ── Artifact node ── */
.artifact-title {
  font-size: 10px;
  color: #7a7060;
  letter-spacing: .06em;
  text-transform: uppercase;
  padding: 7px 28px 5px 11px;
  border-bottom: 0.5px solid #d8d4c8;
  font-family: system-ui, sans-serif;
}
.artifact-body {
  padding: 9px 11px;
  font-size: 12.5px;
  line-height: 1.6;
  color: #2a2820;
  font-family: system-ui, sans-serif;

  & table { width: 100%; border-collapse: collapse; font-size: 12px; }
  & td, & th { padding: 4px 7px; border-bottom: 0.5px solid #e0dcd2; text-align: left; }
  & th { color: #7a7060; font-weight: 500; }
}

/* ── Document node ──
   Created when the user drops a text or markdown file onto the canvas.
   Wider than default nodes; scrollable body; filename as header. */
.node.document-node {
  background: #f8f7f2;
  min-width: 220px;
  max-width: 360px;
  box-shadow:
    0 0 0 0.5px #b8b4a4,
    0 1px 5px rgba(0,0,0,0.06);
}
.node.document-node:hover {
  box-shadow:
    0 0 0 0.5px #8a8478,
    0 2px 8px rgba(0,0,0,0.09);
}
.node.document-node .node-clip { max-height: 420px; }

.doc-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 28px 6px 11px;
  border-bottom: 0.5px solid #d8d4c8;
  font-family: system-ui, sans-serif;
  min-width: 0;
}

.doc-icon {
  font-size: 13px;
  color: #9a9080;
  flex-shrink: 0;
  line-height: 1;
}

.doc-title {
  font-size: 11px;
  color: #5a5248;
  letter-spacing: .02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  flex: 1;
  font-family: system-ui, sans-serif;
}

.doc-body {
  padding: 9px 13px;
  font-size: 12.5px;
  line-height: 1.65;
  color: #2a2820;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  user-select: text;
  cursor: text;

  /* Inherit synthesis-md styles for markdown rendering */
  & .synthesis-md { font-style: normal; }
  & p  { margin: 0 0 0.55em; }
  & p:last-child { margin-bottom: 0; }
  & h1, & h2, & h3 {
    font-style: normal;
    font-weight: 500;
    margin: 0.6em 0 0.3em;
    font-size: 1em;
    color: #3a3020;
  }
  & ul, & ol { padding-left: 1.2em; margin: 0.3em 0 0.5em; }
  & li { margin-bottom: 0.15em; }
  & code {
    font-family: var(--font-mono, monospace);
    font-size: 0.88em;
    background: rgba(0,0,0,0.05);
    padding: 1px 4px;
    border-radius: 2px;
  }
}

.doc-footer {
  padding: 4px 13px 5px;
  border-top: 0.5px solid #e4e0d8;
  font-size: 10px;
  color: #b0a890;
  font-family: system-ui, sans-serif;
  letter-spacing: .03em;
  flex-shrink: 0;
}

/* ── Agent context bar ── */
#ctx-bar {
  position: fixed;
  bottom: 58px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 7px;
  background: rgba(255,253,248,0.92);
  border: 0.5px solid #c4bfb0;
  border-radius: 14px;
  padding: 4px 10px 4px 12px;
  z-index: 399;
  font-family: system-ui, sans-serif;
  font-size: 11px;
  backdrop-filter: blur(6px);
  box-shadow: 0 1px 8px rgba(0,0,0,0.05);
  max-width: 480px;
  min-width: 180px;
  transition: bottom .2s;
}
body.trash-open #ctx-bar { bottom: 94px; }

#ctx-bar-label {
  font-size: 9.5px;
  color: #b0a890;
  letter-spacing: .07em;
  text-transform: uppercase;
  white-space: nowrap;
  flex-shrink: 0;
}

#ctx-bar-preview {
  flex: 1;
  color: #9a9080;
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  min-width: 0;

  &:empty::before { content: 'no context set'; color: #c4bfb0; }
  &.has-content { color: #5a5248; }
}

#ctx-bar-edit {
  background: none;
  border: none;
  cursor: pointer;
  color: #b0a890;
  font-size: 12px;
  padding: 0 2px;
  line-height: 1;
  flex-shrink: 0;
  transition: color .1s;

  &:hover { color: #5a5248; }
}

#ctx-bar-panel {
  position: fixed;
  bottom: 92px;
  left: 50%;
  transform: translateX(-50%);
  width: 480px;
  z-index: 401;
  background: rgba(255,253,248,0.98);
  border: 0.5px solid #c4bfb0;
  border-radius: 10px;
  padding: 10px;
  box-shadow: 0 4px 18px rgba(0,0,0,0.1);
  font-family: system-ui, sans-serif;
  display: none;

  &.open { display: block; }
}
body.trash-open #ctx-bar-panel { bottom: 128px; }

#ctx-bar-textarea {
  width: 100%;
  min-height: 72px;
  max-height: 180px;
  border: 0.5px solid #c4bfb0;
  border-radius: 5px;
  padding: 7px 9px;
  font-size: 12px;
  line-height: 1.6;
  font-family: system-ui, sans-serif;
  color: #2a2820;
  background: #fffef9;
  resize: vertical;
  outline: none;
  display: block;

  &:focus { border-color: #7a6f5a; }
}

#ctx-bar-actions {
  display: flex;
  gap: 6px;
  margin-top: 7px;
  justify-content: flex-end;

  & button {
    font-size: 11px;
    padding: 3px 10px;
    border-radius: 9px;
    cursor: pointer;
    font-family: system-ui, sans-serif;
    border: 0.5px solid #c4bfb0;
    background: #eee9de;
    color: #4a4030;
    transition: background .1s;

    &:hover { background: #e0dcd0; }
  }

  & #ctx-bar-save {
    background: #2a2820;
    color: #faf9f6;
    border-color: #2a2820;

    &:hover { background: #4a4438; }
  }
}

/* ── Toolbar ── */
#toolbar {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255,253,248,0.94);
  border: 0.5px solid #c4bfb0;
  border-radius: 22px;
  padding: 6px 14px;
  z-index: 400;
  font-family: system-ui, sans-serif;
  font-size: 11.5px;
  backdrop-filter: blur(6px);
  box-shadow: 0 2px 12px rgba(0,0,0,0.07);
}
.tb-wordmark { font-size: 10px; letter-spacing: .07em; color: #9a9080; text-transform: uppercase; }
.tb-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 11.5px;
  color: #6a6458;
  padding: 3px 8px;
  border-radius: 11px;
  transition: background .1s;
  font-family: system-ui, sans-serif;
  white-space: nowrap;

  &:hover { background: #ede9e0; color: #2a2820; }
  &.on { background: #2a2820; color: #faf9f6; }
}
.tb-sep { width: 0.5px; height: 14px; background: #c4bfb0; flex-shrink: 0; }

/* ── Agent eye toggle ── */
.tb-eye {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3px 6px;
}
.eye-icon { display: block; flex-shrink: 0; }
/* Off state: show closed eye */
#btn-agent .eye-open  { display: none; }
#btn-agent .eye-closed { display: block; }
/* On state: show open eye, keep pill */
#btn-agent.on .eye-open  { display: block; }
#btn-agent.on .eye-closed { display: none; }
.sens-wrap { display: flex; align-items: center; gap: 5px; font-size: 10.5px; color: #9a9080; white-space: nowrap; }
.sens-wrap input[type=range] { width: 50px; accent-color: #7a6f5a; }

/* ── IO bar (bottom right) ── */
#io-bar {
  position: fixed;
  bottom: 16px;
  right: 20px;
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255,253,248,0.94);
  border: 0.5px solid #c4bfb0;
  border-radius: 22px;
  padding: 6px 12px;
  z-index: 400;
  backdrop-filter: blur(6px);
  box-shadow: 0 2px 12px rgba(0,0,0,0.07);
}

/* ── Status ── */
.sdot {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: #6a6458;   /* grey — unloaded */
  flex-shrink: 0;
  transition: background 0.4s;

  &.flashing { background: #a09060; animation: sdot-flash 0.8s ease-in-out infinite; }
  &.ready    { background: #7a9060; animation: none; }
}
@keyframes sdot-flash { 0%,100% { opacity: 1; } 50% { opacity: 0.15; } }
#stext { font-size: 10.5px; color: #9a9080; font-family: system-ui, sans-serif; white-space: nowrap; }
#ws-status {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: #d8d4c8;
  flex-shrink: 0;
  transition: background .3s;

  &.connected { background: #7a9060; }
  &.disconnected { background: #c87060; }
}

/* ── Hint ── */
#hint {
  position: fixed;
  bottom: 96px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  color: #b8b0a0;
  font-family: system-ui, sans-serif;
  pointer-events: none;
  white-space: nowrap;
  transition: opacity .4s;
  z-index: 10;
}

/* ── Selection rect ── */
#sel-rect {
  position: absolute;
  border: 1px dashed #9a9080;
  background: rgba(122,111,90,0.04);
  pointer-events: none;
  display: none;
  z-index: 50;
}

/* ── Context menu ── */
#ctx {
  position: fixed;
  z-index: 500;
  background: #fffef9;
  border: 0.5px solid #c4bfb0;
  border-radius: 8px;
  padding: 5px 0;
  box-shadow: 0 4px 18px rgba(0,0,0,0.1);
  font-family: system-ui, sans-serif;
  font-size: 12.5px;
  display: none;
  min-width: 170px;
}
.ctx-section { padding: 3px 14px; font-size: 10px; color: #9a9080; letter-spacing: .06em; text-transform: uppercase; }
.ctx-row { padding: 7px 14px; cursor: pointer; color: #2a2820; display: flex; align-items: center; gap: 9px; }
.ctx-row:hover { background: #f0ede4; }
.ctx-row.danger { color: #8a3020; }
.ctx-row.danger:hover { background: #faf0ee; }
.ctx-sep { height: 0.5px; background: #e0dcd2; margin: 4px 0; }

/* ── Trash tray ── */
#trash {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: rgba(250,249,246,0.96);
  border-top: 0.5px solid #d8d4c8;
  padding: 0 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 300;
  height: 0;
  overflow: hidden;
  transition: height .2s;

  &.has-items { height: 34px; }
}

/* Push toolbar and io-bar up when trash tray is open */
#trash.has-items ~ #toolbar,
body.trash-open #toolbar  { bottom: 52px; }
body.trash-open #io-bar   { bottom: 52px; }
body.trash-open #hint     { bottom: 92px; }

#trash-label {
  font-size: 10px;
  color: #9a9080;
  letter-spacing: .05em;
  text-transform: uppercase;
  font-family: system-ui, sans-serif;
  white-space: nowrap;
  flex-shrink: 0;
}
#trash-items {
  display: flex;
  gap: 5px;
  flex-wrap: nowrap;
  overflow-x: auto;
  flex: 1;
  align-items: center;
  /* Hide scrollbar — navigation is gestural */
  scrollbar-width: none;
  &::-webkit-scrollbar { display: none; }
}

/* Gradient fade on the right edge — visible only when there's overflow to scroll */
#trash-fade {
  position: absolute;
  right: 0; top: 0; bottom: 0;
  width: 80px;
  pointer-events: none;
  background: linear-gradient(to left, rgba(250,249,246,0.97) 0%, rgba(250,249,246,0) 100%);
  opacity: 0;
  transition: opacity .15s;
}
#trash.scrollable #trash-fade {
  opacity: 1;
}
.trash-chip {
  font-size: 10.5px;
  color: #7a7060;
  background: #eee9de;
  border: 0.5px solid #c4bfb0;
  border-radius: 11px;
  padding: 2px 9px;
  cursor: pointer;
  white-space: nowrap;
  font-family: system-ui, sans-serif;
  flex-shrink: 0;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;

  &:hover { background: #e0dcd2; }
}

/* ── Cluster SVG layer ── */
#clusters-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  overflow: visible;
}

/* ── Cluster name input ── */
.cluster-name-el {
  font-size: 10.5px;
  color: #6a6050;
  letter-spacing: .05em;
  font-family: system-ui, sans-serif;
  cursor: text;
  outline: none;
  display: inline-block;
  min-width: 30px;
  background: #faf9f6;
  padding: 1px 4px;
  border: 0.5px solid transparent;
  border-radius: 2px;

  &:focus { border-color: #9a9080; background: #fffef9; }
}

/* Agent-named cluster labels are italic; user edits clear this */
.cluster-name-el.lm-label {
  font-style: italic;
}

/* ── Cluster picker submenu ── */
#cluster-picker {
  position: fixed;
  z-index: 600;
  background: #fffef9;
  border: 0.5px solid #c4bfb0;
  border-radius: 7px;
  padding: 4px 0;
  box-shadow: 0 4px 18px rgba(0,0,0,0.1);
  font-family: system-ui, sans-serif;
  font-size: 12.5px;
  display: none;
  min-width: 150px;
}
#cluster-picker-list .ctx-row { padding: 6px 13px; }
#cluster-picker-list .ctx-row:hover { background: #f0ede4; }

/* ── Edge labels ──
   Both the draft/proposal pill and the confirmed label use the same
   base style. Machine-suggested labels are italic. Blank labels fade
   until the edge is hovered. */

.edge-label-overlay {
  position: absolute;
  pointer-events: all;
  transform: translate(-50%, -50%);
  display: inline-flex;
  align-items: center;
  border-radius: 6px;
  background: rgba(255,253,248,0.93);
  border: 0.5px solid rgba(196,191,176,0.85);
  min-width: 44px;
  max-width: 240px;
  font-family: system-ui, sans-serif;
  font-size: 11px;
  color: #2a2820;
  white-space: nowrap;
  cursor: text;
  padding: 2px 5px 2px 7px;
  transition: opacity .2s;
}

/* Blank label: invisible until the SVG line is hovered.
   We detect "blank" via the .blank class set from JS. */
.edge-label-overlay.blank {
  opacity: 0;
}
.edge-line-group:hover + * .edge-label-overlay.blank,
.edge-label-overlay.blank:hover {
  opacity: 1;
}

/* LM-authored edge labels are italic */
.edge-label-overlay.lm-label .edge-label-text {
  font-style: italic;
}

.edge-label-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  outline: none;
}

.edge-label-delete {
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 11px;
  padding: 0;
  margin-left: 5px;
  opacity: 0.45;
  color: #7a7060;
  flex-shrink: 0;
  transition: opacity .1s;

  &:hover { opacity: 1; }
}

/* Proposed edge pill — same shape as confirmed label, dashed border */
/* Proposed edge pill inherits .edge-label-overlay base styles.
   Only overrides: dashed border (vs solid), italic label (machine-authored),
   and confirm buttons. Position/background/shadow come from the base class. */
.edge-proposal-pill {
  border-style: dashed;
  border-color: #b0a070;
  gap: 5px;
}
.edge-proposal-label {
  font-style: italic;
  color: #5a5040;
  flex: 1;
}
.edge-proposal-yes,
.edge-proposal-no {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 13px;
  padding: 0 2px;
  line-height: 1;
  flex-shrink: 0;
}
.edge-proposal-yes { color: #5a7a5a; }
.edge-proposal-yes:hover { color: #2a5a2a; }
.edge-proposal-no  { color: #9a5050; }
.edge-proposal-no:hover  { color: #6a2020; }

/* ── Drop overlay ── */
#drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(255,253,248,0.88);
  display: none;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  font-family: system-ui, sans-serif;
  font-size: 18px;
  color: #7a6f5a;
  letter-spacing: .04em;

  &.active { display: flex; }
}
#drop-overlay-inner {
  border: 1.5px dashed #b0a890;
  border-radius: 12px;
  padding: 40px 60px;
  text-align: center;
}

/* ── Bubble / action set system ──
   Bubbles arrange in a row along the bottom edge of their cluster hull.
   Each bubble is absolutely positioned by JS relative to the cluster. */

#bubble-overlay { position: absolute; inset: 0; pointer-events: none; z-index: 15; }
.bubble-set { position: absolute; pointer-events: none; }

.bubble-btn {
  position: absolute;
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(255,253,248,0.97);
  border: 0.5px solid #c4bfb0;
  border-radius: 18px;
  padding: 3px 9px 3px 7px;
  font-family: system-ui, sans-serif;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,0.07);
  transition: background .1s, border-color .1s;
  pointer-events: all;
  white-space: nowrap;
  opacity: 0;
  animation: bubble-in .14s ease forwards;
}
@keyframes bubble-in {
  from { opacity: 0; transform: translateY(3px); }
  to   { opacity: 1; transform: translateY(0); }
}
.bubble-btn:hover {
  background: #f0ede4;
  border-color: #9a9080;
}
.bubble-btn-ratify { border-style: dashed; border-color: #b0a070; }

.bubble-icon {
  font-size: 11px;
  line-height: 1;
  flex-shrink: 0;
  color: #9a9080;
}

/* Labels are italic — agent register, not user voice */
.bubble-label {
  font-size: 10.5px;
  font-style: italic;
  color: #5a5248;
  line-height: 1.3;
}

.bubble-confirm-yes, .bubble-confirm-no {
  font-size: 12px;
  cursor: pointer;
  padding: 0 2px;
  transition: color .1s;
  font-style: normal;
}
.bubble-confirm-yes { color: #5a7a5a; }
.bubble-confirm-yes:hover { color: #2a5a2a; }
.bubble-confirm-no  { color: #9a5050; }
.bubble-confirm-no:hover  { color: #6a2020; }

/* Dismiss circle — same visual family as the buttons, sits on the left */
.bubble-dismiss {
  position: absolute;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: rgba(255,253,248,0.97);
  border: 0.5px solid #c4bfb0;
  font-size: 11px;
  color: #9a9080;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: all;
  line-height: 1;
  padding: 0;
  box-shadow: 0 1px 4px rgba(0,0,0,0.07);
  transition: background .1s, border-color .1s, color .1s;

  &:hover {
    background: #f0ede4;
    border-color: #9a9080;
    color: #5a5248;
  }
}

/* ── Action set node (legacy inline variant) ── */
.node.action-set-node {
  background: #f5f2ea;
  min-width: 160px;
  max-width: 280px;
  overflow: visible;

  & .node-clip { max-height: 400px; }
}
.action-set-header {
  padding: 6px 28px 5px 11px;
  font-size: 10px;
  color: #7a6f5a;
  letter-spacing: .06em;
  text-transform: uppercase;
  border-bottom: 0.5px solid #d8d2c4;
  font-family: system-ui, sans-serif;
  display: flex;
  align-items: center;
  position: relative;
}
.action-set-title { flex: 1; }
.action-set-body { padding: 7px 9px; display: flex; flex-direction: column; gap: 4px; }
.action-set-action {
  width: 100%;
  text-align: left;
  background: #eee9de;
  border: 0.5px solid #c4bfb0;
  border-radius: 4px;
  padding: 5px 10px;
  font-size: 12px;
  color: #2a2820;
  cursor: pointer;
  font-family: system-ui, sans-serif;
  transition: background .1s;

  &:hover:not(:disabled) { background: #e4dfd4; }
  &:disabled { color: #9a9080; cursor: default; }
}

/* ── Additional utility classes (replace inline JS styles) ── */

/* Chat node x-button positioned inside the header row, not absolutely */
.chat-x-btn {
  opacity: 1 !important;
  position: relative !important;
  top: auto !important;
  right: auto !important;
  font-size: 13px;
}

/* Image node inner padding (different from default) */
.image-inner {
  padding: 8px 8px 8px 8px;
}

/* Radio "other" label */
.radio-other-label {
  color: #9a9080;
  flex-shrink: 0;
}

/* z-index when selected (replaces JS inline style.zIndex) */
.node.selected { z-index: 20; }

/* Ensure node-clip doesn't add a second border — it only clips, no visual border.
   The single visual border lives on .node via box-shadow. */
.node-clip {
  border: none;
}

/* Bot/synthesis/comment node text is italic via .span-agent inside .node-content-mixed.
   The .synthesis-md rule covers the document node path only. */

/* ── Blank edge labels: fade until hovered ──
   The SVG line lives in #clusters-layer; we can't use adjacent sibling CSS
   on it from the HTML overlay. Instead we rely on the overlay element itself
   being hovered (pointer-events:all ensures this works). */
.edge-label-overlay.blank { opacity: 0; pointer-events: all; }
.edge-label-overlay.blank:hover { opacity: 1; }
/* Also reveal on focus (user clicked into the text field) */
.edge-label-overlay.blank:focus-within { opacity: 1; }
