/* ----------------------------------------------------------------------- */
/* Form / workflow editor (form_versions/edit)                              */
/* ----------------------------------------------------------------------- */

.editor-card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  margin-bottom: var(--gap-3);
}
.editor-card__header {
  display: flex;
  align-items: center;
  gap: var(--gap-3);
  padding: 0.55rem 0.95rem;
  background: var(--bg);
  border-bottom: 1px solid var(--rule);
  border-radius: var(--radius) var(--radius) 0 0;
  cursor: grab;
}
.editor-card__header:active { cursor: grabbing; }
/* Address cards aren't reorderable — drop the grab/grabbing cursor
   inherited from the shared .editor-card__header rule. The class is
   shared with form_versions' workflow stage editor, which IS
   draggable; the [data-address-card] scoping keeps that behavior
   intact while neutralizing it here. */
[data-address-card] .editor-card__header,
[data-address-card] .editor-card__header:active { cursor: default; }
.editor-card__drag {
  color: var(--ink-muted);
  font-size: 1.1rem;
  user-select: none;
}
.editor-card__title {
  flex: 1 1 auto;
  font-family: var(--sans);
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.editor-card__actions { display: inline-flex; gap: 0.4rem; }
.editor-card__actions button {
  padding: 0.15rem 0.35rem;
  font-size: 0.78rem;
  background: transparent;
  border: 0;
  color: var(--ink-muted);
}
.editor-card__actions button:hover {
  background: transparent;
  color: var(--accent);
  border: 0;
}
.editor-card__body { padding: var(--gap-4); }

.editor-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--gap-3);
}
.editor-row > .field { flex: 1 1 12rem; margin-bottom: 0; }

.editor-card.is-dragging { opacity: 0.4; }
.editor-card.drop-before { border-top: 2px solid var(--accent); }
.editor-card.drop-after  { border-bottom: 2px solid var(--accent); }

/* Form-editor locked state — set when another admin holds the edit
   lock. Read-only visual + pointer-events disabled. */
.editor-form--locked { opacity: 0.6; pointer-events: none; }

/* Sticky save bar */
body:has(.save-bar) { padding-bottom: 5rem; }
.save-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-top: 1px solid var(--rule-strong);
  padding: 0.7rem 0;
  z-index: 10;
  box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.05);
}
.save-bar__inner {
  max-width: var(--col-wide);
  margin: 0 auto;
  padding: 0 var(--gap-5);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap-3);
  flex-wrap: wrap;
}

/* Field summary list */
.field-summary {
  list-style: none;
  padding: 0;
  margin: 0;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--surface);
}
.field-summary li {
  display: flex;
  align-items: center;
  gap: var(--gap-3);
  padding: 0.55rem 0.95rem;
  border-bottom: 1px solid var(--rule-soft);
  margin: 0;
  font-family: var(--sans);
  font-size: 0.92rem;
}
.field-summary li:last-child { border-bottom: 0; }
.field-summary__key {
  width: 8rem;
  flex-shrink: 0;
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--ink-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.field-summary__label {
  flex: 1 1 auto;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ----------------------------------------------------------------------- */
/* Workflow builder — Kissflow-style canvas (workflows/_form)               */
/* ----------------------------------------------------------------------- */

/* Two-column layout: palette on the left, canvas on the right. The
   palette stays a fixed width; the canvas takes the remainder and
   scrolls internally so a tall flow doesn't blow out the page. */
.wf-builder {
  display: grid;
  grid-template-columns: 14rem 1fr;
  gap: var(--gap-4);
  align-items: stretch;
}

/* Palette — column of draggable building blocks. Each item carries
   the kind's accent dot so the canvas connectors / borders read as
   the same color story. */
.wf-palette {
  display: flex;
  flex-direction: column;
  gap: var(--gap-2);
  padding: var(--gap-3);
  background: var(--surface-2);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
}
.wf-palette__title {
  margin: 0 0 var(--gap-1) 0;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-muted);
}
.wf-palette__item {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  column-gap: var(--gap-2);
  padding: 0.5rem 0.65rem;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  cursor: grab;
  user-select: none;
  transition: border-color 100ms, transform 80ms;
}
.wf-palette__item:hover {
  border-color: var(--accent);
}
.wf-palette__item:active { cursor: grabbing; transform: translateY(1px); }
.wf-palette__dot {
  grid-row: 1 / span 2;
  width: 0.65rem;
  height: 0.65rem;
  align-self: center;
  border-radius: var(--radius-pill);
}
.wf-palette__dot--approval     { background: var(--accent); }
.wf-palette__dot--notification { background: var(--ink-faint); }
.wf-palette__dot--wait         { background: var(--warn); }
.wf-palette__dot--end          { background: var(--ink); }
.wf-palette__dot--start        { background: var(--ok); }
.wf-palette__dot--fork         { background: #7c4dff; } /* purple — parallel */
.wf-palette__dot--join         { background: #0288d1; } /* cyan — convergence */
.wf-palette__title-line {
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--ink);
}
.wf-palette__blurb {
  font-size: 0.78rem;
  color: var(--ink-muted);
  line-height: 1.3;
}

/* Tiny dots in the legend at the top of the panel. */
.wf-legend {
  display: inline-block;
  width: 0.55rem;
  height: 0.55rem;
  border-radius: var(--radius-pill);
  vertical-align: 0;
  margin: 0 0.15rem 0 0.5rem;
}
.wf-legend--approve { background: #2e7d3a; }
.wf-legend--reject  { background: #c1272d; }

/* Canvas wrapper — gives the canvas a fixed-height scroll area so
   nodes can sprawl horizontally / vertically without blowing the
   page layout. */
.wf-canvas-wrap {
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}
.wf-canvas {
  position: relative;
  min-height: 30rem;
  max-height: 70vh;
  overflow: auto;
  background:
    radial-gradient(var(--rule-soft) 1px, transparent 1px) 0 0 / 16px 16px;
}
.wf-canvas:focus { outline: 2px solid var(--accent); outline-offset: -2px; }

/* SVG sits behind the nodes so node interactions take priority. */
.wf-svg {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
}
.wf-svg path[data-wire] { transition: stroke-width 80ms; }

.wf-nodes { position: relative; z-index: 2; }

/* Empty drop zone shown when the canvas has no nodes. Centered hint
   text; doesn't intercept the drop event (pointer-events: none lets
   the surrounding canvas handle it). */
.wf-canvas__empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-muted);
  font-size: 0.9rem;
  pointer-events: none;
  z-index: 1;
}

/* --- Node card --- */
.wf-node {
  position: absolute;
  width: 16.25rem; /* 260px — must match NODE_WIDTH in the JS controller */
  left: var(--node-x, 0);
  top:  var(--node-y, 0);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(0,0,0,0.04), 0 4px 12px rgba(0,0,0,0.04);
  z-index: 3;
}
.wf-node.is-moving {
  z-index: 10;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  cursor: grabbing;
}
.wf-node[data-step-kind="approval"]     { border-left: 4px solid var(--accent); }
.wf-node[data-step-kind="notification"] { border-left: 4px solid var(--ink-faint); }
.wf-node[data-step-kind="wait"]         { border-left: 4px solid var(--warn); }
.wf-node[data-step-kind="end"]          { border-left: 4px solid var(--ink); background: var(--surface-2); }
.wf-node[data-step-kind="start"]        { border-left: 4px solid var(--ok); background: var(--surface-2); }
.wf-node[data-step-kind="fork"]         { border-left: 4px solid #7c4dff; }
.wf-node[data-step-kind="join"]         { border-left: 4px solid #0288d1; }
.wf-node.is-destroyed { display: none; }

.wf-node__header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.55rem;
  background: var(--bg);
  border-bottom: 1px solid var(--rule);
  border-radius: var(--radius) var(--radius) 0 0;
  cursor: grab;
}
.wf-node__header:active { cursor: grabbing; }
.wf-node__pos {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.4rem;
  height: 1.4rem;
  padding: 0 0.35rem;
  background: var(--surface-2);
  border: 1px solid var(--rule);
  border-radius: var(--radius-pill);
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--ink-soft);
}
.wf-node__title {
  flex: 1 1 auto;
  font-size: 0.88rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.wf-node__actions { display: inline-flex; gap: 0.1rem; }
.wf-node__btn {
  padding: 0.1rem 0.35rem;
  font-size: 0.85rem;
  background: transparent;
  border: 0;
  color: var(--ink-muted);
  cursor: pointer;
  line-height: 1;
}
.wf-node__btn:hover { color: var(--accent); background: transparent; border: 0; }

.wf-node__body {
  padding: 0.6rem 0.7rem 0.7rem 0.7rem;
  font-size: 0.85rem;
}
.wf-node__body .field { margin-bottom: 0.4rem; }
.wf-node__body label  { font-size: 0.78rem; }

.wf-node__advanced {
  border-top: 1px dashed var(--rule);
  padding-top: 0.5rem;
  margin-top: 0.5rem;
}
.wf-node__advanced > summary {
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--ink-muted);
  user-select: none;
}
.wf-node__advanced[open] > summary { color: var(--ink); }

/* Notifications never branch on reject — hide the section in the
   node body to avoid implying it does anything. */
.wf-node[data-step-kind="notification"] [data-step-reject-line] {
  display: none;
}

.wf-node__wires {
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px dashed var(--rule);
}
.wf-node__wires .hint { margin: 0; font-size: 0.78rem; }
.button-link--mini {
  font-size: 0.72rem;
  padding: 0;
}

/* Output ports — circular dots on the right edge. Drag from these
   to wire to another node. Pointer-events: auto overrides the
   parent's none-during-drag suppression. */
.wf-node__port {
  position: absolute;
  right: -7px;
  width: 14px;
  height: 14px;
  border-radius: var(--radius-pill);
  border: 2px solid var(--surface);
  cursor: crosshair;
  z-index: 4;
}
.wf-node__port--approve { top: 19px; background: #2e7d3a; }
.wf-node__port--reject  { top: 43px; background: #c1272d; }
.wf-node__port:hover    { transform: scale(1.15); }
/* Hide reject port on kinds that can't fail-route. */
.wf-node[data-step-kind="notification"] .wf-node__port--reject,
.wf-node[data-step-kind="wait"]         .wf-node__port--reject,
.wf-node[data-step-kind="end"]          .wf-node__port--reject,
.wf-node[data-step-kind="start"]        .wf-node__port--reject,
.wf-node[data-step-kind="fork"]         .wf-node__port--reject,
.wf-node[data-step-kind="join"]         .wf-node__port--reject { display: none; }
/* End is terminal — no outgoing ports at all. */
.wf-node[data-step-kind="end"] .wf-node__port--approve { display: none; }
/* Recolor the "Next →" port per kind so the wire endpoint reads
   as the same palette accent. Fork's approve port becomes the
   fan-out port (purple); a single drag is one parallel arm. */
.wf-node[data-step-kind="wait"]  .wf-node__port--approve { background: var(--warn); }
.wf-node[data-step-kind="start"] .wf-node__port--approve { background: var(--ok); }
.wf-node[data-step-kind="fork"]  .wf-node__port--approve { background: #7c4dff; }
.wf-node[data-step-kind="join"]  .wf-node__port--approve { background: #0288d1; }

/* Wire-mode temporary line (drawn during drag). */
.wf-svg .wf-wire--temp { opacity: 0.85; }

/* Inline hint that turns warn-orange when validation will trip
   server-side (e.g. approval step with no assignee_role). */
.hint--warn { color: var(--warn); }

/* Fullscreen builder mode. The whole `Flow` panel jumps to a
   fixed-position viewport overlay so the user gets every pixel for
   the canvas; the canvas itself drops its max-height cap so wires
   can sprawl without scrolling within a small box. Triggered by
   the controller's toggleFullscreen action; ESC also exits. */
.wf-builder.is-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 999;
  background: var(--bg);
  padding: var(--gap-4);
  display: grid;
  grid-template-columns: 14rem 1fr;
  grid-template-rows: 1fr;
  gap: var(--gap-4);
  overflow: hidden;
}
.wf-builder.is-fullscreen .wf-canvas-wrap { height: 100%; }
.wf-builder.is-fullscreen .wf-canvas {
  max-height: none;
  height: 100%;
}
/* Hide page scroll while the builder owns the viewport. */
body.wf-fullscreen-active { overflow: hidden; }

/* Floating exit button — only visible when the builder is in
   fullscreen mode. Top-right corner of the overlay; high z so it
   sits above the canvas + palette. */
.wf-fullscreen-exit {
  display: none;
  position: absolute;
  top: 0.65rem;
  right: 0.65rem;
  z-index: 11;
  padding: 0.35rem 0.7rem;
  font-size: 0.85rem;
}
.wf-builder.is-fullscreen .wf-fullscreen-exit { display: inline-flex; }

