/* ── Automatizaciones: mapa, editor de flujos y detalle ─────────────────
   Mismo lenguaje que el grafo de sistemas de Compliance: tarjetas de esquinas
   rectas, líneas ortogonales grises y flujo animado en lo que ocurre solo. */

.automations-panel + .automations-panel {
  margin-top: 20px;
}

.automations-panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px 12px;
}

.automations-panel__head h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 650;
}

.automation-row {
  cursor: pointer;
}

.automation-row:hover td {
  background: #f7f7f5;
}

.automation-row:focus-visible {
  outline: none;
}

.automation-row:focus-visible td {
  background: #f1f1ee;
  box-shadow: inset 0 -1px 0 var(--ink);
}

.automation-row__chevron {
  width: 36px;
  color: var(--soft);
  text-align: right;
}

.automation-row:hover .automation-row__chevron {
  color: var(--ink);
}

/* ── Modales de detalle ─────────────────────────────────────────────── */

.modal--automation {
  width: min(820px, calc(100vw - 32px));
}

.modal--automation-wide {
  width: min(1080px, calc(100vw - 32px));
}

.modal--automation .client-tabs {
  margin-bottom: 20px;
}

.automation-detail p {
  margin: 0 0 12px;
  line-height: 1.55;
}

.automation-lead {
  color: #3f3f3b;
  font-size: 14px;
}

.automation-facts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px 24px;
  margin: 0 0 18px;
}

.automation-facts div {
  min-width: 0;
}

.automation-facts dt {
  margin-bottom: 4px;
  color: var(--label);
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.automation-facts dd {
  margin: 0;
  overflow-wrap: anywhere;
  font-size: 14px;
}

.automation-facts dd small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.automation-facts__wide {
  grid-column: 1 / -1;
}

.automation-facts--technical dd {
  font-size: 13px;
}

.automation-facts--stack {
  grid-template-columns: 1fr;
  gap: 10px;
  margin-top: 8px;
}

.automation-subhead {
  margin: 22px 0 10px;
  font-size: 13px;
  font-weight: 650;
}

.automation-subhead:first-child {
  margin-top: 0;
}

.automation-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 1px;
  margin: 0 0 8px;
  border: 1px solid var(--line);
  background: var(--line);
}

.automation-stats div {
  padding: 12px 14px;
  background: #fff;
}

.automation-stats dt {
  color: var(--label);
  font-size: 11px;
  font-weight: 600;
}

.automation-stats dd {
  margin: 4px 0 0;
  font-size: 20px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.automations-table--compact {
  min-width: 620px;
}

.automations-table--compact td,
.automations-table--compact th {
  font-size: 13px;
}

/* Nombres de variables y códigos de sistema: nunca partidos a mitad. */
.automations-table--compact code {
  white-space: nowrap;
  overflow-wrap: normal;
}

.automation-nowrap {
  white-space: nowrap;
}

.automation-list {
  margin: 0 0 8px;
  padding-left: 18px;
  line-height: 1.55;
}

.automation-list li + li {
  margin-top: 4px;
}

.automation-list--errors {
  color: #9f1d1d;
  font-size: 13px;
}

.automation-code {
  margin: 0;
  padding: 0;
  list-style: none;
}

.automation-code li + li {
  margin-top: 6px;
}

.automation-code code,
.automation-detail code,
.automation-facts code {
  padding: 2px 5px;
  background: var(--fill);
  font-family: Consolas, Monaco, monospace;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.automation-columns {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 0 24px;
}

.automation-soft {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.automation-empty {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 13px;
}

.automation-loading {
  color: var(--muted);
}

.automation-hint {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.automation-danger {
  margin-right: auto;
}

.link-button {
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink);
  font: inherit;
  text-align: left;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

.automation-switch {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
  font-weight: 600;
  cursor: pointer;
}

.automation-switch input {
  width: 18px;
  height: 18px;
  accent-color: var(--ink);
}

.automation-settings textarea {
  font-family: inherit;
}

/* ── Plantillas ─────────────────────────────────────────────────────── */

.automation-template__grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 24px;
}

.automation-template__row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.automation-template__preview {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 8px;
}

.automation-template__preview iframe {
  width: 100%;
  min-height: 460px;
  flex: 1;
  border: 1px solid var(--line-strong);
  background: #fff;
}

.automation-variables {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: -6px 0 16px;
}

.automation-chip {
  padding: 4px 9px;
  border: 1px solid var(--line-strong);
  background: #fff;
  color: #3f3f3b;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.automation-chip:hover {
  border-color: var(--ink);
  color: var(--ink);
}

.automation-client-results {
  max-height: 200px;
  margin: -8px 0 16px;
  padding: 0;
  overflow-y: auto;
  border: 1px solid var(--line);
  list-style: none;
}

.automation-client-results:empty {
  display: none;
}

.automation-client-results button {
  width: 100%;
  padding: 9px 12px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: #fff;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.automation-client-results button:hover {
  background: var(--fill);
}

/* ── Lienzo (mapa y editor) ─────────────────────────────────────────── */

.automation-map-panel {
  padding: 0;
  overflow: hidden;
}

.automation-map-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

.automation-map-legend span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.legend-mark {
  display: inline-block;
  width: 14px;
  height: 10px;
  border: 1px solid #bdbdbd;
  background: #fff;
}

.legend-mark--auto {
  border-color: #333;
}

.legend-mark--manual {
  border-style: dashed;
}

.legend-mark--email {
  background: #f4f4f1;
}

.legend-mark--flow {
  border-color: #333;
  background: #333;
}

.flow-canvas {
  position: relative;
  overflow: hidden;
  /* clip: ni el foco ni el navegador pueden desplazar el lienzo por dentro; solo el zoom. */
  overflow: clip;
  background: #f9f9f9;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.flow-canvas:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: -2px;
}

.flow-canvas.is-panning {
  cursor: grabbing;
}

.flow-canvas--map {
  height: min(680px, calc(100vh - 300px));
  min-height: 420px;
}

.flow-world {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
}

.flow-lane {
  position: absolute;
  left: 0;
  border-top: 1px solid #e6e6e6;
}

.flow-lane span {
  position: absolute;
  top: 18px;
  left: 18px;
  width: 118px;
  color: #5f5f5a;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.07em;
  line-height: 1.4;
  text-transform: uppercase;
}

.flow-edges {
  position: absolute;
  top: 0;
  left: 0;
  width: 1px;
  height: 1px;
  overflow: visible;
  pointer-events: none;
}

.flow-edge {
  color: #858585;
  pointer-events: none;
}

.flow-edge__hit {
  fill: none;
  stroke: transparent;
  stroke-width: 14px;
  vector-effect: non-scaling-stroke;
  pointer-events: stroke;
  cursor: pointer;
}

/* En el mapa las líneas no se editan: solo enseñan su etiqueta al pasar por encima. */
.flow-canvas--map .flow-edge__hit {
  cursor: help;
}

/* Trazos de grosor constante con cualquier zoom: nítidos y sin engordar. */
.flow-edge__line {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5px;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.flow-edge {
  color: #a3a3a0;
}

.flow-edge--automatic .flow-edge__line {
  color: #d4d4d1;
}

.flow-edge__flow {
  fill: none;
  stroke: #5c5c58;
  stroke-width: 1.5px;
  stroke-linecap: round;
  stroke-dasharray: 3 7;
  vector-effect: non-scaling-stroke;
  animation: flow-edge-dash 0.6s linear infinite;
}

.flow-edge.is-selected .flow-edge__line {
  color: #111;
  stroke-width: 2.25px;
}

.flow-edges marker path {
  fill: #a3a3a0;
}

.flow-edge__label rect {
  fill: #f9f9f9;
  stroke: #e4e4e1;
  stroke-width: 1px;
  vector-effect: non-scaling-stroke;
}

.flow-edge__label text {
  fill: #5f5f5a;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.flow-edge__draft {
  fill: none;
  stroke: #333;
  stroke-width: 1.5px;
  stroke-dasharray: 5 5;
  vector-effect: non-scaling-stroke;
}

@keyframes flow-edge-dash {
  to {
    stroke-dashoffset: -10;
  }
}

@media (prefers-reduced-motion: reduce) {
  .flow-edge__flow {
    animation: none;
  }
}

.flow-node {
  position: absolute;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 12px 12px 11px;
  border: 1px solid #deded9;
  border-radius: 0;
  background: #fff;
  box-shadow: 0 4px 16px rgb(50 50 50 / 4%);
  color: #323232;
  font: inherit;
  text-align: left;
}

button.flow-node,
.flow-node--wait,
.flow-node--condition,
.flow-node--email,
.flow-node--trigger {
  cursor: pointer;
}

button.flow-node:hover,
.flow-node:not(.flow-node--map):hover {
  border-color: #c2c2c2;
  background: #fcfcfc;
}

.flow-node:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.flow-node.is-selected {
  border-color: #333;
  box-shadow: 0 6px 20px rgb(117 117 117 / 12%);
}

.flow-node.is-dragging {
  z-index: 3;
  border-color: #565656;
  box-shadow: 0 18px 38px rgba(30, 30, 30, 0.18);
  cursor: grabbing;
}

.flow-node.has-error {
  border-color: #c24141;
}

.flow-node__icon {
  display: inline-flex;
  width: 26px;
  height: 26px;
  flex: 0 0 26px;
  align-items: center;
  justify-content: center;
  background: #f4f4f1;
  color: #3f3f3b;
  font-size: 14px;
}

.flow-node__text {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 3px;
}

.flow-node__text em {
  color: #6b6b66;
  font-size: 10.5px;
  font-style: normal;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.flow-node__text strong {
  display: -webkit-box;
  overflow: hidden;
  color: #1f1f1d;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.005em;
  line-height: 1.3;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.flow-node__text small {
  overflow: hidden;
  color: #6b6b66;
  font-size: 12.5px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.flow-node__error {
  color: #9f1d1d !important;
  white-space: normal !important;
}

/* Mapa: lo automático con borde oscuro, lo manual discontinuo, lo apagado atenuado. */
.flow-node--map.flow-node--manual {
  border-style: dashed;
  box-shadow: none;
}

.flow-node--map.flow-node--email .flow-node__icon,
.flow-node--map.flow-node--automation .flow-node__icon {
  background: #333;
  color: #fff;
}

.flow-node--map.flow-node--email {
  background: #fbfbf9;
}

.flow-node--map.flow-node--flow {
  border-color: #333;
}

.flow-node--map.flow-node--flow .flow-node__icon {
  background: #111;
  color: #fff;
}

.flow-node--map.is-live {
  border-color: #333;
}

.flow-node--map.is-off {
  opacity: 0.55;
  border-style: dashed;
}

.flow-node--map.is-draft {
  border-style: dashed;
}

/* Editor: disparador oscuro, puertos a los lados. */
.flow-node--trigger {
  border-color: #333;
}

.flow-node--trigger .flow-node__icon {
  background: #111;
  color: #fff;
}

.flow-node.is-trace-ok {
  box-shadow: inset 3px 0 0 #1f7a3a, 0 4px 16px rgb(50 50 50 / 4%);
}

.flow-node.is-trace-failed {
  box-shadow: inset 3px 0 0 #c24141, 0 4px 16px rgb(50 50 50 / 4%);
}

.flow-node.is-trace-skipped {
  opacity: 0.55;
}

.flow-node.is-trace-waiting {
  box-shadow: inset 3px 0 0 #a16207, 0 4px 16px rgb(50 50 50 / 4%);
}

.flow-port {
  position: absolute;
  width: 12px;
  height: 12px;
  border: 1.5px solid #333;
  border-radius: 50%;
  background: #fff;
}

.flow-port--in {
  top: calc(50% - 6px);
  left: -7px;
  pointer-events: none;
}

.flow-port--out {
  top: calc(50% - 6px);
  right: -7px;
  cursor: crosshair;
}

.flow-port--out:hover {
  background: #333;
}

.flow-port--yes {
  top: 34px;
}

.flow-port--no {
  top: 66px;
}

.flow-port b {
  position: absolute;
  top: -15px;
  left: 12px;
  color: #6f6f6f;
  font-size: 9px;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.flow-zoom {
  position: absolute;
  right: 12px;
  bottom: 12px;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border: 1px solid #dedede;
  background: #fff;
}

.flow-zoom span {
  min-width: 44px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* ── Editor de flujos ───────────────────────────────────────────────── */

.flow-editor {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.flow-editor__bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.flow-editor__name {
  min-width: 200px;
  flex: 1 1 280px;
  padding: 8px 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 20px;
  font-weight: 650;
}

.flow-editor__name:hover,
.flow-editor__name:focus {
  border-color: var(--line-strong);
  background: #fff;
  outline: none;
}

.flow-editor__dirty {
  color: #a16207;
  font-size: 12px;
  font-weight: 600;
}

.flow-editor__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-left: auto;
}

.flow-editor__body {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr) 320px;
  height: calc(100vh - 210px);
  min-height: 520px;
  border: 1px solid var(--line-strong);
  background: #fff;
}

.flow-palette,
.flow-panel {
  min-width: 0;
  padding: 16px;
  overflow-y: auto;
}

.flow-palette {
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-right: 1px solid var(--line);
}

.flow-palette__item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border: 1px solid #dedede;
  background: #fff;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}

.flow-palette__item:hover {
  border-color: #333;
}

.flow-editor .flow-canvas {
  min-height: 0;
}

.flow-panel {
  border-left: 1px solid var(--line);
}

.flow-panel__title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 16px;
  font-size: 15px;
  font-weight: 650;
}

.flow-panel__subtitle {
  margin: 20px 0 8px;
  font-size: 13px;
  font-weight: 650;
}

.flow-panel__inline {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: -6px 0 16px;
}

.flow-panel .field {
  margin-bottom: 14px;
}

.flow-panel .field input,
.flow-panel .field select {
  min-height: 40px;
}

.flow-runs,
.flow-trace {
  margin: 0 0 16px;
  padding: 0;
  list-style: none;
}

.flow-runs li,
.flow-trace li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.flow-runs small,
.flow-trace small {
  flex-basis: 100%;
  color: var(--muted);
  font-size: 12px;
}

@media (max-width: 1100px) {
  .flow-editor__body {
    grid-template-columns: minmax(0, 1fr) 300px;
  }

  .flow-palette {
    grid-column: 1 / -1;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .flow-palette .automation-soft {
    flex-basis: 100%;
    margin: 0;
  }

  .flow-editor__body {
    grid-template-rows: auto minmax(0, 1fr);
  }
}

@media (max-width: 760px) {
  .flow-editor__body {
    display: flex;
    height: auto;
    flex-direction: column;
  }

  .flow-editor .flow-canvas {
    height: 420px;
  }

  .flow-panel {
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .automation-template__grid,
  .automation-template__row {
    grid-template-columns: 1fr;
  }

  .flow-editor__actions {
    margin-left: 0;
  }
}

.automation-danger-fill {
  border-color: #9f1d1d;
  background: #9f1d1d;
  color: #fff;
}

.automation-danger-fill:hover {
  border-color: #7f1616;
  background: #7f1616;
}

.automation-notice {
  margin: 0 0 18px;
  padding: 10px 12px;
  border-left: 3px solid #a16207;
  background: #fdf8ed;
  color: #5b3b05;
  font-size: 13px;
  line-height: 1.5;
}

.automation-warning {
  color: #9f1d1d !important;
}

.automation-switch--confirm {
  font-weight: 500;
  font-size: 13px;
}

.automation-push {
  margin-right: auto;
}

/* ── Resumen de un proceso ───────────────────────────────────────────── */

.automation-summary {
  display: grid;
  gap: 18px;
}

.automation-summary__status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 12px;
  color: var(--muted);
  font-size: 13px;
}

.automation-summary__note {
  color: #3f3f3b;
}

.automation-summary__note::before {
  content: "·";
  margin-right: 12px;
  color: var(--soft);
}

.automation-summary__lead {
  max-width: 62ch;
  margin: 0;
  color: var(--ink);
  font-size: 16px;
  line-height: 1.5;
}

.automation-steps {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  margin: 0;
  padding: 0;
  border: 1px solid var(--line);
  list-style: none;
}

.automation-steps li {
  position: relative;
  display: grid;
  grid-template-columns: 22px 1fr;
  align-content: start;
  gap: 4px 10px;
  padding: 14px 16px;
  background: #fff;
}

.automation-steps li + li {
  border-left: 1px solid var(--line);
}

.automation-steps__number {
  display: inline-flex;
  width: 22px;
  height: 22px;
  grid-row: span 2;
  align-items: center;
  justify-content: center;
  background: var(--ink);
  color: #fff;
  font-size: 11px;
  font-weight: 650;
}

.automation-steps__label {
  color: var(--label);
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.automation-steps__text {
  color: #2b2b28;
  font-size: 13px;
  line-height: 1.45;
}

.automation-figures {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 16px 24px;
  margin: 0;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.automation-figures dt {
  margin-bottom: 4px;
  color: var(--label);
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.automation-figures dd {
  margin: 0;
  font-size: 14px;
  font-weight: 550;
  line-height: 1.45;
}

@media (max-width: 640px) {
  .automation-steps li + li {
    border-top: 1px solid var(--line);
    border-left: 0;
  }
}

/* ── Pantalla completa del lienzo ───────────────────────────────────────
   Ocupa toda la ventana por encima de la navegación, pero debajo de los
   modales (z-index 100) para que los detalles se sigan abriendo encima. */

.automation-map-panel.is-canvas-fullscreen,
.flow-editor.is-canvas-fullscreen {
  position: fixed;
  z-index: 90;
  inset: 0;
  display: flex;
  flex-direction: column;
  margin: 0;
  border: 0;
  border-radius: 0;
  background: #fff;
}

.automation-map-panel.is-canvas-fullscreen .flow-canvas--map {
  height: auto;
  min-height: 0;
  flex: 1;
}

.flow-editor.is-canvas-fullscreen {
  gap: 10px;
  padding: 12px 16px 16px;
}

.flow-editor.is-canvas-fullscreen .flow-editor__body {
  height: auto;
  min-height: 0;
  flex: 1;
}

body.has-canvas-fullscreen {
  overflow: hidden;
}

.flow-zoom [data-flow-fullscreen] {
  margin-left: 2px;
  border-left: 1px solid #e6e6e3;
}
