:root {
  --bg: #f6f7f9; --surface: #fff; --surface-2: #f0f2f5; --border: #dde1e7; --text: #1b1f27; --muted: #6b7280;
  --accent: #f6821f; --accent-text: #fff; --ok: #1f9d55; --err: #d64545; --run: #3b82f6;
  --grid: #e3e6eb; --edge: #8b95a5; --edge-sel: #f6821f;
  --c-trigger: #f6821f; --c-flow: #7c5cff; --c-action: #2f7de1; --c-data: #12a594;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a; --surface: #1c1f25; --surface-2: #252932; --border: #323744; --text: #e8eaee; --muted: #8b93a3;
    --grid: #23262d; --edge: #6b7486;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { font: 13px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 5px 11px; cursor: pointer; }
button:hover { background: var(--surface-2); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.primary:hover { filter: brightness(1.06); }
button.ghost { background: transparent; border-color: transparent; }
button.ghost:hover { background: var(--surface-2); }
button.danger { color: var(--err); }
button.small { padding: 2px 8px; font-size: 12px; }
input[type=text], input:not([type]), input[type=number], input[type=password], select, textarea {
  width: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 5px 8px;
}
textarea { resize: vertical; }
textarea.code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.muted { color: var(--muted); }
.pad { padding: 14px; }
.spacer { flex: 1; }

#app { display: grid; grid-template-columns: 224px 1fr 340px; height: 100vh; }
#sidebar { background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.brand { padding: 14px 16px; font-weight: 700; font-size: 15px; letter-spacing: .2px; }
.brand::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--accent); margin-right: 8px; }
.side-section { padding: 6px 10px 10px; border-top: 1px solid var(--border); overflow: auto; }
.side-section.grow { flex: 1; min-height: 0; }
.side-head { display: flex; justify-content: space-between; align-items: center; margin: 4px 4px 6px; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .6px; }
#wf-list { max-height: 220px; overflow: auto; }
.wf-item { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.wf-item:hover { background: var(--surface-2); }
.wf-item.sel { background: var(--surface-2); font-weight: 600; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--border); flex: none; }
.dot.on, .dot.success { background: var(--ok); }
.dot.error { background: var(--err); }
.dot.running, .dot.queued { background: var(--run); }
.small-link { display: inline-block; margin: 6px 8px 0; color: var(--muted); cursor: pointer; font-size: 12px; }
.small-link:hover { color: var(--text); }
.pal-group { margin: 8px 4px 4px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
.pal-item { display: flex; align-items: center; gap: 8px; padding: 5px 8px; border-radius: 6px; cursor: grab; user-select: none; }
.pal-item:hover { background: var(--surface-2); }
.swatch { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.cat-trigger { --cat: var(--c-trigger); } .cat-flow { --cat: var(--c-flow); } .cat-action { --cat: var(--c-action); } .cat-data { --cat: var(--c-data); }

#main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
#topbar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--surface); border-bottom: 1px solid var(--border); }
#wf-name { max-width: 320px; font-weight: 600; border-color: transparent; background: transparent; }
#wf-name:hover, #wf-name:focus { border-color: var(--border); background: var(--surface); }
.switch { display: flex; align-items: center; gap: 6px; cursor: pointer; margin-right: 4px; }
#canvas-wrap { position: relative; flex: 1; min-height: 0; }
#canvas { position: absolute; inset: 0; overflow: hidden; cursor: grab; touch-action: none;
  background-color: var(--bg); background-image: radial-gradient(var(--grid) 1px, transparent 1px); background-size: 22px 22px; }
#canvas.panning { cursor: grabbing; }
#world { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
#edges { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; }
#edges path { fill: none; stroke: var(--edge); stroke-width: 2; pointer-events: none; }
#edges path.hit { stroke: transparent; stroke-width: 14; pointer-events: stroke; cursor: pointer; }
#edges path.sel { stroke: var(--edge-sel); }
#edges path.temp { stroke: var(--accent); stroke-dasharray: 5 4; }
#empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); pointer-events: none; }
#zoom { position: absolute; right: 12px; bottom: 12px; display: flex; gap: 2px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 2px; }

.node { position: absolute; width: 190px; background: var(--surface); border: 1.5px solid var(--border); border-radius: 9px; cursor: move; user-select: none; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.node.sel { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.node-head { display: flex; align-items: center; gap: 7px; padding: 8px 10px 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.node-head .swatch { background: var(--cat); }
.node-sub { padding: 0 10px 8px 25px; color: var(--muted); font-size: 11px; }
.node-badge { margin-left: 6px; font-size: 10px; padding: 1px 6px; border-radius: 9px; background: var(--surface-2); color: var(--muted); }
.node-badge.success { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.node-badge.error { background: color-mix(in srgb, var(--err) 18%, transparent); color: var(--err); }
.node.status-error { border-color: var(--err); }
.port { position: absolute; width: 13px; height: 13px; border-radius: 50%; background: var(--surface); border: 2px solid var(--edge); transform: translate(-50%, -50%); cursor: crosshair; }
.port:hover, .port.hot { border-color: var(--accent); background: var(--accent); }
.port-label { position: absolute; font-size: 10px; color: var(--muted); transform: translate(-100%, -50%); padding-right: 11px; pointer-events: none; white-space: nowrap; }

#panel { background: var(--surface); border-left: 1px solid var(--border); overflow: auto; min-height: 0; }
.field { margin: 0 14px 12px; }
.field > label { display: block; margin-bottom: 4px; font-size: 12px; font-weight: 600; }
.field .help { margin-top: 3px; color: var(--muted); font-size: 11.5px; }
.field.check { display: flex; align-items: center; gap: 8px; }
.field.check label { margin: 0; }
.field.check input { width: auto; }
.kv-row { display: flex; gap: 6px; margin-bottom: 6px; }
.kv-row input { flex: 1; min-width: 0; }
.kv-row button { padding: 2px 8px; }
.panel-title { padding: 14px 14px 4px; font-weight: 700; font-size: 14px; }
.panel-desc { padding: 0 14px 12px; color: var(--muted); }
.panel-sep { border-top: 1px solid var(--border); margin: 6px 0 12px; }
.url-box { background: var(--surface-2); border-radius: 6px; padding: 7px 9px; word-break: break-all; font-family: ui-monospace, monospace; font-size: 11.5px; }
.run-block { margin: 0 14px 10px; border: 1px solid var(--border); border-radius: 7px; }
.run-block summary { padding: 6px 9px; cursor: pointer; display: flex; gap: 8px; align-items: center; }
.run-block pre { margin: 0; padding: 8px 10px; border-top: 1px solid var(--border); max-height: 220px; overflow: auto; font-size: 11.5px; white-space: pre-wrap; word-break: break-word; }
.run-block .lbl { color: var(--muted); font-size: 11px; padding: 6px 10px 0; }
.err-text { color: var(--err); padding: 6px 10px; }

#drawer { height: 150px; background: var(--surface); border-top: 1px solid var(--border); display: flex; flex-direction: column; }
.drawer-head { display: flex; gap: 10px; padding: 6px 12px; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .6px; }
#exec-list { overflow: auto; flex: 1; padding: 0 6px 6px; }
.exec-item { display: flex; align-items: center; gap: 10px; padding: 4px 8px; border-radius: 6px; cursor: pointer; }
.exec-item:hover, .exec-item.sel { background: var(--surface-2); }
.exec-item .mode { color: var(--muted); width: 58px; }
.exec-item .time { color: var(--muted); }
.exec-item .err { color: var(--err); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* --- account, workspace, invites --- */
.avatar { width: 26px; height: 26px; border-radius: 50%; background: var(--surface-2); border: 1px solid var(--border);
  display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 12px; flex: none; overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
#identity { display: flex; align-items: center; gap: 8px; }
.me-info { flex: 1; min-width: 0; }
.ellip { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#me-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#me-role { font-size: 11px; text-transform: capitalize; }
#ws-select { margin: 2px 0 2px; }

.overlay { position: fixed; inset: 0; background: var(--bg); display: grid; place-items: center; z-index: 20; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 26px 30px; width: 340px;
  display: flex; flex-direction: column; gap: 10px; box-shadow: 0 8px 30px rgba(0,0,0,.12); }
.login-card .brand { padding: 0 0 4px; }
.login-card button { padding: 8px 12px; }
.login-card a { color: var(--accent); }

#ws-dialog { width: 520px; max-height: 82vh; overflow: auto; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.dialog-head h3 { margin: 0; }
.ws-sub { margin: 16px 0 6px; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .6px; }
.ws-row { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; }
.ws-row input { flex: 1; min-width: 0; }
.member-row { display: flex; gap: 8px; align-items: center; padding: 5px 0; border-bottom: 1px solid var(--border); }
.member-row:last-child { border-bottom: none; }
.role-sel { width: auto; }
.role-tag { text-transform: capitalize; }

dialog { border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text); padding: 18px; width: 440px; }
dialog::backdrop { background: rgba(0,0,0,.35); }
dialog h3 { margin: 0 0 4px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
#toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 8px; z-index: 10; }
