/* Editor de canvas. */
.ed-host { height: 100vh; }
.ed { display: grid; grid-template-rows: 52px 1fr; height: 100vh; position: relative; }
.ed-top { display: flex; align-items: center; gap: var(--space-2); padding: 0 var(--space-3); border-bottom: 1px solid var(--line); background: var(--bg); z-index: 5; }
.ed-saved { color: var(--dim); font-size: var(--text-xs); white-space: nowrap; }
.ed-body { position: relative; display: grid; grid-template-columns: 64px 1fr 360px; min-height: 0; }
.ed.sem-painel .ed-body { grid-template-columns: 64px 1fr 0; }
.ed.sem-painel .ed-agent { display: none; }


.ed-stage { position: relative; overflow: hidden; outline: none; cursor: default; touch-action: none;
  background-color: var(--bg); background-image: radial-gradient(var(--hi-08) 1px, transparent 1.2px); }
.ed-stage.hand, .ed-stage.pan-ready { cursor: grab; }
.ed-stage.panning { cursor: grabbing; }
.ed-stage.drop { box-shadow: inset 0 0 0 2px var(--pri); }
.ed-world { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.ed-edges { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; }
.ed-line { fill: none; stroke: var(--line2); stroke-width: 2; }
.ed-line.sel { stroke: var(--pri-lt); stroke-width: 2.5; }
.ed-line.tmp { stroke: var(--pri-lt); stroke-dasharray: 6 5; }
.ed-hit { fill: none; stroke: transparent; stroke-width: 14; pointer-events: stroke; cursor: pointer; }
.ed-cut { pointer-events: all; cursor: pointer; }
.ed-cut circle { fill: var(--danger-solid); }
.ed-cut path { stroke: #fff; stroke-width: 2; stroke-linecap: round; }
.ed-marquee { position: absolute; border: 1px solid var(--pri-lt); background: var(--pri-a08); pointer-events: none; }

/* Nó */
.nd { position: absolute; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow-md), var(--edge-hi); user-select: none; }
.nd::before { content: ''; position: absolute; left: 12px; right: 12px; top: -1px; height: 2px; border-radius: 2px; background: var(--nd-cor); opacity: 0.8; }
.nd.sel { border-color: var(--pri); box-shadow: 0 0 0 1px var(--pri), var(--shadow-lg); }
.nd.alvo { border-color: var(--pri-lt); box-shadow: 0 0 0 3px var(--pri-a35); }
.nd-head { display: flex; align-items: center; gap: 6px; height: 44px; padding: 0 6px 0 12px; border-bottom: 1px solid var(--line); cursor: grab; }
.nd-head > .ic { color: var(--nd-cor); }
.nd-title { flex: 1; min-width: 0; background: transparent; border: 1px solid transparent; padding: 3px 6px; font-weight: var(--weight-semibold); font-size: var(--text-sm); border-radius: var(--radius-sm); }
.nd-title:hover { border-color: var(--line); }
.nd-title:focus { box-shadow: none; cursor: text; }
.nd-title:not(:focus) { cursor: grab; }
.nd-kind { font-size: 12px; color: var(--dim); }
.nd-more { width: 28px; height: 28px; }
.nd-body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 8px; cursor: grab; }
.nd-body textarea { width: 100%; min-height: 64px; font-size: var(--text-sm); user-select: text; cursor: text; background: var(--card); }
.nd-hint { font-size: var(--text-xs); color: var(--dim); line-height: var(--leading-wrap); }
.nd-meta { font-size: 12px; color: var(--dim); }
.nd-params { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.nd-params label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--dim); }
.nd-params select { height: 30px; padding: 0 6px; font-size: var(--text-xs); background: var(--card); }
.nd-actions { display: flex; justify-content: flex-end; gap: 6px; }
.nd-out { border-radius: var(--radius); border: 1px dashed var(--line2); background: var(--card); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; color: var(--dim); font-size: var(--text-xs); text-align: center; padding: 10px; max-height: 260px; min-height: 80px; width: 100%; }
.nd-audio .nd-out { min-height: 64px; }
.nd-out.is-pending { border: 1px solid var(--attention-line); background: var(--attention-soft); color: var(--attention-ink); }
.nd-out.is-pending strong { font-size: var(--text-sm); }
.nd-saida { border-radius: var(--radius); border: 1px solid var(--line2); background: var(--card); color: var(--fg); font-size: var(--text-xs); line-height: var(--leading-wrap); white-space: pre-wrap; padding: 10px; max-height: 220px; overflow: auto; user-select: text; }
.nd-note { min-height: 110px !important; background: color-mix(in srgb, var(--cat-lime) 10%, var(--card)) !important; border-color: transparent !important; }
.nd-drop { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 22px 10px; border: 1px dashed var(--line2); border-radius: var(--radius); color: var(--mut); cursor: pointer; text-align: center; font-size: var(--text-sm); }
.nd-drop small { color: var(--dim); font-size: 12px; }
.nd-drop:hover { border-color: var(--nd-cor); color: var(--fg); }
.nd-ref { border-radius: var(--radius); overflow: hidden; background: var(--card); min-height: 80px; display: grid; place-items: center; }
.nd-ref img, .nd-ref video { display: block; width: 100%; max-height: 220px; object-fit: contain; }
.nd-ref audio { width: 100%; }
.nd-ref-load { color: var(--dim); font-size: var(--text-xs); padding: 20px; }
.nd-res-grade { grid-template-columns: 1fr 1fr; gap: 2px; place-items: stretch; }
.nd-res-grade img { height: 100%; max-height: 140px; object-fit: cover; }
.nd-file { display: flex; align-items: center; gap: 6px; font-size: var(--text-xs); color: var(--mut); }
.nd-file span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nd-file label { cursor: pointer; }
.port { position: absolute; top: 15px; width: 14px; height: 14px; border-radius: 50%; background: var(--panel); border: 2px solid var(--nd-cor); }
.port.in { left: -8px; }
.port.out { right: -8px; cursor: crosshair; }
.port.out:hover { background: var(--nd-cor); transform: scale(1.25); }

.ed-empty { position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%); text-align: center; max-width: 420px; padding: var(--space-6); border: 1px dashed var(--line2); border-radius: var(--radius-lg); background: rgba(15, 15, 21, 0.7); }
.ed-empty h3 { font-size: var(--text-xl); margin-bottom: 6px; }
.ed-empty p { color: var(--mut); margin: 0 0 var(--space-4); }
.ed-empty .row { justify-content: center; }
.ed-pop { position: absolute; z-index: 20; min-width: 200px; padding: 6px; border-radius: var(--radius); background: var(--card); border: 1px solid var(--line2); box-shadow: var(--shadow-lg); display: flex; flex-direction: column; }
.ed-pop button { display: flex; align-items: center; gap: 10px; height: 34px; padding: 0 10px; border-radius: var(--radius-sm); font-size: var(--text-sm); text-align: left; }
.ed-pop button:hover, .ed-pop button:focus-visible { background: var(--hi-08); outline: none; }
.ed-pop button.perigo { color: var(--danger-ink); }
.ed-pop hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }

/* Barra do projeto */
.ed-proj { display: flex; align-items: center; gap: 4px; padding: 3px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
.ed-name { background: transparent; border: 1px solid transparent; font-weight: var(--weight-semibold); font-size: var(--text-base); padding: 4px 8px; width: min(260px, 24vw); cursor: default; }
.ed-name[readonly]:focus { box-shadow: none; border-color: transparent; }
.ed-name:not([readonly]) { cursor: text; border-color: var(--pri); }
.ed-name:hover { border-color: var(--line); }
.ed-brand { display: flex; align-items: center; gap: 8px; opacity: 0.9; }
.ed-brand .wordmark { font-size: 12px; }
.ed-app { display: inline-flex; align-items: center; gap: 6px; padding-left: 8px; border-left: 1px solid var(--line2); font-family: var(--type-display); font-weight: var(--weight-bold); font-size: 13px; }
.ed-app img { border-radius: 4px; }
.ed-tk-n { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 99px; background: var(--attention-line); color: var(--fg); font-size: 11px; display: inline-grid; place-items: center; }

/* Lateral esquerda: Adicionar, Fluxos, Recursos, Histórico, Atalhos */
.ed-side { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: var(--space-3) 0; border-right: 1px solid var(--line); background: var(--bg); z-index: 6; }
.tool { width: 54px; min-height: 52px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; border-radius: var(--radius); color: var(--mut); font-size: 11px; font-weight: var(--weight-medium); }
.tool:hover { background: var(--hi-08); color: var(--fg); }
.tool.on { background: var(--pri-a16); color: var(--pri-lt); }
.ed-fly { position: absolute; left: 64px; top: 0; bottom: 0; width: 300px; z-index: 7; background: var(--panel); border-right: 1px solid var(--line); box-shadow: var(--shadow-lg); padding: 14px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; animation: fly-in var(--dur-base) var(--ease-out); }
@keyframes fly-in { from { opacity: 0; transform: translateX(-8px); } }
.fly-head { display: flex; align-items: center; justify-content: space-between; }
.fly-head h3 { font-size: var(--text-lg); }
.fly-sub { margin: -4px 0 0; color: var(--dim); font-size: var(--text-xs); }
.fly-sec { font-size: var(--text-xs); text-transform: uppercase; letter-spacing: var(--tracking-caps); color: var(--dim); font-weight: var(--weight-semibold); margin-top: 6px; }
.fly-list { display: flex; flex-direction: column; gap: 4px; }
.fly-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius); border: 1px solid transparent; text-align: left; cursor: pointer; color: var(--fg); }
.fly-item .ic { color: var(--nd-cor, var(--pri-lt)); flex: none; }
.fly-item:hover { background: var(--hi-08); border-color: var(--line); }
.fly-item span { display: flex; flex-direction: column; min-width: 0; }
.fly-item b { font-size: var(--text-sm); font-weight: var(--weight-semibold); }
.fly-item small { color: var(--dim); font-size: 12px; }
.fly-rc { padding: 0 4px 0 0; }
.fly-rc > button:first-child { flex: 1; display: flex; align-items: center; gap: 10px; padding: 8px 10px; text-align: left; min-width: 0; }
.fly-rc > .icon-btn .ic { color: var(--mut); }
.fly-vazio { color: var(--dim); font-size: var(--text-xs); margin: 4px 2px; }
.fly-imp { align-self: flex-start; margin-top: 6px; cursor: pointer; }

/* Grupos */
.gr { position: absolute; border-radius: 16px; border: 1.5px dashed color-mix(in srgb, var(--gr-cor) 70%, transparent); background: color-mix(in srgb, var(--gr-cor) 6%, transparent); pointer-events: none; }
.gr-sb { border-style: solid; }
.gr-head { position: absolute; left: 10px; right: 10px; top: 8px; height: 30px; display: flex; align-items: center; gap: 8px; pointer-events: auto; cursor: grab; font-size: var(--text-sm); }
.gr-head b { font-weight: var(--weight-semibold); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gr-dot { width: 10px; height: 10px; border-radius: 3px; background: var(--gr-cor); flex: none; }
.gr-n { color: var(--dim); font-size: 12px; }
.gr-tag { font-size: 11px; color: var(--mut); border: 1px solid var(--line2); border-radius: 99px; padding: 1px 8px; white-space: nowrap; }
.gr-head .btn { margin-left: auto; }
.gr-head .icon-btn { width: 28px; height: 28px; }
.gr-cores { display: flex; gap: 8px; flex-wrap: wrap; }
.gr-cor { width: 28px; height: 28px; border-radius: 8px; background: var(--gr-cor); cursor: pointer; position: relative; display: block !important; }
.gr-cor input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.gr-cor:has(input:checked) { box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--fg); }
.gr-cor:has(input:focus-visible) { outline: var(--focus-outline); outline-offset: 4px; }
.nd-num { min-width: 22px; height: 20px; padding: 0 5px; border-radius: 6px; background: var(--gr-cor); color: #070609; font-size: 12px; font-weight: var(--weight-bold); display: inline-grid; place-items: center; }

/* Nó de texto: modo. Nó de roteiro: tabela editável */
.nd-modo { display: flex !important; flex-direction: row !important; align-items: center; gap: 8px; font-size: 12px; color: var(--dim); }
.nd-modo select { flex: 1; height: 28px; padding: 0 6px; font-size: var(--text-xs); background: var(--card); }
.nd-tab-bar { display: flex; gap: 6px; align-items: center; }
.nd-tab-bar input { flex: 1; min-width: 0; height: 26px; padding: 0 8px; font-size: var(--text-xs); background: var(--card); }
.nd-tab-wrap { max-height: 300px; overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); cursor: default; user-select: text; }
.nd-tab { width: 100%; border-collapse: collapse; font-size: var(--text-xs); }
.nd-tab th { position: sticky; top: 0; background: var(--card); color: var(--dim); font-weight: var(--weight-semibold); text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.nd-tab td { padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; min-width: 40px; word-break: break-word; }
.nd-tab td[data-cell]:hover { background: var(--hi-08); cursor: text; }
.nd-tab td[contenteditable="true"] { outline: 2px solid var(--pri); outline-offset: -2px; background: var(--card); }
.nd-tab-n { color: var(--dim); width: 28px; }
.nd-tab-x { width: 22px; height: 22px; opacity: 0.5; }
.nd-tab tr:hover .nd-tab-x { opacity: 1; }
.nd-tab-vazio { text-align: center; color: var(--dim); padding: 16px !important; }
.nd-actions { flex-wrap: wrap; align-items: center; }
.nd-actions .grow { flex: 1; }

/* Barra de controle (canto inferior esquerdo) e minimapa */
.ed-ctrl { position: absolute; left: 12px; bottom: 12px; display: flex; align-items: center; gap: 2px; padding: 3px 6px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow-md); z-index: 4; }
.ed-ctrl i { width: 1px; height: 20px; background: var(--line); margin: 0 4px; }
.ed-ctrl .icon-btn { width: 30px; height: 30px; }
.ed-ctrl .icon-btn.on { background: var(--pri-a16); color: var(--pri-lt); }
.ed-ctrl input[type="range"] { width: 110px; accent-color: var(--pri); padding: 0; border: 0; background: none; box-shadow: none; }
.ed-pct { min-width: 40px; text-align: center; font-size: var(--text-xs); color: var(--mut); font-variant-numeric: tabular-nums; }
.ed-mini-box { position: absolute; left: 12px; bottom: 58px; padding: 6px; border-radius: var(--radius); background: rgba(15, 15, 21, 0.92); border: 1px solid var(--line); box-shadow: var(--shadow-lg); z-index: 4; }
.ed-mini { display: block; width: 220px; height: 140px; cursor: pointer; }

/* Menus: título, caixas de seleção, painel de tarefas */
.ed-pop button span { flex: 1; }
.ed-pop kbd { font-size: 11px; color: var(--dim); }
.pop-t { padding: 6px 10px 4px; font-size: 12px; color: var(--dim); font-weight: var(--weight-semibold); text-transform: uppercase; letter-spacing: var(--tracking-caps); }
.pop-chk { display: flex; align-items: center; gap: 8px; height: 30px; padding: 0 10px; font-size: var(--text-sm); cursor: pointer; border-radius: var(--radius-sm); }
.pop-chk:hover { background: var(--hi-08); }
.ed-tasks { width: 330px; max-height: 70vh; overflow-y: auto; }
.tk-sec { display: flex; flex-direction: column; gap: 2px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.tk-sec span { font-size: 12px; color: var(--dim); text-transform: uppercase; letter-spacing: var(--tracking-caps); font-weight: var(--weight-semibold); }
.tk-sec small { color: var(--dim); font-size: 12px; }
.tk-pend { color: var(--attention-ink); }
.tk-list { display: flex; flex-direction: column; padding: 4px 0; }
.tk-list p { padding: 6px 10px; margin: 0; font-size: var(--text-xs); }
.ed-pop .tk-list button { height: auto; padding: 6px 10px; }
.tk-list button span { display: flex; flex-direction: column; min-width: 0; }
.tk-list small { color: var(--dim); font-size: 12px; }
.tk-list em { font-style: normal; font-size: 11px; color: var(--attention-ink); }

/* Painel do agente */
.ed-agent { display: flex; flex-direction: column; min-height: 0; border-left: 1px solid var(--line); background: var(--panel); }
.ag-head { display: flex; align-items: center; justify-content: space-between; padding: 0 8px 0 16px; height: 48px; border-bottom: 1px solid var(--line); font-weight: var(--weight-semibold); }
.ag-head span { display: flex; align-items: center; gap: 8px; }
.ag-head .ic { color: var(--pri-lt); }
.ag-skill { border-bottom: 1px solid var(--line); }
.ag-skill-cover { height: 72px; padding: 8px; display: flex; justify-content: flex-end; align-items: flex-start; }
.ag-skill-info { padding: 12px 16px 14px; display: flex; flex-direction: column; gap: 6px; }
.ag-skill-info h4 { font-size: var(--text-lg); }
.ag-skill-info p { margin: 0; color: var(--mut); font-size: var(--text-xs); line-height: var(--leading-wrap); }
.ag-need { color: var(--fg) !important; }
.ag-steps { margin: 4px 0; padding-left: 18px; color: var(--mut); font-size: var(--text-xs); display: flex; flex-direction: column; gap: 3px; }
.ag-skill-btns { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.ag-empty { padding: 16px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.ag-empty p { margin: 0; color: var(--mut); font-size: var(--text-sm); }
.ag-sugs { display: flex; flex-wrap: wrap; gap: 6px; }
.ag-sugs .pill { height: 28px; font-size: 12px; }
.ag-msgs { flex: 1; overflow-y: auto; padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.ag-hint { color: var(--dim); font-size: var(--text-sm); text-align: center; margin: auto 0; }
.msg { max-width: 92%; padding: 8px 12px; border-radius: 12px; font-size: var(--text-sm); line-height: var(--leading-wrap); }
.msg p { margin: 0; white-space: pre-wrap; }
.msg-voce { align-self: flex-end; background: var(--btn); color: var(--ink-on-accent); border-bottom-right-radius: 4px; }
.msg-agente { align-self: flex-start; background: var(--card); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg-who { display: block; font-size: 12px; color: var(--pri-lt); font-weight: var(--weight-semibold); margin-bottom: 2px; }
.ag-form { display: flex; align-items: flex-end; gap: 8px; padding: 12px; border-top: 1px solid var(--line); }
.ag-form textarea { flex: 1; resize: none; max-height: 160px; background: var(--card); }

@media (max-width: 980px) {
  .ed-body, .ed.sem-painel .ed-body { grid-template-columns: 56px 1fr 0; }
  .tool { width: 48px; }
  .ed-fly { left: 56px; width: min(300px, calc(100vw - 64px)); }
  .ed-brand .wordmark, .ed-tk > span { display: none; }
  .ed:not(.sem-painel) .ed-agent { display: flex; position: absolute; right: 0; top: 52px; bottom: 0; width: min(360px, 100%); z-index: 10; box-shadow: var(--shadow-lg); }
  .ed-saved { display: none; }
  .ed-ctrl input[type="range"] { display: none; }
  .ed-top .btn span { display: none; }
  .ed-name { width: 30vw; }
}
