/* ============================================================
   Manda — Constructor visual de flujos (estilo ManyChat)
   Reusa los tokens de styles.css (púrpura/lima/navy/ground).
   ============================================================ */

/* ---------- Lista de flujos ---------- */
.flow-grid { display: flex; flex-wrap: wrap; gap: 18px; padding: 4px 26px 26px; }
.flow-card {
  width: 220px; height: 210px; border-radius: 18px; background: #fff;
  border: 1px solid var(--line); box-shadow: var(--sh-sm);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; position: relative; cursor: pointer;
  /* Sólo transiciones que NO cambian el tamaño/posición: así el cursor no
     "pierde" la tarjeta y no parpadea el hover. */
  transition: box-shadow .15s ease, border-color .15s ease;
}
.flow-card:hover { box-shadow: var(--m-sh-md, var(--sh-md)); border-color: var(--purpura); }
.flow-card .fc-icon { width: 56px; height: 56px; color: var(--navy); }
.flow-card .fc-name { font-weight: 800; font-size: 16px; }
.flow-card .fc-badge {
  position: absolute; top: 14px; left: 14px; font-size: 11px; font-weight: 800;
  padding: 4px 10px; border-radius: 999px;
}
.flow-card .fc-badge.on { background: rgba(34,165,101,.14); color: var(--ok); }
.flow-card .fc-badge.off { background: rgba(226,61,109,.14); color: #E23D6D; }
.flow-card .fc-menu {
  position: absolute; top: 12px; right: 12px; width: 30px; height: 30px; border-radius: 8px;
  border: 1px solid var(--line); background: #fff; cursor: pointer; display: grid; place-items: center; color: var(--muted);
}
.flow-card .fc-menu:hover { background: var(--ground); }
.flow-card .fc-toggle { position: absolute; bottom: 14px; left: 14px; }
.flow-card.new {
  background: var(--lima); border: 0; color: var(--navy);
}
.flow-card.new .fc-plus { font-size: 40px; font-weight: 300; line-height: 1; }
.flow-card.new .fc-name { color: var(--navy); }

.fc-pop {
  position: absolute; top: 46px; right: 12px; background: #fff; border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--sh-md); padding: 6px; z-index: 10; min-width: 150px;
}
.fc-pop button { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 9px 11px; border-radius: 8px; cursor: pointer; font: inherit; font-size: 13.5px; }
.fc-pop button:hover { background: var(--ground); }
.fc-pop button.danger { color: #E23D6D; }

/* ---------- Editor ---------- */
#flowEditor { position: fixed; inset: 0; z-index: 60; background: var(--ground); display: flex; flex-direction: column; }
.fe-top {
  height: 62px; flex-shrink: 0; background: #fff; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 14px; padding: 0 18px;
}
.fe-top .fe-back { width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--line); background: #fff; cursor: pointer; display: grid; place-items: center; color: var(--ink); }
.fe-top .fe-back:hover { background: var(--ground); }
.fe-top .fe-name { font-weight: 800; font-size: 16px; border: 0; outline: none; background: transparent; min-width: 120px; }
.fe-top .fe-beta { font-size: 11px; font-weight: 800; color: #E23D6D; background: rgba(226,61,109,.1); padding: 3px 9px; border-radius: 999px; }
.fe-top .fe-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.fe-saved { font-size: 12.5px; color: var(--ok); font-weight: 700; opacity: 0; transition: opacity .2s; }
.fe-saved.show { opacity: 1; }

.fe-body { flex: 1; display: flex; min-height: 0; }

/* Paleta */
.fe-palette { width: 260px; flex-shrink: 0; background: #fff; border-right: 1px solid var(--line); overflow-y: auto; padding: 14px; }
.fe-palette h4 { margin: 6px 4px 10px; font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.fe-palette h4 .dot { width: 8px; height: 8px; border-radius: 50%; }
.pal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 18px; }
.pal-item {
  border: 1px solid var(--line); border-radius: 12px; padding: 14px 8px; text-align: center;
  cursor: grab; background: #fff; transition: border-color .15s, box-shadow .15s, transform .1s; user-select: none;
}
.pal-item:hover { border-color: #C7CBE0; box-shadow: var(--sh-sm); }
.pal-item:active { transform: scale(.97); }
.pal-item svg { width: 24px; height: 24px; margin-bottom: 7px; }
.pal-item .pal-name { font-size: 12.5px; font-weight: 700; }

/* Lienzo */
.fe-canvas { flex: 1; position: relative; overflow: hidden; background:
  radial-gradient(circle, #D5D9EC 1.2px, transparent 1.2px);
  background-size: 22px 22px; cursor: grab; }
.fe-canvas.panning { cursor: grabbing; }
#flowInner { position: absolute; top: 0; left: 0; width: 6000px; height: 4000px; transform-origin: 0 0; }

/* ---- Controles de zoom (abajo-izquierda) ---- */
.fe-zoom { position: absolute; left: 14px; bottom: 14px; z-index: 20;
  display: flex; align-items: center; gap: 2px; background: #fff;
  border: 1px solid #D5D9EC; border-radius: 12px; padding: 4px;
  box-shadow: 0 6px 18px rgba(39,51,77,.14); }
.fe-zoom button { width: 30px; height: 30px; border: none; background: transparent;
  border-radius: 8px; font-size: 18px; line-height: 1; color: #27334D; cursor: pointer;
  display: flex; align-items: center; justify-content: center; }
.fe-zoom button:hover { background: #EEF0FA; }
.fe-zoom #feZoomLbl { min-width: 46px; text-align: center; font-size: 12px;
  font-weight: 700; color: #4C4DC3; user-select: none; }

/* ---- Minimapa (abajo-derecha) ---- */
.fe-minimap { position: absolute; right: 14px; bottom: 14px; z-index: 20;
  width: 190px; height: 130px; background: rgba(255,255,255,.92);
  border: 1px solid #D5D9EC; border-radius: 12px; overflow: hidden;
  box-shadow: 0 6px 18px rgba(39,51,77,.14); cursor: pointer; }
.fe-minimap .mm-node { position: absolute; background: #B9BEE8; border-radius: 2px;
  min-width: 3px; min-height: 2px; }
.fe-minimap .mm-node.start { background: #4C4DC3; }
.fe-minimap .mm-view { position: absolute; border: 1.5px solid #4C4DC3;
  background: rgba(76,77,195,.10); border-radius: 3px; pointer-events: none; }
/* Las líneas van POR ENCIMA del cuerpo de los nodos (z-index 1) pero por
   DEBAJO de los puntos de conexión (.fport z-index 3), así la línea nace
   claramente del puntito que está encima y no queda tapada por el nodo. */
#flowEdges { position: absolute; top: 0; left: 0; width: 6000px; height: 4000px; pointer-events: none; overflow: visible; z-index: 1; }
#flowEdges path { fill: none; stroke: #B6BAD3; stroke-width: 2.5; }
#flowEdges path.temp { stroke: var(--purpura); stroke-dasharray: 6 5; }
#flowEdges .edge-hit { stroke: transparent; stroke-width: 16; pointer-events: stroke; cursor: pointer; }

.fnode {
  position: absolute; width: 230px; background: #fff; border-radius: 14px;
  border: 1px solid var(--line); box-shadow: var(--sh-sm); user-select: none;
}
.fnode.sel { border-color: var(--purpura); box-shadow: 0 0 0 3px rgba(76,77,195,.18), var(--sh-md); }
.fnode .fn-head {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px; cursor: grab;
  border-bottom: 1px solid var(--ground); border-radius: 14px 14px 0 0;
}
.fnode .fn-head .fn-ic { width: 20px; height: 20px; flex-shrink: 0; }
.fnode .fn-head .fn-title { font-weight: 800; font-size: 13.5px; flex: 1; }
.fnode .fn-head .fn-del { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 16px; line-height: 1; padding: 2px 4px; }
.fnode .fn-head .fn-del:hover { color: #E23D6D; }
.fnode .fn-body { padding: 11px 12px; font-size: 12.5px; color: var(--muted); min-height: 22px; word-break: break-word; cursor: pointer; }
.fnode .fn-body .empty { font-style: italic; opacity: .7; }
.fnode.start .fn-head { background: var(--navy); color: #fff; border-radius: 14px 14px 0 0; }
.fnode.start .fn-head .fn-title { color: #fff; }
.fnode .fn-media { max-width: 100%; border-radius: 8px; margin-top: 6px; }
.fn-opt { display: flex; align-items: center; gap: 6px; padding: 6px 8px; margin-top: 6px; background: var(--purpura-050); border-radius: 8px; font-weight: 700; color: var(--purpura); font-size: 12px; position: relative; }

/* Puertos */
.fport {
  position: absolute; width: 15px; height: 15px; border-radius: 50%;
  background: #fff; border: 2.5px solid var(--purpura); cursor: crosshair; z-index: 3;
}
.fport.in { left: -8px; top: 18px; }
.fport.out { right: -8px; top: 18px; background: var(--purpura); }
.fport.out.opt { top: auto; }
.fport:hover { transform: scale(1.25); }

/* Panel de edición de nodo */
.fe-panel {
  width: 340px; flex-shrink: 0; background: #fff; border-left: 1px solid var(--line);
  overflow-y: auto; padding: 18px; transform: translateX(100%); transition: transform .2s;
  position: absolute; right: 0; top: 62px; bottom: 0; box-shadow: var(--sh-lg); z-index: 5;
}
.fe-panel.open { transform: translateX(0); }
.fe-panel h3 { margin: 0 0 4px; font-size: 16px; font-weight: 800; display: flex; align-items: center; gap: 8px; }
.fe-panel .p-sub { color: var(--muted); font-size: 12.5px; margin-bottom: 16px; }
.fe-panel .field { margin-bottom: 15px; }
.fe-panel .p-close { position: absolute; top: 14px; right: 14px; border: 0; background: transparent; font-size: 20px; cursor: pointer; color: var(--muted); }
.opt-row { display: flex; gap: 8px; margin-bottom: 8px; }
.opt-row input { flex: 1; }
.opt-row button { border: 1.5px solid rgba(226,61,109,.3); background: #fff; color: #E23D6D; border-radius: 9px; width: 38px; cursor: pointer; }
.add-opt { width: 100%; border: 1.5px dashed var(--line); background: #fff; color: var(--purpura); font-weight: 700; padding: 9px; border-radius: 10px; cursor: pointer; font: inherit; }
.add-opt:hover { border-color: var(--purpura); background: var(--purpura-050); }
.up-drop { border: 1.5px dashed var(--line); border-radius: 11px; padding: 16px; text-align: center; color: var(--muted); cursor: pointer; font-size: 13px; }
.up-drop:hover { border-color: var(--purpura); background: var(--purpura-050); }
.up-preview { margin-top: 10px; }
.up-preview img, .up-preview video { max-width: 100%; border-radius: 10px; }

.seg { display: flex; gap: 6px; background: var(--ground); padding: 4px; border-radius: 11px; }
.seg button { flex: 1; min-width: 0; border: 0; background: transparent; padding: 8px; border-radius: 8px; font: inherit; font-size: 12.5px; font-weight: 700; cursor: pointer; color: var(--muted); }
.seg button.sel { background: #fff; color: var(--purpura); box-shadow: var(--sh-sm); }
/* El disparador tiene 4 opciones: no entran en una fila del panel angosto.
   Lo pasamos a grilla 2×2 para que no se desborde. */
#pTrigSeg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
#pTrigSeg button { flex: none; line-height: 1.2; }

/* ---- Botón + modal de Configuración del flujo ---- */
.fe-cfg { display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--line); background: #fff; color: var(--ink); border-radius: 10px; padding: 8px 13px; font: inherit; font-size: 13.5px; font-weight: 700; cursor: pointer; margin-left: 10px; }
.fe-cfg:hover { border-color: var(--purpura); color: var(--purpura); }
.fe-cfg svg { width: 17px; height: 17px; }
.flowcfg-overlay { position: fixed; inset: 0; z-index: 90; background: rgba(30,38,58,.5); backdrop-filter: blur(4px); display: grid; place-items: center; padding: 20px; }
.flowcfg { background: #fff; border-radius: 18px; box-shadow: var(--sh-lg); width: 640px; max-width: calc(100vw - 40px); max-height: 88vh; display: flex; flex-direction: column; }
.flowcfg-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--line); }
.flowcfg-head h3 { margin: 0; font-size: 17px; font-weight: 800; }
.flowcfg-x { border: 0; background: transparent; font-size: 24px; line-height: 1; color: var(--muted); cursor: pointer; }
.flowcfg-body { padding: 20px 22px; overflow-y: auto; }
.fc-section { margin-bottom: 22px; }
.fc-toggle-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.fc-toggle-row > span { display: flex; flex-direction: column; gap: 3px; }
.fc-toggle-row small { color: var(--muted); font-size: 12.5px; line-height: 1.4; }
.fc-sub { margin-top: 14px; background: var(--ground); border-radius: 12px; padding: 14px; }
.fc-sub.hidden { display: none; }
.fc-sub-title { font-size: 12.5px; font-weight: 800; color: var(--muted); margin-bottom: 10px; }
.fc-radio { display: flex; align-items: center; gap: 9px; padding: 8px 4px; font-size: 13.5px; cursor: pointer; }
.fc-radio input { accent-color: var(--purpura); width: 17px; height: 17px; }
.fc-log-head { display: flex; align-items: center; justify-content: space-between; }
.fc-log-head h4 { margin: 0; font-size: 15px; font-weight: 800; }
.fc-dl { padding: 8px 13px; font-size: 13px; }
.fc-hint { color: var(--muted); font-size: 12.5px; margin: 4px 0 12px; }
.fc-log { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; max-height: 340px; overflow-y: auto; }
.fc-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.fc-table th { text-align: left; padding: 10px 12px; background: var(--ground); font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); position: sticky; top: 0; }
.fc-table td { padding: 10px 12px; border-top: 1px solid var(--line); }
.fc-log-empty { padding: 24px; text-align: center; color: var(--muted); font-size: 13px; }
