.editor {
  display: grid;
  grid-template-columns: 240px 1fr 320px;
  height: 100%;
  background: var(--bg);
}

.editor-sidebar {
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 16px;
}
.editor-section { margin-bottom: 22px; }
.editor-section h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  padding: 9px 0;
  margin: 0 0 6px;
  border-bottom: 1px solid var(--border);
}

.node-palette { list-style: none; padding: 0; margin: 0; }
.node-palette li {
  padding: 9px 10px;
  margin: 4px 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: grab;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--text);
  user-select: none;
}
.node-palette li:hover { border-color: var(--accent-border); color: var(--accent); }
.node-palette li i { width: 16px; text-align: center; color: var(--accent); }

.editor-canvas-wrap {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: rgba(0,0,0,0.25);
  border-bottom: 1px solid var(--border);
}
.editor-toolbar strong { font-weight: 600; }
.editor-toolbar .save-status {
  font-size: 12px;
  color: var(--muted);
  padding: 0 4px;
  transition: color 200ms ease;
}
.editor-toolbar .save-status.dirty { color: var(--warn); font-weight: 600; }
.btn.btn-icon-only {
  width: 32px;
  padding: 6px 0;
  justify-content: center;
}
.btn.btn-icon-only:disabled,
.btn.btn-icon-only[disabled] {
  opacity: 0.35;
  cursor: not-allowed;
  filter: none;
}

/* ─── Per-flow settings popover (gear button in toolbar) ─────────────── */
.flow-settings-pop {
  position: absolute;
  top: 48px;
  /* Anchor under the gear icon — toolbar has position: relative so this works. */
  right: 220px;
  width: 380px;
  max-width: calc(100vw - 32px);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  z-index: 110;
  box-shadow: 0 18px 40px rgba(0,0,0,0.5);
}
.flow-settings-pop[hidden] { display: none; }
.flow-settings-pop__title { margin: 0 0 6px; font-size: 13px; }
.flow-settings-pop__hint {
  font-size: 12px;
  color: var(--muted);
  margin: 0 0 12px;
  line-height: 1.4;
}
.flow-settings-pop__switch {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
  font-size: 13px;
  padding: 4px 0 12px;
}
.flow-settings-pop__switch input { position: absolute; opacity: 0; pointer-events: none; }
.flow-settings-pop__switch-thumb {
  width: 36px;
  height: 20px;
  background: rgba(255,255,255,0.12);
  border-radius: 999px;
  position: relative;
  transition: background 160ms ease;
  flex-shrink: 0;
}
.flow-settings-pop__switch-thumb::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: #fff;
  border-radius: 50%;
  transition: transform 160ms ease;
}
.flow-settings-pop__switch input:checked + .flow-settings-pop__switch-thumb {
  background: var(--accent);
}
.flow-settings-pop__switch input:checked + .flow-settings-pop__switch-thumb::after {
  transform: translateX(16px);
  background: #00170f;
}
.flow-settings-pop__url-row {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-bottom: 8px;
}
.flow-settings-pop__url {
  flex: 1;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  padding: 8px 10px;
}
.flow-settings-pop__actions {
  display: flex;
  justify-content: flex-end;
  padding-top: 4px;
  border-top: 1px solid var(--border);
  margin-top: 8px;
}
.flow-settings-pop__field {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.flow-settings-pop__label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0;
  margin-bottom: 4px;
}
.flow-settings-pop__hint--small { font-size: 11px; margin-bottom: 8px; }

/* Branding asset (bg / logo) widget */
.flow-settings-pop__asset-row {
  display: flex;
  gap: 12px;
  align-items: center;
}
.flow-settings-pop__asset-preview {
  width: 84px;
  height: 56px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel-2);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.flow-settings-pop__asset-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
}
.flow-settings-pop__asset-empty { color: var(--muted); font-size: 18px; opacity: 0.5; }
.flow-settings-pop__asset-actions { display: flex; gap: 6px; align-items: center; }

/* Accent color picker row */
.flow-settings-pop__color-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.flow-settings-pop__color {
  appearance: none;
  -webkit-appearance: none;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0;
  background: var(--panel-2);
  cursor: pointer;
}
.flow-settings-pop__color::-webkit-color-swatch-wrapper { padding: 3px; }
.flow-settings-pop__color::-webkit-color-swatch { border: none; border-radius: 5px; }
.flow-settings-pop__color-hex {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  color: var(--muted);
}

.drawflow-host {
  flex: 1;
  background:
    linear-gradient(rgba(255,255,255,0.02) 1px, transparent 1px) 0 0 / 24px 24px,
    linear-gradient(90deg, rgba(255,255,255,0.02) 1px, transparent 1px) 0 0 / 24px 24px,
    var(--bg);
  position: relative;
  overflow: hidden;
}

.editor-properties {
  border-left: 1px solid var(--border);
  padding: 16px;
  overflow-y: auto;
}
.editor-properties .muted { padding: 20px 0; text-align: center; }
.prop-field { margin-bottom: 12px; }
.prop-field label { display:block; padding: 9px 0 4px; }
.prop-audio { display:flex; gap:6px; align-items:center; }
.prop-audio .name { flex:1; padding: 6px 10px; background: var(--panel); border:1px solid var(--border); border-radius: 8px; font-size: 13px; min-height: 20px; }
.prop-branches { border:1px solid var(--border); border-radius: 8px; padding: 10px; }
.prop-branch { display:flex; gap:6px; margin-bottom:6px; align-items:center; }
.prop-branch select { flex: 1; }
.prop-branch .match { width: 90px; }

/* ─── Drawflow node styling ──────────────────────────────────────────
   Drawflow's default stylesheet ships aggressive rules (#0ff bg, red selected,
   #4682b4 5px wires, #ff0 input dots). We win by:
   1. Loading drawflow.min.css BEFORE this file (see index.php)
   2. Matching or exceeding its specificity on every rule
   3. Using !important on the few properties where Drawflow's defaults are
      load-bearing visual mistakes for us (background colors, stroke). */
.drawflow .drawflow-node {
  background: linear-gradient(180deg, var(--panel) 0%, var(--panel-2) 100%) !important;
  border: 1px solid var(--border) !important;
  border-radius: 20px !important;
  color: var(--text) !important;
  padding: 12px 18px;
  min-width: 200px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  transition: box-shadow 160ms ease, border-color 160ms ease;
  /* Drawflow's stock CSS sets `position: absolute` on this element so it can
     place nodes by setting style.top/left. We intentionally DON'T override
     that — `position: absolute` is also the positioning anchor for the
     absolutely-positioned `.outputs` container below. Setting `position:
     relative` here (an earlier attempt) put the nodes in normal document
     flow and made getBoundingClientRect() return positions that drifted
     from each node's stated pos_x/pos_y, which silently broke the connection
     SVG path math (paths drew as tiny stubs near a node-stacking point). */
}
.drawflow .drawflow-node:hover { border-color: rgba(255,255,255,0.18) !important; }
.drawflow .drawflow-node.selected {
  background: linear-gradient(180deg, var(--panel) 0%, var(--panel-2) 100%) !important;
  border-color: var(--accent-border) !important;
  box-shadow:
    0 0 0 1px rgba(24,255,184,0.4),
    0 0 22px 2px rgba(24,255,184,0.32),
    0 4px 16px rgba(0,0,0,0.4);
}
.drawflow .drawflow-node .title {
  font-weight: 600;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
  letter-spacing: 0.01em;
  color: var(--text);
  min-width: 0; /* let the inner label ellipsis */
}
.drawflow .drawflow-node .title i { color: var(--accent); width: 14px; text-align: center; flex: 0 0 auto; }
.drawflow .drawflow-node .title .placeholder-chip {
  margin-left: auto;
  padding-left: 8px;
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  cursor: help;
}
.drawflow .drawflow-node .title .placeholder-chip i {
  color: var(--warn);
  width: auto;
  font-size: 12px;
}
.drawflow .drawflow-node .subtitle { font-size: 11px; color: var(--muted); margin-top: 4px; }
.drawflow .drawflow-node .node-label {
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

/* Connection ports (input / output dots) */
.drawflow .drawflow-node .input,
.drawflow .drawflow-node .output {
  background: var(--panel-2) !important;
  border: 2px solid var(--accent-border) !important;
  width: 14px !important;
  height: 14px !important;
  transition: background 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
}
.drawflow .drawflow-node .input:hover,
.drawflow .drawflow-node .output:hover {
  background: var(--accent) !important;
  border-color: var(--accent) !important;
  box-shadow: 0 0 0 4px rgba(24,255,184,0.18);
}

/* Anchor the outputs container to the right edge of the node, full height,
   evenly distributing dots vertically. The dot's center sits ON the node's
   right border — half inside, half outside. Inputs are left to Drawflow's
   default positioning (which the user confirmed looks correct). */
.drawflow .drawflow-node .outputs {
  position: absolute !important;
  right: -7px;
  top: 0;
  bottom: 0;
  width: 14px;
  display: flex !important;
  flex-direction: column;
  justify-content: space-around;
  align-items: center;
  pointer-events: none;
}
.drawflow .drawflow-node .outputs .output {
  position: relative !important;
  right: 0 !important;
  top: 0 !important;
  margin: 0 !important;
  pointer-events: auto;
}

/* Connection wires — deep indigo with a slow-pulsing cyan glow.
   Override Drawflow's 5px steel-blue default with !important. */
.drawflow .connection .main-path {
  stroke: #0C00FF !important;
  stroke-width: 2.5px !important;
  fill: none !important;
  filter: drop-shadow(0 0 3px rgba(55,225,255,0.3));
  animation: wire-pulse 3.2s ease-in-out infinite;
}
.drawflow .connection .main-path:hover { stroke: #37E1FF !important; }
@keyframes wire-pulse {
  0%, 100% { filter: drop-shadow(0 0 2px rgba(55,225,255,0.2)); }
  50%      { filter: drop-shadow(0 0 6px rgba(55,225,255,0.4)); }
}
.drawflow .connection .main-path.selected {
  stroke: #37E1FF !important;
  filter: drop-shadow(0 0 5px rgba(55,225,255,0.6));
  animation: none;
}
.drawflow .connection .point { fill: var(--panel-2) !important; stroke: var(--accent) !important; }

/* Right-click delete chip — replace Drawflow's text "x" with a Font Awesome xmark
   so it's always perfectly centered. Hide the original text via font-size: 0. */
.drawflow-delete {
  width: 22px !important;
  height: 22px !important;
  background: var(--danger) !important;
  border: 1px solid rgba(0,0,0,0.4) !important;
  color: transparent !important;
  font-size: 0 !important;
  line-height: 0 !important;
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
  display: flex !important;
  align-items: center;
  justify-content: center;
}
.drawflow-delete::before {
  content: "\f00d"; /* fa-xmark */
  font-family: "Font Awesome 6 Free";
  font-weight: 900;
  font-size: 11px;
  color: #fff;
  line-height: 1;
}

/* ─── Per-type accents ──────────────────────────────────────────────── */
.drawflow .drawflow-node.node-start .title i { color: var(--accent); }
.drawflow .drawflow-node.node-hangup .title i { color: var(--danger); }

/* Sticky-note comment */
.drawflow .drawflow-node.node-comment {
  background: linear-gradient(180deg, rgba(255,200,87,0.16), rgba(255,200,87,0.10));
  border-color: rgba(255,200,87,0.45);
  color: #f5e3b3;
  min-width: 180px;
  max-width: 280px;
  box-shadow: 0 6px 14px rgba(0,0,0,0.35), inset 0 0 0 1px rgba(255,200,87,0.05);
  transform: rotate(-0.6deg);
}
.drawflow .drawflow-node.node-comment .title {
  font-size: 11px;
  color: rgba(255,200,87,0.85);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px dashed rgba(255,200,87,0.25);
  padding-bottom: 6px;
  margin-bottom: 6px;
}
.drawflow .drawflow-node.node-comment .title i { color: rgba(255,200,87,0.9); }
.drawflow .drawflow-node.node-comment .comment-body {
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  color: #f5e3b3;
  min-height: 24px;
}

/* ─── Port labels for nodes with multiple outputs ────────────────────── */
/* Labels sit INSIDE the node, just to the LEFT of the output dot.
   The dot itself stays at the node's right edge (Drawflow's responsibility).
   `right: 22px` projects the label's right edge leftward from the dot — the
   exact value places the label inside the node's right padding. */
.drawflow .drawflow-node .output {
  position: relative !important;
}
.drawflow .drawflow-node .output::after {
  position: absolute;
  right: 22px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 9px;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  pointer-events: none;
  opacity: 0.9;
}
.drawflow .drawflow-node .output:hover::after { color: var(--accent); opacity: 1; }

/* gather_digits: 1=got digits, 2=invalid, 3=timeout */
.drawflow .drawflow-node.node-gather_digits .output_1::after { content: "Got digits"; }
.drawflow .drawflow-node.node-gather_digits .output_2::after { content: "Invalid"; color: var(--warn); }
.drawflow .drawflow-node.node-gather_digits .output_3::after { content: "Timeout"; color: var(--warn); }

/* audio_quiz: 1=pass, 2=wrong, 3=timeout. The Wrong port is hidden when the
   node is in "Reset on wrong" mode (handled in JS via the .reset-mode class). */
.drawflow .drawflow-node.node-audio_quiz .output_1::after { content: "Pass"; }
.drawflow .drawflow-node.node-audio_quiz .output_2::after { content: "Wrong"; color: var(--danger); }
.drawflow .drawflow-node.node-audio_quiz .output_3::after { content: "Timeout"; color: var(--warn); }
.drawflow .drawflow-node.node-audio_quiz.reset-mode .output.output_2 { display: none !important; }

/* voice_password: 1=match, 2=no match, 3=timeout */
.drawflow .drawflow-node.node-voice_password .output_1::after { content: "Match"; }
.drawflow .drawflow-node.node-voice_password .output_2::after { content: "No match"; color: var(--danger); }
.drawflow .drawflow-node.node-voice_password .output_3::after { content: "Timeout"; color: var(--warn); }

/* hold_music: 1=complete, 2=keypad interrupt */
.drawflow .drawflow-node.node-hold_music .output_1::after { content: "Complete"; }
.drawflow .drawflow-node.node-hold_music .output_2::after { content: "Interrupt"; }

/* conditional_branch: labels are dynamic per-port via data-label attribute.
   output_1 is always FALSE (the no-match catch-all); output_2.. are the
   user-defined match values. */
.drawflow .drawflow-node.node-conditional_branch .output::after { content: attr(data-label); }
.drawflow .drawflow-node.node-conditional_branch .output.output_1::after {
  color: var(--muted);
  font-style: italic;
}

/* Multi-output nodes need extra width so the title and the port labels never
   share horizontal space. The title clips to `calc(100% - 100px)` so even
   long titles like "Voice password" stay on a single line and labels (right
   side) get a guaranteed 100px column. */
.drawflow .drawflow-node.node-gather_digits,
.drawflow .drawflow-node.node-audio_quiz,
.drawflow .drawflow-node.node-voice_password,
.drawflow .drawflow-node.node-hold_music,
.drawflow .drawflow-node.node-conditional_branch { min-width: 260px; }
.drawflow .drawflow-node.node-gather_digits .title,
.drawflow .drawflow-node.node-audio_quiz .title,
.drawflow .drawflow-node.node-voice_password .title,
.drawflow .drawflow-node.node-hold_music .title,
.drawflow .drawflow-node.node-conditional_branch .title { max-width: calc(100% - 100px); }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: grid;
  place-items: center;
  z-index: 200;
  padding: 24px;
}
.modal[hidden] { display: none; }
.modal-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: min(720px, 100%);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}
.modal-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-head h2 { margin: 0; font-size: 16px; }
.modal-body { padding: 16px 18px; overflow-y: auto; }

.file-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 12px;
}
.file-row {
  display: grid;
  grid-template-columns: 20px 24px 1fr auto auto;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-2);
  font-size: 13px;
}
.file-row .file-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-row .actions { display: flex; gap: 4px; }
.play-toggle { color: var(--accent); }

.bulk-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  margin-top: 10px;
  background: var(--panel-2);
  border: 1px solid var(--accent-border);
  border-radius: 10px;
}

.check-inline { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; padding: 9px 0; }

/* Highlight applied to the canvas node currently "playing" in the simulator.
   (The old sim-panel/keypad/etc. CSS got replaced by sim-phone.css — the new
   simulator is a phone-style widget mounted in .sim-phone-wrap.) */
.drawflow .drawflow-node.sim-active {
  border-color: var(--accent) !important;
  box-shadow: 0 0 0 3px rgba(24,255,184,0.35) !important;
}
