/* Node board: canvas, tiles, edges, tray */
:root {
  --input: #2563eb;
  --input-soft: #e8efff;
  --output: #7c3aed;
  --output-soft: #f1eaff;
  --edge-ok: #16a34a;
  --dots: #d5d9e0;
  --canvas: #f7f8fa;
}
@media (prefers-color-scheme: dark) {
  :root {
    --input: #5b93ff;
    --input-soft: #172441;
    --output: #a78bfa;
    --output-soft: #231a3d;
    --edge-ok: #34d399;
    --dots: #2a2f3a;
    --canvas: #12141a;
  }
}

#app:not([hidden]) { display: flex; flex-direction: column; height: 100vh; }
#app > main { flex: 1; min-height: 0; width: 100%; overflow: auto; }
main.full { max-width: none; padding: 0; overflow: hidden; display: flex; }
.board { display: flex; flex-direction: column; flex: 1; min-width: 0; min-height: 0; }

.toolbar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.toolbar .legend { display: flex; gap: 14px; margin-left: 12px; color: var(--muted); font-size: 12.5px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 22px; height: 0; border-top: 2.5px solid; vertical-align: middle; margin-right: 5px; }
.legend .l-ok { border-color: var(--edge-ok); }
.legend .l-paused { border-color: var(--muted); border-top-style: dashed; }
.legend .l-broken { border-color: var(--danger); border-top-style: dashed; }
.zoom { margin-left: auto; display: inline-flex; align-items: center; gap: 2px; border: 1px solid var(--border); border-radius: 8px; padding: 2px; background: var(--surface); }
.zoom button { background: none; border: 0; padding: 4px 9px; border-radius: 6px; cursor: pointer; font-weight: 600; }
.zoom button:hover { background: var(--surface-2); }
.zoom span { min-width: 44px; text-align: center; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.banner { padding: 8px 16px; background: var(--warn-soft); color: var(--warn); font-size: 13px; border-bottom: 1px solid var(--border); }

.canvas {
  position: relative; flex: 1; overflow: hidden; cursor: grab; touch-action: none; user-select: none;
  background-color: var(--canvas);
  background-image: radial-gradient(var(--dots) 1.2px, transparent 1.3px);
}
.canvas.panning { cursor: grabbing; }
.world { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
#edges { position: absolute; left: 0; top: 0; width: 1px; height: 1px; overflow: visible; pointer-events: none; }
.world.animate { transition: transform .4s cubic-bezier(.2, .7, .2, 1); }
.canvas.animate { transition: background-position .4s cubic-bezier(.2, .7, .2, 1), background-size .4s cubic-bezier(.2, .7, .2, 1); }
.canvas-empty {
  position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; text-align: center; color: var(--muted); padding: 24px;
}
.canvas-empty strong { display: block; color: var(--text); font-size: 15px; margin-bottom: 4px; }

/* ---------- edges */
.edge-line { fill: none; stroke-width: 2.5; stroke-linecap: round; }
.edge-hit { fill: none; stroke: transparent; stroke-width: 18; pointer-events: stroke; cursor: context-menu; }
.edge-flow { fill: none; stroke-width: 2.5; stroke-linecap: round; stroke-dasharray: 2 14; animation: flow 1s linear infinite; }
.e-active .edge-line { stroke: var(--edge-ok); }
.e-active .edge-flow { stroke: #fff; opacity: .6; }
.e-paused .edge-line { stroke: var(--muted); stroke-dasharray: 7 6; }
.e-broken .edge-line { stroke: var(--danger); stroke-dasharray: 7 5; }
.edge:hover .edge-line { stroke-width: 4; }
.edge-temp { fill: none; stroke: var(--edge-ok); stroke-width: 2.5; stroke-dasharray: 6 5; }
@keyframes flow { to { stroke-dashoffset: -16; } }

/* ---------- node tiles */
.node {
  position: absolute; left: 0; top: 0; width: 310px; cursor: grab;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 4px 12px rgba(16, 24, 40, .05);
}
.node.dragging { cursor: grabbing; box-shadow: 0 12px 32px rgba(16, 24, 40, .22); z-index: 5; }
.node.drop-ok { outline: 2px solid var(--edge-ok); outline-offset: 2px; }
.node.input { border-top: 3px solid var(--input); }
.node.output { border-top: 3px solid var(--output); }
.node-head { display: flex; align-items: center; gap: 7px; padding: 10px 10px 6px 12px; height: 22px; box-sizing: content-box; }
.kind { font-size: 10px; font-weight: 700; letter-spacing: .08em; padding: 1px 6px; border-radius: 5px; flex: none; }
.kind.input { background: var(--input-soft); color: var(--input); }
.kind.output { background: var(--output-soft); color: var(--output); }
.st { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.st-ok { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.st-paused { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-soft); }
.st-err { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
.node-name { font-weight: 650; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn { background: none; border: 0; border-radius: 6px; padding: 0 6px; cursor: pointer; color: var(--muted); font-size: 16px; line-height: 22px; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.node-info { display: grid; grid-template-columns: 74px 1fr; gap: 1px 10px; margin: 0; padding: 0 12px; font-size: 12.5px; }
.node-info .com { font-family: var(--mono); font-size: 13px; }
.node-info dt { color: var(--muted); }
.node-info dd { margin: 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.node-stats { display: flex; justify-content: space-between; gap: 8px; padding: 6px 12px 0; font-size: 12px; color: var(--muted); }
.node-sig { padding: 6px 12px 0; height: 24px; box-sizing: content-box; display: flex; align-items: center; }
.node-sig .dim { opacity: .45; }
.node-error { margin: 8px 10px 0; padding: 6px 8px; border-radius: 7px; background: var(--danger-soft); color: var(--danger); font-size: 12px; }
.node-note { margin: 8px 10px 0; padding: 5px 8px; border-radius: 7px; background: var(--surface-2); color: var(--muted); font-size: 12px; }
.node-actions { display: flex; gap: 6px; align-items: center; padding: 8px 10px 10px; height: 30px; box-sizing: content-box; }
/* status strip hanging below the tile – keeps the tile height constant */
.node-strip {
  position: absolute; left: 12px; right: 12px; top: 100%; margin-top: -1px;
  padding: 5px 9px; border-radius: 0 0 9px 9px; font-size: 12px; line-height: 1.35;
  border: 1px solid var(--border); border-top: 0;
}
.node-strip.err { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
.node-strip.info { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
.node-strip.note { background: var(--surface-2); color: var(--muted); }
.node-head .switch { margin-left: 2px; }
.handle {
  position: absolute; top: 50%; width: 14px; height: 14px; margin-top: -7px; border-radius: 50%;
  background: var(--surface); border: 2.5px solid; cursor: crosshair; z-index: 2;
}
.handle:hover { transform: scale(1.3); }
.handle-out { right: -8px; border-color: var(--input); }
.handle-in { left: -8px; border-color: var(--output); }

/* switch */
.switch { display: inline-flex; flex-direction: row; align-items: center; gap: 7px; cursor: pointer; font-size: 12px; font-weight: 500; }
.switch input { display: none; }
.switch .slider { width: 32px; height: 18px; border-radius: 99px; background: var(--border); position: relative; transition: background .15s; flex: none; }
.switch .slider::after {
  content: ""; position: absolute; left: 2px; top: 2px; width: 14px; height: 14px; border-radius: 50%;
  background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0, 0, 0, .25);
}
.switch input:checked + .slider { background: var(--edge-ok); }
.switch input:checked + .slider::after { transform: translateX(14px); }

/* ---------- tray */
.tray { border-top: 1px solid var(--border); background: var(--surface); transition: background .12s; }
.tray.drop { background: var(--danger-soft); }
.tray-head { display: flex; align-items: baseline; gap: 10px; padding: 8px 16px 0; }
.tray-head b { font-size: 13px; }
.tray-list { display: flex; gap: 10px; overflow-x: auto; padding: 8px 16px 12px; min-height: 84px; align-items: stretch; }
.tray-empty { color: var(--muted); font-size: 12.5px; align-self: center; }
.tray-item {
  position: relative; flex: none; width: 220px; padding: 8px 28px 8px 10px; border-radius: 10px;
  border: 1px dashed var(--border); background: var(--surface-2); font-size: 12.5px;
}
.tray-item.draggable { cursor: grab; border-style: solid; }
.tray-item .t-name { font-weight: 600; display: flex; gap: 6px; align-items: center; margin-bottom: 2px; }
.tray-item .t-name span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tray-item .t-meta { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tray-item .x { position: absolute; top: 4px; right: 4px; }
.tray-item.offline { opacity: .75; }
.drag-ghost { position: fixed; z-index: 200; pointer-events: none; opacity: .9; box-shadow: 0 12px 32px rgba(0, 0, 0, .25); }

/* ---------- context menu */
.ctx-menu {
  position: fixed; z-index: 150; min-width: 180px; padding: 4px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 9px; box-shadow: 0 8px 24px rgba(0, 0, 0, .16);
}
.ctx-menu button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 7px 10px; border-radius: 6px; cursor: pointer; }
.ctx-menu button:hover { background: var(--surface-2); }
.ctx-menu button.danger { color: var(--danger); }

.grid.name-com { grid-template-columns: 1fr 130px; }
fieldset.viewers { border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px 10px; margin: 0; }
fieldset.viewers legend { font-size: 13px; font-weight: 500; padding: 0 4px; }
.viewer-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 4px 12px; margin-top: 6px; }
.dlg-danger { margin-top: 4px; border-top: 1px solid var(--border); padding-top: 12px; display: flex; justify-content: space-between; align-items: center; gap: 12px; }

.agent-badge { font-size: 10px; padding: 0 6px; margin-left: 4px; background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.agent-head .spacer { flex: 1; }
