/* Estilos próprios da tela (antes inline no HTML) */
  /* ---------- Estrutura: barra lateral + conteúdo ---------- */
  #app { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; }
  .side { position: sticky; top: 0; height: 100vh; background: var(--sidebar); color: var(--sidebar-text); display: flex; flex-direction: column; padding: 18px 14px; gap: 18px; border-right: 1px solid rgba(255,255,255,.04); }
  .side .brandmark { padding: 4px 6px; }
  .side .brandmark small { display: block; font-size: 11.5px; font-weight: 500; color: var(--sidebar-muted); margin-top: 1px; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .side .group { font-size: 10.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--sidebar-muted); padding: 0 10px; margin: 6px 0 -6px; }
  #nav { display: grid; gap: 2px; }
  #nav button, .side .foot a, .side .foot button {
    all: unset; box-sizing: border-box; display: flex; align-items: center; gap: 11px; width: 100%; padding: 9px 10px; border-radius: 8px;
    color: var(--sidebar-text); font: 500 13.5px var(--font); cursor: pointer; transition: background .15s, color .15s;
  }
  #nav button svg, .side .foot svg { width: 18px; height: 18px; flex: none; opacity: .85; }
  #nav button:hover, .side .foot a:hover, .side .foot button:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
  #nav button.on { background: rgba(16,185,129,.14); color: #fff; box-shadow: inset 3px 0 0 #22c58f; }
  #nav button.on svg { color: #34d399; opacity: 1; }
  #nav button:focus-visible, .side .foot a:focus-visible, .side .foot button:focus-visible { outline: 2px solid #34d399; outline-offset: -2px; }
  .side .foot { margin-top: auto; display: grid; gap: 2px; padding-top: 12px; border-top: 1px solid rgba(255,255,255,.07); }
  .side .user { display: flex; align-items: center; gap: 10px; padding: 8px 10px 10px; }
  .side .avatar { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: var(--sidebar-2); color: #9be7c6; font-weight: 700; font-size: 13px; flex: none; border: 1px solid rgba(255,255,255,.08); }
  .side .user b { display: block; color: #fff; font-size: 13px; font-weight: 600; }
  .side .user span { font-size: 11.5px; color: var(--sidebar-muted); }

  main { min-width: 0; }
  .wa-banner { display: flex; gap: 12px; align-items: flex-start; padding: 12px 16px; border-radius: 10px; margin-bottom: 18px;
    background: var(--danger-soft); color: var(--danger); border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent); }
  .wa-banner b { display: block; }
  .wa-banner span { color: var(--text-2); font-size: 13px; }

  .page { display: none; padding: 26px 32px 32px; }
  .page.on { display: block; animation: fade .2s ease; }
  @keyframes fade { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }

  .pagehead { display: flex; align-items: flex-end; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
  .pagehead .titles { flex: 1; min-width: 260px; }
  .pagehead .titles > span { display: block; color: var(--muted); margin-top: 4px; font-size: 14px; }
  .pagehead .actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
  .crumb { font-size: 12px; font-weight: 600; color: var(--accent-ink); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 6px; }

  .lay { display: grid; gap: 20px; align-items: start; }
  .lay > .card { min-width: 0; }
  .lay-actions { grid-template-columns: minmax(0, 1.55fr) minmax(360px, 1fr); }
  .lay-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .lay-kb { grid-template-columns: minmax(260px, .8fr) minmax(0, 1.25fr) minmax(0, 1fr); }
  .lay-agents { grid-template-columns: minmax(0, 1.55fr) minmax(340px, 1fr); }
  .lay-1 { grid-template-columns: 1fr; }
  .sticky { position: sticky; top: 24px; }

  /* ---------- Fluxos ---------- */
  .flowbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; box-shadow: var(--shadow-sm); margin-bottom: 16px; }
  .flowbar select, .flowbar input { width: auto; flex: 1 1 200px; max-width: 280px; }
  .flowbar .sep { width: 1px; height: 26px; background: var(--border); margin: 0 2px; }
  .flowbar .spacer { flex: 1; }
  #flowStatus { font-size: 12.5px; }
  #flowLayout { display: grid; grid-template-columns: 300px minmax(380px, 1fr) minmax(380px, 1.15fr); gap: 16px; height: calc(100vh - 190px); min-height: 520px; }
  #flowLayout > .card { display: flex; flex-direction: column; min-height: 0; overflow: hidden; padding: 16px; }
  #nodeForm { overflow-y: auto !important; padding: 20px !important; }
  /* minmax(0, 1fr): os itens nunca ficam mais largos que a lista (o texto termina em "…") */
  #nodeList { display: grid; grid-template-columns: minmax(0, 1fr); align-content: start; gap: 2px; flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; padding-right: 4px; scrollbar-gutter: stable; }
  .node { min-width: 0; padding: 9px 10px; border-radius: 9px; cursor: pointer; border: 1px solid transparent; display: flex; align-items: center; gap: 10px; transition: background .12s, border-color .12s; }
  .node:hover { background: var(--surface-2); }
  .node.sel { border-color: color-mix(in srgb, var(--accent) 45%, transparent); background: var(--accent-soft); }
  .node .num { width: 24px; height: 24px; flex: none; border-radius: 7px; background: var(--surface-3); color: var(--muted); font-size: 11px; font-weight: 700; display: grid; place-items: center; }
  .node.sel .num { background: var(--accent); color: var(--accent-text); }
  .node .txt { flex: 1; min-width: 0; }
  .node .txt b { display: block; font-weight: 600; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
  .node .txt small { display: block; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .node .tag::before { display: none; }
  #diagram { overflow: auto; flex: 1; min-height: 0; margin-top: 4px; border-radius: 10px; padding: 16px; border: 1px solid var(--border);
    background-color: var(--surface-2); background-image: radial-gradient(var(--border-strong) 1px, transparent 1px); background-size: 18px 18px; }
  #diagram svg { height: auto; display: block; margin: 0 auto; }
  #diagram g.node { cursor: pointer; }
  .zoom { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 8px; overflow: hidden; }
  .zoom button { border: 0; border-radius: 0; box-shadow: none; padding: 6px 10px; }
  .zoom button + button { border-left: 1px solid var(--border); }
  /* Editor de passo: o layout acompanha a largura do próprio cartão (container query) */
  #nodeForm, .card { container-type: inline-size; }
  .opt { display: grid; grid-template-columns: minmax(0, .8fr) minmax(0, 1.3fr) minmax(0, 1.4fr) 36px; gap: 8px; align-items: center; }
  .opt.list { grid-template-columns: minmax(0, .8fr) minmax(0, 1.2fr) minmax(0, 1.2fr) minmax(0, 1.3fr) 36px; }
  .optHead { display: grid; grid-template-columns: minmax(0, .8fr) minmax(0, 1.3fr) minmax(0, 1.4fr) 36px; gap: 8px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
  .optHead.list { grid-template-columns: minmax(0, .8fr) minmax(0, 1.2fr) minmax(0, 1.2fr) minmax(0, 1.3fr) 36px; }
  .opt > button, .kv > button { width: 36px; height: 36px; padding: 0; }
  .kv { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.5fr) 36px; gap: 8px; }
  @container (max-width: 620px) {
    /* cada opção vira um bloco: código + texto em cima, destino embaixo */
    .optHead, .optHead.list { display: none; }
    .opt, .opt.list { grid-template-columns: minmax(0, 1fr) minmax(0, 1.6fr) 36px; padding: 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); }
    .opt > select { grid-column: 1 / 3; grid-row: 2; }
    .opt.list > input:nth-child(3) { grid-column: 1 / 3; grid-row: 2; }
    .opt.list > select { grid-row: 3; }
    .opt > button { grid-column: 3; grid-row: 1; }
  }
  @container (max-width: 420px) {
    .kv { grid-template-columns: minmax(0, 1fr) 36px; }
    .kv > input:nth-child(2) { grid-column: 1; }
    .kv > button { grid-row: 1 / span 2; grid-column: 2; }
    .hours { grid-template-columns: 22px minmax(70px, 1fr) minmax(0, 1fr) 18px minmax(0, 1fr); }
  }
  @container (max-width: 360px) {
    .zoom button { padding: 6px 8px; }
  }
  #nodeForm h2 { font-size: 17px; }
  #jsonText { font-family: var(--mono); font-size: 12.5px; }

  /* ---------- Listas ---------- */
  .kbItem { padding: 12px 0; border-bottom: 1px solid var(--border); display: flex; gap: 10px; align-items: center; }
  .kbItem:last-child { border-bottom: 0; }
  .kbItem::before { content: ''; width: 34px; height: 34px; border-radius: 9px; flex: none; background: var(--info-soft) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' fill='none' stroke='%232563eb' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' viewBox='0 0 24 24'%3E%3Cpath d='M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z'/%3E%3Cpath d='M14 2v6h6M8 13h8M8 17h5'/%3E%3C/svg%3E") center no-repeat; }
  .kbItem .txt { flex: 1; min-width: 0; }
  .kbItem .txt b { display: block; font-weight: 600; }
  #kbResults > div { border: 1px solid var(--border); border-radius: 10px; padding: 12px; background: var(--surface-2); }
  #kbResults pre { white-space: pre-wrap; background: transparent; border: 0; padding: 6px 0 0; font-family: var(--font); font-size: 13px; color: var(--text-2); }

  /* ---------- Horários ---------- */
  .hours { display: grid; grid-template-columns: 22px 92px minmax(0, 140px) 22px minmax(0, 140px); gap: 10px 8px; align-items: center; }
  .hours label { font-weight: 550; }
  .hours .off { opacity: .4; }
  .hours .sep { color: var(--muted); text-align: center; font-size: 12.5px; }

  /* ---------- Simulador (aparência de celular) ---------- */
  #simLayout { grid-template-columns: minmax(0, 440px) minmax(0, 1fr); }
  .phone { border-radius: 28px !important; padding: 10px !important; background: #111b21 !important; border: 1px solid #222e35 !important; box-shadow: var(--shadow-lg) !important; display: flex; flex-direction: column; }
  .phone .ph-head { display: flex; align-items: center; gap: 10px; padding: 10px 12px 12px; color: #e9edef; }
  .phone .ph-head .avatar { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: linear-gradient(135deg, #22c58f, #0d9467); color: #fff; }
  .phone .ph-head .avatar svg { width: 18px; height: 18px; }
  .phone .ph-head b { display: block; font-size: 14.5px; }
  .phone .ph-head span { font-size: 12px; color: #8696a0; }
  .phone .ph-head select { margin-left: auto; width: 130px; background-color: #202c33; border-color: #2a3942; color: #e9edef; font-size: 12px; padding: 6px 28px 6px 8px; }
  .phone .ph-head button { background: #202c33; border-color: #2a3942; color: #e9edef; box-shadow: none; }
  #simChat {
    background: #0b141a; border-radius: 16px 16px 0 0; flex: 1; min-height: 360px; height: calc(100vh - 360px); overflow-y: auto; padding: 14px 12px; display: flex; flex-direction: column; gap: 6px;
    background-image: radial-gradient(rgba(255,255,255,.035) 1px, transparent 1px); background-size: 16px 16px;
  }
  #simChat:empty::before { content: 'Digite "oi" abaixo para começar, como se fosse o cliente no WhatsApp.'; color: #8696a0; text-align: center; margin: auto; max-width: 240px; font-size: 13px; background: #182229; padding: 10px 14px; border-radius: 10px; }
  .b { max-width: 82%; padding: 7px 10px; border-radius: 10px; background: #202c33; color: #e9edef; white-space: pre-wrap; word-wrap: break-word; align-self: flex-start; font-size: 13.5px; box-shadow: 0 1px .5px rgba(0,0,0,.3); border-top-left-radius: 3px; }
  .b.me { background: #005c4b; align-self: flex-end; border-top-left-radius: 10px; border-top-right-radius: 3px; }
  .b a { color: #53bdeb; }
  .b .choices { display: flex; flex-direction: column; gap: 0; margin: 8px -10px -7px; border-top: 1px solid rgba(255,255,255,.08); }
  .b .choices button { all: unset; cursor: pointer; text-align: center; color: #53bdeb; font: 500 13.5px var(--font); padding: 9px 10px; border-bottom: 1px solid rgba(255,255,255,.06); }
  .b .choices button:last-child { border-bottom: 0; }
  .b .choices button:hover { background: rgba(255,255,255,.04); }
  .sys { align-self: center; font-size: 11.5px; background: #182229; border-radius: 8px; padding: 4px 10px; color: #8696a0; }
  .ph-input { display: flex; gap: 8px; padding: 10px; background: #202c33; border-radius: 0 0 16px 16px; }
  .ph-input input { background: #2a3942; border: 0; color: #e9edef; border-radius: 20px; padding: 10px 16px; }
  .ph-input input::placeholder { color: #8696a0; }
  .ph-input button.primary { border-radius: 50%; width: 42px; height: 42px; padding: 0; background: #00a884; border: 0; color: #fff; }
  .ph-short { display: flex; gap: 6px; flex-wrap: wrap; padding: 10px 4px 2px; }
  .ph-short button { background: #202c33; border-color: #2a3942; color: #d1d7db; box-shadow: none; border-radius: 999px; }
  .ph-short button:hover { background: #2a3942; color: #fff; }
  .steps { display: grid; gap: 14px; margin: 0 0 18px; padding: 0; list-style: none; counter-reset: s; }
  .steps li { display: flex; gap: 12px; color: var(--text-2); counter-increment: s; }
  .steps li::before { content: counter(s); width: 26px; height: 26px; border-radius: 8px; background: var(--accent-soft); color: var(--accent-ink); font-weight: 700; font-size: 12.5px; display: grid; place-items: center; flex: none; }

  /* ---------- Responsivo ---------- */
  @media (max-width: 1360px) {
    #flowLayout { grid-template-columns: 280px minmax(0, 1fr); height: auto; }
    #flowLayout > .card { max-height: calc(100vh - 190px); }
    #diagramCard { grid-column: 1 / -1; height: 70vh; }
  }
  @media (max-width: 1100px) {
    .lay-actions, .lay-2, .lay-kb, .lay-agents, #simLayout { grid-template-columns: 1fr; }
    .sticky { position: static; }
  }
  @media (max-width: 900px) {
    #app { grid-template-columns: 1fr; }
    .side { position: sticky; z-index: 20; height: auto; flex-direction: row; align-items: center; padding: 10px 12px; gap: 10px; overflow-x: auto; }
    .side .brandmark small, .side .group, .side .user, .side .foot a span { display: none; }
    #nav { display: flex; gap: 2px; }
    #nav button { width: auto; padding: 8px 10px; }
    #nav button span { display: none; }
    .side .foot { margin: 0 0 0 auto; border: 0; padding: 0; display: flex; }
    .side .foot a, .side .foot button { width: auto; }
    .page { padding: 18px 14px; }
    #flowLayout { grid-template-columns: 1fr; }
    #flowLayout > .card { max-height: none; }
    #nodeList { max-height: 40vh; }
    #diagramCard { height: 60vh; }
  }
  @media (max-width: 1500px) {
    .pagehead .actions .ghost .lbl { display: none; }
  }
  @media (max-width: 700px) {
    .pagehead .actions .lbl, .flowbar .ghost .lbl { display: none; }
    .card { padding: 16px; }
    .tablewrap { margin: 0 -16px; }
    .flowbar select, .flowbar input { max-width: none; flex-basis: 100%; }
    .flowbar .sep, .flowbar .spacer { display: none; }
    .opt, .opt.list { grid-template-columns: 1fr 1fr; }
    .optHead { display: none; }
    .kv { grid-template-columns: 1fr 1fr 34px; }
    .hours { grid-template-columns: 22px 1fr 1fr 18px 1fr; }
    table.stack thead { display: none; }
    table.stack tr { display: block; border-bottom: 1px solid var(--border); padding: 10px 16px; }
    table.stack td { display: block; border: 0; padding: 3px 0; }
    table.stack td[data-l]::before { content: attr(data-l) ': '; color: var(--muted); font-size: 12px; }
    #simChat { height: 55vh; }
  }

/* Mapa do fluxo (Mermaid): a fonte fica aqui, num arquivo, porque a CSP bloqueia o <style> que o Mermaid
   injeta enquanto mede os textos. Assim a medição e o desenho final usam a mesma fonte (sem rótulo cortado). */
#diagram svg, body > div[id^="dd"] svg { font-family: Inter, system-ui, sans-serif; font-size: 15px; line-height: 1.5; }
#diagram svg .nodeLabel, #diagram svg .edgeLabel, body > div[id^="dd"] svg .nodeLabel, body > div[id^="dd"] svg .edgeLabel { font-family: inherit; font-size: inherit; line-height: inherit; }
