/* n9e editor.
   One stylesheet, no framework, no build step — the same reasoning as the zero-dependency runtime.
   Everything is driven by the tokens below, so the whole editor re-themes from one block. */

:root {
  --bg:        #12141a;
  --bg-raised: #191c24;
  --bg-input:  #0e1015;
  --panel:     #1d212b;
  --line:      #2b303d;
  --line-soft: #232834;

  --text:      #e6e9f0;
  --text-dim:  #99a1b3;
  --text-faint:#6b7386;

  --accent:      #6a8dff;
  --accent-soft: #6a8dff22;
  --ok:          #3fb984;
  --warn:        #e0a33e;
  --err:         #e8615f;
  --skip:        #5b6376;

  --trigger: #b07cf0;
  --action:  #4ea3e6;
  --logic:   #e0a33e;

  --radius: 9px;
  --radius-sm: 6px;
  --shadow: 0 8px 28px #0008;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------------------------------------------------------------- top bar */

.topbar {
  height: 52px; flex: 0 0 52px;
  display: flex; align-items: center; gap: 14px;
  padding: 0 16px;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; letter-spacing: .2px; }
.brand-mark { color: var(--accent); font-size: 18px; }
.crumbs { display: flex; align-items: center; gap: 8px; color: var(--text-dim); min-width: 0; flex: 1; }
.crumbs a:hover { color: var(--text); }
.crumbs .sep { color: var(--text-faint); }
.crumbs .current { color: var(--text); font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { display: flex; align-items: center; gap: 10px; }

main { height: calc(100% - 52px); overflow: auto; }

/* ---------------------------------------------------------------- controls */

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 13px; border-radius: var(--radius-sm);
  background: var(--panel); border: 1px solid var(--line);
  cursor: pointer; white-space: nowrap;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: #242936; border-color: #39405180; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #0b0e16; font-weight: 600; }
.btn-primary:hover { background: #7e9dff; border-color: #7e9dff; }
.btn-danger { color: var(--err); }
.btn-danger:hover { background: #e8615f1a; border-color: #e8615f55; }
.btn-sm { padding: 4px 9px; font-size: 12.5px; }
.btn-icon { padding: 6px 8px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field > label { font-size: 12.5px; color: var(--text-dim); font-weight: 550; }
.field .help { font-size: 12px; color: var(--text-faint); line-height: 1.45; }

input[type=text], input[type=number], input[type=password], select, textarea {
  background: var(--bg-input); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 8px 10px; width: 100%;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 78px; }
textarea.code, input.mono { font-family: var(--mono); font-size: 12.5px; }
.row { display: flex; gap: 8px; align-items: center; }
.row > * { min-width: 0; }
.check { display: flex; align-items: center; gap: 9px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px; border-radius: 999px; font-size: 12px;
  background: var(--panel); border: 1px solid var(--line); color: var(--text-dim);
}
.pill-ok   { color: var(--ok);   border-color: #3fb98455; background: #3fb9841a; }
.pill-off  { color: var(--text-faint); }
.pill-err  { color: var(--err);  border-color: #e8615f55; background: #e8615f1a; }

.empty { text-align: center; padding: 70px 20px; color: var(--text-dim); }
.empty h2 { color: var(--text); margin: 0 0 8px; font-size: 18px; }
.empty p { margin: 0 auto 20px; max-width: 46ch; }

/* ---------------------------------------------------------------- lists */

.page { max-width: 1080px; margin: 0 auto; padding: 32px 24px 64px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 26px; }
.page-head h1 { margin: 0 0 6px; font-size: 22px; }
.page-head p { margin: 0; color: var(--text-dim); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(258px, 1fr)); gap: 14px; }

.card {
  background: var(--bg-raised); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; cursor: pointer;
  transition: border-color .12s, transform .12s;
  position: relative; overflow: hidden;
}
.card:hover { border-color: #3d445780; transform: translateY(-1px); }
.card h3 { margin: 0 0 6px; font-size: 15px; }
.card p { margin: 0 0 12px; color: var(--text-dim); font-size: 13px; min-height: 19px; }
.card .meta { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.card .stripe { position: absolute; inset: 0 auto 0 0; width: 3px; }

.list { display: flex; flex-direction: column; gap: 8px; }
.list-item {
  display: flex; align-items: center; gap: 14px;
  background: var(--bg-raised); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 13px 16px; cursor: pointer;
}
.list-item:hover { border-color: #3d445780; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .name { font-weight: 550; }
.list-item .sub { color: var(--text-faint); font-size: 12.5px; margin-top: 2px; }

/* ---------------------------------------------------------------- editor */

.editor { display: flex; height: 100%; }

.palette {
  width: 232px; flex: 0 0 232px; overflow-y: auto;
  background: var(--bg-raised); border-right: 1px solid var(--line); padding: 14px;
}
.palette h4 { margin: 14px 0 8px; font-size: 11px; text-transform: uppercase; letter-spacing: .09em; color: var(--text-faint); }
.palette h4:first-child { margin-top: 0; }
.palette-item {
  display: flex; align-items: center; gap: 9px; width: 100%;
  padding: 8px 10px; margin-bottom: 5px; text-align: left;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius-sm); cursor: pointer;
}
.palette-item:hover { border-color: var(--accent); background: var(--accent-soft); }
.palette-item .dot { width: 8px; height: 8px; border-radius: 3px; flex: 0 0 8px; }
.palette-item .t { font-size: 13px; }

.canvas-wrap { flex: 1; position: relative; overflow: hidden; background: var(--bg); }
.canvas-wrap.connecting { cursor: crosshair; }

/* The dotted grid is painted on the wrapper and offset by JS, so panning a huge canvas costs one
   background-position update instead of re-rendering anything. */
.canvas-grid { position: absolute; inset: 0; background-image: radial-gradient(#ffffff12 1px, transparent 1px); }

.canvas { position: absolute; inset: 0; transform-origin: 0 0; }
.edges { position: absolute; overflow: visible; left: 0; top: 0; width: 1px; height: 1px; pointer-events: none; }

.edge { stroke: #515a70; stroke-width: 2; fill: none; pointer-events: stroke; cursor: pointer; }
.edge:hover { stroke: var(--accent); }
.edge.sel { stroke: var(--accent); stroke-width: 3; }
.edge-hit { stroke: transparent; stroke-width: 14; fill: none; pointer-events: stroke; cursor: pointer; }
.edge-live { stroke: var(--accent); stroke-width: 2; stroke-dasharray: 5 4; }

.node {
  position: absolute; width: 190px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: 0 2px 10px #0006;
  user-select: none;
}
.node:hover { border-color: #444c61; }
.node.sel { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft), 0 2px 10px #0006; }
.node.disabled { opacity: .5; }
.node-head { display: flex; align-items: center; gap: 8px; padding: 9px 11px; cursor: grab; }
.node-head:active { cursor: grabbing; }
.node-kind { width: 9px; height: 9px; border-radius: 3px; flex: 0 0 9px; }
.node-name { font-size: 13px; font-weight: 550; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.node-type { padding: 0 11px 9px; font-size: 11.5px; color: var(--text-faint); font-family: var(--mono);
             overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.port {
  position: absolute; width: 13px; height: 13px; border-radius: 50%;
  background: var(--bg-raised); border: 2px solid #5b6376; cursor: crosshair; z-index: 2;
}
.port:hover, .port.armed { border-color: var(--accent); background: var(--accent); }
.port-in  { left: -7px; }
.port-out { right: -7px; }
.port-label { position: absolute; right: 14px; font-size: 10px; color: var(--text-faint); white-space: nowrap; }

/* Run status ring around a node after an execution. */
.node .run-badge {
  position: absolute; top: -9px; right: -9px;
  min-width: 19px; height: 19px; padding: 0 5px; border-radius: 10px;
  font-size: 11px; font-weight: 650; display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--bg);
}
.run-success { background: var(--ok);   color: #06281c; }
.run-error   { background: var(--err);  color: #2d0b0b; }
.run-skipped { background: var(--skip); color: #0b0e16; }

.canvas-hud {
  position: absolute; left: 12px; bottom: 12px; display: flex; gap: 6px; align-items: center;
  background: #12141ac9; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 5px;
  backdrop-filter: blur(6px);
}
.canvas-hint {
  position: absolute; right: 12px; bottom: 12px;
  color: var(--text-faint); font-size: 12px; background: #12141ac9;
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 6px 10px;
}

/* ---------------------------------------------------------------- inspector */

.inspector {
  width: 356px; flex: 0 0 356px; overflow-y: auto;
  background: var(--bg-raised); border-left: 1px solid var(--line);
}
.inspector-head { padding: 14px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--bg-raised); z-index: 3; }
.inspector-head .row { justify-content: space-between; }
.inspector-body { padding: 14px; }
.inspector h5 { margin: 20px 0 10px; font-size: 11px; text-transform: uppercase; letter-spacing: .09em; color: var(--text-faint); }
.inspector h5:first-child { margin-top: 0; }

.kv-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 6px; margin-bottom: 6px; }
.cond-row { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: 6px; margin-bottom: 6px; }

.expr-hint { font-size: 11px; color: var(--text-faint); font-family: var(--mono); }

.webhook-url {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-input); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 8px 10px;
  font-family: var(--mono); font-size: 12px; word-break: break-all;
}
.webhook-url .u { flex: 1; min-width: 0; }
.webhook-url .env-part { color: var(--accent); font-weight: 650; }

/* ---------------------------------------------------------------- run panel */

.runbar {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: var(--bg-raised); border-top: 1px solid var(--line);
  max-height: 46%; display: flex; flex-direction: column;
}
.runbar-head { display: flex; align-items: center; gap: 10px; padding: 9px 14px; border-bottom: 1px solid var(--line-soft); }
.runbar-body { overflow: auto; padding: 10px 14px 14px; }
.run-node {
  display: flex; align-items: center; gap: 10px; padding: 7px 9px;
  border-radius: var(--radius-sm); cursor: pointer; border: 1px solid transparent;
}
.run-node:hover { background: var(--panel); }
.run-node.sel { background: var(--panel); border-color: var(--line); }
.run-node .n { flex: 1; }
.run-dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 8px; }
pre.json {
  background: var(--bg-input); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 10px; margin: 8px 0 0; overflow: auto; max-height: 220px;
  font-family: var(--mono); font-size: 12px; color: #c7d0e4;
}

/* ---------------------------------------------------------------- modal + toast */

.modal-backdrop {
  position: fixed; inset: 0; background: #060810bb; z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal {
  background: var(--bg-raised); border: 1px solid var(--line); border-radius: var(--radius);
  width: min(560px, 100%); max-height: 85vh; overflow: auto; box-shadow: var(--shadow);
}
.modal-head { padding: 16px 18px; border-bottom: 1px solid var(--line); font-weight: 600; }
.modal-body { padding: 18px; }
.modal-foot { padding: 14px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 9px; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 11px 16px; box-shadow: var(--shadow); z-index: 60; max-width: 78vw;
}
.toast.err { border-color: #e8615f77; color: #ffb3b2; }
.toast.ok  { border-color: #3fb98477; }
