"use strict"; const $ = (id) => document.getElementById(id); const esc = (s) => String(s ?? "").replace(/[&<>"']/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" }[c])); const fmtD = (iso) => { const m = String(iso || "").match(/^(\d{4})-(\d{2})-(\d{2})/); return m ? `${m[3]}/${m[2]}/${m[1]}` : "—"; }; const dayNum = (iso) => { const m = String(iso || "").match(/^(\d{4})-(\d{2})-(\d{2})/); return m ? Date.UTC(+m[1], +m[2] - 1, +m[3]) / 86400000 : NaN; }; // Preços do claude-opus-5 (USD por 1M tokens) para o custo estimado no rodapé. const PRECO = { input: 5, output: 25, cache_read: 0.5, cache_write: 6.25 }; let statusApp = null; let sdAtual = null; // { id, numero, status, chat, rascunho, validacao, bloqueios, uso } let ocupado = false; let modoExterno = false; // tela "Validar JSON externo" let externo = null; // { sd, exportado, validacao, bloqueios } let ultimosBloqueios = []; // ---------- Markdown mínimo (negrito, código, títulos, listas, OPCAO:) ---------- function renderMd(texto) { const linhas = String(texto || "").split("\n"); const out = []; let lista = null; // "ul" | "ol" const fechaLista = () => { if (lista) { out.push(``); lista = null; } }; const inline = (s) => esc(s) .replace(/\*\*([^*]+)\*\*/g, "$1") .replace(/`([^`]+)`/g, "$1"); for (const raw of linhas) { const l = raw.trimEnd(); if (/^OPCAO:/i.test(l.trim())) continue; // vira botão, não texto const h = l.match(/^(#{1,4})\s+(.*)/); const ul = l.match(/^\s*[-•]\s+(.*)/); const ol = l.match(/^\s*\d+[.)]\s+(.*)/); if (h) { fechaLista(); out.push(`

${inline(h[2])}

`); } else if (ul) { if (lista !== "ul") { fechaLista(); out.push("