/* ============================================================
   Routing flow canvas — ported from the revreply-mock (Next + Tailwind + shadcn)
   into the Orchestrator plain-CSS style.
   §4 compliance: green carries NO meaning (the original used green for
   "matched"/dedupe — re-mapped); red is reserved for overdue/at-risk only;
   amber is reserved for temperature. Node accents therefore use a COOL
   categorical set, and the MATCHED branch uses the BRAND accent (not green).
   Tokens used (already defined in the project): --surface --border --fg
   --fg-strong --muted --dim --brand --sunken --r-sm --r-md --r-lg --font-mono.
   ============================================================ */

.rf-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--r-lg, 12px);
  background: var(--surface);
}

.rf-canvas {
  position: relative;
  background-image: radial-gradient(circle, color-mix(in srgb, var(--border) 70%, transparent) 1px, transparent 1px);
  background-size: 20px 20px;
  /* cool, §4-safe per-node-type accents (categorical decoration, not state) */
  --rf-trigger: var(--brand);
  --rf-entry:   oklch(0.55 0.045 255);
  --rf-dup:     oklch(0.60 0.085 195);
  --rf-delay:   oklch(0.58 0.11 250);
  --rf-rule:    var(--c-action, oklch(0.56 0.13 290));
  --rf-assign:  oklch(0.60 0.085 195);
  --rf-field:   oklch(0.58 0.11 250);
  --rf-camp:    oklch(0.62 0.10 215);
  --rf-task:    oklch(0.56 0.10 285);
  --rf-goal:    oklch(0.55 0.15 300);
  --rf-sched:   oklch(0.58 0.10 230);
  --rf-notify:  oklch(0.54 0.10 310);
  --rf-review:  oklch(0.66 0.13 70);
}

/* ---- integration logo chips (via tray.ai) ---- */
.rf-logo { width: 22px; height: 22px; border-radius: var(--r-sm); flex: none; display: inline-flex; align-items: center; justify-content: center; color: var(--brand-fg); font-size: 9px; font-weight: 800; letter-spacing: .01em; box-shadow: inset 0 0 0 1px rgba(255,255,255,.18); }
.rf-logo.sm { width: 17px; height: 17px; border-radius: 5px; font-size: 8px; }
.rf-logo.more { background: var(--sunken) !important; color: var(--muted); box-shadow: inset 0 0 0 1px var(--border); }
.route-logos { display: inline-flex; align-items: center; gap: 4px; }
.route-logos.big .rf-logo { width: 24px; height: 24px; font-size: 9.5px; }

/* ---- node corner logo + add-node ---- */
.rf-node-logo { margin-left: auto; display: inline-flex; }
.rf-node-logos { margin-left: auto; display: inline-flex; gap: 3px; }
.rf-node-anysrc { margin-left: auto; font-size: 8.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); background: var(--sunken); padding: 1px 6px; border-radius: 999px; }
.rf-node-top .rf-node-badge { margin-left: 6px; }
.rf-node-add { border-style: dashed !important; opacity: .85; }
.rf-node-add .rf-node-title { color: var(--brand); font-weight: 600; }

/* ---- free-form editor: palette + canvas ---- */
.rf-editor { display: flex; gap: 12px; align-items: stretch; position: relative; }
.rf-palette { flex: none; width: 156px; display: flex; flex-direction: column; gap: 5px; padding: 10px; border: 1px solid var(--border); border-radius: var(--r-lg, 12px); background: var(--surface); align-self: flex-start; }
.rf-palette-h { font-size: 9.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 3px; }
.rf-pal-chip { display: flex; align-items: center; gap: 8px; padding: 7px 9px; border: 1px solid var(--border); border-left: 3px solid var(--rf-accent, var(--brand)); border-radius: 8px; background: var(--surface); cursor: grab; font-size: 11.5px; font-weight: 600; color: var(--fg); user-select: none; }
.rf-pal-chip:hover { background: var(--sunken); }
.rf-pal-chip:active { cursor: grabbing; }
.rf-pal-chip .rf-node-ic { width: 14px; height: 14px; color: var(--rf-accent, var(--brand)); flex: none; }
.rf-palette-tip { font-size: 10px; color: var(--dim); line-height: 1.5; margin-top: 6px; padding-top: 8px; border-top: 1px solid var(--hairline); }
.rf-editor .rf-wrap { flex: 1; min-width: 0; max-height: calc(100vh - 230px); }

/* node positioning + drag */
.rf-node { position: absolute; box-sizing: border-box; cursor: grab; user-select: none; }
.rf-node.dragging { cursor: grabbing; z-index: 20; box-shadow: 0 12px 28px rgba(20,20,50,.22); }
.rf-node.is-sel { z-index: 15; }
.rf-node-del { position: absolute; top: -9px; right: -9px; width: 20px; height: 20px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface); color: var(--alert); font-size: 13px; line-height: 1; cursor: pointer; z-index: 22; box-shadow: 0 2px 6px rgba(0,0,0,.15); }
.rf-node-del:hover { background: var(--alert); color: var(--brand-fg); }

/* connection handles */
.rf-handle { position: absolute; width: 12px; height: 12px; border-radius: 50%; background: var(--surface); border: 2px solid var(--rf-accent, var(--brand)); cursor: crosshair; opacity: 0; transition: opacity .12s, transform .12s; z-index: 18; }
.rf-node:hover .rf-handle, .rf-node.is-sel .rf-handle { opacity: 1; }
.rf-handle:hover { transform: scale(1.25); }
.rf-handle.out-matched { right: -7px; top: 50%; margin-top: -6px; border-color: var(--brand); }
.rf-handle.out-flow { bottom: -7px; left: 50%; margin-left: -6px; }

/* edges + temp edge + delete */
.rf-edges { position: absolute; inset: 0; pointer-events: none; overflow: visible; }
.rf-edge { fill: none; stroke: var(--dim); stroke-width: 1.6; }
.rf-edge.matched { stroke: var(--brand); stroke-width: 2; }
.rf-edge.temp { stroke: var(--brand); stroke-dasharray: 5 4; stroke-width: 2; }
.rf-edge-del { position: absolute; transform: translate(-50%, -50%); width: 18px; height: 18px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface); color: var(--dim); font-size: 12px; line-height: 1; cursor: pointer; z-index: 12; opacity: 0; transition: opacity .12s; }
.rf-canvas:hover .rf-edge-del { opacity: .55; }
.rf-edge-del:hover { opacity: 1; color: var(--alert); border-color: color-mix(in oklch, var(--alert) 40%, var(--border)); }

/* ---- add-action menu ---- */
.rf-actmenu { position: absolute; z-index: 30; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 10px 30px rgba(20,20,50,.16); padding: 5px; display: flex; flex-direction: column; min-width: 168px; }
.rf-actmenu button { display: flex; align-items: center; gap: 9px; text-align: left; padding: 8px 10px; border: none; background: transparent; font-family: inherit; font-size: 12.5px; color: var(--fg); cursor: pointer; border-radius: 7px; }
.rf-actmenu button:hover { background: var(--sunken); }
.rf-actmenu .rf-node-ic { width: 14px; height: 14px; color: var(--muted); }

/* ---- node card ---- */
.rf-node {
  position: absolute;
  width: 220px;
  height: 96px;
  box-sizing: border-box;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md, 10px);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  box-shadow: 0 1px 2px rgba(20,20,40,.04);
  transition: box-shadow .12s ease, border-color .12s ease;
}
.rf-node:hover { border-color: var(--rf-accent, var(--brand)); }
.rf-node.is-sel { border-color: var(--rf-accent, var(--brand)); box-shadow: 0 0 0 2px color-mix(in oklch, var(--rf-accent, var(--brand)) 45%, transparent); }

/* coloured banner */
.rf-node-top {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 10px;
  background: color-mix(in oklch, var(--rf-accent, var(--brand)) 13%, var(--surface));
  border-bottom: 1px solid color-mix(in oklch, var(--rf-accent, var(--brand)) 22%, transparent);
}
.rf-node-ic { width: 13px; height: 13px; flex: none; color: var(--rf-accent, var(--brand)); }
.rf-node-kind {
  font-size: 9px; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: var(--rf-accent, var(--brand));
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.rf-node-badge { margin-left: auto; font-size: 9px; font-weight: 600; color: color-mix(in oklch, var(--rf-accent, var(--brand)) 80%, var(--fg)); white-space: nowrap; flex: none; }

/* white body */
.rf-node-body { flex: 1; min-height: 0; padding: 8px 11px 9px; display: flex; flex-direction: column; gap: 3px; }
.rf-node-title {
  font-size: 12.5px; font-weight: 600; color: var(--fg-strong, var(--fg));
  line-height: 1.2; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden;
}
.rf-node-sub {
  font-size: 10px; color: var(--muted); line-height: 1.3;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-family: var(--mono);
}

/* ---- edges (svg layer) ---- */
.rf-edges { position: absolute; inset: 0; pointer-events: none; }
.rf-edge { fill: none; stroke: var(--dim); stroke-width: 1.5; opacity: .65; }
.rf-edge.matched { stroke: var(--brand); opacity: .9; }

/* ---- edge labels (html chips) ---- */
.rf-lab {
  position: absolute; transform: translate(-50%, -50%);
  font-size: 8.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  padding: 1px 7px; border-radius: 999px; white-space: nowrap; pointer-events: none;
}
.rf-lab.matched { color: var(--brand); background: color-mix(in oklch, var(--brand) 13%, var(--surface)); border: 1px solid color-mix(in oklch, var(--brand) 30%, transparent); }
.rf-lab.muted   { color: var(--dim);   background: var(--sunken, color-mix(in oklch, var(--muted) 45%, var(--surface))); border: 1px solid var(--border); }

/* ---- side panel — floating popover anchored beside the clicked node ---- */
.rf-panel {
  position: absolute; width: 276px; max-height: 320px;
  background: var(--surface); border: 1px solid var(--border);
  border-left: 3px solid var(--rf-accent, var(--brand));
  border-radius: var(--r-md, 10px);
  padding: 15px 17px; overflow: auto; box-sizing: border-box;
  box-shadow: 0 8px 28px rgba(20,20,50,.16), 0 2px 6px rgba(20,20,50,.08);
  z-index: 20; animation: rf-pop .12s ease;
}
@keyframes rf-pop { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.rf-panel-kind { font-size: 9.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--rf-accent, var(--brand)); }
.rf-panel-title { font-size: 15px; font-weight: 700; color: var(--fg-strong, var(--fg)); margin: 4px 0 14px; }
.rf-panel-x { position: absolute; top: 12px; right: 14px; cursor: pointer; color: var(--dim); font-size: 16px; line-height: 1; border: none; background: none; }
.rf-row { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 12px; }
.rf-row .k { color: var(--muted); }
.rf-row .v { color: var(--fg); text-align: right; font-weight: 500; }
.rf-bullets { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.rf-bullets li { font-size: 12px; color: var(--fg); padding-left: 14px; position: relative; line-height: 1.4; }
.rf-bullets li::before { content: ""; position: absolute; left: 0; top: 7px; width: 5px; height: 5px; border-radius: 50%; background: var(--rf-accent, var(--brand)); }

/* ============================================================
   Inspector / editor (right-rail form) + condition builder
   ============================================================ */
.rfi-panel {
  position: fixed; top: 96px; right: 18px; width: 348px; max-height: calc(100vh - 130px);
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: 0 16px 48px rgba(20,20,50,.18), 0 2px 8px rgba(20,20,50,.08);
  z-index: 50; display: flex; flex-direction: column; overflow: hidden; animation: rf-pop .14s ease;
}
.rfi-head { display: flex; align-items: center; padding: 14px 16px 0; }
.rfi-kind { font-size: 9.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--brand); }
.rfi-x { margin-left: auto; cursor: pointer; color: var(--dim); font-size: 18px; line-height: 1; border: none; background: none; }
.rfi-x:hover { color: var(--fg-strong); }
.rfi-title { font-size: 15px; font-weight: 700; color: var(--fg-strong); padding: 4px 16px 12px; border-bottom: 1px solid var(--hairline); }
.rfi-body { padding: 14px 16px 18px; overflow: auto; display: flex; flex-direction: column; gap: 13px; }
.rfi-field { display: flex; flex-direction: column; gap: 5px; }
.rfi-field > label { font-size: 11px; font-weight: 600; color: var(--muted); }
.rfi-hint { font-size: 10.5px; color: var(--dim); line-height: 1.4; }
.rfi-inp { width: 100%; box-sizing: border-box; border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; font-family: inherit; font-size: 12.5px; color: var(--fg); background: var(--surface); outline: none; }
.rfi-inp:focus { border-color: var(--brand); }
select.rfi-inp { cursor: pointer; }
.rfi-inp.area { min-height: 58px; resize: vertical; line-height: 1.5; }
.rfi-note { font-size: 11px; color: var(--muted); line-height: 1.5; background: var(--sunken); border: 1px solid var(--border); border-radius: 8px; padding: 9px 11px; }
.rfi-note code { font-family: var(--mono); font-size: 10.5px; background: var(--surface); padding: 1px 4px; border-radius: 4px; }
.rfi-sect { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-top: 6px; padding-top: 12px; border-top: 1px solid var(--hairline); }
.rfi-sub { font-size: 11px; font-weight: 600; color: var(--fg); display: flex; justify-content: space-between; align-items: baseline; margin-top: 4px; }
.rfi-sub span { font-size: 10px; font-weight: 500; color: var(--dim); }

/* toggle + seg */
.rfi-tog { width: 34px; height: 20px; border-radius: 999px; border: none; background: var(--border); position: relative; cursor: pointer; flex: none; transition: background .15s; align-self: flex-start; }
.rfi-tog::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--surface); transition: left .15s; box-shadow: var(--card-shadow); }
.rfi-tog.on { background: var(--brand); }
.rfi-tog.on::after { left: 16px; }
.rfi-seg { display: inline-flex; background: var(--sunken); border: 1px solid var(--border); border-radius: 8px; padding: 2px; gap: 2px; }
.rfi-seg button { font-family: inherit; font-size: 11px; font-weight: 600; color: var(--muted); background: transparent; border: none; padding: 5px 10px; border-radius: 6px; cursor: pointer; white-space: nowrap; }
.rfi-seg button.is-active { background: var(--surface); color: var(--fg-strong); box-shadow: 0 1px 2px rgba(0,0,0,.06); }

/* integration picker */
.rfi-intpick { display: flex; flex-wrap: wrap; gap: 6px; }
.rfi-srcany { border-bottom: 1px solid var(--hairline); padding-bottom: 8px; margin-bottom: 4px; }
.rfi-srclist { display: flex; flex-direction: column; gap: 2px; }
.rfi-srclist.is-disabled { opacity: 0.45; }
.rfi-srcrow { display: flex; align-items: center; gap: 9px; padding: 6px 4px; cursor: pointer; }
.rfi-srcrow input { width: 15px; height: 15px; flex-shrink: 0; accent-color: var(--brand); cursor: pointer; }
.rfi-srcmain { display: flex; flex-direction: column; gap: 1px; font-size: 12px; font-weight: 600; color: var(--fg-strong); min-width: 0; }
.rfi-srcsub { font-size: 10px; font-weight: 500; color: var(--muted); }
.rfi-intopt { display: inline-flex; align-items: center; gap: 6px; font-family: inherit; font-size: 11px; font-weight: 600; color: var(--fg); border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 3px 9px 3px 4px; cursor: pointer; }
.rfi-intopt.is-active { border-color: var(--brand); background: color-mix(in oklch, var(--brand) 9%, transparent); }

/* condition builder */
.rfi-cond { display: flex; flex-direction: column; gap: 7px; }
.rfi-cond-join { display: flex; align-items: center; gap: 9px; }
.rfi-cond-hint { font-size: 10.5px; color: var(--dim); }
.rfi-cond-empty { font-size: 11px; color: var(--dim); font-style: italic; }
.rfi-cond-row { display: grid; grid-template-columns: 1fr 0.8fr 1fr auto; gap: 5px; align-items: center; }
.rfi-cond-row .rfi-inp { padding: 6px 8px; font-size: 11.5px; }
.rfi-cond-x { width: 22px; height: 22px; border: 1px solid var(--border); background: var(--surface); border-radius: 6px; color: var(--dim); cursor: pointer; font-size: 13px; line-height: 1; flex: none; }
.rfi-cond-x:hover { color: var(--alert); border-color: color-mix(in oklch, var(--alert) 40%, var(--border)); }
.rfi-cond-nested { position: relative; padding: 9px 9px 9px 11px; border: 1px dashed var(--border); border-radius: 8px; background: var(--sunken); }
.rfi-cond-nested .rfi-cond-x { position: absolute; top: 7px; right: 7px; }
.rfi-cond-adds { display: flex; gap: 8px; }
.rfi-cond-adds button { font-family: inherit; font-size: 11px; font-weight: 600; color: var(--brand); background: transparent; border: 1px dashed color-mix(in oklch, var(--brand) 40%, var(--border)); border-radius: 7px; padding: 5px 9px; cursor: pointer; }
.rfi-cond-adds button:hover { background: color-mix(in oklch, var(--brand) 7%, transparent); }

/* action bar + reps */
.rfi-actbar { display: flex; align-items: center; gap: 7px; margin-top: 6px; padding-top: 12px; border-top: 1px solid var(--hairline); }
.rfi-actbar button { font-family: inherit; font-size: 12px; font-weight: 600; color: var(--muted); background: var(--surface); border: 1px solid var(--border); border-radius: 7px; padding: 6px 10px; cursor: pointer; }
.rfi-actbar button:disabled { opacity: .4; cursor: default; }
.rfi-actbar button.danger { color: var(--alert); margin-left: auto; border-color: color-mix(in oklch, var(--alert) 30%, var(--border)); }
.rfi-actbar button:not(:disabled):hover { color: var(--fg-strong); }
.rfi-actbar button.danger:hover { color: var(--alert); background: color-mix(in oklch, var(--alert) 7%, transparent); }
.rfi-rep { display: flex; align-items: center; gap: 6px; }
.rfi-rep .rfi-inp { flex: 1; }
.rfi-inp.wt { width: 58px; flex: none; text-align: center; }
.rfi-pct { font-size: 11px; color: var(--muted); }
.rfi-add { font-family: inherit; font-size: 11px; font-weight: 600; color: var(--brand); background: transparent; border: 1px dashed color-mix(in oklch, var(--brand) 40%, var(--border)); border-radius: 7px; padding: 6px 10px; cursor: pointer; align-self: flex-start; }
