/* WorkflowViz — n8n-editor-style SVG diagram. Pairs with workflow-viz.js */

.wfviz-wrapper {
  position: relative;
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 0.75rem 0.75rem;
  background-color: #fafbfc;
  /* n8n canvas dot grid */
  background-image: radial-gradient(circle, #d6dce2 1px, transparent 1px);
  background-size: 18px 18px;
  background-position: 0 0;
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  box-shadow: inset 0 0 0 1px #ffffff, 0 8px 24px 0 rgba(15, 23, 42, 0.04);
}

.wfviz-svg {
  width: 100%;
  height: auto;
  display: block;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  overflow: visible;
}

/* ===== TILE (main nodes — Webhook, Switch, AI Agent, Gmail, etc.) ===== */
.wfviz-tile {
  fill: #ffffff;
  stroke: #dfe3e8;
  stroke-width: 1.25;
  transition: stroke 260ms ease, stroke-width 260ms ease, fill 260ms ease;
}
.wfviz-node-tile .wfviz-icon { transition: transform 260ms ease; }

.wfviz-label {
  fill: #4b5563;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.01em;
  pointer-events: none;
  user-select: none;
  transition: fill 260ms ease, font-weight 260ms ease;
}
.wfviz-sublabel {
  fill: #94a3b8;
  font-size: 9.5px;
  font-weight: 400;
  letter-spacing: 0.01em;
  pointer-events: none;
  user-select: none;
}

/* ===== SUB-TOOLS (Groq, Parser) — dashed circles below the agent ===== */
.wfviz-sub-circle {
  fill: #ffffff;
  stroke: #cbd5e1;
  stroke-width: 1.25;
  stroke-dasharray: 3 3;
  transition: stroke 260ms ease, stroke-width 260ms ease;
}
.wfviz-label-sub {
  font-size: 9.5px;
  fill: #64748b;
}

/* ===== EDGES ===== */
.wfviz-edge {
  stroke: #b7c0cb;
  stroke-width: 1.25;
  stroke-linecap: round;
  opacity: 0.9;
  transition: stroke 300ms ease, stroke-width 300ms ease, opacity 300ms ease;
}
.wfviz-edge-dashed {
  stroke-dasharray: 4 4 !important;
  opacity: 0.7;
}
.wfviz-edge.is-active {
  stroke: #6366f1;
  stroke-width: 1.75;
  opacity: 1;
  filter: drop-shadow(0 0 3px rgba(99, 102, 241, 0.35));
}

.wfviz-port-dot {
  fill: #ffffff;
  stroke: #94a3b8;
  stroke-width: 1;
}
.wfviz-edge-label {
  fill: #94a3b8;
  font-size: 9.5px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  pointer-events: none;
}
.wfviz-port-label {
  fill: #94a3b8;
  font-size: 9px;
  font-weight: 400;
  pointer-events: none;
}
.wfviz-port-num {
  fill: #64748b;
  font-size: 9px;
  font-weight: 600;
  pointer-events: none;
}

/* ===== STATES ===== */

/* Listening — webhook breathes softly so visitor reads it as "live" */
.wfviz-node.is-listening .wfviz-tile {
  animation: wfviz-breath 2.4s ease-in-out infinite;
}
@keyframes wfviz-breath {
  0%, 100% { filter: drop-shadow(0 1px 2px rgba(234, 75, 42, 0)); stroke: #dfe3e8; }
  50%      { filter: drop-shadow(0 0 8px rgba(234, 75, 42, 0.35)); stroke: #ea4b2a; }
}

/* Pulse — fires on every quiz answer */
.wfviz-node.is-pulse .wfviz-tile {
  animation: wfviz-pulse 640ms ease-out;
}
@keyframes wfviz-pulse {
  0%   { filter: drop-shadow(0 0 0 rgba(234, 75, 42, 0)); }
  50%  { filter: drop-shadow(0 0 10px rgba(234, 75, 42, 0.75)); stroke: #ea4b2a; }
  100% { filter: drop-shadow(0 0 0 rgba(234, 75, 42, 0)); }
}

/* Active — indigo border + soft glow, matching n8n execution highlight */
.wfviz-node.is-active .wfviz-tile,
.wfviz-node.is-active .wfviz-sub-circle {
  stroke: #6366f1;
  stroke-width: 2;
  filter: drop-shadow(0 0 8px rgba(99, 102, 241, 0.4));
}
.wfviz-node.is-active .wfviz-label { fill: #0f172a; font-weight: 600; }

/* Thinking — AI nodes that are processing. Slow indigo pulse. */
.wfviz-node.is-thinking .wfviz-tile,
.wfviz-node.is-thinking .wfviz-sub-circle {
  stroke: #818cf8;
  stroke-width: 1.75;
  animation: wfviz-think 1.2s ease-in-out infinite;
}
.wfviz-node.is-thinking .wfviz-label { fill: #3730a3; font-weight: 600; }
@keyframes wfviz-think {
  0%, 100% { filter: drop-shadow(0 0 2px rgba(99, 102, 241, 0.3)); }
  50%      { filter: drop-shadow(0 0 14px rgba(99, 102, 241, 0.8)); }
}

/* Complete — green check flash */
.wfviz-node.is-complete .wfviz-tile,
.wfviz-node.is-complete .wfviz-sub-circle {
  stroke: #10b981;
  stroke-width: 2;
  animation: wfviz-done 900ms ease-out;
}
.wfviz-node.is-complete .wfviz-label { fill: #065f46; font-weight: 600; }
@keyframes wfviz-done {
  0%   { filter: drop-shadow(0 0 0 rgba(16, 185, 129, 0)); }
  40%  { filter: drop-shadow(0 0 12px rgba(16, 185, 129, 0.75)); }
  100% { filter: drop-shadow(0 0 0 rgba(16, 185, 129, 0)); }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .wfviz-node.is-listening .wfviz-tile,
  .wfviz-node.is-thinking .wfviz-tile,
  .wfviz-node.is-thinking .wfviz-sub-circle,
  .wfviz-node.is-pulse .wfviz-tile,
  .wfviz-node.is-complete .wfviz-tile,
  .wfviz-node.is-complete .wfviz-sub-circle {
    animation: none !important;
  }
  .wfviz-edge { transition: none !important; }
}

@media (max-width: 640px) {
  .wfviz-wrapper { padding: 0.5rem 0.25rem; background-size: 14px 14px; }
  .wfviz-label { font-size: 10.5px; }
  .wfviz-sublabel { font-size: 9px; }
}

/* Mobile fallback: hide per-phase Start/Done buttons; keep hero+pulse+reset.
   The IntersectionObserver autoplay (in the variations page) covers the
   storytelling, so phone visitors don't need granular controls. */
@media (max-width: 899px) {
  .controls .btn-start,
  .controls .btn-complete { display: none; }
}

/* ===== Clickable nodes (no focus rectangle) ===== */
.wfviz-node[data-has-explainer] { cursor: pointer; outline: none; }
.wfviz-node[data-has-explainer]:focus { outline: none; }
.wfviz-node[data-has-explainer]:focus-visible .wfviz-tile,
.wfviz-node[data-has-explainer]:focus-visible .wfviz-sub-circle {
  stroke: #6366f1;
  stroke-width: 2;
}
.wfviz-node[data-has-explainer].is-selected .wfviz-tile,
.wfviz-node[data-has-explainer].is-selected .wfviz-sub-circle {
  stroke: #6366f1;
  stroke-width: 2;
}

/* ===== Narration rail — also hosts module explanations ===== */
.wfviz-narration-rail {
  padding: 1rem 1.05rem;
  min-height: 12em;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}
.rail-pill {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  background: #f1f5f9;
  border-radius: 999px;
  font-size: 10.5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  color: #475569;
  letter-spacing: 0.04em;
  text-transform: lowercase;
  margin-bottom: 0.55rem;
}
.rail-text {
  margin: 0;
  font-size: 14px;
  line-height: 1.5;
  color: #0f172a;
  min-height: 1.45em;
  transition: opacity 220ms ease;
}
.wfviz-narration-rail.is-empty .rail-text { color: #94a3b8; }

/* Module explanation block (rendered when a node is clicked) */
.rail-module .rail-title {
  margin: 0 0 0.4rem;
  font-size: 15px;
  font-weight: 600;
  color: #0f172a;
}
.rail-module .rail-summary {
  margin: 0 0 0.7rem;
  font-size: 13px;
  line-height: 1.55;
  color: #334155;
}
.rail-module .rail-subhead {
  margin: 0.7rem 0 0.3rem;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #64748b;
}
.rail-module .rail-bullets {
  margin: 0 0 0.5rem;
  padding: 0 0 0 1.1rem;
  font-size: 12.5px;
  line-height: 1.5;
  color: #334155;
}
.rail-module .rail-bullets li { margin: 0.15rem 0; }
.rail-module .rail-context {
  margin: 0.3rem 0 0;
  padding: 0.55rem 0.65rem;
  background: #f8fafc;
  border-left: 3px solid #6366f1;
  border-radius: 4px;
  font-size: 12.5px;
  line-height: 1.5;
  color: #334155;
}

@media (prefers-reduced-motion: reduce) {
  .rail-text { transition: none; }
}
