/* ============================================================================
   Rule Flow — visual flow designer.
   Aesthetic matches the rule-engine (Vercel/Linear inspired light theme).
   All node shapes are rectangles. Condition has two stacked output ports
   (YES on top-right, NO on bottom-right) but uses the same rect chrome.
   ============================================================================ */

:root {
    --rf-bg:            #f8fafc;
    --rf-surface:       #ffffff;
    --rf-surface-2:     #f1f5f9;
    --rf-surface-3:     #e2e8f0;
    --rf-ink:           #0f172a;
    --rf-ink-2:         #475569;
    --rf-ink-3:         #94a3b8;
    --rf-border:        rgb(15 23 42 / 0.08);
    --rf-border-strong: rgb(15 23 42 / 0.16);
    --rf-accent:        #2563eb;
    --rf-accent-soft:   rgb(37 99 235 / 0.08);
    --rf-yes:           #10b981;
    --rf-no:            #f43f5e;
    --rf-ease:          cubic-bezier(.175, .885, .32, 1.1);
    --rf-shadow-b:      inset 0 0 0 1px var(--rf-border);
    --rf-shadow-card:   0 1px 3px 0 rgb(15 23 42 / 0.04), 0 1px 2px -1px rgb(15 23 42 / 0.05), inset 0 0 0 1px var(--rf-border);
    --rf-shadow-elev:   0 12px 28px -12px rgb(15 23 42 / 0.18), 0 0 0 1px var(--rf-border);
    --rf-shadow-focus:  0 0 0 2px #fff, 0 0 0 4px var(--rf-accent);
}

/* ----------------------------------------------------------------------------
   Palette (left aside)
   ---------------------------------------------------------------------------- */
.palette-block {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    background: #fff;
    box-shadow: var(--rf-shadow-b);
    border-radius: 10px;
    cursor: grab;
    transition: background-color .15s var(--rf-ease), box-shadow .15s var(--rf-ease), transform .15s var(--rf-ease);
}
.palette-block:hover {
    background: var(--rf-surface-2);
    box-shadow: 0 1px 2px rgb(15 23 42 / 0.06), inset 0 0 0 1px var(--rf-border-strong);
    transform: translateY(-0.5px);
}
.palette-block:active  { cursor: grabbing; transform: translateY(0); }
.palette-block.dragging { opacity: 0.5; }
.palette-icon {
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 12px;
    background: #0f172a;
    border-radius: 6px;
    flex-shrink: 0;
}
/* Per-type palette icon tints (match canvas chrome) */
.palette-icon.type-start    { background: #047857; }
.palette-icon.type-end      { background: #475569; }
.palette-icon.type-return   { background: #2563eb; }
.palette-icon.type-condition{ background: #7c3aed; }
.palette-icon.type-and,
.palette-icon.type-or,
.palette-icon.type-not      { background: #0f172a; }
.palette-icon.type-field    { background: #0369a1; }
.palette-icon.type-constant { background: #b45309; }
.palette-icon.type-function { background: #0d9488; }

.palette-body { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.palette-label { font-size: 12.5px; font-weight: 600; color: var(--rf-ink); }
.palette-desc  { font-size: 10.5px; color: var(--rf-ink-2); margin-top: 1px; }

/* ----------------------------------------------------------------------------
   Canvas wrapper + dot grid background
   ---------------------------------------------------------------------------- */
#canvas-wrap {
    background-color: var(--rf-bg);
    background-image: radial-gradient(circle, rgb(15 23 42 / 0.08) 1px, transparent 1px);
    background-size: 18px 18px;
    cursor: grab;
}
#canvas-wrap.is-panning {
    cursor: grabbing;
    scroll-behavior: auto; /* disable smooth-scroll while user is panning */
}
#canvas-wrap.is-panning .flow-canvas { pointer-events: none; }

.flow-canvas {
    position: relative;
    width: 3000px;
    height: 2000px;
    transform-origin: 0 0;
    will-change: transform;
}

.nodes-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

/* SVG sits below nodes so node ports stay clickable. */
.edges-svg {
    position: absolute;
    inset: 0;
    overflow: visible;
    pointer-events: none;
}
.edges-svg path {
    fill: none;
    stroke-linecap: round;
    pointer-events: stroke;
    cursor: pointer;
    transition: stroke .15s var(--rf-ease), stroke-width .15s var(--rf-ease);
}
.edges-svg path.edge          { stroke: #94a3b8; stroke-width: 1.75; marker-end: url(#arrow-default); }
.edges-svg path.edge.yes      { stroke: var(--rf-yes); marker-end: url(#arrow-yes); }
.edges-svg path.edge.no       { stroke: var(--rf-no);  marker-end: url(#arrow-no); }
.edges-svg path.edge:hover    { stroke-width: 2.5; }
.edges-svg path.edge.selected { stroke: var(--rf-accent); stroke-width: 2.5; marker-end: url(#arrow-active); }

/* Animated active edge during a test run */
.edges-svg path.edge.active {
    stroke: var(--rf-accent);
    stroke-width: 2.5;
    marker-end: url(#arrow-active);
    stroke-dasharray: 6 4;
    animation: dashFlow 0.6s linear infinite;
    filter: drop-shadow(0 0 6px rgb(37 99 235 / 0.35));
}
.edges-svg path.edge.traversed {
    stroke: var(--rf-accent);
    stroke-width: 2;
    marker-end: url(#arrow-active);
    opacity: 0.55;
}
@keyframes dashFlow { to { stroke-dashoffset: -10; } }

/* Edge labels (YES/NO + per-edge value chip) */
.edge-label {
    pointer-events: none;
    user-select: none;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}
.edge-label.yes { fill: var(--rf-yes); }
.edge-label.no  { fill: var(--rf-no);  }

/* Value chip painted on traversed edges — shows what value flowed across */
.edge-value-bg { fill: #ffffff; stroke: var(--rf-accent); stroke-width: 0.75; opacity: 0.95; }
.edge-value-tx { fill: var(--rf-accent); font-size: 10px; font-family: 'JetBrains Mono', Consolas, monospace; pointer-events: none; user-select: none; }

/* Ghost edge while dragging from a port */
.edges-svg path.edge-ghost {
    stroke: var(--rf-accent);
    stroke-width: 1.75;
    stroke-dasharray: 4 4;
    fill: none;
    pointer-events: none;
}

/* ----------------------------------------------------------------------------
   Nodes — all rectangles. Per-type tint stripes give visual recognition.
   ---------------------------------------------------------------------------- */
.flow-node {
    position: absolute;
    pointer-events: auto;
    user-select: none;
    cursor: grab;
    transition: filter .15s var(--rf-ease), transform .15s var(--rf-ease);
}
.flow-node.dragging      { cursor: grabbing; }
.flow-node.is-selected .node-shape { box-shadow: 0 0 0 1px var(--rf-accent), 0 12px 24px -10px rgb(37 99 235 / 0.35); }
.flow-node.is-current  .node-shape { animation: nodePulse 1.1s var(--rf-ease) infinite; }
.flow-node.is-visited  .node-shape { box-shadow: 0 0 0 1px rgb(37 99 235 / 0.45), 0 1px 2px rgb(15 23 42 / 0.05); }
.flow-node.is-rejected .node-shape { opacity: 0.5; filter: grayscale(.35); }

@keyframes nodePulse {
    0%, 100% { box-shadow: 0 0 0 1px var(--rf-accent), 0 0 0 0 rgb(37 99 235 / 0.0), 0 12px 24px -10px rgb(37 99 235 / 0.4); }
    50%      { box-shadow: 0 0 0 1px var(--rf-accent), 0 0 0 8px rgb(37 99 235 / 0.18), 0 16px 32px -10px rgb(37 99 235 / 0.5); }
}

.node-shape {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: #ffffff;
    border-radius: 10px;
    box-shadow: var(--rf-shadow-card);
    min-width: 150px;
    max-width: 280px;
    color: var(--rf-ink);
    font-size: 12.5px;
    font-weight: 500;
    line-height: 1.25;
    transition: box-shadow .2s var(--rf-ease), transform .15s var(--rf-ease);
}
.node-shape .node-icon {
    width: 18px;
    height: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--rf-ink-2);
    font-size: 11px;
    flex-shrink: 0;
}
.node-shape .node-label {
    min-width: 0;
    text-align: left;
    word-break: break-word;
    font-family: 'JetBrains Mono', Consolas, monospace;
    font-size: 11.5px;
    color: var(--rf-ink);
}
.node-shape .node-pin {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 18px;
    height: 18px;
    border-radius: 999px;
    background: #fff;
    color: var(--rf-ink-3);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 9px;
    box-shadow: var(--rf-shadow-b);
    opacity: 0;
    transition: opacity .15s var(--rf-ease), color .15s var(--rf-ease);
    cursor: pointer;
}
.flow-node:hover .node-pin { opacity: 1; }
.node-shape .node-pin:hover { color: var(--rf-ink); }

/* Per-type chrome tints */
.flow-node[data-type="start"]     .node-shape { background: linear-gradient(180deg, #ecfdf5, #ffffff); box-shadow: 0 1px 3px rgb(15 23 42 / 0.05), inset 0 0 0 1px rgb(16 185 129 / 0.35); border-radius: 999px; padding: 8px 18px; font-weight: 600; letter-spacing: 0.02em; }
.flow-node[data-type="start"]     .node-icon  { color: #047857; }
.flow-node[data-type="end"]       .node-shape { background: linear-gradient(180deg, #f1f5f9, #ffffff); box-shadow: 0 1px 3px rgb(15 23 42 / 0.05), inset 0 0 0 1px rgb(71 85 105 / 0.35); border-radius: 999px; padding: 8px 18px; font-weight: 600; letter-spacing: 0.02em; }
.flow-node[data-type="end"]       .node-icon  { color: var(--rf-ink-2); }
.flow-node[data-type="return"]    .node-shape { background: linear-gradient(180deg, #eff6ff, #ffffff); box-shadow: 0 1px 3px rgb(15 23 42 / 0.05), inset 0 0 0 1px rgb(37 99 235 / 0.30); }
.flow-node[data-type="return"]    .node-icon  { color: var(--rf-accent); }
.flow-node[data-type="condition"] .node-shape { background: linear-gradient(180deg, #fdf4ff, #ffffff); box-shadow: 0 1px 3px rgb(15 23 42 / 0.05), inset 0 0 0 1px rgb(168 85 247 / 0.30); padding-right: 26px; min-height: 56px; }
.flow-node[data-type="condition"] .node-icon  { color: #7c3aed; }
.flow-node[data-type="field"]     .node-shape { background: linear-gradient(180deg, #ecfeff, #ffffff); box-shadow: 0 1px 3px rgb(15 23 42 / 0.05), inset 0 0 0 1px rgb(14 165 233 / 0.30); }
.flow-node[data-type="field"]     .node-icon  { color: #0369a1; }
.flow-node[data-type="constant"]  .node-shape { background: linear-gradient(180deg, #fffbeb, #ffffff); box-shadow: 0 1px 3px rgb(15 23 42 / 0.05), inset 0 0 0 1px rgb(245 158 11 / 0.30); }
.flow-node[data-type="constant"]  .node-icon  { color: #b45309; }
.flow-node[data-type="function"]  .node-shape { background: linear-gradient(180deg, #f0fdfa, #ffffff); box-shadow: 0 1px 3px rgb(15 23 42 / 0.05), inset 0 0 0 1px rgb(20 184 166 / 0.30); }
.flow-node[data-type="function"]  .node-icon  { color: #0d9488; }
.flow-node[data-type="and"]       .node-shape,
.flow-node[data-type="or"]        .node-shape,
.flow-node[data-type="not"]       .node-shape { background: linear-gradient(180deg, #f8fafc, #ffffff); box-shadow: 0 1px 3px rgb(15 23 42 / 0.05), inset 0 0 0 1px rgb(15 23 42 / 0.12); }

/* Sub-label (configured operands shown beneath the main label, e.g. for Condition / Field) */
.node-sub {
    display: block;
    margin-top: 2px;
    font-size: 10px;
    color: var(--rf-ink-3);
    font-family: 'JetBrains Mono', Consolas, monospace;
    letter-spacing: 0;
    text-transform: none;
    font-weight: 500;
}

/* ----------------------------------------------------------------------------
   Ports
   ---------------------------------------------------------------------------- */
.node-port {
    position: absolute;
    width: 14px;
    height: 14px;
    border-radius: 999px;
    background: #ffffff;
    box-shadow: 0 0 0 1.5px var(--rf-ink-2), 0 1px 2px rgb(15 23 42 / 0.1);
    cursor: crosshair;
    z-index: 5;
    transition: transform .12s var(--rf-ease), box-shadow .15s var(--rf-ease), background-color .15s var(--rf-ease);
}
.node-port:hover {
    transform: scale(1.18);
    box-shadow: 0 0 0 1.5px var(--rf-accent), 0 0 0 4px rgb(37 99 235 / 0.18);
}
.node-port.port-in      { background: #fff; }
.node-port.port-out     { background: #fff; box-shadow: 0 0 0 1.5px var(--rf-accent), 0 1px 2px rgb(37 99 235 / 0.18); }
.node-port.port-out-yes { background: #fff; box-shadow: 0 0 0 1.5px var(--rf-yes), 0 1px 2px rgb(16 185 129 / 0.18); }
.node-port.port-out-no  { background: #fff; box-shadow: 0 0 0 1.5px var(--rf-no),  0 1px 2px rgb(244 63 94 / 0.18); }
.node-port.is-connecting { background: var(--rf-accent); }
.node-port.is-target     { transform: scale(1.25); background: var(--rf-accent); box-shadow: 0 0 0 2px var(--rf-accent), 0 0 0 6px rgb(37 99 235 / 0.18); }

/* Standard rect ports — left/right midpoints */
.flow-node .port-in  { left: -7px;  top: 50%; transform: translateY(-50%); }
.flow-node .port-out { right: -7px; top: 50%; transform: translateY(-50%); }
.flow-node .port-in:hover  { transform: translateY(-50%) scale(1.18); }
.flow-node .port-out:hover { transform: translateY(-50%) scale(1.18); }

/* Condition: stacked YES (top) / NO (bottom) on the right edge */
.flow-node[data-type="condition"] .port-out-yes { right: -7px; top: 30%;  transform: translateY(-50%); }
.flow-node[data-type="condition"] .port-out-no  { right: -7px; top: 70%;  transform: translateY(-50%); }
.flow-node[data-type="condition"] .port-out-yes:hover { transform: translateY(-50%) scale(1.18); }
.flow-node[data-type="condition"] .port-out-no:hover  { transform: translateY(-50%) scale(1.18); }

/* Multi-input nodes (AND, OR, FUNCTION with >1 param). Each port carries its
   own `top` via inline style; we just normalize positioning + label slots. */
.flow-node.has-multi-in .node-shape { padding-left: 24px; min-height: 56px; align-items: flex-start; padding-top: 12px; padding-bottom: 12px; }
.flow-node.has-multi-in .node-shape .node-icon  { margin-top: 1px; }
.flow-node .port-in-multi { left: -7px; transform: translate(0, -50%); }
.flow-node .port-in-multi:hover { transform: translate(0, -50%) scale(1.18); }

/* Tiny YES / NO label next to each output port */
.port-tag {
    position: absolute;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--rf-ink-2);
    pointer-events: none;
}
.flow-node[data-type="condition"] .port-tag.yes { right: -34px; top: 30%; transform: translateY(-50%); color: var(--rf-yes); }
.flow-node[data-type="condition"] .port-tag.no  { right: -28px; top: 70%; transform: translateY(-50%); color: var(--rf-no);  }

/* Input-port labels (A/B/C for AND/OR, param names for FUNCTION).
   Painted inside the left edge of the box, next to each port. */
.port-tag.in-tag {
    left: 8px;
    transform: translateY(-50%);
    color: var(--rf-ink-2);
    background: rgb(255 255 255 / 0.85);
    padding: 1px 5px;
    border-radius: 999px;
    font-size: 9px;
    box-shadow: inset 0 0 0 1px var(--rf-border);
    max-width: 88px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-family: 'JetBrains Mono', Consolas, monospace;
    text-transform: none;
    letter-spacing: 0;
    font-weight: 600;
}

/* ----------------------------------------------------------------------------
   Trace chips — input / output values painted on each box during a run.
   ---------------------------------------------------------------------------- */
.trace-chip {
    position: absolute;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 6px;
    border-radius: 999px;
    font-size: 10px;
    font-family: 'JetBrains Mono', Consolas, monospace;
    font-weight: 600;
    line-height: 1.4;
    background: #ffffff;
    box-shadow: 0 1px 2px rgb(15 23 42 / 0.08), inset 0 0 0 1px var(--rf-border-strong);
    white-space: nowrap;
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    pointer-events: none;
    z-index: 4;
    animation: chipIn .22s var(--rf-ease) both;
}
.trace-chip i { font-size: 8px; }
.trace-chip.tc-in  { left: 8px;  top: -10px; color: var(--rf-ink-2); }
.trace-chip.tc-in  i { color: var(--rf-ink-3); }
.trace-chip.tc-out { right: 8px; bottom: -10px; color: var(--rf-accent); }
.trace-chip.tc-out i { color: var(--rf-accent); }
.trace-chip.tc-yes { right: 8px; bottom: -10px; color: #047857; box-shadow: 0 1px 2px rgb(15 23 42 / 0.08), inset 0 0 0 1px rgb(16 185 129 / 0.45); background: #ecfdf5; }
.trace-chip.tc-yes i { color: #059669; }
.trace-chip.tc-no  { right: 8px; bottom: -10px; color: #be123c; box-shadow: 0 1px 2px rgb(15 23 42 / 0.08), inset 0 0 0 1px rgb(244 63 94 / 0.45); background: #fef2f2; }
.trace-chip.tc-no  i { color: #e11d48; }

@keyframes chipIn {
    from { opacity: 0; transform: translateY(-4px) scale(.94); }
    to   { opacity: 1; transform: translateY(0)    scale(1); }
}

/* ----------------------------------------------------------------------------
   Empty-canvas hint
   ---------------------------------------------------------------------------- */
.empty-hint {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}
.empty-hint-card {
    background: rgb(255 255 255 / 0.92);
    backdrop-filter: blur(6px);
    padding: 22px 28px;
    border-radius: 14px;
    text-align: center;
    box-shadow: var(--rf-shadow-elev);
    max-width: 320px;
}

/* ----------------------------------------------------------------------------
   Node editor popover
   ---------------------------------------------------------------------------- */
.node-editor {
    position: fixed;
    z-index: 120;
    width: 340px;
    background: #ffffff;
    border-radius: 14px;
    box-shadow: 0 16px 36px -10px rgb(15 23 42 / 0.22), 0 0 0 1px var(--rf-border);
    overflow: hidden;
    animation: ePopIn .18s var(--rf-ease) both;
    transform-origin: top left;
    max-height: calc(100vh - 32px);
    display: flex;
    flex-direction: column;
}
@keyframes ePopIn {
    from { opacity: 0; transform: scale(.96) translateY(-4px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}
.node-editor-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    box-shadow: var(--rf-shadow-b);
    background: var(--rf-surface-2);
    flex-shrink: 0;
}
.node-editor-type {
    font-size: 10.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--rf-ink-2);
}
.node-editor-close {
    width: 26px;
    height: 26px;
    border-radius: 6px;
    background: #fff;
    color: var(--rf-ink-2);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    box-shadow: var(--rf-shadow-b);
    transition: background-color .12s var(--rf-ease), color .12s var(--rf-ease);
}
.node-editor-close:hover { background: var(--rf-surface-2); color: var(--rf-ink); }
.node-editor-body { padding: 14px; overflow-y: auto; }
.node-editor-body .form-label { display: block; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--rf-ink-2); font-weight: 600; margin-bottom: 4px; }
.node-editor-body .form-input,
.node-editor-body .form-select {
    width: 100%;
    background: #fff;
    box-shadow: var(--rf-shadow-b);
    color: var(--rf-ink);
    font-size: 12.5px;
    height: 34px;
    padding: 0 10px;
    border-radius: 8px;
    transition: box-shadow .15s var(--rf-ease);
}
.node-editor-body .form-input:focus,
.node-editor-body .form-select:focus { outline: none; box-shadow: var(--rf-shadow-focus); }
.node-editor-body .form-hint { font-size: 10.5px; color: var(--rf-ink-3); margin-top: 4px; }

/* Per-type editor field groups */
.ne-fields { margin-top: 12px; display: flex; flex-direction: column; gap: 12px; }
.ne-group {
    padding: 10px;
    border-radius: 10px;
    background: var(--rf-surface-2);
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.ne-group-title {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--rf-ink-2);
}
.ne-group-title.op-yes { color: var(--rf-yes); }
.ne-group-title.op-no  { color: var(--rf-no); }
.ne-row { display: flex; gap: 6px; align-items: center; }
.ne-row > .form-input,
.ne-row > .form-select { flex: 1; }
.ne-row .ne-shrink     { flex: 0 0 90px; }

.ne-kind-toggle {
    display: inline-flex;
    padding: 2px;
    border-radius: 8px;
    background: #fff;
    box-shadow: var(--rf-shadow-b);
    gap: 0;
}
.ne-kind-toggle button {
    padding: 4px 8px;
    font-size: 10.5px;
    font-weight: 600;
    color: var(--rf-ink-2);
    border-radius: 6px;
    background: transparent;
    transition: background-color .15s var(--rf-ease), color .15s var(--rf-ease);
}
.ne-kind-toggle button.active { background: var(--rf-ink); color: #fff; }
.ne-kind-toggle button:hover:not(.active) { background: var(--rf-surface-2); color: var(--rf-ink); }

.node-editor-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--rf-border);
}
.node-editor-actions .flex-1 { flex: 1; }
.node-editor-delete {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    height: 30px;
    padding: 0 10px;
    border-radius: 6px;
    background: #fff;
    color: #be123c;
    font-size: 12px;
    font-weight: 500;
    box-shadow: var(--rf-shadow-b);
    transition: background-color .15s var(--rf-ease);
}
.node-editor-delete:hover { background: #fee2e2; }
.node-editor-cancel {
    height: 30px;
    padding: 0 12px;
    border-radius: 6px;
    background: #fff;
    color: var(--rf-ink-2);
    font-size: 12px;
    font-weight: 500;
    box-shadow: var(--rf-shadow-b);
    transition: background-color .15s var(--rf-ease);
}
.node-editor-cancel:hover { background: var(--rf-surface-2); }
.node-editor-save {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    height: 30px;
    padding: 0 12px;
    border-radius: 6px;
    background: var(--rf-ink);
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    transition: background-color .15s var(--rf-ease);
}
.node-editor-save:hover { background: #1e293b; }

/* ----------------------------------------------------------------------------
   Trace panel (right column)
   ---------------------------------------------------------------------------- */
.trace-steps {
    list-style: none;
    padding: 0;
    margin: 0 0 0 6px;
    border-left: 1px solid var(--rf-border);
    padding-left: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.trace-steps li.trace-empty {
    border: none;
    color: var(--rf-ink-3);
    font-size: 11px;
    font-style: italic;
    padding-left: 0;
}
.trace-step {
    position: relative;
    background: #fff;
    box-shadow: var(--rf-shadow-b);
    padding: 8px 10px;
    border-radius: 8px;
    font-size: 11.5px;
    animation: traceIn .25s var(--rf-ease) both;
}
.trace-step::before {
    content: '';
    position: absolute;
    left: -17px;
    top: 14px;
    width: 9px;
    height: 9px;
    border-radius: 999px;
    background: #fff;
    box-shadow: 0 0 0 1.5px var(--rf-accent), inset 0 0 0 2px var(--rf-accent);
}
.trace-step.is-yes::before { box-shadow: 0 0 0 1.5px var(--rf-yes), inset 0 0 0 2px var(--rf-yes); }
.trace-step.is-no::before  { box-shadow: 0 0 0 1.5px var(--rf-no),  inset 0 0 0 2px var(--rf-no); }
.trace-step.is-final::before { box-shadow: 0 0 0 1.5px var(--rf-ink), inset 0 0 0 2px var(--rf-ink); }
.trace-step .ts-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.trace-step .ts-type {
    font-size: 9.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--rf-ink-2);
}
.trace-step .ts-time {
    font-size: 10px;
    color: var(--rf-ink-3);
    font-family: 'JetBrains Mono', Consolas, monospace;
}
.trace-step .ts-label {
    color: var(--rf-ink);
    font-family: 'JetBrains Mono', Consolas, monospace;
    font-size: 11.5px;
    margin-top: 2px;
    word-break: break-word;
}
.trace-step .ts-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 1px 6px;
    border-radius: 999px;
    font-size: 9.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.trace-step .ts-tag.yes  { background: #d1fae5; color: #047857; }
.trace-step .ts-tag.no   { background: #ffe4e6; color: #be123c; }
.trace-step .ts-tag.done { background: #dbeafe; color: #1d4ed8; }

/* Inline data table inside a trace-step — shows inputs → calc → output. */
.ts-flow {
    margin-top: 6px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-family: 'JetBrains Mono', Consolas, monospace;
    font-size: 10.5px;
    line-height: 1.4;
}
.ts-flow .ts-row {
    display: flex;
    gap: 6px;
    align-items: baseline;
}
.ts-flow .ts-key {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    min-width: 46px;
    color: var(--rf-ink-3);
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.ts-flow .ts-key i { font-size: 8px; }
.ts-flow .ts-val { color: var(--rf-ink); word-break: break-word; }
.ts-flow .ts-val.is-yes  { color: #047857; }
.ts-flow .ts-val.is-no   { color: #be123c; }
.ts-flow .ts-val.is-out  { color: var(--rf-accent); }

@keyframes traceIn {
    from { opacity: 0; transform: translateX(4px); }
    to   { opacity: 1; transform: translateX(0); }
}

/* ----------------------------------------------------------------------------
   Output card states (mirrors rule-engine)
   ---------------------------------------------------------------------------- */
#flow-output-card.is-pass    { background: linear-gradient(180deg, #ecfdf5, #ffffff); box-shadow: 0 1px 3px 0 rgb(15 23 42 / 0.04), inset 0 0 0 1px rgb(16 185 129 / 0.25); }
#flow-output-card.is-pass    #flow-output-value { color: #047857; }
#flow-output-card.is-fail    { background: linear-gradient(180deg, #fef2f2, #ffffff); box-shadow: 0 1px 3px 0 rgb(15 23 42 / 0.04), inset 0 0 0 1px rgb(244 63 94 / 0.25); }
#flow-output-card.is-fail    #flow-output-value { color: #be123c; }
#flow-output-card.is-numeric { background: linear-gradient(180deg, #eff6ff, #ffffff); box-shadow: 0 1px 3px 0 rgb(15 23 42 / 0.04), inset 0 0 0 1px rgb(37 99 235 / 0.25); }
#flow-output-card.is-numeric #flow-output-value { color: var(--rf-accent); }

/* ----------------------------------------------------------------------------
   Stage tabs (segmented control)
   ---------------------------------------------------------------------------- */
.flow-stage-tab.active {
    color: var(--rf-ink);
    background: #ffffff;
    box-shadow: 0 0 0 1px var(--rf-border), 0 1px 2px rgb(15 23 42 / 0.04);
}

/* ----------------------------------------------------------------------------
   Drop indication on the canvas while dragging a palette block
   ---------------------------------------------------------------------------- */
#canvas-wrap.drop-active::after {
    content: '';
    position: absolute;
    inset: 8px;
    border-radius: 12px;
    box-shadow: inset 0 0 0 2px rgb(37 99 235 / 0.4);
    pointer-events: none;
}

/* ----------------------------------------------------------------------------
   Scrollbars
   ---------------------------------------------------------------------------- */
#canvas-wrap::-webkit-scrollbar,
#palette-aside::-webkit-scrollbar,
.node-editor-body::-webkit-scrollbar { width: 10px; height: 10px; }
#canvas-wrap::-webkit-scrollbar-thumb,
#palette-aside::-webkit-scrollbar-thumb,
.node-editor-body::-webkit-scrollbar-thumb { background: rgb(15 23 42 / 0.12); border-radius: 999px; }
#canvas-wrap::-webkit-scrollbar-thumb:hover,
#palette-aside::-webkit-scrollbar-thumb:hover,
.node-editor-body::-webkit-scrollbar-thumb:hover { background: rgb(15 23 42 / 0.22); }

/* ----------------------------------------------------------------------------
   Example flows modal
   ---------------------------------------------------------------------------- */
.rf-modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    animation: rfModalFade .18s var(--rf-ease) both;
}
.rf-modal.hidden { display: none; }
.rf-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgb(15 23 42 / 0.42);
    backdrop-filter: blur(4px);
}
.rf-modal-card {
    position: relative;
    width: min(880px, 100%);
    max-height: 84vh;
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 30px 60px -16px rgb(15 23 42 / 0.35), 0 0 0 1px var(--rf-border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: rfModalPop .22s var(--rf-ease) both;
}
@keyframes rfModalFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes rfModalPop  { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: translateY(0) scale(1); } }

.rf-modal-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 18px 22px 14px;
    box-shadow: var(--rf-shadow-b);
    background: linear-gradient(180deg, #f8fafc, #ffffff);
}
.rf-modal-eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--rf-ink-2);
    font-weight: 700;
}
.rf-modal-title { font-size: 18px; font-weight: 600; color: var(--rf-ink); margin-top: 4px; letter-spacing: -0.01em; }
.rf-modal-sub   { font-size: 12px; color: var(--rf-ink-2); margin-top: 4px; max-width: 540px; }
.rf-modal-body  { padding: 18px 22px 22px; overflow-y: auto; }

.rf-examples-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 12px;
}

.rf-example-card {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 14px;
    background: #ffffff;
    border-radius: 12px;
    box-shadow: var(--rf-shadow-card);
    text-align: left;
    cursor: pointer;
    transition: transform .15s var(--rf-ease), box-shadow .2s var(--rf-ease);
}
.rf-example-card:hover  { transform: translateY(-1px); box-shadow: 0 8px 22px -10px rgb(15 23 42 / 0.18), inset 0 0 0 1px var(--rf-border-strong); }
.rf-example-card:active { transform: translateY(0); }

.rf-example-head { display: flex; align-items: center; gap: 10px; }
.rf-example-icon {
    width: 32px; height: 32px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--rf-surface-2);
    color: var(--rf-ink-2);
    font-size: 13px;
    flex-shrink: 0;
}
.rf-example-icon.tone-blue    { background: #eff6ff; color: var(--rf-accent); }
.rf-example-icon.tone-emerald { background: #ecfdf5; color: #047857; }
.rf-example-icon.tone-sky     { background: #ecfeff; color: #0369a1; }
.rf-example-icon.tone-rose    { background: #fef2f2; color: #be123c; }
.rf-example-icon.tone-cyan    { background: #ecfeff; color: #0e7490; }
.rf-example-icon.tone-amber   { background: #fffbeb; color: #b45309; }

.rf-example-title { font-size: 13px; font-weight: 600; color: var(--rf-ink); line-height: 1.3; }
.rf-example-tag {
    display: inline-flex;
    align-items: center;
    padding: 1px 6px;
    border-radius: 999px;
    font-size: 9.5px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    background: var(--rf-surface-2);
    color: var(--rf-ink-2);
}
.rf-example-card[data-tone="blue"]    .rf-example-tag { background: #eff6ff; color: var(--rf-accent); }
.rf-example-card[data-tone="emerald"] .rf-example-tag { background: #ecfdf5; color: #047857; }
.rf-example-card[data-tone="sky"]     .rf-example-tag { background: #ecfeff; color: #0369a1; }
.rf-example-card[data-tone="rose"]    .rf-example-tag { background: #fef2f2; color: #be123c; }
.rf-example-card[data-tone="cyan"]    .rf-example-tag { background: #ecfeff; color: #0e7490; }

.rf-example-desc {
    font-size: 11.5px;
    color: var(--rf-ink-2);
    line-height: 1.45;
}
.rf-example-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 4px;
    font-size: 10.5px;
    color: var(--rf-ink-3);
    font-family: 'JetBrains Mono', Consolas, monospace;
}
.rf-example-meta .dot { width: 3px; height: 3px; border-radius: 999px; background: var(--rf-ink-3); }
.rf-example-load {
    margin-top: 6px;
    align-self: flex-start;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    height: 26px;
    padding: 0 10px;
    border-radius: 6px;
    background: var(--rf-ink);
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    transition: background-color .15s var(--rf-ease);
    pointer-events: none; /* card click handles it */
}
.rf-example-card:hover .rf-example-load { background: #1e293b; }

/* ----------------------------------------------------------------------------
   Toasts
   ---------------------------------------------------------------------------- */
.toast {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 10px;
    background: #fff;
    box-shadow: 0 16px 36px -10px rgb(15 23 42 / 0.18), 0 0 0 1px var(--rf-border);
    color: var(--rf-ink);
    font-size: 12px;
    font-weight: 500;
    opacity: 0;
    transform: translateY(8px) scale(.98);
    transition: opacity .22s var(--rf-ease), transform .22s var(--rf-ease);
}
.toast.show { opacity: 1; transform: translateY(0) scale(1); }
.toast .ico {
    width: 20px;
    height: 20px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
}
.toast.toast-success .ico { background: #d1fae5; color: #059669; }
.toast.toast-error   .ico { background: #fee2e2; color: #dc2626; }
.toast.toast-info    .ico { background: #dbeafe; color: var(--rf-accent); }
