/* ── Visual Workflow Builder ── */

/* Full-screen overlay for the builder */
.wfb-overlay {
  position: fixed;
  inset: 0;
  z-index: 10002;
  background: #FAF7F2;
  display: flex;
  flex-direction: column;
  pointer-events: none;
}
.wfb-overlay.is-open {
  pointer-events: auto;
}

/* Top toolbar */
.wfb-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 14px 18px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--text);
  flex-shrink: 0;
  border-bottom: 1px solid rgba(15, 23, 42, 0.08);
  backdrop-filter: blur(20px);
  z-index: 10;
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.06);
}
.wfb-toolbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}
.wfb-toolbar-right {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}
.wfb-back-btn {
  background: rgba(248, 250, 252, 0.96);
  border: 1px solid rgba(15, 23, 42, 0.1);
  color: #334155;
  font-size: 12px;
  font-weight: 700;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
.wfb-back-btn:hover {
  background: #fff;
  color: #0f172a;
  border-color: rgba(15, 23, 42, 0.18);
}
.wfb-title-input {
  background: #fff;
  border: 1px solid rgba(15, 23, 42, 0.1);
  color: #0f172a;
  font-size: 18px;
  font-family: var(--font-heading);
  font-weight: 600;
  padding: 9px 14px;
  border-radius: 14px;
  min-width: 280px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
.wfb-title-input:hover { border-color: rgba(15, 23, 42, 0.18); }
.wfb-title-input:focus {
  outline: none;
  border-color: rgba(37, 99, 235, 0.45);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12);
}
.wfb-status-badge {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 5px 11px;
  border-radius: 40px;
}
.wfb-status-badge.active { background: rgba(16, 185, 129, 0.14); color: #059669; }
.wfb-status-badge.draft { background: rgba(148, 163, 184, 0.16); color: #475569; }
.wfb-save-btn {
  background: linear-gradient(180deg, #1c2b38 0%, #243746 100%);
  color: #fff;
  border: 1px solid rgba(15, 23, 42, 0.08);
  padding: 10px 18px;
  border-radius: 14px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  font-family: var(--font-body);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 14px 28px rgba(15, 23, 42, 0.12);
}
.wfb-save-btn:hover { background: linear-gradient(180deg, #223444 0%, #2d4558 100%); }
.wfb-btn-ghost {
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(15, 23, 42, 0.1);
  color: #334155;
  font-size: 12px;
  font-weight: 700;
  padding: 8px 14px;
  border-radius: 12px;
  cursor: pointer;
  font-family: var(--font-body);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
.wfb-btn-ghost:hover { background: #fff; color: #0f172a; border-color: rgba(15, 23, 42, 0.18); }
.wfb-btn-ghost.danger { border-color: rgba(220, 38, 38, 0.18); color: #b91c1c; }
.wfb-btn-ghost.danger:hover { background: rgba(254, 242, 242, 0.98); color: #991b1b; }

/* Main canvas area */
.wfb-body {
  flex: 1;
  display: flex;
  gap: 18px;
  overflow: auto;
  min-height: 0;
  padding: 18px;
}
.wfb-rail {
  width: 320px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
}
.wfb-rail-card {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 24px;
  padding: 18px;
  box-shadow: 0 18px 38px rgba(15, 23, 42, 0.08);
}
.wfb-rail-kicker,
.wfb-canvas-kicker {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #64748b;
}
.wfb-rail-card h3,
.wfb-canvas-header h3 {
  margin: 8px 0 6px;
  font-size: 20px;
  font-weight: 700;
  color: #0f172a;
}
.wfb-rail-card p,
.wfb-canvas-header p {
  margin: 0;
  font-size: 13px;
  line-height: 1.6;
  color: #526071;
}
.wfb-summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 16px;
}
.wfb-summary-card {
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 18px;
  padding: 12px 13px;
  background: #f8fafc;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.wfb-summary-card span {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #64748b;
}
.wfb-summary-card strong {
  font-size: 14px;
  color: #0f172a;
}
.wfb-summary-card-wide {
  grid-column: 1 / -1;
}
.wfb-checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: #334155;
  font-weight: 600;
}
.wfb-checkbox-row input {
  width: 16px;
  height: 16px;
}
.wfb-canvas-wrap {
  flex: 1;
  overflow: auto;
  position: relative;
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 28px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.92) 0%, rgba(249,250,251,0.96) 100%),
    radial-gradient(circle, rgba(15, 23, 42, 0.045) 1px, transparent 1px);
  background-size: auto, 24px 24px;
  box-shadow: 0 28px 56px rgba(15, 23, 42, 0.09);
}
.wfb-canvas-header {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding: 20px 24px 12px;
  background: linear-gradient(180deg, rgba(255,255,255,0.98) 0%, rgba(255,255,255,0.88) 100%);
  border-bottom: 1px solid rgba(15, 23, 42, 0.06);
  backdrop-filter: blur(14px);
}
.wfb-canvas-chips {
  display: flex;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 8px;
}
.wfb-canvas-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.04);
  border: 1px solid rgba(15, 23, 42, 0.08);
  color: #334155;
  font-size: 12px;
  font-weight: 700;
}
.wfb-canvas {
  position: relative;
  min-width: 100%;
  min-height: 100%;
  padding: 32px 60px 220px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* SVG connectors layer */
.wfb-svg-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
}
.wfb-connector {
  stroke: var(--border);
  stroke-width: 2;
  fill: none;
}
.wfb-connector-yes { stroke: #2ecc71; }
.wfb-connector-no { stroke: #e74c3c; }
.wfb-connector-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  fill: var(--text-muted);
}
.wfb-connector-label.yes { fill: #2ecc71; }
.wfb-connector-label.no { fill: #e74c3c; }

/* Node base */
.wfb-node {
  position: relative;
  background: #fff;
  border: 1px solid rgba(15, 23, 42, 0.1);
  border-radius: 18px;
  width: 320px;
  min-height: 70px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 15px 16px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
  z-index: 1;
  margin: 0 auto;
  box-shadow: 0 12px 26px rgba(15, 23, 42, 0.08);
}
.wfb-node:hover {
  border-color: rgba(37, 99, 235, 0.34);
  box-shadow: 0 18px 36px rgba(15, 23, 42, 0.12);
  transform: translateY(-1px);
}
.wfb-node.selected {
  border-color: rgba(37, 99, 235, 0.42);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12), 0 18px 36px rgba(15, 23, 42, 0.12);
}

/* Node icon */
.wfb-node-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  color: #fff;
}

/* Node body */
.wfb-node-body {
  flex: 1;
  min-width: 0;
}
.wfb-node-type {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #64748b;
}
.wfb-node-label {
  font-size: 13px;
  font-weight: 600;
  color: #0f172a;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Delete button on node */
.wfb-node-delete {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 20px;
  height: 20px;
  background: var(--danger);
  color: #fff;
  border: 2px solid #fff;
  border-radius: 50%;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 5;
}
.wfb-node:hover .wfb-node-delete { display: flex; }

/* Trigger node (special) */
.wfb-node.trigger {
  background: linear-gradient(135deg, #1c2b38 0%, #243746 100%);
  border-color: transparent;
  color: #fff;
}
.wfb-node.trigger .wfb-node-type { color: rgba(255,255,255,0.64); }
.wfb-node.trigger .wfb-node-label { color: #fff; }
.wfb-node.trigger:hover { box-shadow: 0 20px 40px rgba(15, 23, 42, 0.18); }

/* Decision node */
.wfb-node.decision {
  border-color: rgba(245, 158, 11, 0.3);
  background: #fff8eb;
  border-style: solid;
}
.wfb-node.decision .wfb-node-icon { background: #f39c12; }

/* Add-node button (the "+" between nodes) */
.wfb-add-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #fff;
  color: #1f3b50;
  border: 1px solid rgba(15, 23, 42, 0.12);
  font-size: 18px;
  font-weight: 400;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 6px auto;
  z-index: 2;
  position: relative;
  transition: transform 0.15s, background 0.15s, border-color 0.15s, color 0.15s;
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.08);
}
.wfb-add-btn:hover {
  transform: scale(1.15);
  background: #eff6ff;
  border-color: rgba(37, 99, 235, 0.24);
  color: #1d4ed8;
}

/* Vertical connector line between nodes */
.wfb-vline {
  width: 2px;
  height: 20px;
  background: var(--border);
  margin: 0 auto;
  z-index: 0;
}

/* Decision branch layout */
.wfb-branch-container {
  display: flex;
  gap: 40px;
  justify-content: center;
  position: relative;
  z-index: 1;
}
.wfb-branch {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 280px;
}
.wfb-branch-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 3px 12px;
  border-radius: 40px;
  margin-bottom: 4px;
  z-index: 2;
}
.wfb-branch-label.yes { background: rgba(46,204,113,0.12); color: #27ae60; }
.wfb-branch-label.no { background: rgba(231,76,60,0.12); color: #c0392b; }

/* Horizontal connector line for branches */
.wfb-hline-container {
  position: relative;
  width: 100%;
  height: 30px;
  z-index: 0;
}
.wfb-hline-svg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* End / rejoin node */
.wfb-end-node {
  width: 120px;
  padding: 8px;
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--accent-light);
  border: 1px dashed var(--border);
  border-radius: 40px;
  margin: 6px auto;
  z-index: 1;
}

/* ── Action picker dropdown ── */
.wfb-action-picker {
  position: absolute;
  z-index: 10010;
  background: #fff;
  border: 1px solid rgba(15, 23, 42, 0.1);
  border-radius: 22px;
  box-shadow: 0 28px 56px rgba(15, 23, 42, 0.18);
  width: 300px;
  max-height: 400px;
  overflow-y: auto;
  padding: 10px 0;
}
.wfb-action-picker-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #64748b;
  padding: 10px 18px 6px;
}
.wfb-action-pick-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  cursor: pointer;
  transition: background 0.1s;
}
.wfb-action-pick-item:hover { background: rgba(37, 99, 235, 0.06); }
.wfb-action-pick-icon {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: #fff;
  flex-shrink: 0;
}
.wfb-action-pick-info {
  flex: 1;
}
.wfb-action-pick-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}
.wfb-action-pick-desc {
  font-size: 11px;
  color: var(--text-muted);
}

/* ── Side panel (node config) ── */
.wfb-panel {
  width: 360px;
  background: rgba(255, 255, 255, 0.98);
  border-left: 1px solid rgba(15, 23, 42, 0.08);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: wfbSlideIn 0.2s ease-out;
  box-shadow: -18px 0 36px rgba(15, 23, 42, 0.08);
}
@keyframes wfbSlideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
.wfb-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(15, 23, 42, 0.08);
}
.wfb-panel-header h3 {
  font-size: 14px;
  font-weight: 600;
  margin: 0;
}
.wfb-panel-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
}
.wfb-panel-close:hover { color: var(--text); }
.wfb-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}
.wfb-panel-footer {
  border-top: 1px solid rgba(15, 23, 42, 0.08);
  padding: 12px 16px;
  display: flex;
  gap: 8px;
}

/* Form fields inside panel */
.wfb-field {
  margin-bottom: 14px;
}
.wfb-field label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: #64748b;
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.wfb-field input,
.wfb-field select,
.wfb-field textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid rgba(15, 23, 42, 0.1);
  border-radius: 14px;
  font-family: var(--font-body);
  font-size: 13px;
  color: #0f172a;
  background: #fff;
}
.wfb-field input:focus,
.wfb-field select:focus,
.wfb-field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(2,53,39,0.1);
}
.wfb-field textarea {
  min-height: 80px;
  resize: vertical;
}
.wfb-field-row {
  display: flex;
  gap: 8px;
}
.wfb-field-row .wfb-field {
  flex: 1;
}
.wfb-field .wfb-hint {
  font-size: 11px;
  color: #64748b;
  margin-top: 3px;
}

/* WhatsApp-specific */
.wfb-whatsapp-preview {
  background: #dcf8c6;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  line-height: 1.5;
  margin-top: 8px;
  position: relative;
  max-width: 260px;
}
.wfb-whatsapp-preview::before {
  content: "";
  position: absolute;
  top: 0;
  left: -6px;
  width: 0;
  height: 0;
  border-top: 6px solid #dcf8c6;
  border-left: 6px solid transparent;
}
.wfb-whatsapp-bubble-wrap {
  background: #e5ddd5;
  border-radius: 8px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}
.wfb-whatsapp-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
  align-self: stretch;
}
.wfb-whatsapp-header-icon {
  width: 24px;
  height: 24px;
  background: #25D366;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 14px;
}
.wfb-whatsapp-header-text {
  font-size: 12px;
  font-weight: 600;
  color: #666;
}

/* Variable tag chips */
.wfb-var-tag {
  display: inline-block;
  padding: 1px 6px;
  background: rgba(2,53,39,0.08);
  border-radius: 3px;
  font-size: 11px;
  font-weight: 500;
  color: var(--accent);
  cursor: pointer;
  margin: 1px;
}
.wfb-var-tag:hover { background: rgba(2,53,39,0.15); }

/* Condition builder */
.wfb-condition-row {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-bottom: 6px;
}
.wfb-condition-row select,
.wfb-condition-row input {
  padding: 5px 8px;
  font-size: 12px;
  border: 1px solid var(--input-border);
  border-radius: var(--radius);
  font-family: var(--font-body);
}
.wfb-condition-remove {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 2px;
}
.wfb-add-condition {
  font-size: 12px;
  color: var(--accent);
  background: none;
  border: none;
  cursor: pointer;
  font-weight: 600;
  padding: 4px 0;
}
.wfb-add-condition:hover { text-decoration: underline; }

@media (max-width: 1180px) {
  .wfb-body {
    flex-direction: column;
    padding: 14px;
  }
  .wfb-rail {
    width: 100%;
    max-height: 240px;
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
  }
  .wfb-rail-card {
    min-width: 320px;
  }
  .wfb-canvas-wrap {
    min-height: 520px;
  }
}

@media (max-width: 860px) {
  .wfb-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  .wfb-toolbar-left,
  .wfb-toolbar-right {
    flex-wrap: wrap;
  }
  .wfb-toolbar-right {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .wfb-title-input {
    min-width: 0;
    width: 100%;
  }
  .wfb-canvas-header {
    flex-direction: column;
    align-items: flex-start;
  }
  .wfb-node {
    width: min(100%, 320px);
  }
}

@media (max-width: 560px) {
  .wfb-toolbar-right {
    grid-template-columns: 1fr;
  }
  .wfb-back-btn,
  .wfb-btn-ghost,
  .wfb-save-btn {
    width: 100%;
  }
}

/* ── Dark mode ── */
:root.dark .wfb-overlay { background: var(--bg); }
:root.dark .wfb-node { background: #1e2a4a; border-color: rgba(255,255,255,0.1); }
:root.dark .wfb-node:hover { border-color: var(--accent); }
:root.dark .wfb-node.trigger { background: #0f3460; border-color: #0f3460; }
:root.dark .wfb-node.decision { background: #3d3020; border-color: #f39c12; }
:root.dark .wfb-action-picker { background: #16213e; border-color: rgba(255,255,255,0.1); }
:root.dark .wfb-action-pick-item:hover { background: rgba(78,204,163,0.1); }
:root.dark .wfb-panel { background: #16213e; border-color: rgba(255,255,255,0.1); }
:root.dark .wfb-vline { background: rgba(255,255,255,0.1); }
:root.dark .wfb-connector { stroke: rgba(255,255,255,0.15); }
:root.dark .wfb-end-node { background: rgba(78,204,163,0.08); border-color: rgba(255,255,255,0.1); }
:root.dark .wfb-canvas-wrap {
  background: radial-gradient(circle, rgba(255,255,255,0.03) 1px, transparent 1px);
  background-size: 20px 20px;
}
:root.dark .wfb-whatsapp-bubble-wrap { background: #1a1a2e; }
:root.dark .wfb-whatsapp-preview { background: #264d3b; color: #e0e0e0; }
:root.dark .wfb-whatsapp-preview::before { border-top-color: #264d3b; }
:root.dark .wfb-node-delete { border-color: #1e2a4a; }
