/* gopascal-sci — Fluxos de automacao (ScreenFluxos.pas + js/fluxos.js)
   Namespace fx-. Usa os tokens de tema do projeto (--card-bg, --primary,
   --text, ...); a cor de cada TIPO de no vem inline em --fx-cor. */

.fx {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--topbar-h, 4rem) - var(--tabs-h, 2.75rem) - 4.5rem);
  min-height: 560px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg, 14px);
  overflow: hidden;
  position: relative;
  color: var(--text);
}
.fx-carregando { margin: auto; color: var(--text-muted); }
.fx-oculto { display: none !important; }
.fx-esp { flex: 1 1 auto; }

/* ---- barra ---------------------------------------------------------- */
.fx-barra {
  display: flex; align-items: center; gap: .4rem; flex-wrap: wrap;
  padding: .5rem .65rem; border-bottom: 1px solid var(--card-border);
}
/* a faixa de titulo (.page-titlebar) e a barra de ferramentas numa peca so,
   no topo do card */
.fx > .page-titlebar.fx-barra { margin: 0; border-radius: 0; flex: 0 0 auto; }
.fx-titulo { margin-right: .5rem; white-space: nowrap; }
.fx-sel {
  min-width: 260px; max-width: 420px; padding: .42rem .6rem;
  border: 1px solid var(--card-border); border-radius: var(--radius, 10px);
  background: var(--card-bg); color: var(--text); font-weight: 600;
}
.fx-btn {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .42rem .7rem; border: 1px solid var(--card-border);
  border-radius: var(--radius, 10px); background: var(--card-bg); color: var(--text);
  font-size: .85rem; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.fx-btn:hover:not(:disabled) { border-color: var(--primary); }
.fx-btn:disabled { opacity: .45; cursor: default; }
.fx-btn--pri { background: var(--primary); border-color: var(--primary); color: #111; }
.fx-btn--pri:hover:not(:disabled) { background: var(--primary-hover); }
.fx-btn--perigo { color: var(--danger); }
.fx-btn--mini { padding: .2rem .5rem; font-size: .75rem; }
.fx-btn--ocupado { pointer-events: none; opacity: .6; }
.fx-btn--ocupado i { animation: fx-gira 1s linear infinite; }
@keyframes fx-gira { to { transform: rotate(360deg); } }
.fx-status { display: inline-flex; gap: .3rem; flex-wrap: wrap; }
.fx-chip {
  display: inline-block; padding: .1rem .5rem; border-radius: 999px;
  font-size: .72rem; font-weight: 700; background: var(--primary-soft); color: var(--text);
  border: 1px solid var(--card-border);
}
.fx-chip--ok { background: color-mix(in srgb, var(--success) 18%, transparent); border-color: color-mix(in srgb, var(--success) 45%, transparent); }
.fx-chip--warn { background: color-mix(in srgb, var(--warning) 20%, transparent); border-color: color-mix(in srgb, var(--warning) 50%, transparent); }
.fx-chip--ro { background: color-mix(in srgb, var(--info) 18%, transparent); border-color: color-mix(in srgb, var(--info) 45%, transparent); }

/* ---- corpo: paleta | canvas | painel -------------------------------- */
.fx-corpo-geral { flex: 1 1 auto; display: flex; min-height: 0; }
.fx-paleta {
  width: 170px; flex: 0 0 170px; overflow-y: auto; padding: .5rem;
  border-right: 1px solid var(--card-border);
}
.fx-pal-grupo {
  font-size: .68rem; font-weight: 800; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-muted); margin: .7rem 0 .3rem;
}
.fx-pal-grupo:first-child { margin-top: .1rem; }
.fx-pal-item {
  display: flex; align-items: center; gap: .45rem; padding: .38rem .5rem; margin-bottom: .3rem;
  border: 1px solid var(--card-border); border-left: 4px solid var(--fx-cor);
  border-radius: 8px; font-size: .8rem; font-weight: 600; cursor: grab; user-select: none;
  background: var(--card-bg);
}
.fx-pal-item i { color: var(--fx-cor); width: 1rem; text-align: center; }
.fx-pal-item:hover { box-shadow: var(--shadow); }

.fx-canvas { flex: 1 1 auto; position: relative; min-width: 0; }
.fx-df {
  position: absolute; inset: 0;
  background-color: var(--app-bg);
  background-image: radial-gradient(color-mix(in srgb, var(--text-muted) 35%, transparent) 1px, transparent 1px);
  background-size: 22px 22px;
}
.fx-zoom {
  position: absolute; right: .6rem; bottom: .6rem; display: flex; gap: .25rem; z-index: 5;
}
.fx-zoom button {
  width: 2rem; height: 2rem; border-radius: 8px; border: 1px solid var(--card-border);
  background: var(--card-bg); color: var(--text); font-weight: 800; cursor: pointer;
}
.fx-ro {
  position: absolute; left: 50%; top: .6rem; transform: translateX(-50%); z-index: 5;
  background: var(--info); color: #fff; padding: .35rem .8rem; border-radius: 999px; font-size: .8rem; font-weight: 700;
}
.fx-ro button { background: transparent; border: 0; color: #fff; text-decoration: underline; font-weight: 800; cursor: pointer; }

.fx-lado {
  width: 400px; flex: 0 0 400px; display: flex; flex-direction: column; min-height: 0;
  border-left: 1px solid var(--card-border);
}
.fx-abas { display: flex; border-bottom: 1px solid var(--card-border); }
.fx-abas button {
  flex: 1; padding: .55rem .3rem; border: 0; background: transparent; color: var(--text-muted);
  font-weight: 700; font-size: .82rem; cursor: pointer; border-bottom: 3px solid transparent;
}
.fx-abas button.is-on { color: var(--text); border-bottom-color: var(--primary); }
.fx-corpo { flex: 1 1 auto; overflow-y: auto; padding: .7rem .75rem 2rem; font-size: .84rem; }

/* ---- nos no Drawflow -------------------------------------------------- */
.fx-df .drawflow .drawflow-node.fx-df-no {
  width: 200px; min-height: 64px; padding: 0; border-radius: 10px;
  background: var(--card-bg); color: var(--text);
  border: 1px solid var(--card-border); box-shadow: var(--shadow);
}
.fx-df .drawflow .drawflow-node.fx-df-no.selected {
  background: var(--card-bg); border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft), var(--shadow-lg);
}
.fx-df .drawflow .drawflow-node .drawflow_content_node { width: 100%; }
.fx-no { border-top: 4px solid var(--fx-cor); border-radius: 10px; padding: .4rem .55rem .45rem; }
.fx-no-cab {
  display: flex; align-items: center; gap: .35rem; font-size: .66rem; font-weight: 800;
  text-transform: uppercase; letter-spacing: .05em; color: var(--fx-cor);
}
.fx-no-nome { font-weight: 700; font-size: .86rem; line-height: 1.2; margin-top: .15rem; }
.fx-no-chave { font-family: ui-monospace, Consolas, monospace; font-size: .68rem; color: var(--text-muted); }

.fx-df .drawflow .drawflow-node .input,
.fx-df .drawflow .drawflow-node .output {
  width: 13px; height: 13px; border: 2px solid var(--card-bg);
  background: color-mix(in srgb, var(--text-muted) 70%, transparent);
}
.fx-df .drawflow .drawflow-node .output { position: relative; background: var(--primary); }
.fx-df .drawflow .drawflow-node .output::after {
  content: attr(data-porta); position: absolute; left: 15px; top: -3px;
  font-size: 10px; font-weight: 700; color: var(--text-muted); white-space: nowrap; pointer-events: none;
}
.fx-df .drawflow .drawflow-node .outputs { gap: 4px; }
.fx-df .drawflow .connection .main-path { stroke: color-mix(in srgb, var(--text-muted) 75%, transparent); stroke-width: 2.5px; }
.fx-df .drawflow .connection .main-path:hover,
.fx-df .drawflow .connection .main-path.selected { stroke: var(--primary); }

/* validacao / simulacao no desenho */
.fx-df .drawflow-node.fx-tem-aviso { box-shadow: 0 0 0 2px var(--warning), var(--shadow); }
.fx-df .drawflow-node.fx-tem-erro { box-shadow: 0 0 0 3px var(--danger), var(--shadow); }
.fx-df .drawflow-node.fx-passou { border-color: var(--success); box-shadow: 0 0 0 3px color-mix(in srgb, var(--success) 45%, transparent); }
.fx-df .drawflow-node.fx-agora { animation: fx-pulsa 1s ease-in-out infinite; }
.fx-df .drawflow-node.fx-pisca { animation: fx-pulsa .45s ease-in-out 3; }
@keyframes fx-pulsa { 50% { box-shadow: 0 0 0 7px var(--primary-soft); } }
.fx-df .connection.fx-passou .main-path { stroke: var(--success); stroke-width: 4px; }

/* ---- painel --------------------------------------------------------- */
.fx-dica { color: var(--text-muted); line-height: 1.45; }
.fx-lbl { display: flex; flex-direction: column; gap: .2rem; margin-bottom: .55rem; font-size: .74rem; font-weight: 700; color: var(--text-muted); }
.fx-in {
  width: 100%; padding: .4rem .5rem; border: 1px solid var(--card-border); border-radius: 8px;
  background: var(--card-bg); color: var(--text); font: inherit; font-size: .82rem; font-weight: 500;
}
textarea.fx-in { resize: vertical; line-height: 1.4; }
.fx-in:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.fx-in:disabled { opacity: .75; }
.fx-in--curto { width: 7.5rem; flex: 0 0 auto; }
.fx-in--num { width: 8rem; }
.fx-mono { font-family: ui-monospace, Consolas, monospace; font-size: .76rem; }
.fx-bruto { min-height: 360px; }
.fx-linha { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; margin: .4rem 0; }
.fx-linha--fim { justify-content: flex-end; margin-top: 1rem; }
.fx-grade { display: grid; grid-template-columns: 1fr 1fr; gap: 0 .6rem; }
.fx-chk { display: inline-flex; align-items: center; gap: .35rem; font-size: .8rem; font-weight: 600; cursor: pointer; }
.fx-secao {
  display: flex; align-items: center; gap: .4rem; margin: .9rem 0 .4rem;
  font-size: .72rem; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted);
}
.fx-secao-info { text-transform: none; letter-spacing: 0; font-weight: 600; }
.fx-no-titulo {
  display: flex; align-items: center; gap: .45rem; padding: .45rem .6rem; margin-bottom: .6rem;
  border-left: 4px solid var(--fx-cor); background: var(--primary-soft); border-radius: 8px;
}
.fx-no-titulo i { color: var(--fx-cor); }
.fx-no-titulo code { margin-left: auto; font-size: .75rem; }
.fx-saidas { display: flex; flex-direction: column; gap: .3rem; }
.fx-saida { display: grid; grid-template-columns: 1.2rem 1fr 1fr 1.4fr; gap: .3rem; align-items: center; }
.fx-saida-n { font-size: .7rem; font-weight: 800; color: var(--text-muted); text-align: center; }
.fx-card {
  border: 1px solid var(--card-border); border-radius: 10px; padding: .55rem .65rem; margin: .5rem 0;
  background: color-mix(in srgb, var(--app-bg) 60%, var(--card-bg));
}
.fx-card--ok { border-color: color-mix(in srgb, var(--success) 55%, transparent); background: color-mix(in srgb, var(--success) 10%, var(--card-bg)); }
.fx-card--erro { border-color: color-mix(in srgb, var(--danger) 55%, transparent); background: color-mix(in srgb, var(--danger) 9%, var(--card-bg)); }
.fx-kv { display: flex; gap: .5rem; justify-content: space-between; padding: .12rem 0; font-size: .8rem; }
.fx-kv span { color: var(--text-muted); }
.fx-kv code { font-size: .72rem; }
.fx-msgs { list-style: none; margin: .3rem 0; padding: 0; display: flex; flex-direction: column; gap: .25rem; }
.fx-msg { padding: .35rem .5rem; border-radius: 7px; font-size: .79rem; line-height: 1.35; border-left: 3px solid var(--text-muted); background: var(--app-bg); }
.fx-msg code { font-size: .72rem; font-weight: 700; }
.fx-msg--erro { border-left-color: var(--danger); }
.fx-msg--aviso { border-left-color: var(--warning); }
.fx-msg--info { border-left-color: var(--info); }
.fx-msg--link { cursor: pointer; }
.fx-msg--link:hover { background: var(--primary-soft); }
.fx-det { margin: .3rem 0; }
.fx-det summary { cursor: pointer; font-size: .78rem; font-weight: 700; color: var(--text-muted); }
.fx-det--erro summary { color: var(--danger); }
.fx-pre {
  white-space: pre-wrap; word-break: break-word; max-height: 360px; overflow: auto;
  font-family: ui-monospace, Consolas, monospace; font-size: .72rem; line-height: 1.4;
  background: var(--app-bg); border: 1px solid var(--card-border); border-radius: 8px; padding: .45rem .55rem; margin: .3rem 0;
}
.fx-pre--erro { border-color: var(--danger); }
.fx-resposta { margin: .35rem 0 0; white-space: pre-wrap; line-height: 1.45; }

/* linha do tempo da simulacao */
.fx-tl { list-style: none; margin: .5rem 0; padding: 0 0 0 .6rem; border-left: 2px solid var(--card-border); }
.fx-tl-item { position: relative; margin: 0 0 .55rem .55rem; }
.fx-tl-item::before {
  content: ""; position: absolute; left: -1.05rem; top: .3rem; width: .6rem; height: .6rem;
  border-radius: 50%; background: var(--fx-cor); border: 2px solid var(--card-bg);
}
.fx-tl-cab { display: flex; align-items: center; gap: .35rem; cursor: pointer; }
.fx-tl-cab i { color: var(--fx-cor); }
.fx-tl-cab small { margin-left: auto; color: var(--text-muted); }
.fx-tl-txt { font-size: .78rem; color: var(--text-muted); line-height: 1.4; white-space: pre-wrap; word-break: break-word; }
.fx-tl-parcial { margin: 0 0 .4rem .55rem; font-size: .74rem; font-style: italic; color: var(--text-muted); }

/* editor de config (JSON em formulario) */
.fx-cfg-corpo { margin-top: .4rem; }
.fx-campo { display: grid; grid-template-columns: 8.5rem 1fr auto; gap: .35rem; align-items: start; margin: .25rem 0; }
.fx-campo--col { display: block; }
.fx-k {
  font-family: ui-monospace, Consolas, monospace; font-size: .72rem; font-weight: 700; color: var(--text-muted);
  padding-top: .45rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.fx-x { border: 0; background: transparent; color: var(--text-muted); cursor: pointer; font-size: 1rem; line-height: 1; padding: .3rem .2rem; }
.fx-x:hover { color: var(--danger); }
.fx-obj { margin: .25rem 0; padding: .1rem 0 .1rem .55rem; border-left: 2px solid var(--card-border); }
.fx-obj > summary { cursor: pointer; display: flex; align-items: center; gap: .3rem; padding: .2rem 0; }
.fx-obj > summary .fx-k { padding-top: 0; }
.fx-obj > summary .fx-x { margin-left: auto; }
.fx-item { margin: .2rem 0; border: 1px solid var(--card-border); border-radius: 8px; padding: .1rem .45rem; background: var(--card-bg); }
.fx-item[open] { padding-bottom: .4rem; }
.fx-item > summary { cursor: pointer; display: flex; align-items: center; gap: .3rem; padding: .25rem 0; font-size: .78rem; font-weight: 600; }
.fx-item-rot { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fx-item-acoes { margin-left: auto; display: inline-flex; gap: .1rem; }
.fx-item-acoes button { border: 0; background: transparent; color: var(--text-muted); cursor: pointer; font-size: .8rem; padding: 0 .25rem; }
.fx-item-acoes button:hover { color: var(--primary); }
.fx-add-campo { margin-top: .4rem; }

/* dialogo e avisos */
.fx-conf {
  position: absolute; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center;
  background: rgba(15, 23, 42, .35);
}
.fx-conf-box {
  width: min(440px, 92%); background: var(--card-bg); color: var(--text); border-radius: 12px;
  padding: 1rem 1.1rem; box-shadow: var(--shadow-lg); border: 1px solid var(--card-border);
}
.fx-conf-box h4 { margin: 0 0 .6rem; font-size: 1rem; }
.fx-conf-box p { margin: 0 0 .8rem; line-height: 1.45; }
.fx-conf-acoes { display: flex; justify-content: flex-end; gap: .45rem; margin-top: .4rem; }
.fx-toasts { position: absolute; left: 50%; bottom: 1rem; transform: translateX(-50%); z-index: 40; display: flex; flex-direction: column; gap: .35rem; align-items: center; }
.fx-toast {
  padding: .5rem .9rem; border-radius: 10px; font-size: .84rem; font-weight: 600; color: #fff;
  background: var(--info); box-shadow: var(--shadow-lg); max-width: 560px;
}
.fx-toast--ok { background: var(--success); }
.fx-toast--erro { background: var(--danger); }

@media (max-width: 1100px) {
  .fx-lado { width: 330px; flex-basis: 330px; }
  .fx-paleta { width: 140px; flex-basis: 140px; }
}
@media (max-width: 800px) {
  .fx { height: auto; }
  .fx-corpo-geral { flex-direction: column; }
  .fx-paleta { width: auto; flex-basis: auto; display: flex; flex-wrap: wrap; gap: .3rem; border-right: 0; border-bottom: 1px solid var(--card-border); }
  .fx-pal-grupo { display: none; }
  .fx-canvas { height: 60vh; flex: 0 0 60vh; }
  .fx-lado { width: auto; flex-basis: auto; border-left: 0; border-top: 1px solid var(--card-border); }
}

/* ---- simulacao com dialogo (no "perguntar") -------------------------- */
.fx-card--pergunta { border-color: color-mix(in srgb, var(--warning) 60%, transparent); background: color-mix(in srgb, var(--warning) 10%, var(--card-bg)); }
.fx-card--pergunta .fx-linha .fx-in { flex: 1 1 auto; }
.fx-resposta { white-space: pre-wrap; }
.fx-conversa { display: flex; flex-direction: column; gap: .35rem; margin-bottom: .6rem; }
.fx-msg-conv { max-width: 88%; padding: .4rem .6rem; border-radius: 10px; font-size: .82rem; white-space: pre-wrap; border: 1px solid var(--card-border); }
.fx-msg-conv--usuario { align-self: flex-end; background: var(--primary-soft); }
.fx-msg-conv--fluxo { align-self: flex-start; background: var(--card-bg); color: var(--text-muted); }
.fx-chip-x { border: 0; background: none; cursor: pointer; font-weight: 700; color: inherit; padding: 0 .15rem; }
