:root {
  --bg: #f7f6f2;
  --grid: #e7e4dc;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #d6d3cb;
  --panel: #ffffff;
  --accent: #4f46e5;
  --accent-soft: #eef2ff;
  --negocio: #4f46e5;
  --pessoa: #0e9f6e;
  --ideia: #d97706;
  --produto: #0891b2;
  --nota: #ca8a04;
  --ok: #16a34a;
  --warn: #eab308;
  --bad: #dc2626;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 14px rgba(0,0,0,.07);
  --radius: 14px;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); overflow: hidden; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }

/* ---------- barra de ferramentas ---------- */
#barra {
  position: fixed; top: 10px; left: 50%; transform: translateX(-50%); z-index: 20;
  display: flex; gap: 4px; align-items: center; padding: 6px; background: var(--panel);
  border-radius: 16px; box-shadow: var(--shadow); max-width: calc(100vw - 20px); overflow-x: auto;
}
#barra-dir { position: fixed; top: 10px; right: 10px; z-index: 21; display: flex; gap: 2px; align-items: center; padding: 6px; background: var(--panel); border-radius: 16px; box-shadow: var(--shadow); }
#barra { left: 10px; transform: none; max-width: calc(100vw - 420px); }
#barra .sep { width: 1px; height: 26px; background: var(--line); margin: 0 4px; flex: none; }
.ferr {
  border: 0; background: transparent; border-radius: 10px; min-width: 38px; height: 38px; padding: 0 9px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; font-size: 14px; white-space: nowrap; flex: none;
}
.ferr:hover { background: #f1f0ec; }
.ferr.ativo { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.ferr .k { font-size: 10px; color: var(--muted); }
#cores { display: inline-flex; gap: 5px; align-items: center; padding: 0 4px; flex: none; }
.cor { width: 22px; height: 22px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line); flex: none; padding: 0; }
.cor.ativo { box-shadow: 0 0 0 2px var(--accent); }
#marca { font-weight: 700; padding: 0 8px; letter-spacing: -.02em; flex: none; }
#salvo { font-size: 12px; color: var(--muted); padding: 0 8px; flex: none; min-width: 70px; }
#salvo.erro { color: var(--bad); font-weight: 600; }

/* ---------- área infinita ---------- */
#viewport {
  position: fixed; inset: 0; touch-action: none; user-select: none; -webkit-user-select: none;
  background-color: var(--bg);
  background-image: radial-gradient(var(--grid) 1.2px, transparent 1.2px);
}
#viewport.mao { cursor: grab; }
#viewport.arrastando { cursor: grabbing; }
#viewport.caneta { cursor: crosshair; }
#viewport.borracha { cursor: cell; }
#mundo { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
#svg { position: absolute; left: -50000px; top: -50000px; width: 100000px; height: 100000px; overflow: visible; pointer-events: none; }
.aresta { fill: none; stroke: #9ca3af; stroke-width: 2.2; }
.aresta.sinergia { stroke: #a855f7; stroke-dasharray: 8 6; }
.aresta.socio { stroke: #0e9f6e; stroke-width: 2; stroke-dasharray: 2 5; stroke-linecap: round; }
.aresta.sel { stroke: var(--accent); stroke-width: 3.5; }
.aresta-hit { fill: none; stroke: transparent; stroke-width: 18; pointer-events: stroke; cursor: pointer; }
.rotulo { font-size: 13px; fill: #4b5563; paint-order: stroke; stroke: var(--bg); stroke-width: 5px; stroke-linejoin: round; pointer-events: none; }
.traco { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.traco.sel { filter: drop-shadow(0 0 3px rgba(79,70,229,.8)); }
#caixa-sel { fill: rgba(79,70,229,.08); stroke: var(--accent); stroke-dasharray: 4 4; }

/* ---------- nós (balões) ---------- */
.no {
  position: absolute; transform: translate(-50%, -50%); width: max-content; min-width: 150px; max-width: 280px; padding: 10px 14px 10px;
  background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); border: 2px solid transparent;
  border-top: 5px solid var(--c); cursor: default; touch-action: none;
}
.no .titulo { font-weight: 650; font-size: 15px; line-height: 1.25; word-break: break-word; }
.no .sub { display: flex; gap: 8px; align-items: center; font-size: 12px; color: var(--muted); margin-top: 5px; flex-wrap: wrap; }
.no .tipo { text-transform: uppercase; letter-spacing: .05em; font-size: 10px; font-weight: 700; color: var(--c); }
.no .emo { position: absolute; top: -14px; right: -10px; font-size: 22px; filter: drop-shadow(0 1px 1px rgba(0,0,0,.2)); }
.no .saude { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.no .dinheiro.pos { color: var(--ok); font-weight: 600; }
.no .dinheiro.neg { color: var(--bad); font-weight: 600; }
.no.negocio { --c: var(--negocio); min-width: 200px; padding: 14px 18px; }
.no.negocio .titulo { font-size: 19px; }
.no.pessoa { --c: var(--pessoa); border-radius: 999px; border-top-width: 2px; border-color: var(--pessoa); min-width: 0; padding: 8px 16px; text-align: center; }
.no.pessoa .sub { justify-content: center; }
.no.ideia { --c: var(--ideia); border-radius: 26px; border: 2px dashed var(--ideia); }
.no.produto { --c: var(--produto); }
.no.nota { --c: var(--nota); background: #fef9c3; border-radius: 4px; transform: translate(-50%,-50%) rotate(-1deg); }
.no.sel { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79,70,229,.25), var(--shadow); }
.no.pessoa.sel { border-color: var(--accent); }
.no.alvo { box-shadow: 0 0 0 4px rgba(14,159,110,.45), var(--shadow); }
.no .alca {
  position: absolute; right: -15px; top: 50%; transform: translateY(-50%); width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent); color: #fff; display: none; align-items: center; justify-content: center; font-size: 18px; line-height: 1;
  box-shadow: var(--shadow); cursor: crosshair; touch-action: none;
}
.no.sel .alca { display: flex; }
.no.realce { animation: pisca 1.2s ease 2; }
@keyframes pisca { 50% { box-shadow: 0 0 0 10px rgba(79,70,229,.25); } }

/* ---------- painel lateral ---------- */
#painel {
  position: fixed; top: 64px; right: 10px; bottom: 10px; width: min(440px, calc(100vw - 20px)); z-index: 15;
  background: var(--panel); border-radius: 16px; box-shadow: var(--shadow); display: none; flex-direction: column; overflow: hidden;
}
#painel.aberto { display: flex; }
#painel header { padding: 14px 16px 8px; border-bottom: 1px solid #eee; }
#painel header input.titulo { width: 100%; font-size: 20px; font-weight: 700; border: 0; outline: 0; padding: 2px 0; background: transparent; }
#painel .abas { display: flex; gap: 2px; margin-top: 8px; overflow-x: auto; }
#painel .abas button { border: 0; background: transparent; padding: 6px 10px; border-radius: 8px; font-size: 13px; color: var(--muted); white-space: nowrap; }
#painel .abas button.ativo { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
#painel .corpo { padding: 14px 16px 24px; overflow-y: auto; flex: 1; }
#painel .fechar { position: absolute; right: 10px; top: 10px; border: 0; background: transparent; font-size: 20px; color: var(--muted); }
.campo { margin-bottom: 14px; }
.campo > label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 5px; text-transform: uppercase; letter-spacing: .04em; }
.campo input, .campo select, .campo textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: #fff; outline-color: var(--accent);
}
.campo textarea { min-height: 90px; resize: vertical; line-height: 1.45; }
.linha { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.linha2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 5px 10px; font-size: 13px; }
.chip.ativo { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.chip.emo { font-size: 13px; }
.cartao { border: 1px solid #eee; border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; background: #fcfcfb; }
.cartao .topo { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.cartao small { color: var(--muted); }
.botao { border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 8px 12px; font-size: 14px; }
.botao.prim { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.botao.perigo { color: var(--bad); border-color: #fecaca; }
.botao:disabled { opacity: .5; cursor: default; }
.resumo-fin { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.resumo-fin div { background: #f8f8f6; border-radius: 10px; padding: 8px; text-align: center; }
.resumo-fin b { display: block; font-size: 15px; }
.resumo-fin span { font-size: 11px; color: var(--muted); text-transform: uppercase; }
.md { line-height: 1.55; font-size: 14px; }
.md h1, .md h2, .md h3 { margin: 1em 0 .4em; line-height: 1.25; }
.md h1 { font-size: 20px; } .md h2 { font-size: 17px; } .md h3 { font-size: 15px; }
.md code { background: #f3f4f6; padding: 1px 4px; border-radius: 4px; }
.vazio { color: var(--muted); font-size: 14px; padding: 8px 0; }

/* ---------- barra da IA ---------- */
#ia-barra {
  position: fixed; left: 50%; bottom: 14px; transform: translateX(-50%); z-index: 18; display: flex; gap: 6px; align-items: center;
  background: var(--panel); border-radius: 16px; box-shadow: var(--shadow); padding: 6px; width: min(720px, calc(100vw - 20px));
}
#ia-barra input { flex: 1; border: 0; outline: 0; padding: 8px 10px; background: transparent; min-width: 0; }
#ia-barra .botao { white-space: nowrap; }

/* ---------- modais ---------- */
.modal-fundo { position: fixed; inset: 0; background: rgba(17,24,39,.35); z-index: 40; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: var(--panel); border-radius: 18px; box-shadow: var(--shadow); width: min(980px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; overflow: hidden; }
.modal header { padding: 14px 18px; border-bottom: 1px solid #eee; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.modal header h2 { margin: 0; font-size: 18px; }
.modal .conteudo { padding: 16px 18px; overflow: auto; }
.modal footer { padding: 12px 18px; border-top: 1px solid #eee; display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
table.macro { width: 100%; border-collapse: collapse; font-size: 14px; }
table.macro th { text-align: left; font-size: 11px; text-transform: uppercase; color: var(--muted); letter-spacing: .04em; padding: 8px; border-bottom: 1px solid #eee; position: sticky; top: 0; background: #fff; }
table.macro td { padding: 9px 8px; border-bottom: 1px solid #f2f2f0; vertical-align: top; }
table.macro tr.clic:hover td { background: #fafaf8; cursor: pointer; }
table.macro td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.macro tfoot td { font-weight: 700; border-top: 2px solid #eee; }
.pos { color: var(--ok); } .neg { color: var(--bad); }
.term-log { background: #0f172a; color: #e2e8f0; font-family: ui-monospace, "SFMono-Regular", Menlo, monospace; font-size: 12.5px; border-radius: 12px; padding: 12px; min-height: 260px; max-height: 50vh; overflow: auto; white-space: pre-wrap; }
.term-log .f { color: #93c5fd; } .term-log .a { color: #fbbf24; } .term-log .ok { color: #86efac; } .term-log .er { color: #fca5a5; }
.op-lista label { display: flex; gap: 8px; align-items: flex-start; padding: 6px 0; border-bottom: 1px solid #f3f3f1; font-size: 14px; }
.toast { position: fixed; left: 50%; bottom: 80px; transform: translateX(-50%); background: #111827; color: #fff; padding: 10px 16px; border-radius: 12px; z-index: 60; font-size: 14px; max-width: calc(100vw - 32px); }
.carregando::after { content: ""; display: inline-block; width: 12px; height: 12px; margin-left: 8px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: gira .8s linear infinite; vertical-align: -2px; }
@keyframes gira { to { transform: rotate(360deg); } }

/* ---------- login ---------- */
.login { display: flex; align-items: center; justify-content: center; height: 100%; }
.login form { background: #fff; padding: 28px; border-radius: 18px; box-shadow: var(--shadow); width: min(360px, calc(100vw - 32px)); }
.login h1 { margin: 0 0 4px; font-size: 22px; }
.login p { margin: 0 0 18px; color: var(--muted); font-size: 14px; }

body:has(#painel.aberto) #ia-barra { left: 10px; transform: none; width: calc(100vw - 480px); min-width: 320px; }

@media (max-width: 1500px) {
  #barra [data-novo] .rot, #b-arrumar .rot { display: none; }
}
@media (max-width: 1100px) {
  #barra .rot { display: none; }
  #barra { max-width: calc(100vw - 20px); top: 66px; }
  #barra-dir { left: 10px; right: auto; }
  #painel { top: 122px; }
}
@media (max-width: 900px) {
  body:has(#painel.aberto) #ia-barra { display: none; }
}
@media (max-width: 700px) {
  #barra { top: 62px; }
  #barra-dir .rot { display: none; }
  #ia-barra { bottom: 8px; }
  #painel { top: auto; height: 62vh; }
  .ferr .rot { display: none; }
}
