/* ═══════════════════════════════════════════════════════════════════
   Workflow Builder — all canvas, step, connector, and drag-drop styles
   ═══════════════════════════════════════════════════════════════════ */

.canvas-scroll {
    overflow: auto;
    padding-bottom: 1rem;
    display: flex;
    justify-content: center;
}

.wf-canvas {
    padding: 1rem 2rem 2rem;
    margin: 0 auto;
}

/* Step cell wrapper — centres the card within its grid column */
.wf-step-cell {
    display: flex;
    justify-content: center;
    padding: 0 4px;
}

/* Step card */
.wf-step-card {
    position: relative;
    width: 220px;
    border: 1px solid var(--theme-border);
    border-radius: var(--theme-radius);
    background: var(--theme-background-subtle);
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
    text-align: center;
    user-select: none;
}

.wf-step-delete {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 20px;
    height: 20px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--theme-text-muted);
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transition: opacity 150ms ease, color 150ms ease, background 150ms ease;
    padding: 0;
    line-height: 1;
}

/* MultiSplit loop-back indicator — branches return to this step until exit */
.wf-step-loopback {
    position: absolute;
    top: 2px;
    left: 4px;
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--theme-primary);
    font-size: 0.85rem;
    line-height: 1;
    pointer-events: auto;
}

.wf-step-card:hover .wf-step-delete {
    opacity: 1;
}

.wf-step-delete:hover {
    background: var(--theme-danger, #dc3545);
    color: #fff;
}

.wf-step-card:hover {
    border-color: var(--theme-primary);
    background: var(--theme-background-hover);
}

.wf-step-type {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--theme-text-secondary);
    margin-bottom: 0.2rem;
}

.wf-step-name {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    font-size: 0.78rem;
    line-height: 1.2;
    color: var(--theme-text);
    font-weight: 500;
    overflow: hidden;
    /* 2-line clamp: allows two-line wrap, then ellipsis on the third */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    text-overflow: ellipsis;
    word-break: break-word;
}

.wf-step-name i {
    flex-shrink: 0;
    margin-right: 0.25rem;
}

/* Workflow pseudo step (start/end) */
.wf-step-workflow {
    border-color: var(--theme-primary);
    background: var(--theme-primary-muted);
}

.wf-step-workflow .wf-step-type {
    color: var(--theme-primary);
}

/* Option pseudo step */
.wf-step-option {
    border-color: var(--theme-offset);
    background: var(--theme-offset-muted);
}

.wf-step-option .wf-step-type {
    color: var(--theme-offset);
}

/* Exit option pseudo step */
.wf-step-exit {
    border-color: var(--theme-accent);
    background: var(--theme-accent-muted);
}

.wf-step-exit .wf-step-type {
    color: var(--theme-accent);
}

/* Vertical gap cell */
.wf-vgap-cell {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0;
    height: 56px;
}

/* Dead-zone filler — stretch to match row, no add button */
.wf-deadzone-cell {
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100%;
    padding: 0;
}

/* Loop-back terminator — drawn at the bottom of each non-exit branch of a
   MultiSplit step. A heavy bar that caps the trail line from the "+" above.
   Pairs with the .wf-step-loopback badge on the parent step. */
.wf-loopback-terminator {
    width: 60px;
    height: 4px;
    background: var(--theme-primary);
    border-radius: 2px;
    margin: 0 auto;
}

.wf-vgap-line {
    width: 2px;
    flex: 1;
    background: var(--theme-border-subtle);
}

.wf-add-btn {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 1px solid var(--theme-border-subtle);
    background: var(--theme-background-subtle);
    color: var(--theme-text-secondary);
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: border-color 0.15s, color 0.15s, background 0.15s;
    flex-shrink: 0;
}

.wf-add-btn:hover {
    border-color: var(--theme-primary);
    color: var(--theme-primary);
    background: var(--theme-primary-muted);
}

/* Horizontal branch/merge connector cells — same height as VGap so all G rows are 56px */
.wf-hconn {
    height: 56px;
    padding: 0;
    overflow: visible;
}

/* SVG bracket connectors */
.wf-connector-svg {
    display: block;
    width: 100%;
    height: 100%;
}

.wf-connector-svg path {
    stroke: var(--theme-border-subtle);
    stroke-width: 2;
    stroke-linecap: round;
    fill: none;
}

.wf-connector-svg.wf-multisplit path {
    stroke: var(--theme-offset);
    opacity: 0.5;
}

/* Loop-back connector */
.wf-loopback {
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    width: 28px;
}

.wf-loopback-top {
    flex-shrink: 0;
    height: 24px;
}

.wf-loopback-bottom {
    flex-shrink: 0;
    height: 32px;
}

.wf-loopback-mid {
    flex: 1;
    width: 2px;
    margin-left: 13px;
    background: repeating-linear-gradient(
        to bottom,
        var(--theme-text-muted) 0px,
        var(--theme-text-muted) 5px,
        transparent 5px,
        transparent 9px
    );
}

/* ── Drag-and-drop ─────────────────────────────────────────────── */

/* Draggable steps */
.wf-step-name[draggable="true"] {
    cursor: grab;
}
.wf-step-name[draggable="true"]:active {
    cursor: grabbing;
    opacity: 0.5;
}

/* Drop target: highlight via @ondragenter/@ondragleave toggling .wf-drag-over
   (CSS :hover doesn't fire during HTML5 drag operations) */
.wf-drag-over .wf-add-btn {
    border-color: var(--theme-accent, #0d6efd);
    color: var(--theme-accent, #0d6efd);
    background: var(--theme-accent-muted, rgba(13,110,253,0.15));
    transform: scale(1.4);
    transition: transform 0.12s ease, background 0.12s ease, border-color 0.12s ease;
    box-shadow: 0 0 8px rgba(13,110,253,0.3);
}
.wf-drop-target:hover .wf-vgap-line {
    background: var(--theme-accent, #0d6efd);
    transition: background 0.12s ease;
}

/* ── Drag-mode drop indicator — modest pill, parent cell catches drops ──── */
/* The parent .wf-vgap-cell remains the full 220×56 hit area during drag —
   only the visual indicator changes from a tiny (+) to a more obvious pill,
   so users see exactly where they can drop without the canvas turning into
   a wall of giant boxes. */
.wf-vgap-cell.wf-dragging {
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.wf-drop-zone {
    min-width: 110px;
    height: 32px;
    padding: 0 0.65rem;
    border: 2px dashed var(--theme-border-subtle, #b0b7bf);
    border-radius: 16px;
    background: var(--theme-background-subtle, #f8f9fa);
    color: var(--theme-text-muted, #6c757d);
    font-size: 0.72rem;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease, transform 0.12s ease;
    user-select: none;
    pointer-events: none; /* parent cell handles drop events */
}
.wf-vgap-cell.wf-dragging.wf-drag-over .wf-drop-zone {
    border-color: var(--theme-accent, #0d6efd);
    border-style: solid;
    background: var(--theme-accent-muted, rgba(13,110,253,0.15));
    color: var(--theme-accent, #0d6efd);
    transform: scale(1.08);
    box-shadow: 0 0 10px rgba(13,110,253,0.25);
}

/* Ensure canvas scrolls during drag */
.canvas-scroll {
    scroll-behavior: smooth;
}
