:root {
  --ink: oklch(0.24 0.04 45);
  --ink-soft: oklch(0.39 0.03 45);
  --card: oklch(0.995 0.004 80);
  --coral: oklch(0.58 0.17 35);
  --coral-deep: oklch(0.46 0.13 35);
  --line: oklch(0.88 0.02 70);
  --ok: oklch(0.46 0.11 155);
  --font-d: "Red Hat Display", "Segoe UI", sans-serif;
  --font-b: "Atkinson Hyperlegible", "Segoe UI", sans-serif;
  --shadow: 0 22px 50px oklch(0.42 0.08 35 / 0.22);
  --z-token: 4;
  --z-node: 2;
  --z-wire: 1;
  color-scheme: light;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-b);
  font-size: 1.0625rem;
  line-height: 1.55;
  color: var(--ink);
  background:
    radial-gradient(ellipse at 8% 0%, oklch(0.9 0.12 85), transparent 42%),
    radial-gradient(ellipse at 96% 18%, oklch(0.72 0.16 15), transparent 40%),
    linear-gradient(118deg, oklch(0.84 0.13 68), oklch(0.73 0.15 36) 52%, oklch(0.76 0.12 12));
}
button, input { font: inherit; color: inherit; }
h1, h2 { font-family: var(--font-d); text-wrap: balance; letter-spacing: -0.03em; }
h1 { font-size: clamp(1.8rem, 3vw, 2.4rem); line-height: 1.05; margin: 0; font-weight: 800; }
p { text-wrap: pretty; }

.orb {
  position: fixed; border-radius: 50%; pointer-events: none;
  background: radial-gradient(circle at 35% 30%, oklch(0.97 0.04 90), oklch(0.78 0.14 55) 55%, oklch(0.7 0.15 30));
  animation: float 8s ease-in-out infinite;
}
.orb-a { width: 72px; height: 72px; left: 4%; top: 8%; }
.orb-b { width: 110px; height: 110px; right: 6%; top: 4%; animation-delay: -3s; background: radial-gradient(circle at 35% 30%, oklch(0.96 0.03 50), oklch(0.74 0.14 10)); }
.orb-c { width: 64px; height: 64px; left: 8%; bottom: 6%; animation-delay: -2s; }
@keyframes float { 50% { transform: translateY(-12px); } }

main { min-height: 100vh; display: grid; place-items: center; padding: 28px 16px; }
.board {
  width: min(1120px, 100%);
  background: var(--card);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 22px 22px 18px;
  position: relative;
}
.brand { display: inline-flex; align-items: center; gap: 8px; font-family: var(--font-d); font-weight: 750; letter-spacing: -0.03em; }
.mark { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; color: white; background: oklch(0.66 0.18 38); }
.board-top, .board-title, .sim-actions, .lead-card, .board-tools { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.board-tools { gap: 12px; }
.view-switch { display: flex; padding: 3px; border-radius: 999px; background: oklch(0.96 0.01 75); border: 1px solid var(--line); }
.view-switch button { border: 0; background: transparent; border-radius: 999px; padding: 6px 12px; cursor: pointer; font-family: var(--font-d); font-weight: 700; }
.view-switch button[aria-pressed="true"] { background: var(--ink); color: white; }
.profiles { display: flex; gap: 8px; }
.profile {
  width: 52px; height: 52px; padding: 0; border-radius: 50%; border: 2px solid transparent; overflow: hidden; cursor: pointer; background: white;
}
.profile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.profile[aria-selected="true"] { border-color: var(--coral); box-shadow: 0 0 0 3px oklch(0.72 0.14 55 / 0.45); }
.profile:hover { transform: translateY(-2px); }
.avatar { overflow: hidden; padding: 0; }
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar.pop { animation: pop 0.45s cubic-bezier(0.16, 1, 0.3, 1); }
@keyframes pop { 50% { transform: scale(1.08); } }
.board-top { padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.last-run { margin: 0; display: flex; align-items: center; gap: 8px; font-size: 0.92rem; color: var(--ink-soft); }
.last-run strong { color: var(--ok); font-weight: 700; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 4px oklch(0.92 0.05 155); }
.board-title { align-items: flex-end; margin: 18px 0; }
.board-title p { margin: 0; max-width: 42ch; color: var(--ink-soft); font-size: 0.98rem; }

.sim { display: grid; gap: 14px; margin-bottom: 16px; }
.lead-card { justify-content: flex-start; background: oklch(0.97 0.015 75); border-radius: 14px; padding: 12px; }
.avatar {
  width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: oklch(0.66 0.16 38); color: white; font-family: var(--font-d); font-weight: 750;
}
.lead-fields { display: flex; gap: 12px; flex: 1; min-width: 0; }
.lead-fields label, .switches label { display: grid; gap: 4px; font-size: 0.82rem; font-family: var(--font-d); font-weight: 650; color: var(--ink-soft); }
.lead-fields input { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: white; width: 100%; }
.lead-fields input:focus, .node:focus-visible, .btn:focus-visible { outline: 3px solid oklch(0.72 0.14 55); outline-offset: 2px; }
.status {
  margin: 0 0 0 auto; background: white; border-radius: 999px; padding: 6px 12px;
  font-family: var(--font-d); font-weight: 700; font-size: 0.85rem; white-space: nowrap;
}
.switches { display: flex; flex-wrap: wrap; gap: 8px 14px; }
.switch { display: flex; align-items: center; gap: 8px; color: var(--ink); font-size: 0.95rem; font-family: var(--font-b); font-weight: 400; }
.switch input { width: 1.05rem; height: 1.05rem; accent-color: var(--coral); }
.switch:has(input:disabled) { color: oklch(0.45 0.02 50); }
.sim-actions { flex-wrap: wrap; justify-content: flex-start; }
.step-count { margin: 0 0 0 auto; color: var(--ink-soft); font-size: 0.92rem; }
.btn { border: 1px solid var(--line); background: white; border-radius: 999px; padding: 10px 16px; cursor: pointer; font-family: var(--font-d); font-weight: 700; }
.btn:hover { border-color: var(--coral); }
.btn-primary { background: var(--coral); border-color: var(--coral); color: white; }
.btn-primary:hover { background: var(--coral-deep); }
.btn:disabled { cursor: not-allowed; opacity: 0.5; }

.map { position: relative; padding: 8px 4px 4px; }
.stage { position: relative; }
#wires { position: absolute; inset: 0; width: 100%; height: 100%; z-index: var(--z-wire); overflow: visible; pointer-events: none; }
.wire { fill: none; stroke: oklch(0.62 0.02 50); stroke-width: 1.6; }
.wire.flowing { stroke-dasharray: 7 8; animation: dash 0.9s linear infinite; }
.wire.active { stroke: var(--coral); stroke-width: 2.6; }
@keyframes dash { to { stroke-dashoffset: -30; } }
.runner { fill: oklch(0.48 0.04 50); }
.runner.active { fill: var(--coral); }
.runner.phone { fill: oklch(0.46 0.1 175); }
.wire.phone { stroke: oklch(0.5 0.08 175); }
.wire-label { font-family: var(--font-d); font-size: 12px; font-weight: 700; fill: var(--ink); paint-order: stroke; stroke: #f4f4f6; stroke-width: 5px; }
.token {
  position: absolute; z-index: var(--z-token); width: 36px; height: 36px; margin-left: -18px; margin-top: -42px;
  border-radius: 50%; overflow: hidden; border: 2px solid white;
  box-shadow: 0 6px 16px oklch(0.3 0.05 40 / 0.28);
  transition: transform 0.55s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: none;
}
.token img { width: 100%; height: 100%; object-fit: cover; display: block; }
.port { display: none; }
.flow { position: relative; z-index: var(--z-node); display: grid; gap: 22px; }
.flow-row { display: flex; flex-wrap: wrap; gap: 14px 18px; align-items: center; }
.split { display: grid; grid-template-columns: 1.7fr 0.8fr; gap: 18px; }
.lane { border-radius: 16px; padding: 12px 12px 14px; background: oklch(0.97 0.02 75); }
.lane h2 { font-size: 0.95rem; letter-spacing: 0; margin: 0 0 10px; color: var(--ink-soft); font-weight: 700; }
.lane-phone { background: oklch(0.95 0.03 175); }
.lane-phone h2 { color: oklch(0.35 0.05 175); }

.node {
  appearance: none; border: 1px solid var(--line); background: white; border-radius: 12px;
  min-width: 108px; min-height: 74px; padding: 8px 10px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  position: relative;
}
.node:hover { border-color: var(--coral); }
.node .ico { color: var(--accent, var(--coral)); display: grid; }
.node .ico svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.node .label { font-family: var(--font-d); font-size: 0.78rem; font-weight: 700; text-align: center; }
.node.is-current { border-color: var(--coral); box-shadow: 0 0 0 3px oklch(0.72 0.14 55 / 0.45); animation: nodepulse 1.1s ease-in-out infinite; }
@keyframes nodepulse { 50% { transform: translateY(-2px); } }
.decision.is-current { animation: none; }
.node.is-done { border-color: var(--ok); }
.node.is-done::after {
  content: "✓"; position: absolute; top: -7px; right: -7px; width: 16px; height: 16px;
  border-radius: 50%; background: white; color: var(--ok); font-size: 0.7rem; font-weight: 700;
  display: grid; place-items: center; line-height: 1; box-shadow: 0 0 0 1px var(--ok);
}
.node.is-off { background: oklch(0.96 0.005 80); color: oklch(0.42 0.02 50); }
.node.is-off .ico { color: oklch(0.55 0.02 50); }
.decision {
  width: 78px; height: 78px; min-width: 78px; border-radius: 10px; transform: rotate(45deg);
  background: oklch(0.97 0.04 85); border-color: oklch(0.78 0.1 75);
}
.decision .face { transform: rotate(-45deg); display: flex; flex-direction: column; align-items: center; gap: 2px; }
.decision .label { font-size: 0.72rem; }
.decision.is-current { box-shadow: 0 0 0 3px oklch(0.72 0.14 55 / 0.45); }

.inspector { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.inspector h2 { font-size: 1.25rem; margin: 0 0 0.25em; }
.inspector p { margin: 0; max-width: 75ch; color: var(--ink-soft); }
.map-hint { margin: 10px 0 0; font-size: 0.88rem; color: var(--ink-soft); }

@media (max-width: 900px) {
  .board-title, .split { display: grid; grid-template-columns: 1fr; }
  .lead-card { flex-wrap: wrap; }
  .status, .step-count { margin-left: 0; }
}
@media (max-width: 640px) {
  .lead-fields { flex-direction: column; }
  h1 { font-size: 1.7rem; }
}
.zoom { position: absolute; z-index: 5; right: 10px; bottom: 10px; display: flex; gap: 6px; }
.zoom button { border: 1px solid var(--line); background: white; border-radius: 8px; min-width: 36px; height: 32px; cursor: pointer; font-family: var(--font-d); font-weight: 700; }
.map.canvas-n8n { padding: 0; overflow: auto; height: 420px; border-radius: 16px; cursor: grab; background: #f4f4f6; }
.map.canvas-n8n.is-panning { cursor: grabbing; }
.map.canvas-n8n .stage { width: 1480px; height: 540px; transform-origin: 0 0; background-image: radial-gradient(#cfcfd4 1.15px, transparent 1.15px); background-size: 20px 20px; }
.map.canvas-n8n .flow, .map.canvas-n8n .split, .map.canvas-n8n .lane, .map.canvas-n8n .flow-row { display: contents; }
.map.canvas-n8n .lane h2 { display: none; }
.map.canvas-n8n .node {
  position: absolute; z-index: 3; width: max-content; min-width: 0; max-width: none;
  min-height: 44px; height: auto; overflow: visible;
  flex-direction: row; justify-content: flex-start; gap: 8px; padding: 8px 14px 8px 22px;
  border-radius: 8px; box-shadow: 0 1px 2px #00000014, 0 8px 18px #0000000a;
}
.map.canvas-n8n .node .label { white-space: nowrap; line-height: 1.2; text-align: left; overflow: visible; background: white; }
.map.canvas-n8n .decision { transform: none; width: max-content; height: auto; min-width: 0; border-radius: 8px; background: white; }
.map.canvas-n8n .decision .face { transform: none; flex-direction: row; gap: 8px; }
.map.canvas-n8n .decision .label { font-size: 0.78rem; background: transparent; }
.map.canvas-n8n .node .ico { width: 26px; height: 26px; border-radius: 6px; background: color-mix(in srgb, var(--accent) 16%, white); }
.map.canvas-n8n .node.is-current { animation: n8npulse 1s ease-in-out infinite; }
@keyframes n8npulse { 50% { box-shadow: 0 0 0 4px oklch(0.72 0.14 55 / 0.4); } }
.map.canvas-n8n .port {
  display: block; position: absolute; top: 50%; width: 10px; height: 10px; margin-top: -5px; border-radius: 50%;
  background: white; border: 2px solid #b9b9c2;
}
.map.canvas-n8n .port-in { left: -6px; }
.map.canvas-n8n .port-out { right: -6px; }
.map.canvas-n8n .port-alt { right: 18px; top: auto; bottom: -6px; margin: 0; }
.map.canvas-n8n .node.is-done .port-out, .map.canvas-n8n .node.is-current .port-out { border-color: var(--coral); background: var(--coral); }

.tip {
  position: fixed; z-index: 40; width: min(280px, calc(100vw - 16px));
  background: #20243a; color: white; border-radius: 12px; padding: 10px 12px;
  box-shadow: 0 12px 28px #20243a40; pointer-events: none;
}
.tip strong { display: block; font-family: var(--font-d); margin-bottom: 4px; }
.tip span { display: block; font-size: 0.92rem; line-height: 1.4; color: #f3f1ea; }
.tip[hidden] { display: none; }

@media (prefers-reduced-motion: reduce) {
  .orb, .token, .node, .wire, .avatar { animation: none; transition: none; }
}
