@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap");

/* Automation portfolio workflow theme */
:root {
  --canvas: #120e17;
  --canvas-dot: #362340;
  --node-bg: #1a1222;
  --node-border: rgba(185, 144, 255, 0.24);
  --text: #f8f0ff;
  --muted: #b5a4bd;
  --label: #c8c8d0;
  --sub: #826f8c;
  --accent: #b990ff;
  --wire: #4e9dff;
  --wire-hot: #ff6f91;
  --chrome: #09070c;
  --chrome-line: #2b1c34;
  --surface: #1a1222;
  --run: #d6ff6e;
  --font: Inter, system-ui, sans-serif;
  --node: 96px;
  --node-r: 20px;
  --trigger-r: 36px;
  --config: 80px;
  --agent-w: 256px;
  --agent-h: 96px;
  --icon: 48px;
  --icon-config: 36px;
  --handle: 8px;
  --grid: 16px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--canvas);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }

.app { display: grid; grid-template-rows: 48px 1fr 52px; height: 100%; }
.app.embedded { grid-template-rows: 1fr; }
.app.embedded .topbar,
.app.embedded .footer { display: none; }
.app.embedded .stage { min-height: 100%; }

/* ── Editor chrome ──────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 0 14px;
  background: var(--chrome);
  border-bottom: 1px solid var(--chrome-line);
  z-index: 20;
}
.brand {
  display: flex; align-items: center; gap: 8px;
  padding-right: 12px; border-right: 1px solid var(--chrome-line); flex-shrink: 0;
}
.mark {
  width: 22px; height: 22px; border-radius: 6px;
  background: var(--accent); color: #fff;
  display: grid; place-items: center; font-weight: 800; font-size: 10px;
}
.brand small { display: block; font-size: 9px; color: #6a6a76; letter-spacing: .1em; text-transform: uppercase; font-weight: 600; }
.brand strong { font-size: 12px; }
.titles { min-width: 0; flex: 1; }
.titles h1 { font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.titles p { display: none; }
.pill {
  font-size: 11px; font-weight: 600;
  color: #c4c4ce; background: var(--surface);
  border: 1px solid #3a3a44; border-radius: 999px; padding: 3px 10px;
}
.status { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: #6a6a76; }
.actions { display: flex; gap: 6px; flex-shrink: 0; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; height: 28px; padding: 0 10px;
  border-radius: 6px; background: var(--surface); border: 1px solid #3a3a44;
  font-size: 12px; color: var(--muted); line-height: 1;
}
.btn:hover { color: var(--text); border-color: #5a5a66; }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 650; }

/* ── Canvas ─────────────────────────────────────────────── */
.stage { position: relative; overflow: hidden; background: var(--canvas); touch-action: none; }
.stage::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background-image: radial-gradient(circle, var(--canvas-dot) 1px, transparent 1.2px);
  background-size: var(--grid) var(--grid);
}
.world { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; }
.edges { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; z-index: 2; }
.edge {
  fill: none;
  stroke: var(--wire);
  stroke-width: 2;
  stroke-linecap: square;
}
.edge.tool { stroke-dasharray: 5 5; }
.edge.loop { stroke: #9b8cff; }
.edge.hot { stroke: var(--wire-hot); stroke-width: 2.4; }
.edge-run {
  fill: none;
  stroke: var(--run);
  stroke-width: 6;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 0 5px var(--run));
  pointer-events: none;
  opacity: 0;
}
.edge-label {
  fill: var(--muted);
  font-size: 11px;
  font-family: var(--font);
  font-weight: 500;
}

/* ── Sticky notes ───────────────────────────────────────── */
.group {
  position: absolute; border-radius: 8px;
  border: 1px solid color-mix(in srgb, var(--g) 40%, transparent);
  background: color-mix(in srgb, var(--g) 16%, transparent);
  pointer-events: none;
  z-index: 1;
}
.group-label {
  position: absolute; left: 12px; top: 8px;
  font-size: 12px; font-weight: 650;
  color: color-mix(in srgb, var(--g) 72%, #fff);
}

/* ── Standard node: 96×96 rounded square, label below ───── */
.node {
  position: absolute;
  width: var(--node);
  display: flex; flex-direction: column; align-items: center;
  background: transparent; border: 0; padding: 0;
  cursor: pointer;
  z-index: 3;
}
.node-box {
  position: relative;
  width: var(--node); height: var(--node);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--node-bg);
  border: 1.5px solid var(--node-border);
  border-radius: var(--node-r);
  color: var(--c, #a5a5ad);
  transition: border-color 90ms linear, box-shadow 90ms linear, background-color 90ms linear;
}
.node.trigger .node-box {
  border-radius: var(--trigger-r) var(--node-r) var(--node-r) var(--trigger-r);
}
.node-icon {
  width: var(--icon); height: var(--icon);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: inherit;
  line-height: 0;
}
.node-icon svg {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
}
.node-icon.brand svg {
  max-width: 78%;
  max-height: 78%;
}

.node-text {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  width: calc(var(--node) * 2);
  min-width: calc(var(--node) * 2);
  margin-top: 6px;
  display: flex; flex-direction: column; gap: 2px;
  pointer-events: none;
  text-align: center;
}
.node-label {
  font-size: 13px; font-weight: 500; line-height: 1.25; color: #f4f4f6;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; overflow-wrap: anywhere;
}
.node-sub {
  font-size: 11px; font-weight: 400; color: var(--sub); line-height: 1.25;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.port {
  position: absolute;
  top: 50%;
  width: var(--handle); height: var(--handle);
  border-radius: 50%;
  background: var(--node-bg);
  border: 1px solid #8a8a94;
  z-index: 4;
}
.port.in { left: 0; transform: translate(-50%, -50%); }
.port.out { right: 0; transform: translate(50%, -50%); }

.node:hover .node-box, .node.hot .node-box {
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.08);
}
.node.selected .node-box {
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 28%, transparent);
}
.node.lit-out .node-box,
.node.lit-out:hover .node-box,
.node.lit-out.hot .node-box,
.node.lit-out.selected .node-box,
.node.agent-card.lit-out .node-box,
.node.agent-card.lit-out:hover .node-box,
.node.agent-card.lit-out.hot .node-box,
.node.agent-card.lit-out.selected .node-box {
  border-color: color-mix(in srgb, var(--run) 55%, transparent);
  background: color-mix(in srgb, var(--run) 10%, var(--node-bg));
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--run) 40%, transparent), 0 0 8px color-mix(in srgb, var(--run) 22%, transparent);
}
.node.lit-in .node-box,
.node.lit-in:hover .node-box,
.node.lit-in.hot .node-box,
.node.lit-in.selected .node-box,
.node.agent-card.lit-in .node-box,
.node.agent-card.lit-in:hover .node-box,
.node.agent-card.lit-in.hot .node-box,
.node.agent-card.lit-in.selected .node-box,
.node.lit-in.lit-out .node-box,
.node.agent-card.lit-in.lit-out .node-box {
  border-color: var(--run);
  background: color-mix(in srgb, var(--run) 28%, var(--node-bg));
  box-shadow: 0 0 0 3px var(--run), 0 0 18px color-mix(in srgb, var(--run) 70%, transparent);
}

/* Lightning bolt — n8n trigger marker */
.bolt {
  position: absolute;
  right: 100%;
  top: 50%;
  transform: translateY(-50%);
  color: var(--accent);
  padding: 8px 10px 8px 0;
  display: grid; place-items: center;
  pointer-events: none;
}
.bolt svg { width: 18px; height: 18px; display: block; }

/* ── Config / tool nodes: 80px circle ───────────────────── */
.node.config { width: var(--config); }
.node.config .node-box {
  width: var(--config); height: var(--config);
  border-radius: 50%;
}
.node.config .node-icon { width: var(--icon-config); height: var(--icon-config); }
.node.config .node-icon svg,
.node.config .node-icon.brand svg {
  width: auto;
  height: auto;
  max-width: 78%;
  max-height: 78%;
}
.node.config .node-text {
  width: calc(var(--config) * 2);
  min-width: calc(var(--config) * 2);
}
.node.config .port.in, .node.config .port.out { display: none; }

/* ── AI Agent: configurable rectangle 256×96 ────────────── */
.node.agent-card {
  width: var(--agent-w);
  align-items: stretch;
}
.node.agent-card .node-box {
  width: var(--agent-w); height: var(--agent-h);
  display: flex; align-items: center; justify-content: flex-start;
  gap: 12px;
  padding: 0 16px 0 18px;
  border-radius: 12px;
  color: #d4d4dc;
}
.node.agent-card .node-icon {
  width: 28px; height: 28px; flex-shrink: 0;
}
.node.agent-card .node-icon svg { width: 28px; height: 28px; color: #d4d4dc; }
.node.agent-card .node-text {
  position: relative;
  top: auto; left: auto; transform: none;
  width: auto; min-width: 0; flex: 1;
  margin-top: 0; text-align: left;
}
.node.agent-card .node-label {
  font-size: 14px; font-weight: 600; -webkit-line-clamp: 1;
}
.node.agent-card .node-sub { text-align: left; }
.node.agent-card:hover .node-box, .node.agent-card.hot .node-box,
.node.agent-card.selected .node-box {
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.1);
}
.node.agent-card.lit-out:hover .node-box, .node.agent-card.lit-out.hot .node-box,
.node.agent-card.lit-out.selected .node-box {
  border-color: color-mix(in srgb, var(--run) 55%, transparent);
  background: color-mix(in srgb, var(--run) 10%, var(--node-bg));
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--run) 40%, transparent), 0 0 8px color-mix(in srgb, var(--run) 22%, transparent);
}
.node.agent-card.lit-in:hover .node-box, .node.agent-card.lit-in.hot .node-box,
.node.agent-card.lit-in.selected .node-box {
  border-color: var(--run);
  background: color-mix(in srgb, var(--run) 28%, var(--node-bg));
  box-shadow: 0 0 0 3px var(--run), 0 0 18px color-mix(in srgb, var(--run) 70%, transparent);
}

.diamonds {
  position: absolute;
  left: 0; right: 0;
  top: var(--agent-h);
  height: 18px;
  display: flex; justify-content: space-evenly; align-items: flex-start;
  pointer-events: none;
}
.diamond-slot {
  position: relative;
  width: 64px;
  display: flex; flex-direction: column; align-items: center;
}
.diamond {
  width: 9px; height: 9px;
  background: var(--node-bg);
  border: 1px solid #8a8a94;
  transform: rotate(45deg) scale(0.85);
  margin-top: -5px;
}
.dlabel {
  margin-top: 8px;
  font-size: 10px;
  color: var(--muted);
  white-space: nowrap;
  background: color-mix(in srgb, var(--canvas) 85%, transparent);
  padding: 0 2px;
}
.dlabel .req { color: #f43f5e; }

/* n8n dark-mode node icon colors (--node--icon--color--*) */
.type-http, .type-set, .type-vapi, .type-reapit, .type-heygen, .type-leonardo { --c: #898fff; }
.type-webhook, .type-respond { --c: #ff4d80; }
.type-code { --c: #ffb966; }
.type-if { --c: #22c55e; }
.type-wait { --c: #f188a2; }
.type-trigger, .type-schedule, .type-markdown, .type-agent, .type-calc, .type-memory, .type-parser { --c: #c8c8d0; }
.type-merge { --c: #7dd6e3; }
.type-filter, .type-switch { --c: #58abff; }
.type-loop { --c: #86decc; }
.type-error { --c: #f87171; }
.type-html { --c: #ff7755; }
.type-n8n { --c: #f85d82; }
.type-execute, .type-ffmpeg, .type-file, .type-split, .type-aggregate, .type-splitter { --c: #a5a5ad; }

/* ── Tooltip / inspector ────────────────────────────────── */
.tooltip {
  position: fixed; z-index: 40; width: 320px; max-width: calc(100vw - 24px);
  pointer-events: none; opacity: 0; transform: translateY(4px);
  transition: opacity .12s, transform .12s;
  background: #2a2a32; border: 1px solid #4a4a56; border-radius: 10px;
  box-shadow: 0 18px 50px rgba(0,0,0,.5);
  padding: 12px 14px 14px;
}
.tooltip.show { opacity: 1; transform: none; }
.tooltip .kicker {
  display: flex; justify-content: space-between;
  font-size: 10px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--accent); margin-bottom: 6px;
}
.tooltip h3 { font-size: 14px; font-weight: 650; margin-bottom: 4px; }
.tooltip .op { font-size: 11px; color: var(--muted); margin-bottom: 8px; }
.tooltip p { font-size: 12.5px; line-height: 1.5; color: #d4d4dc; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 10px; }
.chip {
  font-size: 10px; font-weight: 600; color: var(--muted);
  border: 1px solid #4a4a56; border-radius: 999px; padding: 2px 8px;
}

.inspector {
  position: absolute; right: 14px; top: 14px; width: 300px;
  background: rgba(20,20,24,.94); backdrop-filter: blur(12px);
  border: 1px solid #3a3a44; border-radius: 12px;
  padding: 14px; z-index: 15; display: none;
  box-shadow: 0 16px 40px rgba(0,0,0,.45);
}
.inspector.open { display: block; }
.inspector h2 { font-size: 15px; margin: 4px 0 8px; }
.inspector .meta { font-size: 11px; color: var(--muted); margin-bottom: 10px; }
.inspector p { font-size: 13px; line-height: 1.5; color: #d4d4dc; }
.inspector .close {
  position: absolute; right: 8px; top: 8px; width: 26px; height: 26px;
  border-radius: 6px; color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center; line-height: 1;
}
.inspector .close:hover { background: #2a2a32; color: var(--text); }

.footer {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 14px; border-top: 1px solid var(--chrome-line); background: var(--chrome);
  font-size: 11px; color: #6a6a76; z-index: 20;
  position: relative;
}
.hint { max-width: 55%; }
.hint span { color: var(--muted); }
.execute {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 34px;
  padding: 0 22px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  line-height: 1;
  white-space: nowrap;
  width: max-content;
  pointer-events: none;
}
.zoom { display: flex; align-items: center; gap: 4px; }
.zoom button {
  width: 26px; height: 26px; border-radius: 6px; border: 1px solid #3a3a44;
  background: var(--surface); color: var(--muted); font-size: 14px;
  display: inline-flex; align-items: center; justify-content: center;
  line-height: 1;
}
.zoom button:hover { color: var(--text); }
.zoom b { min-width: 42px; text-align: center; font-weight: 600; color: var(--muted); font-size: 11px; }

.note {
  position: absolute; padding: 12px 14px; border-radius: 8px;
  font-size: 12px; line-height: 1.45; color: #3d3208;
  background: #e8d36a; border: 0;
  box-shadow: 0 6px 18px rgba(0,0,0,.25);
  pointer-events: none;
}
.note strong { display: block; font-size: 11px; letter-spacing: .04em; text-transform: uppercase; margin-bottom: 6px; color: #5a4a10; }

.value-btn {
  position: absolute;
  left: 100%;
  top: 48px;
  transform: translate(28px, -50%);
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--node);
  height: var(--node);
  padding: 10px 8px;
  border-radius: var(--node-r);
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
  text-align: center;
  box-shadow: 0 0 0 1.5px color-mix(in srgb, var(--accent) 35%, transparent);
  pointer-events: auto;
}
.value-btn span { display: block; }
.value-btn:hover { filter: brightness(1.08); }
.node.config .value-btn { top: 40px; }
.node.value-open .value-btn {
  background: var(--node-bg);
  color: var(--accent);
  box-shadow: 0 0 0 1.5px var(--accent);
}

.run-output {
  position: absolute;
  width: 400px;
  z-index: 4;
  opacity: 0;
  transform: translateX(-10px) scale(0.96);
  transform-origin: left 20px;
  pointer-events: none;
  filter: drop-shadow(0 12px 32px rgba(0, 0, 0, 0.55));
  transition: opacity 0.28s ease, transform 0.28s cubic-bezier(.2, .85, .2, 1);
}
.run-output.show {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}
.run-output-box {
  position: relative;
  background: #0E0E0E;
  border: 0.5px solid color-mix(in srgb, var(--run) 18%, transparent);
  border-radius: 14px;
  padding: 20px 18px 18px;
  overflow: hidden;
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--run) 4%, transparent), 0 16px 40px rgba(0, 0, 0, 0.5);
}
.run-output-box::before {
  content: "";
  position: absolute;
  left: 0; right: 0; top: 0;
  height: 2px;
  background: var(--run);
}
.run-output-kicker {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--run);
}
.run-output-kicker i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--run);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--run) 12%, transparent);
  display: block;
  flex-shrink: 0;
}
.value-close {
  margin-left: auto;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  color: #555;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  line-height: 1;
}
.value-close:hover { color: #F4F4F4; background: #181818; }
.run-output h2 {
  font-size: 18px;
  font-weight: 600;
  color: #F4F4F4;
  margin: 10px 0 16px;
  letter-spacing: -0.03em;
  line-height: 1.3;
}
.run-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  margin: 0 -18px 16px;
  border-top: 0.5px solid #242424;
  border-bottom: 0.5px solid #242424;
  background: #0A0A0A;
}
.run-stat {
  background: transparent;
  border: 0;
  border-right: 0.5px solid #242424;
  border-radius: 0;
  padding: 14px 8px 12px;
  text-align: center;
}
.run-stat:last-child { border-right: 0; }
.run-stat b {
  display: block;
  font-size: 18px;
  color: #F4F4F4;
  font-weight: 500;
  letter-spacing: -0.03em;
  line-height: 1.15;
}
.run-stat span {
  display: block;
  margin-top: 4px;
  font-size: 9px;
  font-weight: 500;
  color: #555555;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  line-height: 1.25;
}
.run-items {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.run-items li {
  font-size: 13px;
  color: #AAAAAA;
  line-height: 1.5;
  padding-left: 22px;
  position: relative;
}
.run-items li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 4px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--run) 10%, transparent);
  border: 0.5px solid color-mix(in srgb, var(--run) 25%, transparent);
}
.run-items li::after {
  content: "";
  position: absolute;
  left: 3.5px;
  top: 7px;
  width: 6px;
  height: 3.5px;
  border-left: 1.6px solid var(--run);
  border-bottom: 1.6px solid var(--run);
  transform: rotate(-45deg);
}

@media (max-width: 820px) {
  .inspector { left: 12px; right: 12px; width: auto; top: auto; bottom: 72px; max-height: 46vh; overflow: auto; }
  .execute { display: none; }
  .brand small, .status, .pill { display: none; }
  .titles h1 { max-width: 42vw; }
  .actions .btn:not(.primary) { display: none; }
  .topbar { gap: 8px; padding: 0 10px; }
  .hint { max-width: none; }
  .footer { padding-bottom: env(safe-area-inset-bottom); }
  .zoom button { width: 36px; height: 36px; }
}
