/* ========================================================================
   FLOW BUILDER — Professional Redesign v2
   ======================================================================== */

/* ----------  Layout  ---------- */
#flowBuilderModal .modal-content { background: #f0f2f5; }

#flowBuilderModal .modal-header {
    background: #ffffff;
    border-bottom: 1px solid #e3e6ea;
    padding: 12px 24px;
    z-index: 20;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

#flowBuilderModal .modal-body {
    display: flex;
    height: calc(100vh - 62px);
    overflow: hidden;
    padding: 0 !important;
}

/* ----------  Header bar  ---------- */
.flow-header-left {
    display: flex;
    align-items: center;
    gap: 14px;
}

.flow-header-logo {
    width: 38px; height: 38px;
    border-radius: 10px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 1.1rem;
    box-shadow: 0 3px 10px rgba(102,126,234,0.35);
}

.flow-header-title { font-weight: 700; font-size: 1.15rem; color: #1a1d21; margin: 0; }
.flow-header-subtitle { font-size: 0.72rem; color: #8b919a; margin: 0; letter-spacing: 0.02em; }

.flow-header-right {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: auto;
}

.flow-header-right .btn { font-size: 0.85rem; border-radius: 8px; padding: 7px 16px; }

.btn-flow-secondary {
    background: #f0f2f5; border: 1px solid #dfe1e5; color: #495057;
    display: flex; align-items: center; gap: 6px;
}
.btn-flow-secondary:hover { background: #e4e6ea; color: #343a40; }

.btn-flow-primary {
    background: linear-gradient(135deg, #667eea, #764ba2);
    border: none; color: #fff;
    display: flex; align-items: center; gap: 6px;
    box-shadow: 0 3px 12px rgba(102,126,234,0.3);
    transition: box-shadow 0.2s, transform 0.2s;
}
.btn-flow-primary:hover {
    box-shadow: 0 5px 20px rgba(102,126,234,0.45);
    transform: translateY(-1px); color: #fff;
}

/* ----------  Sidebar  ---------- */
.flow-sidebar {
    width: 310px;
    min-width: 310px;
    background: #ffffff;
    border-right: 1px solid #e3e6ea;
    display: flex;
    flex-direction: column;
    z-index: 15;
    transition: margin-left 0.3s cubic-bezier(.4,0,.2,1), opacity 0.3s;
    overflow: hidden;
}

.flow-sidebar.collapsed {
    margin-left: -310px;
    opacity: 0;
    pointer-events: none;
}

.flow-sidebar-section {
    padding: 18px 20px;
    border-bottom: 1px solid #f0f2f5;
}

.flow-sidebar-section:last-child { border-bottom: none; }

.flow-sidebar-scroll {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0;
}

.flow-sidebar-scroll::-webkit-scrollbar { width: 5px; }
.flow-sidebar-scroll::-webkit-scrollbar-track { background: transparent; }
.flow-sidebar-scroll::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 10px; }

/* Config section */
.flow-config-section .form-label { font-size: 0.82rem; font-weight: 500; color: #6c757d; margin-bottom: 4px; }
.flow-config-section small { font-size: 0.72rem; color: #adb5bd; }
.flow-config-section .form-select,
.flow-config-section .form-control {
    font-size: 0.85rem; border-radius: 8px; border: 1px solid #e3e6ea;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.flow-config-section .form-select:focus,
.flow-config-section .form-control:focus {
    border-color: #667eea; box-shadow: 0 0 0 3px rgba(102,126,234,0.15);
}

/* Switch */
.custom-switch .form-check-input { width: 2.5em; height: 1.25em; cursor: pointer; }
.custom-switch .form-check-label { padding-top: 0.15rem; cursor: pointer; }

/* Search */
.flow-search-wrap { position: relative; margin-bottom: 16px; }
.flow-search-wrap input {
    width: 100%; padding: 9px 14px 9px 36px; border: 1px solid #e3e6ea; border-radius: 10px;
    font-size: 0.85rem; background: #f8f9fb; transition: all 0.2s;
}
.flow-search-wrap input:focus { outline: none; border-color: #667eea; box-shadow: 0 0 0 3px rgba(102,126,234,0.12); background: #fff; }
.flow-search-wrap i {
    position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
    color: #adb5bd; font-size: 0.85rem; pointer-events: none;
}

/* Category headers */
.flow-cat-header {
    display: flex; align-items: center; gap: 8px; cursor: pointer;
    padding: 10px 20px; margin: 0; font-size: 0.7rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.08em; color: #8b919a;
    user-select: none; transition: background 0.15s;
}
.flow-cat-header:hover { background: #f8f9fb; }
.flow-cat-header .cat-chevron {
    margin-left: auto; transition: transform 0.25s; font-size: 0.65rem;
}
.flow-cat-header.collapsed .cat-chevron { transform: rotate(-90deg); }

.flow-cat-body { padding: 4px 16px 12px; }
.flow-cat-body.collapsed-cat { display: none; }

/* Node cards in sidebar */
.nodes-grid { display: flex; flex-direction: column; gap: 8px; }

.drag-drawflow {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 14px; background: #fff; border: 1px solid #ebedf0;
    border-radius: 10px; cursor: grab; user-select: none;
    transition: all 0.2s ease; position: relative; overflow: hidden;
}
.drag-drawflow::before {
    content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
    border-radius: 10px 0 0 10px;
}
.drag-drawflow:hover {
    transform: translateX(4px);
    box-shadow: 0 4px 14px rgba(0,0,0,0.06);
    border-color: #d1d5db;
}
.drag-drawflow:active { cursor: grabbing; transform: translateX(2px); }
.drag-drawflow[hidden] { display: none !important; }

/* Category color bars */
.drag-drawflow.cat-trigger::before  { background: linear-gradient(180deg,#0dcaf0,#0aa2c0); }
.drag-drawflow.cat-action::before   { background: linear-gradient(180deg,#198754,#157347); }
.drag-drawflow.cat-logic::before    { background: linear-gradient(180deg,#dc3545,#b02a37); }
.drag-drawflow.cat-crm::before      { background: linear-gradient(180deg,#f97316,#ea580c); }
.drag-drawflow.cat-util::before     { background: linear-gradient(180deg,#6f42c1,#59359a); }

.node-icon {
    width: 34px; height: 34px; border-radius: 9px;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.95rem; flex-shrink: 0;
}
.node-info { display: flex; flex-direction: column; min-width: 0; }
.node-title { font-weight: 600; font-size: 0.85rem; color: #343a40; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.node-desc  { font-size: 0.72rem; color: #8b919a; margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ----------  Canvas area  ---------- */
.flow-main {
    flex: 1; position: relative; overflow: hidden;
    background: #f0f2f5;
}

#drawflow {
    width: 100%; height: 100%;
    background-color: #f6f7f9;
    background-image:
        radial-gradient(circle, rgba(15,23,42,0.06) 1px, transparent 1px);
    background-size: 20px 20px;
}

/* ----------  Floating toolbar  ---------- */
.flow-toolbar {
    position: absolute; left: 50%; bottom: 20px; transform: translateX(-50%);
    display: flex; align-items: center; gap: 4px;
    background: rgba(255,255,255,0.92);
    backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
    border-radius: 14px; padding: 6px 10px;
    box-shadow: 0 6px 24px rgba(0,0,0,0.08), 0 0 0 1px rgba(0,0,0,0.04);
    z-index: 20;
}

.flow-toolbar .tb-sep {
    width: 1px; height: 24px; background: #e3e6ea; margin: 0 4px;
}

.flow-toolbar .tb-btn {
    width: 36px; height: 36px; border-radius: 10px; border: none;
    background: transparent; color: #495057;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.9rem; cursor: pointer;
    transition: all 0.15s;
}
.flow-toolbar .tb-btn:hover { background: #f0f2f5; color: #1a1d21; }
.flow-toolbar .tb-btn.active { background: #667eea; color: #fff; }
.flow-toolbar .tb-btn.danger:hover { background: #fff5f5; color: #dc3545; }

.flow-toolbar .zoom-display {
    font-size: 0.78rem; font-weight: 600; color: #495057;
    min-width: 42px; text-align: center; user-select: none; padding: 0 4px;
}

/* Sidebar toggle (always visible) */
.flow-sidebar-toggle {
    position: absolute; top: 16px; left: 16px; z-index: 25;
    width: 38px; height: 38px; border-radius: 10px;
    background: rgba(255,255,255,0.92); backdrop-filter: blur(10px);
    border: 1px solid #e3e6ea; color: #495057;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; font-size: 0.95rem;
    box-shadow: 0 4px 14px rgba(0,0,0,0.06);
    transition: all 0.2s;
}
.flow-sidebar-toggle:hover { background: #fff; color: #1a1d21; }

/* Node count badge */
.flow-node-count {
    position: absolute; top: 16px; right: 16px; z-index: 25;
    background: rgba(255,255,255,0.92); backdrop-filter: blur(10px);
    border: 1px solid #e3e6ea; border-radius: 10px;
    padding: 6px 14px; font-size: 0.78rem; font-weight: 600; color: #495057;
    box-shadow: 0 4px 14px rgba(0,0,0,0.06);
    display: flex; align-items: center; gap: 8px;
}
.flow-node-count .count-dot {
    width: 8px; height: 8px; border-radius: 50%; background: #198754;
    display: inline-block;
    animation: pulse-dot 2s infinite;
}
@keyframes pulse-dot {
    0%,100% { opacity: 1; } 50% { opacity: 0.4; }
}

/* ========================================================================
   DRAWFLOW NODE STYLES
   ======================================================================== */
.drawflow .parent-node {
    z-index: 2;
}
.drawflow .parent-node:has(.drawflow-node.selected) {
    z-index: 4 !important;
}

/* --- Node card base --- */
.drawflow .drawflow-node {
    background: #ffffff;
    border: 1.5px solid #dbe1ea;
    border-radius: 14px;
    box-shadow: 0 4px 16px rgba(15, 23, 42, 0.07), 0 1px 3px rgba(15, 23, 42, 0.04);
    display: flex;
    align-items: center;
    padding: 0;
    min-width: 260px;
    width: auto;
    max-width: 420px;
    transition: box-shadow 0.3s ease, border-color 0.3s ease;
    overflow: visible;
    z-index: 2;
}

#flowBuilderModal .drawflow .drawflow-node {
    background: #ffffff !important;
    color: #1f2937 !important;
}

#flowBuilderModal .drawflow .drawflow-node .drawflow_content_node {
    width: 100% !important;
    max-width: none !important;
    display: block !important;
    flex: 1 1 auto;
    min-width: 0;
}

#flowBuilderModal .drawflow .drawflow-node .drawflow_content_node > * {
    width: 100%;
}

.drawflow .drawflow-node:hover {
    box-shadow: 0 8px 28px rgba(15, 23, 42, 0.13), 0 2px 6px rgba(15, 23, 42, 0.06);
    border-color: #b8c2d4;
}

.drawflow .drawflow-node.selected {
    border: 1.5px solid #667eea;
    box-shadow: 0 0 0 3px rgba(102,126,234,0.18), 0 10px 32px rgba(15, 23, 42, 0.14);
    z-index: 4;
}

#flowBuilderModal .drawflow .drawflow-node.selected {
    background: #ffffff !important;
}

/* Node color stripe on top */
.drawflow .drawflow-node .title-box {
    padding: 11px 16px;
    border-bottom: 1px solid #e9edf3;
    border-radius: 14px 14px 0 0;
    font-weight: 700; font-size: 0.82rem;
    display: flex; align-items: center;
    color: #1f2937;
    position: relative;
    overflow: visible;
    letter-spacing: 0.01em;
}

.drawflow .drawflow-node .title-box::before {
    content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px;
}

.drawflow .drawflow-node .title-box i {
    margin-right: 9px; font-size: 0.92rem; flex-shrink: 0;
}

.drawflow .drawflow-node .title-box .node-badge {
    margin-left: auto; font-size: 0.58rem; font-weight: 700;
    padding: 2px 8px; border-radius: 999px; text-transform: uppercase;
    letter-spacing: 0.06em;
}

/* Collapse toggle in title */
.drawflow .drawflow-node .title-box .node-collapse-btn {
    margin-left: 8px; cursor: pointer; font-size: 0.7rem; color: #adb5bd;
    transition: transform 0.25s, color 0.15s; flex-shrink: 0;
    width: 22px; height: 22px; border-radius: 6px;
    display: flex; align-items: center; justify-content: center;
}
.drawflow .drawflow-node .title-box .node-collapse-btn:hover { color: #495057; background: rgba(0,0,0,0.05); }
.drawflow .drawflow-node .title-box .node-collapse-btn.collapsed-node { transform: rotate(-90deg); }

/* Node actions menu */
.drawflow .drawflow-node .title-box .node-actions {
    margin-left: 8px;
    position: relative;
    flex-shrink: 0;
}
.drawflow .drawflow-node .title-box .node-actions-toggle {
    cursor: pointer;
    width: 22px;
    height: 22px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #94a3b8;
    transition: color 0.15s, background 0.15s;
}
.drawflow .drawflow-node .title-box .node-actions-toggle:hover {
    color: #475569;
    background: rgba(0,0,0,0.06);
}
.drawflow .drawflow-node .title-box .node-actions-menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 178px;
    border: 1px solid #e2e8f0;
    background: #ffffff;
    border-radius: 10px;
    box-shadow: 0 10px 24px rgba(15,23,42,0.18);
    padding: 6px;
    z-index: 1200;
    display: none;
}
.drawflow .drawflow-node .title-box .node-actions.open .node-actions-menu {
    display: block;
}
.drawflow .drawflow-node .title-box .node-action-item {
    width: 100%;
    border: none;
    background: transparent;
    color: #334155;
    text-align: left;
    font-size: 0.74rem;
    font-weight: 600;
    border-radius: 8px;
    padding: 8px 10px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.drawflow .drawflow-node .title-box .node-action-item:hover {
    background: #f1f5f9;
}
.drawflow .drawflow-node .title-box .node-action-item.danger {
    color: #b91c1c;
}
.drawflow .drawflow-node .title-box .node-action-item.danger:hover {
    background: #fef2f2;
}

/* Right-click context menu */
.flow-context-menu {
    position: fixed;
    min-width: 180px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    box-shadow: 0 10px 24px rgba(15,23,42,0.2);
    padding: 6px;
    z-index: 100000;
}

.flow-context-menu .ctx-item {
    width: 100%;
    border: none;
    background: transparent;
    color: #334155;
    text-align: left;
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 0.78rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.flow-context-menu .ctx-item:hover {
    background: #f1f5f9;
}

.flow-context-menu .ctx-item.danger {
    color: #b91c1c;
}

.flow-context-menu .ctx-item.danger:hover {
    background: #fef2f2;
}

/* Node body box */
.drawflow .drawflow-node .box {
    padding: 14px 16px 15px;
    transition: max-height 0.3s ease, padding 0.3s ease, opacity 0.2s;
    overflow: hidden;
    width: 100%;
    box-sizing: border-box;
}

.drawflow .drawflow-node .box.node-body-collapsed {
    max-height: 0 !important;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    opacity: 0;
}

/* Labels & inputs */
.drawflow .drawflow-node label {
    font-size: 0.7rem; font-weight: 700; color: #64748b;
    margin-bottom: 5px; display: block; text-transform: uppercase; letter-spacing: 0.04em;
}

.drawflow .drawflow-node input,
.drawflow .drawflow-node textarea,
.drawflow .drawflow-node select {
    width: 100%; padding: 9px 12px;
    border: 1px solid #d8e0ea; border-radius: 10px;
    margin-bottom: 10px; font-size: 0.85rem;
    color: #1f2937;
    background: #f8fafc;
    transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
    box-sizing: border-box;
}
.drawflow .drawflow-node input:focus,
.drawflow .drawflow-node textarea:focus,
.drawflow .drawflow-node select:focus {
    outline: none; border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102,126,234,0.18);
    background: #fff;
}
.drawflow .drawflow-node input:last-child,
.drawflow .drawflow-node textarea:last-child,
.drawflow .drawflow-node select:last-child { margin-bottom: 0; }

.drawflow .drawflow-node textarea { resize: vertical; min-height: 70px; }

.drawflow .drawflow-node .node-help {
    font-size: 0.69rem; color: #94a3b8; margin-top: -5px; margin-bottom: 8px;
    display: flex; align-items: center; gap: 4px;
}

/* Resize handle  */
.drawflow .drawflow-node .node-resize-handle {
    position: absolute; bottom: 4px; right: 4px;
    width: 18px; height: 18px; cursor: nwse-resize;
    opacity: 0; transition: opacity 0.2s, background 0.2s;
    display: flex; align-items: center; justify-content: center;
    border-radius: 6px;
}
.drawflow .drawflow-node .node-resize-handle::after {
    content: '';
    width: 9px; height: 9px;
    border-right: 2px solid #94a3b8; border-bottom: 2px solid #94a3b8;
}
.drawflow .drawflow-node:hover .node-resize-handle { opacity: 1; }
.drawflow .drawflow-node .node-resize-handle:hover { background: rgba(148,163,184,0.15); }

/* --------  per-type color bars  -------- */
.drawflow .drawflow-node.keyword .title-box::before  { background: linear-gradient(90deg,#0dcaf0,#0aa2c0); }
.drawflow .drawflow-node.exact .title-box::before    { background: linear-gradient(90deg,#3b82f6,#2563eb); }
.drawflow .drawflow-node.regex .title-box::before    { background: linear-gradient(90deg,#6366f1,#4f46e5); }
.drawflow .drawflow-node.default_trigger .title-box::before { background: linear-gradient(90deg,#94a3b8,#64748b); }
.drawflow .drawflow-node.welcome_message .title-box::before { background: linear-gradient(90deg,#f59e0b,#d97706); }

.drawflow .drawflow-node.text .title-box::before     { background: linear-gradient(90deg,#10b981,#059669); }
.drawflow .drawflow-node.image .title-box::before    { background: linear-gradient(90deg,#f59e0b,#d97706); }
.drawflow .drawflow-node.video .title-box::before    { background: linear-gradient(90deg,#ec4899,#db2777); }
.drawflow .drawflow-node.audio .title-box::before    { background: linear-gradient(90deg,#8b5cf6,#7c3aed); }
.drawflow .drawflow-node.document .title-box::before { background: linear-gradient(90deg,#e879f9,#c026d3); }
.drawflow .drawflow-node.delay .title-box::before    { background: linear-gradient(90deg,#fb923c,#ea580c); }
.drawflow .drawflow-node.interactive_button .title-box::before { background: linear-gradient(90deg,#0ea5e9,#0284c7); }

.drawflow .drawflow-node.condition .title-box::before { background: linear-gradient(90deg,#ef4444,#dc2626); }
.drawflow .drawflow-node.randomizer .title-box::before { background: linear-gradient(90deg,#d946ef,#c026d3); }
.drawflow .drawflow-node.http_request .title-box::before { background: linear-gradient(90deg,#06b6d4,#0891b2); }
.drawflow .drawflow-node.switcher .title-box::before { background: linear-gradient(90deg,#8b5cf6,#7c3aed); }

.drawflow .drawflow-node.add_tag .title-box::before { background: linear-gradient(90deg,#f97316,#ea580c); }
.drawflow .drawflow-node.assign_agent .title-box::before { background: linear-gradient(90deg,#f97316,#ea580c); }

.drawflow .drawflow-node.note .title-box::before     { background: linear-gradient(90deg,#a78bfa,#7c3aed); }

/* Title bg tints */
.drawflow .drawflow-node.keyword .title-box  { background: #ecfeff; }
.drawflow .drawflow-node.exact .title-box    { background: #eff6ff; }
.drawflow .drawflow-node.regex .title-box    { background: #eef2ff; }
.drawflow .drawflow-node.default_trigger .title-box { background: #f8fafc; }
.drawflow .drawflow-node.welcome_message .title-box { background: #fffbeb; }
.drawflow .drawflow-node.text .title-box     { background: #ecfdf5; }
.drawflow .drawflow-node.image .title-box    { background: #fffbeb; }
.drawflow .drawflow-node.video .title-box    { background: #fdf2f8; }
.drawflow .drawflow-node.audio .title-box    { background: #f5f3ff; }
.drawflow .drawflow-node.document .title-box { background: #fdf4ff; }
.drawflow .drawflow-node.delay .title-box    { background: #fff7ed; }
.drawflow .drawflow-node.interactive_button .title-box { background: #f0f9ff; }
.drawflow .drawflow-node.condition .title-box { background: #fef2f2; }
.drawflow .drawflow-node.randomizer .title-box { background: #fdf4ff; }
.drawflow .drawflow-node.switcher .title-box { background: #f5f3ff; }
.drawflow .drawflow-node.http_request .title-box { background: #ecfeff; }
.drawflow .drawflow-node.add_tag .title-box { background: #fff7ed; }
.drawflow .drawflow-node.assign_agent .title-box { background: #fff7ed; }
.drawflow .drawflow-node.note .title-box     { background: #f5f3ff; }

/* --------  Badges  -------- */
.badge-trigger  { background: #dbeafe; color: #2563eb; }
.badge-action   { background: #d1fae5; color: #059669; }
.badge-logic    { background: #fee2e2; color: #dc2626; }
.badge-crm      { background: #ffedd5; color: #ea580c; }
.badge-util     { background: #ede9fe; color: #7c3aed; }

.drawflow .drawflow-node .badge-trigger  { box-shadow: inset 0 0 0 1px rgba(37,99,235,0.15); }
.drawflow .drawflow-node .badge-action   { box-shadow: inset 0 0 0 1px rgba(5,150,105,0.15); }
.drawflow .drawflow-node .badge-logic    { box-shadow: inset 0 0 0 1px rgba(220,38,38,0.15); }
.drawflow .drawflow-node .badge-crm      { box-shadow: inset 0 0 0 1px rgba(234,88,12,0.15); }
.drawflow .drawflow-node .badge-util     { box-shadow: inset 0 0 0 1px rgba(124,58,237,0.15); }

/* ========================================================================
   CONNECTION LINES — Modern Animated Design
   ======================================================================== */

/* SVG connection container */
.drawflow .connection {
    z-index: 1;
    position: absolute;
    pointer-events: none;
}

/* Main connection path */
.drawflow .connection .main-path {
    stroke: url(#flow-gradient-light) #818cf8;
    stroke-width: 2.5px;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
    filter: drop-shadow(0 1px 2px rgba(99, 102, 241, 0.18));
    transition: stroke-width 0.25s ease, filter 0.25s ease;
    pointer-events: stroke;
    cursor: pointer;
}

/* Animated flowing dash */
.drawflow .connection .main-path {
    stroke-dasharray: none;
}

.drawflow .connection .main-path:hover {
    stroke: #6366f1;
    stroke-width: 3.5px;
    filter: drop-shadow(0 0 6px rgba(99, 102, 241, 0.35));
    stroke-dasharray: 8 4;
    animation: flow-dash 0.6s linear infinite;
}

.drawflow .connection .main-path.selected {
    stroke: #4f46e5;
    stroke-width: 3.5px;
    filter: drop-shadow(0 0 8px rgba(79, 70, 229, 0.45));
    stroke-dasharray: 8 4;
    animation: flow-dash 0.6s linear infinite;
}

@keyframes flow-dash {
    to { stroke-dashoffset: -12; }
}

/* ========================================================================
   CONNECTION POINTS (PORTS) — Modern Clean Design
   ======================================================================== */

/* --- Base port style (shared input & output) --- */
.drawflow .drawflow-node .input,
.drawflow .drawflow-node .output {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2.5px solid #a5b4fc;
    background: #ffffff;
    cursor: crosshair;
    z-index: 10;
    transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
    box-shadow: 0 0 0 3px rgba(255,255,255,0.9), 0 1px 4px rgba(15,23,42,0.12);
    /* No pseudo-elements — clean clickable area */
}

/* Remove any inherited pseudo-elements that block clicks */
.drawflow .drawflow-node .input::before,
.drawflow .drawflow-node .input::after,
.drawflow .drawflow-node .output::before,
.drawflow .drawflow-node .output::after {
    content: none !important;
    display: none !important;
}

/* --- Output port (right side) --- */
.drawflow .drawflow-node .output {
    border-color: #818cf8;
    background: linear-gradient(135deg, #eef2ff 0%, #e0e7ff 100%);
}

/* --- Input port (left side) --- */
.drawflow .drawflow-node .input {
    border-color: #67e8f9;
    background: linear-gradient(135deg, #ecfeff 0%, #cffafe 100%);
}

/* --- Hover states — glow ring --- */
.drawflow .drawflow-node .output:hover {
    background: #818cf8;
    border-color: #6366f1;
    box-shadow: 0 0 0 4px rgba(99,102,241,0.22), 0 0 12px rgba(99,102,241,0.30);
}

.drawflow .drawflow-node .input:hover {
    background: #22d3ee;
    border-color: #06b6d4;
    box-shadow: 0 0 0 4px rgba(6,182,212,0.22), 0 0 12px rgba(6,182,212,0.30);
}

/* --- Active / dragging connection from port --- */
.drawflow .drawflow-node .output.active,
.drawflow .drawflow-node .input.active {
    box-shadow: 0 0 0 5px rgba(99,102,241,0.3), 0 0 16px rgba(99,102,241,0.4);
}

/* --------  Delete button  -------- */
.drawflow-delete {
    display: none !important;
}
.drawflow-delete:hover {
    display: none !important;
}

/* ========================================================================
   DARK MODE
   ======================================================================== */
body.dark-mode #flowBuilderModal .modal-content { background: #1a1d21 !important; }
body.dark-mode #flowBuilderModal .modal-header { background: #212529 !important; border-color: #343a40 !important; }
body.dark-mode .flow-header-title { color: #f8f9fa; }
body.dark-mode .flow-header-subtitle { color: #6c757d; }
body.dark-mode .btn-flow-secondary { background: #2b3035; border-color: #3d444b; color: #ced4da; }
body.dark-mode .btn-flow-secondary:hover { background: #343a40; color: #f8f9fa; }

body.dark-mode .flow-sidebar { background: #212529 !important; border-color: #343a40; }
body.dark-mode .flow-sidebar-section { border-color: #2b3035; }
body.dark-mode .flow-cat-header { color: #6c757d; }
body.dark-mode .flow-cat-header:hover { background: #2b3035; }

body.dark-mode .flow-search-wrap input {
    background: #2b3035; border-color: #3d444b; color: #f8f9fa;
}
body.dark-mode .flow-search-wrap input:focus { background: #343a40; border-color: #667eea; }
body.dark-mode .flow-search-wrap i { color: #6c757d; }

body.dark-mode .flow-config-section .form-label,
body.dark-mode .flow-config-section .form-check-label,
body.dark-mode .flow-config-section small { color: #ced4da !important; }
body.dark-mode .flow-config-section .form-select,
body.dark-mode .flow-config-section .form-control {
    background: #2b3035; border-color: #3d444b; color: #f8f9fa;
}
body.dark-mode .flow-config-section .form-select:focus,
body.dark-mode .flow-config-section .form-control:focus { border-color: #667eea; }

body.dark-mode .drag-drawflow { background: #2b3035; border-color: #3d444b; }
body.dark-mode .drag-drawflow:hover { background: #343a40; border-color: #495057; box-shadow: 0 4px 14px rgba(0,0,0,0.3); }
body.dark-mode .node-title { color: #f8f9fa; }
body.dark-mode .node-desc { color: #6c757d; }

body.dark-mode #drawflow {
    background-color: #1a1d21;
    background-image:
        radial-gradient(circle, rgba(255,255,255,0.05) 1px, transparent 1px);
    background-size: 20px 20px;
}

body.dark-mode .flow-toolbar { background: rgba(33,37,41,0.92); box-shadow: 0 6px 24px rgba(0,0,0,0.3), 0 0 0 1px rgba(255,255,255,0.05); }
body.dark-mode .flow-toolbar .tb-btn { color: #ced4da; }
body.dark-mode .flow-toolbar .tb-btn:hover { background: #343a40; color: #f8f9fa; }
body.dark-mode .flow-toolbar .tb-btn.active { background: #667eea; color: #fff; }
body.dark-mode .flow-toolbar .tb-btn.danger:hover { background: #3b1c1c; color: #f87171; }
body.dark-mode .flow-toolbar .tb-sep { background: #3d444b; }
body.dark-mode .flow-toolbar .zoom-display { color: #ced4da; }

body.dark-mode .flow-sidebar-toggle,
body.dark-mode .flow-node-count {
    background: rgba(33,37,41,0.92); border-color: #3d444b; color: #ced4da;
    box-shadow: 0 4px 14px rgba(0,0,0,0.3);
}
body.dark-mode .flow-sidebar-toggle:hover { background: #343a40; color: #f8f9fa; }

/* --- Dark mode nodes --- */
body.dark-mode .drawflow .drawflow-node {
    background: #252a30;
    border-color: #3a4250;
    color: #f8f9fa;
    box-shadow: 0 4px 16px rgba(0,0,0,0.32), 0 1px 3px rgba(0,0,0,0.2);
}

body.dark-mode #flowBuilderModal .drawflow .drawflow-node {
    background: #252a30 !important;
    color: #f8fafc !important;
}
body.dark-mode .drawflow .drawflow-node:hover {
    box-shadow: 0 8px 28px rgba(0,0,0,0.42);
    border-color: #4f5b6e;
}
body.dark-mode .drawflow .drawflow-node.selected {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102,126,234,0.25), 0 10px 32px rgba(0,0,0,0.4);
}

body.dark-mode .drawflow .drawflow-node .title-box { border-color: #3a4250; }
body.dark-mode .drawflow .drawflow-node .title-box,
body.dark-mode .drawflow .drawflow-node .title-box i {
    color: #f1f5f9;
}
body.dark-mode .drawflow .drawflow-node.keyword .title-box  { background: rgba(13,202,240,0.08); }
body.dark-mode .drawflow .drawflow-node.exact .title-box    { background: rgba(59,130,246,0.08); }
body.dark-mode .drawflow .drawflow-node.regex .title-box    { background: rgba(99,102,241,0.08); }
body.dark-mode .drawflow .drawflow-node.default_trigger .title-box { background: rgba(148,163,184,0.08); }
body.dark-mode .drawflow .drawflow-node.welcome_message .title-box { background: rgba(245,158,11,0.08); }
body.dark-mode .drawflow .drawflow-node.text .title-box     { background: rgba(16,185,129,0.08); }
body.dark-mode .drawflow .drawflow-node.image .title-box    { background: rgba(245,158,11,0.08); }
body.dark-mode .drawflow .drawflow-node.video .title-box    { background: rgba(236,72,153,0.08); }
body.dark-mode .drawflow .drawflow-node.audio .title-box    { background: rgba(139,92,246,0.08); }
body.dark-mode .drawflow .drawflow-node.document .title-box { background: rgba(232,121,249,0.08); }
body.dark-mode .drawflow .drawflow-node.delay .title-box    { background: rgba(251,146,60,0.08); }
body.dark-mode .drawflow .drawflow-node.interactive_button .title-box { background: rgba(14,165,233,0.08); }
body.dark-mode .drawflow .drawflow-node.condition .title-box { background: rgba(239,68,68,0.08); }
body.dark-mode .drawflow .drawflow-node.randomizer .title-box { background: rgba(217,70,239,0.08); }
body.dark-mode .drawflow .drawflow-node.switcher .title-box { background: rgba(139,92,246,0.08); }
body.dark-mode .drawflow .drawflow-node.http_request .title-box { background: rgba(6,182,212,0.08); }
body.dark-mode .drawflow .drawflow-node.add_tag .title-box { background: rgba(249,115,22,0.08); }
body.dark-mode .drawflow .drawflow-node.assign_agent .title-box { background: rgba(249,115,22,0.08); }
body.dark-mode .drawflow .drawflow-node.note .title-box     { background: rgba(167,139,250,0.08); }

body.dark-mode .drawflow .drawflow-node label { color: #8b919a; }
body.dark-mode .drawflow .drawflow-node input,
body.dark-mode .drawflow .drawflow-node textarea,
body.dark-mode .drawflow .drawflow-node select {
    background: #1c2128; border-color: #3a4250; color: #f8f9fa;
}
body.dark-mode .drawflow .drawflow-node input:focus,
body.dark-mode .drawflow .drawflow-node textarea:focus,
body.dark-mode .drawflow .drawflow-node select:focus {
    border-color: #667eea;
    background: #222830;
    box-shadow: 0 0 0 3px rgba(102,126,234,0.25);
}

body.dark-mode .drawflow .drawflow-node .node-help { color: #6c757d; }
body.dark-mode .drawflow .drawflow-node .node-collapse-btn { color: #6c757d; }
body.dark-mode .drawflow .drawflow-node .node-collapse-btn:hover { color: #ced4da; background: rgba(255,255,255,0.05); }
body.dark-mode .drawflow .drawflow-node .node-actions-toggle { color: #6c757d; }
body.dark-mode .drawflow .drawflow-node .node-actions-toggle:hover { color: #ced4da; background: rgba(255,255,255,0.05); }
body.dark-mode .drawflow .drawflow-node .node-actions-menu {
    background: #1f242b;
    border-color: #343a40;
    box-shadow: 0 10px 24px rgba(0,0,0,0.45);
}
body.dark-mode .drawflow .drawflow-node .node-action-item { color: #d1d5db; }
body.dark-mode .drawflow .drawflow-node .node-action-item:hover { background: #2b3035; }
body.dark-mode .drawflow .drawflow-node .node-action-item.danger { color: #f87171; }
body.dark-mode .drawflow .drawflow-node .node-action-item.danger:hover { background: #3b1c1c; }
body.dark-mode .flow-context-menu {
    background: #1f242b;
    border-color: #343a40;
    box-shadow: 0 10px 24px rgba(0,0,0,0.45);
}
body.dark-mode .flow-context-menu .ctx-item { color: #d1d5db; }
body.dark-mode .flow-context-menu .ctx-item:hover { background: #2b3035; }
body.dark-mode .flow-context-menu .ctx-item.danger { color: #f87171; }
body.dark-mode .flow-context-menu .ctx-item.danger:hover { background: #3b1c1c; }

/* --- Dark mode connection points --- */
body.dark-mode .drawflow .drawflow-node .output {
    background: linear-gradient(135deg, #312e81, #3730a3);
    border-color: #818cf8;
    box-shadow: 0 0 0 3px rgba(26,29,33,0.9), 0 1px 4px rgba(0,0,0,0.3);
}

body.dark-mode .drawflow .drawflow-node .input {
    background: linear-gradient(135deg, #164e63, #155e75);
    border-color: #22d3ee;
    box-shadow: 0 0 0 3px rgba(26,29,33,0.9), 0 1px 4px rgba(0,0,0,0.3);
}

body.dark-mode .drawflow .drawflow-node .output:hover {
    background: #818cf8;
    border-color: #a5b4fc;
    box-shadow: 0 0 0 4px rgba(129,140,248,0.25), 0 0 14px rgba(129,140,248,0.35);
}

body.dark-mode .drawflow .drawflow-node .input:hover {
    background: #22d3ee;
    border-color: #67e8f9;
    box-shadow: 0 0 0 4px rgba(34,211,238,0.25), 0 0 14px rgba(34,211,238,0.35);
}

/* --- Dark mode connection lines --- */
body.dark-mode .drawflow .connection .main-path {
    stroke: #4f5b72;
    filter: drop-shadow(0 0 2px rgba(0,0,0,0.3));
}

body.dark-mode .drawflow .connection .main-path:hover {
    stroke: #818cf8;
    filter: drop-shadow(0 0 6px rgba(129,140,248,0.4));
}

body.dark-mode .drawflow .connection .main-path.selected {
    stroke: #a5b4fc;
    filter: drop-shadow(0 0 8px rgba(165,180,252,0.45));
}

body.dark-mode .drawflow .drawflow-node .node-resize-handle::after { border-color: #6c757d; }
body.dark-mode .drawflow .drawflow-node .node-resize-handle:hover { background: rgba(108,117,125,0.22); }

/* --- Space Panning & Multi-Selection --- */
#drawflow.space-panning {
    cursor: grab !important;
}
#drawflow.space-panning:active {
    cursor: grabbing !important;
}
#drawflow.space-panning .drawflow-node {
    pointer-events: none !important;
}

.flow-selection-box {
    position: fixed;
    border: 1px solid #0ea5e9;
    background: rgba(14, 165, 233, 0.15);
    z-index: 99999;
    pointer-events: none;
    display: none;
}

.drawflow-node.multi-selected {
    box-shadow: 0 0 0 2px #0ea5e9, 0 8px 24px rgba(0,0,0,0.12) !important;
}
body.dark-mode .drawflow-node.multi-selected {
    box-shadow: 0 0 0 2px #38bdf8, 0 8px 24px rgba(0,0,0,0.4) !important;
}
