/* ═══════════════════════════════════════════════════════════════
   FACTORY EDITOR · blender-like node graph
   ═══════════════════════════════════════════════════════════════ */

.editor-shell {
  /* override content padding for edge-to-edge editor */
  margin: -28px -28px -48px -28px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: calc(100vh - 60px);       /* minus topbar */
  min-height: 620px;
  background: var(--bg);
  position: relative;
}

/* ── HEADER (mode tabs + meta) ─────────────────────────────── */
.ed-header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 20px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--b1);
  background: var(--s1);
}
.ed-title {
  display: flex; align-items: baseline; gap: 10px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--t3);
}
.ed-title .k {
  color: var(--t1);
  font-weight: 700;
}
.ed-title .slash { color: var(--t3); }
.ed-title .factory-name {
  color: var(--t1);
  font-weight: 700;
}

/* v3 / harness .seg, as .theme-toggle */
.ed-modes {
  display: flex;
  justify-self: center;
  padding: 2px;
  border: 1px solid var(--b2);
  border-radius: var(--r-c);
  background: color-mix(in srgb, var(--t1) 2%, transparent);
}
.ed-modes button {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-weight: 700;
  padding: 6px 14px;
  background: transparent;
  border: 0;
  border-radius: calc(var(--r-c) - 3px);
  color: var(--t2);
  cursor: pointer;
  display: inline-flex; align-items: center; gap: 8px;
  transition: background 0.2s, color 0.2s;
}
.ed-modes button:hover { color: var(--t1); }
.ed-modes button .ix {
  font-size: 9px;
  color: var(--t3);
}
.ed-modes button.on {
  background: var(--t1);
  color: var(--bg);
}
.ed-modes button.on .ix { color: var(--bg); }

.ed-meta {
  display: flex; align-items: center; gap: 10px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--t3);
}
.ed-meta .ed-stamp {
  color: var(--t1);
  border: 1px solid var(--b3);
  border-radius: var(--r-chip);
  padding: 3px 8px;
  font-weight: 700;
}
/* unsaved changes wait on the user: hold */
.ed-meta .dirty {
  color: var(--hold);
  border-color: color-mix(in oklch, var(--hold) 35%, transparent);
  background: var(--hold-wash);
}

/* ── WORKSPACE ─────────────────────────────────────────────── */
.ed-workspace {
  display: grid;
  grid-template-columns: 280px 1fr 330px;
  min-height: 0;
  position: relative;
  transition: grid-template-columns 0.22s ease;
}
.ed-workspace.ins-collapsed {
  grid-template-columns: 280px 1fr 32px;
}
.ed-workspace > .ed-canvas-wrap { padding: 0; }

/* LIBRARY (left) */
.ed-lib {
  border-right: 1px solid var(--b1);
  background: var(--s1);
  display: flex; flex-direction: column;
  min-height: 0;
}
.ed-lib-head {
  padding: 10px 12px 8px;
  border-bottom: 1px solid var(--b1);
}
.ed-lib-head .lh {
  display: flex; align-items: baseline; justify-content: space-between;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--t3);
  margin-bottom: 8px;
}
.ed-lib-head .lh .lhn { color: var(--t1); font-weight: 700; }
.ed-lib-search {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--b2);
  border-radius: var(--r-c);
  color: var(--t1);
  font-family: var(--mono);
  font-size: 12px;
  padding: 6px 9px;
  outline: none;
}
.ed-lib-search:focus { border-color: var(--t1); }

.ed-lib-tabs {
  display: flex; flex-wrap: wrap;
  gap: 0;
  border-bottom: 1px solid var(--b1);
}
.ed-lib-tabs button {
  flex: 1 1 auto;
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-weight: 700;
  padding: 7px 4px;
  background: transparent;
  border: 0;
  border-right: 1px solid var(--b1);
  color: var(--t3);
  cursor: pointer;
  display: inline-flex; flex-direction: column; align-items: center; gap: 2px;
}
.ed-lib-tabs button:last-child { border-right: 0; }
.ed-lib-tabs button .cnt {
  font-size: 10px;
  color: var(--t3);
}
.ed-lib-tabs button:hover { color: var(--t1); }
.ed-lib-tabs button.on {
  color: var(--t1);
  background: var(--s2);
  box-shadow: inset 0 -2px 0 var(--t1);
}
.ed-lib-tabs button.on .cnt { color: var(--t1); }

.ed-lib-list {
  flex: 1;
  overflow-y: auto;
  padding: 0;
}
.ed-lib-group {
  padding: 6px 0;
  border-bottom: 1px dashed var(--b1);
}
.ed-lib-group:last-child { border-bottom: 0; }
.ed-lib-group-title {
  padding: 6px 12px 4px;
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--t3);
  display: flex; justify-content: space-between;
}

.ed-lib-item {
  display: grid;
  grid-template-columns: 16px 1fr auto;
  gap: 8px;
  padding: 5px 12px;
  align-items: center;
  cursor: grab;
  border-left: 2px solid transparent;
}
.ed-lib-item:hover {
  background: var(--s2);
  border-left-color: var(--b3);
}
.ed-lib-item .gl {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  color: var(--t3);
  text-align: center;
}
/* item kinds are categories: the glyph tells them apart, --t1 / --t2 only weights them */
.ed-lib-item.t-skill .gl { color: var(--t1); }
.ed-lib-item.t-model .gl { color: var(--t2); }
.ed-lib-item.t-rag .gl { color: var(--t2); }
.ed-lib-item.t-rule .gl { color: var(--t2); }
.ed-lib-item.t-pkg .gl { color: var(--t1); }
.ed-lib-item.t-agent .gl { color: var(--t1); }
.ed-lib-item.t-ctrl .gl { color: var(--t2); }

.ed-lib-item .nm {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--t1);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ed-lib-item .tg {
  font-family: var(--mono);
  font-size: 9px;
  color: var(--t3);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* ── CANVAS ────────────────────────────────────────────────── */
.ed-canvas-wrap {
  position: relative;
  overflow: auto;
  background:
    radial-gradient(1px 1px at 1px 1px, var(--b3) 1px, transparent 0),
    var(--bg);
  background-size: 24px 24px;
  background-position: 0 0;
}
body.theme-light .ed-canvas-wrap {
  background:
    radial-gradient(1px 1px at 1px 1px, var(--b3) 1px, transparent 0),
    var(--bg);
  background-size: 24px 24px;
}

/* major blueprint lines */
.ed-canvas-wrap::before {
  content: "";
  position: absolute; inset: 0;
  background-image:
    linear-gradient(to right, var(--b1) 1px, transparent 1px),
    linear-gradient(to bottom, var(--b1) 1px, transparent 1px);
  background-size: 120px 120px;
  pointer-events: none;
  opacity: 0.6;
}

/* canvas chrome — corner markers */
.ed-canvas-wrap .corner-label {
  position: absolute;
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--t3);
  pointer-events: none;
  z-index: 2;
}
.ed-canvas-wrap .corner-label.tl { top: 10px; left: 14px; }
.ed-canvas-wrap .corner-label.tr { top: 10px; right: 14px; text-align: right; }
.ed-canvas-wrap .corner-label.bl { bottom: 10px; left: 14px; }
.ed-canvas-wrap .corner-label.br { bottom: 10px; right: 14px; text-align: right; }

/* N-panel toggle label at top of canvas */
.ed-canvas-knobs {
  position: absolute;
  top: 10px; left: 50%;
  transform: translateX(-50%);
  display: flex; gap: 0;
  padding: 2px;
  border: 1px solid var(--b2);
  border-radius: var(--r-c);
  background: var(--s1);
  z-index: 3;
}
.ed-canvas-knobs button {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 700;
  padding: 5px 10px;
  background: transparent;
  border: 0;
  border-radius: calc(var(--r-c) - 3px);
  color: var(--t3);
  cursor: pointer;
}
.ed-canvas-knobs button:hover { color: var(--t1); }
.ed-canvas-knobs button.on { color: var(--t1); background: var(--s3); }
.ed-canvas-knobs button .kbd {
  font-size: 9px;
  color: var(--t3);
  margin-left: 6px;
  border: 1px solid var(--b3);
  border-radius: var(--r-chip);
  padding: 0 3px;
}

/* the actual node surface — fixed large canvas, wrapper scrolls */
.ed-surface {
  position: relative;
  width: 1440px;
  height: 560px;
  min-width: 1440px;
  min-height: 560px;
}
.ed-surface svg.wires {
  position: absolute;
  top: 0; left: 0;
  width: 1440px; height: 560px;
  pointer-events: none;
  z-index: 1;
  overflow: visible;
}
.ed-surface svg.wires path {
  fill: none;
  stroke-width: 1.4;
  stroke: var(--t2);
}
/* edge kinds are categories, told apart by weight and line: hot = live flow (--t1, solid),
   blue = context / data (--t2, long dash), dash = guard / back edge (--t3, short dash) */
.ed-surface svg.wires path.hot  { stroke: var(--t1); stroke-width: 1.8; }
.ed-surface svg.wires path.blue { stroke: var(--t2); stroke-width: 1.6; stroke-dasharray: 8 4; }
.ed-surface svg.wires path.dash { stroke-dasharray: 3 4; stroke: var(--t3); }

/* wire label chips on midpoint */
.wire-label {
  position: absolute;
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--t2);
  background: var(--s1);
  border: 1px solid var(--b2);
  border-radius: var(--r-chip);
  padding: 1px 5px;
  z-index: 2;
  pointer-events: none;
}
.wire-label.hot  { color: var(--t1); border-color: var(--t1); }
.wire-label.blue { color: var(--t2); border-color: var(--b3); border-style: dashed; }

/* ── NODE ──────────────────────────────────────────────────── */
/* node kinds are categories, not states: weight of the edge and head, plus a dashed
   outline for guards. signal = orchestrator / package, blue = research / RAG / model,
   amber = rule / guard, ctrl = control flow, none = worker / skill */
.node {
  position: absolute;
  width: 230px;
  background: var(--s1);
  border: 1px solid var(--b3);
  border-radius: var(--r-m);
  z-index: 2;
  font-family: var(--sans);
  font-size: 12px;
}
.node.signal { border-color: var(--t1); }
.node.blue   { border-color: var(--t2); }
.node.amber  { border-color: var(--t2); border-style: dashed; }

.node.selected {
  outline: 1.5px solid var(--t1);
  outline-offset: 3px;
}

.node-head {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 6px 8px 6px 10px;
  border-radius: calc(var(--r-m) - 1px) calc(var(--r-m) - 1px) 0 0;
  border-bottom: 1px solid var(--b1);
  background: var(--s3);
  color: var(--t1);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.node.signal .node-head { background: var(--t1); color: var(--bg); border-bottom-color: var(--t1); }

.node-head .glyph {
  font-weight: 700;
  font-size: 11px;
}
.node-head .name {
  font-weight: 700;
  letter-spacing: 0.08em;
}
.node-head .nid {
  font-size: 9px;
  color: var(--t3);
}
.node.signal .node-head .nid { color: var(--bg); }

.node-body {
  padding: 8px 10px 9px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--t1);
}
.node-body .role {
  color: var(--t2);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin-bottom: 4px;
}
.node-body .model {
  font-weight: 700;
  color: var(--t1);
}
.node-body .tools {
  display: flex; flex-wrap: wrap; gap: 3px;
  margin-top: 6px;
}
.node-body .skill-chip {
  font-family: var(--mono);
  font-size: 9px;
  padding: 1px 4px;
  border-radius: var(--r-chip);
  border: 1px solid var(--b2);
  color: var(--t2);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.node-body .skill-chip.on { color: var(--t1); border-color: var(--t1); }
.node-body .skill-chip.sig { color: var(--t1); border-color: var(--t1); background: var(--s3); }

.node-foot {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  padding: 5px 10px;
  border-top: 1px solid var(--b1);
  border-radius: 0 0 calc(var(--r-m) - 1px) calc(var(--r-m) - 1px);
  background: var(--s2);
  font-family: var(--mono);
  font-size: 9px;
  color: var(--t3);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
/* no modifier = run: live, white dot with the glow; warn = hold, idle = hollow */
.node-foot .st {
  display: inline-flex; align-items: center; gap: 5px;
  color: var(--t1);
  font-weight: 700;
}
.node-foot .st::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  border: 1px solid currentColor; background: currentColor;
  box-shadow: var(--glow);
}
.node-foot .st.warn { color: var(--hold); }
.node-foot .st.idle { color: var(--t3); }
.node-foot .st.idle::before { background: transparent; }
.node-foot .st.sig { color: var(--fail); }
.node-foot .st.warn::before, .node-foot .st.idle::before, .node-foot .st.sig::before { box-shadow: none; }

/* ports */
.node .port {
  position: absolute;
  width: 10px; height: 10px;
  border: 1.5px solid var(--t1);
  border-radius: 50%;
  background: var(--bg);
  z-index: 3;
}
.node.blue   .port { border-color: var(--t2); }
.node .port.in  { left: -6px;  top: 18px; }
.node .port.out { right: -6px; top: 18px; }
.node .port.in2  { left: -6px;  top: calc(18px + 16px); }
.node .port.out2 { right: -6px; top: calc(18px + 16px); }
.node .port.filled { background: var(--t1); }
.node.blue   .port.filled { background: var(--t2); }

/* specialized node variants */
.node.compact { width: 170px; }
.node.tiny    { width: 140px; }

.node.ctrl .node-head { background: var(--s2); color: var(--t1); border-bottom: 1px solid var(--b2); }
.node.ctrl { border-color: var(--b3); }
.node:hover { border-color: var(--t1); }

/* group box around a squad of nodes */
.node-group {
  position: absolute;
  border: 1px dashed var(--b3);
  border-radius: var(--r);
  background: color-mix(in srgb, var(--t1) 3%, transparent);
  z-index: 1;
}
.node-group .ng-label {
  position: absolute;
  top: -10px; left: 12px;
  padding: 1px 8px;
  background: var(--bg);
  border: 1px solid var(--b3);
  border-radius: var(--r-chip);
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--t2);
}

/* ── INSPECTOR (right column of workspace grid) ───────────────── */
.ed-inspector {
  border-left: 1px solid var(--b1);
  background: var(--s1);
  display: flex; flex-direction: column;
  overflow: hidden;
  min-height: 0;
  z-index: 4;
  width: 330px;
  position: relative;
  transition: width 0.22s ease;
}
.ed-workspace.ins-collapsed .ed-inspector {
  width: 32px;
}
.ed-workspace.ins-collapsed .ed-inspector > *:not(.ed-ins-collapsed-rail) {
  display: none !important;
}
.ed-ins-collapsed-rail {
  display: none;
  width: 32px;
  height: 100%;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding-top: 12px;
  gap: 14px;
  border-left: 1px solid var(--b1);
  background: var(--s2);
  cursor: pointer;
}
.ed-workspace.ins-collapsed .ed-ins-collapsed-rail {
  display: flex;
}
.ed-ins-collapsed-rail .chev {
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 700;
  color: var(--t1);
  line-height: 1;
}
.ed-ins-collapsed-rail .lbl {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--t2);
  font-weight: 700;
}
.ed-ins-collapsed-rail .id {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.15em;
  color: var(--t1);
}
  background: var(--bg);
  border: 1.5px solid var(--t1);
  display: flex; flex-direction: column;
  z-index: 4;
  overflow: hidden;
}
.ed-inspector.hidden { display: none; }
.ed-ins-head {
  display: grid;
  grid-template-columns: 1fr auto;
  padding: 10px 12px;
  border-bottom: 1px solid var(--b1);
  background: var(--s2);
}
.ed-ins-head .t1 {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--t3);
}
.ed-ins-head .t2 {
  font-family: var(--sans);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-top: 2px;
  color: var(--t1);
}
.ed-ins-head .t3 {
  font-family: var(--mono);
  font-size: 9px;
  color: var(--t2);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  margin-top: 2px;
  font-weight: 700;
}
.ed-ins-close {
  border: 1px solid var(--b2);
  border-radius: var(--r-chip);
  background: transparent;
  color: var(--t2);
  font-family: var(--mono);
  font-size: 10px;
  padding: 3px 6px;
  cursor: pointer;
  align-self: start;
  letter-spacing: 0.1em;
  font-weight: 700;
}
.ed-ins-close:hover { color: var(--t1); border-color: var(--b3); }

.ed-ins-tabs {
  display: flex;
  border-bottom: 1px solid var(--b1);
}
.ed-ins-tabs button {
  flex: 1;
  background: transparent;
  border: 0;
  border-right: 1px solid var(--b1);
  padding: 7px 4px;
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--t3);
  font-weight: 700;
  cursor: pointer;
}
.ed-ins-tabs button:last-child { border-right: 0; }
.ed-ins-tabs button:hover { color: var(--t1); }
.ed-ins-tabs button.on {
  color: var(--t1);
  background: var(--s2);
  box-shadow: inset 0 -2px 0 var(--t1);
}

.ed-ins-body {
  flex: 1;
  overflow-y: auto;
  padding: 0;
}
.ed-ins-section {
  padding: 10px 12px;
  border-bottom: 1px dashed var(--b1);
}
.ed-ins-section:last-child { border-bottom: 0; }
.ed-ins-section .st {
  display: flex; justify-content: space-between; align-items: baseline;
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--t3);
  margin-bottom: 6px;
}
.ed-ins-section .st .a { color: var(--t1); font-weight: 700; }

.kv {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 6px 10px;
  font-family: var(--mono);
  font-size: 11px;
}
.kv dt { color: var(--t3); letter-spacing: 0.1em; text-transform: uppercase; font-size: 10px; }
.kv dd { color: var(--t1); text-align: right; }
.kv dd.num { font-variant-numeric: tabular-nums; }
.kv dd.sig { color: var(--t1); font-weight: 700; }
.kv dd.blu { color: var(--t2); }

.ed-ins-input {
  background: var(--bg);
  border: 1px solid var(--b2);
  border-radius: var(--r-c);
  color: var(--t1);
  font-family: var(--mono);
  font-size: 11px;
  padding: 5px 7px;
  width: 100%;
  outline: none;
}
.ed-ins-input:focus { border-color: var(--t1); }
.ed-ins-field {
  display: flex; flex-direction: column; gap: 4px;
  margin-bottom: 8px;
}
.ed-ins-field label {
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--t3);
}

.model-chain {
  display: flex; flex-direction: column; gap: 4px;
}
.model-chain .row {
  display: grid;
  grid-template-columns: 18px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 5px 8px;
  border: 1px solid var(--b2);
  border-radius: var(--r-m);
  font-family: var(--mono);
  font-size: 11px;
}
.model-chain .row .ix { color: var(--t3); font-size: 10px; }
.model-chain .row.primary { border-color: var(--t1); background: var(--s3); color: var(--t1); }
.model-chain .row.primary .ix { color: var(--t1); }
.model-chain .row .w { color: var(--t3); font-size: 10px; letter-spacing: 0.08em; }

.skill-list {
  display: flex; flex-direction: column; gap: 3px;
}
.skill-list .row {
  display: grid;
  grid-template-columns: 14px 1fr auto;
  gap: 8px;
  align-items: center;
  font-family: var(--mono);
  font-size: 11px;
  padding: 3px 2px;
  border-bottom: 1px dashed var(--b1);
}
.skill-list .row:last-child { border-bottom: 0; }
.skill-list .row .b {
  width: 11px; height: 11px;
  border: 1.5px solid var(--t3);
  border-radius: 3px;
  display: inline-block;
}
.skill-list .row.on .b { background: var(--t1); border-color: var(--t1); }
.skill-list .row .k { color: var(--t3); font-size: 10px; }

/* ── STATUS BAR ────────────────────────────────────────────── */
.ed-status {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 18px;
  padding: 5px 14px;
  border-top: 1px solid var(--b1);
  background: var(--s1);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--t3);
}
.ed-status .seg {
  display: inline-flex; gap: 14px;
}
.ed-status .seg .s {
  display: inline-flex; gap: 6px; align-items: center;
}
.ed-status .seg .s .k {
  color: var(--t1);
  font-weight: 700;
}
.ed-status .kbd-hint {
  display: inline-flex; gap: 10px;
  justify-self: center;
  color: var(--t2);
}
.ed-status .kbd-hint .kbd {
  border: 1px solid var(--b2);
  border-radius: var(--r-chip);
  padding: 1px 5px;
  margin-right: 4px;
  color: var(--t1);
  background: var(--bg);
}

/* valid dot: graph state ok, no glow */
.ed-status .dotv {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--mint);
  display: inline-block;
}
