/* =========================================================
   Mapa Mental — estilos
   Ajuste as cores do tema nas variáveis abaixo.
   ========================================================= */
:root {
  --bg: #f5f6f8;
  --grid: #d9dde3;
  --bar: #ffffff;
  --pill: #f1f3f5;
  --surface: #ffffff;
  --surface-2: #f1f3f5;
  --text: #1f2328;
  --muted: #6b7280;
  --border: #e2e5e9;
  --accent: #4263eb;
  --accent-soft: rgba(66, 99, 235, .12);
  --root-bg: #1f2a44;
  --root-text: #ffffff;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 3px 10px rgba(16, 24, 40, .06);
  --shadow-lg: 0 10px 30px rgba(16, 24, 40, .18);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --spd: 1;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111215; --grid: #26292f; --bar: #050506; --pill: #1b1c20; --surface: #1d2026; --surface-2: #262a31;
    --text: #e8eaed; --muted: #9aa0a6; --border: #30353e; --accent: #748ffc;
    --accent-soft: rgba(116, 143, 252, .18); --root-bg: #e8eaed; --root-text: #15171c;
    --shadow: 0 1px 2px rgba(0,0,0,.4); --shadow-lg: 0 10px 30px rgba(0,0,0,.55);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111215; --grid: #26292f; --bar: #050506; --pill: #1b1c20; --surface: #1d2026; --surface-2: #262a31;
  --text: #e8eaed; --muted: #9aa0a6; --border: #30353e; --accent: #748ffc;
  --accent-soft: rgba(116, 143, 252, .18); --root-bg: #e8eaed; --root-text: #15171c;
  --shadow: 0 1px 2px rgba(0,0,0,.4); --shadow-lg: 0 10px 30px rgba(0,0,0,.55);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font); color: var(--text); background: var(--bg);
  display: flex; flex-direction: column; overflow: hidden; font-size: 14px;
}
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- Ícones e botões ---------- */
.i { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.i.sm { width: 12px; height: 12px; margin-left: -2px; }
.btn, .icon-btn {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; border: 1px solid transparent;
  background: transparent; border-radius: 8px; cursor: pointer; padding: 0 10px; white-space: nowrap;
}
.icon-btn { width: 32px; padding: 0; justify-content: center; }
.icon-btn.wide-btn { width: auto; padding: 0 6px; gap: 2px; }
.btn:hover, .icon-btn:hover { background: var(--surface-2); }
.btn:disabled, .icon-btn:disabled { opacity: .35; cursor: default; background: transparent; }
.icon-btn.active { color: var(--accent); background: var(--accent-soft); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.wide { width: 100%; justify-content: center; border-color: var(--border); }
.btn.danger { color: #e03131; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
select {
  height: 32px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); padding: 0 8px; cursor: pointer;
}
select.full { width: 100%; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---------- Barra superior compacta ---------- */
.topbar {
  height: 52px; flex: none; display: flex; align-items: center; gap: 10px;
  padding: 0 12px; background: var(--bar); border-bottom: 1px solid var(--border); z-index: 20;
}
.tb-left, .tb-center, .tb-right { display: flex; align-items: center; gap: 8px; min-width: 0; }
.tb-left { flex: 1 1 0; }
.tb-right { flex: 1 0 auto; justify-content: flex-end; }
.tb-center { flex: none; }
.pill { display: flex; align-items: center; gap: 2px; padding: 3px; background: var(--pill); border-radius: 10px; }
.pill .icon-btn:hover { background: var(--surface-2); }
.icon-btn.boxed { background: var(--pill); width: 34px; height: 34px; border-radius: 10px; }
.doc-meta { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.15; }
.title-input {
  border: 1px solid transparent; background: transparent; border-radius: 6px; padding: 1px 4px; margin-left: -4px;
  font-weight: 700; font-size: 14px; width: 100%; max-width: 260px; min-width: 0; text-overflow: ellipsis;
}
.title-input:hover { border-color: var(--border); }
.title-input:focus { border-color: var(--accent); outline: none; background: var(--surface); }
.status { color: var(--muted); font-size: 11px; white-space: nowrap; }

/* ---------- Área de trabalho ---------- */
.workspace { flex: 1; display: flex; min-height: 0; position: relative; }
.stage { flex: 1; position: relative; display: flex; min-width: 0; }

#viewport {
  flex: 1; position: relative; overflow: hidden; cursor: default; outline: none; touch-action: none;
  background-color: var(--bg);
  background-image: radial-gradient(var(--grid) 1.2px, transparent 1.2px);
  background-size: 22px 22px;
}
#viewport.panning { cursor: grabbing; }
#world { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
#edges { position: absolute; left: 0; top: 0; width: 1px; height: 1px; overflow: visible; pointer-events: none; }
#nodes, #stickers { position: absolute; left: 0; top: 0; }

/* =========================================================
   Tópicos
   Cada caixa usa 3 variáveis: --bg-node (fundo), --fg-node (texto) e --bd-node (borda).
   O nível do tópico define o padrão; o "modelo" e o "preenchimento" podem sobrescrever.
   ========================================================= */
.node {
  --c: var(--accent);
  --bg-node: var(--surface); --fg-node: var(--text); --bd-node: var(--c);
  position: absolute; left: 0; top: 0;
  display: flex; flex-direction: column; justify-content: center;
  width: max-content; max-width: 280px; padding: 7px 14px;
  background: var(--bg-node); color: var(--fg-node);
  border: var(--bw, 1.5px) var(--bs, solid) var(--bd-node); border-radius: 10px; box-shadow: var(--shadow);
  --fs: 14px; font-size: calc(var(--fs) * var(--fk, 1)); line-height: 1.35; cursor: pointer; user-select: none; -webkit-user-select: none;
  white-space: pre-wrap; overflow-wrap: break-word;
}
.node.depth-0 {
  --bg-node: var(--c); --fg-node: var(--root-text); --bd-node: transparent;
  padding: 14px 26px; --fs: 20px; font-weight: 700; max-width: 360px; border-radius: 14px;
}
.node.depth-0.has-color { --fg-node: #fff; }
.node.depth-1 {
  --bg-node: var(--c); --fg-node: #fff; --bd-node: transparent;
  padding: 9px 18px; --fs: 16px; font-weight: 600;
}
.node .row { display: flex; align-items: center; gap: 6px; }

/* ----- Modelos: básicos ----- */
.node.shape-rect { border-radius: 3px; }
.node.shape-pill { border-radius: 999px; }
.node.shape-leaf { border-radius: 22px 2px 22px 2px; }
.node.shape-circle { border-radius: 50%; aspect-ratio: 1; min-width: 90px; max-width: 200px; padding: 16px; text-align: center; }
.node.shape-underline {
  --bg-node: transparent; --fg-node: var(--text);
  border: 0; border-bottom: 2.5px solid var(--c); border-radius: 0; box-shadow: none; padding: 4px 6px;
}
.node.shape-text {
  --bg-node: transparent; --fg-node: var(--text); --bd-node: transparent;
  box-shadow: none; padding: 4px 6px; --fs: 17px;
}

/* ----- Modelos: estilos ----- */
.node.shape-card {
  --bg-node: var(--surface); --fg-node: var(--text);
  border: 1px solid var(--border); border-top: 5px solid var(--c); border-radius: 8px; padding: 10px 16px 12px; min-width: 150px;
}
.node.shape-sticky {
  --bg-node: color-mix(in srgb, var(--c) 32%, #fffbe6); --fg-node: #2b2b2b; --bd-node: transparent;
  border-radius: 2px 2px 16px 2px; box-shadow: 0 8px 16px rgba(0, 0, 0, .18);
  min-width: 140px; min-height: 110px; justify-content: flex-start; padding: 14px 16px; font-weight: 500;
}
.node.shape-image {
  --bg-node: var(--surface); --fg-node: var(--text); padding: 6px; border-radius: 10px; min-width: 80px;
}
.node.shape-image .row:has(.text:empty) { display: none; }
.node.shape-image.editing .row { display: flex; }
.node.shape-image .row { padding: 2px 4px 0; }
.node .node-img {
  display: block; width: 100%; height: auto; border-radius: 6px; pointer-events: none;
  -webkit-user-drag: none; user-select: none; margin-bottom: 6px; min-width: 60px;
}
.node .node-img[hidden] { display: none; }
.node.shape-image .node-img { margin-bottom: 0; }
.node.shape-image .row:not(:has(.text:empty)) { margin-top: 6px; }
.node.shape-folder { border-radius: 0 8px 8px 8px; margin-top: 0; }
.node.shape-folder::after {
  content: ""; position: absolute; left: -1.5px; top: -11px; width: 42%; height: 11px;
  background: var(--bg-node); border: 1.5px solid var(--bd-node); border-bottom: 0; border-radius: 7px 7px 0 0;
}

/* ----- Modelos desenhados em SVG (fluxograma e destaque) ----- */
.node .shape-svg {
  position: absolute; inset: 0; width: 100%; height: 100%; z-index: -1; overflow: visible; pointer-events: none; display: none;
}
.node .shape-svg path { fill: var(--bg-node); stroke: var(--bd-node); stroke-width: var(--bw, 1.5px); stroke-dasharray: var(--dash, none); }
.node.svgshape { background: transparent; border-color: transparent; box-shadow: none; text-align: center; filter: drop-shadow(0 2px 3px rgba(0, 0, 0, .15)); }
.node.svgshape .shape-svg { display: block; }
.node.svgshape .row { justify-content: center; }
.node.shape-diamond { padding: 28px 44px; min-height: 84px; min-width: 130px; }
.node.shape-hexagon { padding: 14px 34px; }
.node.shape-parallelogram { padding: 12px 34px; }
.node.shape-arrow { padding: 12px 40px 12px 18px; }
.node.shape-chevron { padding: 12px 36px 12px 34px; }
.node.shape-flag { padding: 12px 34px 12px 18px; }
.node.shape-octagon { padding: 18px 26px; min-width: 100px; min-height: 70px; }
.node.shape-document { padding: 12px 18px 24px; min-width: 110px; }
.node.shape-cylinder { padding: 28px 22px 18px; min-width: 110px; }
.node.shape-cloud { padding: 28px 36px 26px; min-width: 140px; min-height: 84px; }
.node.shape-trapezoid { padding: 12px 30px; }
.node.shape-delay { padding: 12px 34px 12px 16px; }
.node.shape-tag { padding: 12px 18px 12px 30px; }
.node.shape-star { padding: 40px 44px 34px; min-width: 120px; min-height: 110px; }
.node.shape-shield { padding: 14px 26px 30px; min-width: 100px; }
.node.shape-heart { padding: 18px 30px 34px; min-width: 110px; min-height: 90px; }
.node.shape-callout { padding: 10px 18px 28px; min-width: 110px; text-align: left; }
.node.shape-callout .row { justify-content: flex-start; }
.node.depth-1.svgshape, .node.depth-0.svgshape { --bd-node: transparent; }

/* =========================================================
   Estilos de preenchimento (valem para todos os modelos de caixa)
   ========================================================= */
.node.fill-solid { --bg-node: var(--c); --fg-node: #fff; --bd-node: var(--c); }
.node.depth-0.fill-solid:not(.has-color) { --fg-node: var(--root-text); }
.node.fill-soft { --bg-node: color-mix(in srgb, var(--c) 22%, var(--surface)); --fg-node: var(--text); --bd-node: color-mix(in srgb, var(--c) 60%, var(--surface)); }
.node.fill-pastel { --bg-node: color-mix(in srgb, var(--c) 10%, var(--surface)); --fg-node: color-mix(in srgb, var(--c) 65%, var(--text)); --bd-node: color-mix(in srgb, var(--c) 28%, var(--surface)); box-shadow: none; }
.node.fill-white { --bg-node: #fff; --fg-node: #1f2328; --bd-node: var(--c); }
.node.fill-dark { --bg-node: color-mix(in srgb, var(--c) 16%, #0c0d10); --fg-node: color-mix(in srgb, var(--c) 40%, #fff); --bd-node: color-mix(in srgb, var(--c) 65%, #000); }
.node.fill-gradient { --fg-node: #fff; --bd-node: transparent; background-image: linear-gradient(135deg, var(--c), color-mix(in srgb, var(--c) 50%, #000)); box-shadow: 0 6px 16px color-mix(in srgb, var(--c) 30%, transparent); }
.node.fill-gradient-soft { --fg-node: var(--text); --bd-node: color-mix(in srgb, var(--c) 40%, var(--surface)); background-image: linear-gradient(135deg, color-mix(in srgb, var(--c) 32%, var(--surface)), color-mix(in srgb, var(--c) 5%, var(--surface))); }
.node.fill-glass { --bg-node: color-mix(in srgb, var(--c) 16%, transparent); --fg-node: var(--text); --bd-node: color-mix(in srgb, var(--c) 55%, transparent); --bw: 1px; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.node.fill-outline { --bg-node: transparent; --fg-node: var(--text); --bd-node: var(--c); box-shadow: none; }
.node.fill-dashed { --bg-node: transparent; --fg-node: var(--text); --bd-node: var(--c); --bw: 2px; --bs: dashed; --dash: 6 4; box-shadow: none; }
.node.fill-dotted { --bg-node: color-mix(in srgb, var(--c) 8%, transparent); --fg-node: var(--text); --bd-node: var(--c); --bw: 2.5px; --bs: dotted; --dash: 1 4; box-shadow: none; }
.node.fill-thick { --bg-node: var(--surface); --fg-node: var(--text); --bd-node: var(--c); --bw: 3.5px; }
.node.fill-double { --bg-node: var(--surface); --fg-node: var(--text); --bd-node: var(--c); --bw: 5px; --bs: double; }
.node.fill-accent { --bg-node: var(--surface); --fg-node: var(--text); --bd-node: var(--border); border-left: 6px solid var(--c); }
.node.fill-shadow { --bg-node: var(--surface); --fg-node: var(--text); --bd-node: var(--c); --bw: 2px; box-shadow: 5px 5px 0 var(--c); }
.node.fill-neon { --bg-node: #0b0c10; --fg-node: color-mix(in srgb, var(--c) 35%, #fff); --bd-node: var(--c); box-shadow: 0 0 0 1px var(--c), 0 0 16px color-mix(in srgb, var(--c) 65%, transparent), inset 0 0 10px color-mix(in srgb, var(--c) 30%, transparent); }
.node.fill-none { --bg-node: transparent; --fg-node: var(--text); --bd-node: transparent; box-shadow: none; }
/* Ajustes para as formas desenhadas em SVG */
.node.svgshape.fill-outline, .node.svgshape.fill-none, .node.svgshape.fill-dashed, .node.svgshape.fill-dotted, .node.svgshape.fill-pastel { filter: none; }
.node.svgshape.fill-gradient, .node.svgshape.fill-gradient-soft { background-image: none; box-shadow: none; }
.node.svgshape.fill-shadow { box-shadow: none; filter: drop-shadow(5px 5px 0 var(--c)); }
.node.svgshape.fill-neon { box-shadow: none; filter: drop-shadow(0 0 7px var(--c)); }
.node.svgshape.fill-accent { --bd-node: var(--c); --bw: 3px; border-left: 0; }
.node .shape-svg stop:first-child { stop-color: var(--c); }
.node .shape-svg stop:last-child { stop-color: color-mix(in srgb, var(--c) 50%, #000); }
.node.fill-gradient-soft .shape-svg stop:first-child { stop-color: color-mix(in srgb, var(--c) 32%, var(--surface)); }
.node.fill-gradient-soft .shape-svg stop:last-child { stop-color: color-mix(in srgb, var(--c) 5%, var(--surface)); }
.node.shape-underline[class*="fill-"] { border: 0; border-bottom: 2.5px solid var(--c); }
.node.shape-sticky.fill-outline, .node.shape-sticky.fill-none, .node.shape-sticky.fill-dashed { box-shadow: none; }

/* Grade de estilos (painel e biblioteca) */
.fill-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.fill-grid button {
  display: flex; flex-direction: column; align-items: center; gap: 5px; border: 1px solid var(--border); background: var(--surface-2);
  border-radius: 9px; padding: 8px 3px 5px; cursor: pointer; font-size: 10px; letter-spacing: -.01em; color: var(--muted); min-width: 0;
}
.fill-grid button span.lbl { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.fill-grid button:hover { border-color: var(--accent); }
.fill-grid button.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.node.mini {
  position: relative; transform: none; pointer-events: none; --fs: 11px; padding: 3px 10px; border-radius: 6px;
  max-width: none; width: auto; font-weight: 600; box-shadow: none;
}
.node.mini.fill-shadow { box-shadow: 3px 3px 0 var(--c); }
.node.mini.fill-neon { box-shadow: 0 0 0 1px var(--c), 0 0 8px var(--c); }
.node.mini.fill-gradient { box-shadow: none; }
.node.mini.fill-accent { border-left-width: 4px; }
.lib-sec .fill-grid { margin-bottom: 14px; }

/* ----- Formatação de texto ----- */
.node.italic .text { font-style: italic; }
.node.underline .text { text-decoration-line: underline; }
.node.strike .text { text-decoration-line: line-through; }
.node.underline.strike .text { text-decoration-line: underline line-through; }
.node.ts-s { --fk: .8; }
.node.ts-l { --fk: 1.3; }
.node.ts-xl { --fk: 1.75; }
.node.al-left .row { justify-content: flex-start; } .node.al-left .text { text-align: left; }
.node.al-center .row { justify-content: center; } .node.al-center .text { text-align: center; }
.node.al-right .row { justify-content: flex-end; } .node.al-right .text { text-align: right; }
.node.sized { max-width: none; }

/* ----- Alça de redimensionar e pontos de conexão ----- */
.node .rs {
  position: absolute; right: -7px; bottom: -7px; width: 13px; height: 13px; border-radius: 3px;
  background: var(--accent); border: 2px solid var(--surface); cursor: nwse-resize; display: none; z-index: 3;
  transform: scale(var(--zk, 1)); transform-origin: 50% 50%;
}
.node.selected .rs { display: block; }
.node.editing .rs, .node.editing .port { display: none !important; }
.port {
  position: absolute; width: 12px; height: 12px; border-radius: 50%; z-index: 4;
  background: var(--surface); border: 2px solid var(--accent); cursor: crosshair; display: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
  transform: scale(var(--zk, 1));
}
.port:hover { background: var(--accent); transform: scale(calc(var(--zk, 1) * 1.35)); }
.port[data-port="l"] { left: -7px; top: calc(50% - 6px); }
.port[data-port="r"] { right: -7px; top: calc(50% - 6px); }
.port[data-port="t"] { top: -7px; left: calc(50% - 6px); }
.port[data-port="b"] { bottom: -7px; left: calc(50% - 6px); }
.node:hover > .port, .node.selected > .port, .sticker:hover > .port, .sticker.selected > .port { display: block; }
.node.selected > .port[data-port="b"] { left: calc(50% - 6px); }
#viewport.linking .port { display: block; }
#viewport.tool-draw .port, #viewport.tool-draw .rs { display: none !important; }
.node.link-target, .sticker.link-target { outline: 2.5px dashed var(--accent); outline-offset: 5px; }
.link-temp { fill: none; stroke: var(--accent); stroke-width: 2; stroke-dasharray: 6 5; }
#edges .edge.link .hit { stroke: transparent; stroke-width: 14px; fill: none; pointer-events: stroke; cursor: pointer; }
#edges .edge.link.selected .base { stroke-width: calc(var(--w) * 1px + 1.5px); filter: drop-shadow(0 0 3px var(--accent)); }

/* =========================================================
   Anotações (lápis, seta, retângulo, elipse, texto)
   ========================================================= */
#draws, #drawSel { position: absolute; left: 0; top: 0; width: 1px; height: 1px; overflow: visible; pointer-events: none; }
#dtexts { position: absolute; left: 0; top: 0; }
.draw path { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.draw .hit { stroke: transparent; pointer-events: stroke; cursor: move; }
.draw .vis.filled { pointer-events: fill; cursor: move; }
.draw .head { stroke: none; }
.dtext {
  position: absolute; left: 0; top: 0; white-space: pre; line-height: 1.25; font-weight: 600; padding: 2px 4px;
  cursor: move; user-select: none; -webkit-user-select: none; min-width: 1ch; outline: none; border-radius: 4px;
}
.dtext.editing { cursor: text; user-select: text; -webkit-user-select: text; outline: 1.5px dashed var(--accent); }
.dtext.selected { outline: 1.5px dashed var(--accent); outline-offset: 3px; }
#drawSel rect.box { fill: none; stroke: var(--accent); stroke-dasharray: 5 4; }
#drawSel .dh { fill: var(--accent); stroke: var(--surface); pointer-events: all; cursor: nwse-resize; }
#drawSel .dh[data-handle^="p"] { cursor: move; }
#viewport.tool-draw { cursor: crosshair; }
#viewport.tool-text { cursor: text; }
#viewport.tool-eraser { cursor: cell; }
#viewport.tool-draw .node, #viewport.tool-draw .sticker, #viewport.tool-draw .dtext { cursor: inherit; }

.drawbar {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); display: flex; gap: 8px; align-items: center; z-index: 8;
}
.drawbar .pill { background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-lg); padding: 4px; }
.drawbar .icon-btn.active { color: #fff; background: var(--accent); }
.sep { width: 1px; height: 22px; background: var(--border); margin: 0 4px; }
.dcolors { display: flex; gap: 5px; align-items: center; padding: 0 4px; }
.dcolors button { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--border); cursor: pointer; padding: 0; }
.dcolors button.active { box-shadow: 0 0 0 2px var(--accent); }
.dcolors.big { flex-wrap: wrap; gap: 8px; padding: 0; }
.dcolors.big button { width: 26px; height: 26px; }
.dwidths { display: flex; gap: 2px; }
.dwidths button { width: 30px; height: 30px; border: 0; background: none; border-radius: 7px; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.dwidths button:hover { background: var(--surface-2); }
.dwidths button.active { background: var(--accent-soft); }
.dwidths button i { display: block; width: 16px; border-radius: 4px; background: var(--text); }

/* ----- Etiquetas dentro do tópico ----- */
.node .labels { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.node .labels:empty { display: none; }
.node.svgshape .labels { justify-content: center; }
.label-chip {
  --lc: #495057;
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--lc); color: #fff; font-size: 11px; font-weight: 600; line-height: 1.3;
  padding: 2px 8px; border-radius: 999px; white-space: nowrap;
}
.node.depth-0 .label-chip, .node.depth-1 .label-chip, .node.fill-solid .label-chip { box-shadow: 0 0 0 1.5px rgba(255, 255, 255, .75); }

.node.bold .text { font-weight: 700; }
.node .text { min-width: 1ch; outline: none; }
.node .text:empty::before { content: "\200b"; }
.node .icon { font-size: 1.05em; line-height: 1; }
.node .note-ind { font-size: 12px; opacity: .8; }

.node.selected { outline: 2.5px solid var(--accent); outline-offset: 3px; }
.node.editing { cursor: text; user-select: text; -webkit-user-select: text; }
.node.editing .text { user-select: text; -webkit-user-select: text; }
.node.moving { cursor: grabbing; z-index: 5; }
.node.drop-child { outline: 2.5px dashed var(--accent); outline-offset: 4px; }
.node.drop-before::before, .node.drop-after::after {
  content: ""; position: absolute; left: -4px; right: -4px; height: 3px; border-radius: 3px; background: var(--accent);
  border: 0; width: auto; top: auto;
}
.node.drop-before::before { top: -9px; }
.node.drop-after::after { bottom: -9px; }
.node[data-dir="d"].drop-before::before, .node[data-dir="d"].drop-after::after {
  top: -4px; bottom: -4px; width: 3px; height: auto; left: auto; right: auto;
}
.node[data-dir="d"].drop-before::before { left: -10px; }
.node[data-dir="d"].drop-after::after { right: -10px; }

/* Botão recolher/expandir */
.toggle {
  position: absolute; top: 50%; min-width: 18px; height: 18px; margin-top: -9px; padding: 0 4px;
  border-radius: 9px; border: 1.5px solid var(--c); background: var(--surface); color: var(--text);
  font-size: 11px; font-weight: 600; line-height: 1; cursor: pointer;
  display: none; align-items: center; justify-content: center;
}
.node.has-children:hover .toggle, .node.selected.has-children .toggle, .node.collapsed .toggle { display: inline-flex; }
.node[data-dir="r"] .toggle { left: calc(100% + 12px); }
.node[data-dir="l"] .toggle { right: calc(100% + 12px); }
.node[data-dir="d"] .toggle { top: calc(100% + 12px); left: 50%; margin-top: 0; transform: translateX(-50%); }
.node.depth-0 .toggle { display: none !important; }

/* =========================================================
   Conectores: tipo de linha + efeitos animados
   Variáveis por ligação: --c (cor do ramo), --w (espessura), --fx (cor do brilho)
   A velocidade global vem de --spd (1 = normal).
   ========================================================= */
#edges path, .fx-svg path { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.edge { --fx: var(--c); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .edge { --fx: color-mix(in srgb, var(--c) 50%, #fff); } }
:root[data-theme="dark"] .edge { --fx: color-mix(in srgb, var(--c) 50%, #fff); }

.edge .spine { stroke: none; }
.edge .base { stroke: var(--c); stroke-width: calc(var(--w) * 1px); }
.edge .base.organic { fill: var(--c); stroke: none; }
.edge .head { fill: var(--c); stroke: none; }
.edge .fx-halo { stroke: var(--c); stroke-width: calc(var(--w) * 1px + 7px); opacity: .22; }

/* Energia: pulsos tracejados correndo */
.edge[data-fx="energy"] .base { opacity: .45; }
.edge[data-fx="energy"] .fx-halo, .edge .fx-flow { stroke-dasharray: 10 22; animation: fx-dash calc(1.1s * var(--spd)) linear infinite; }
.edge .fx-flow { stroke: var(--fx); stroke-width: calc(var(--w) * 1px + .5px); }
@keyframes fx-dash { to { stroke-dashoffset: -32; } }

/* Bolinha / Partículas (animação SVG ao longo do caminho) */
.edge[data-fx="dot"] .base, .edge[data-fx="particles"] .base { opacity: .55; }
.edge .fx-dot { fill: var(--fx); }
.edge .fx-dot-halo { fill: var(--c); opacity: .3; }

/* Raio */
.edge[data-fx="lightning"] .base { opacity: .28; }
.edge .fx-bolt { stroke: var(--fx); stroke-width: calc(var(--w) * .8px + .6px); stroke-linejoin: miter; stroke-linecap: butt; }
.edge .fx-bolt-halo { stroke: var(--c); stroke-width: calc(var(--w) * 1px + 6px); opacity: .28; stroke-linejoin: round; }

/* Cometa */
.edge[data-fx="comet"] .base { opacity: .3; }
.edge .fx-tail, .edge .fx-comet { animation: fx-comet calc(1.5s * var(--spd)) linear infinite; }
.edge .fx-tail { stroke: var(--c); stroke-width: calc(var(--w) * 1px + 2px); stroke-dasharray: 22 78; opacity: .55; }
.edge .fx-comet { stroke: var(--fx); stroke-width: calc(var(--w) * 1px + 3px); stroke-dasharray: 0 19 3 78; }
@keyframes fx-comet { from { stroke-dashoffset: 0; } to { stroke-dashoffset: -100; } }

/* Formigas (tracejado marchando) */
.edge[data-fx="ants"] .base { opacity: .3; }
.edge .fx-ants { stroke: var(--fx); stroke-width: calc(var(--w) * 1px); stroke-dasharray: 6 7; stroke-linecap: butt; animation: fx-ants calc(.7s * var(--spd)) linear infinite; }
@keyframes fx-ants { to { stroke-dashoffset: -13; } }

/* Pulsar (brilho que acende e apaga) */
.edge[data-fx="pulse"] .fx-halo { animation: fx-pulse calc(1.6s * var(--spd)) ease-in-out infinite; }
@keyframes fx-pulse { 0%, 100% { opacity: .04; } 50% { opacity: .55; } }

/* Neon (brilho fixo com leve oscilação) */
.edge[data-fx="neon"] .fx-halo { opacity: .38; stroke-width: calc(var(--w) * 1px + 9px); }
.edge .fx-core { stroke: color-mix(in srgb, var(--c) 30%, #fff); stroke-width: max(1px, calc(var(--w) * 1px - 1px)); animation: fx-flicker calc(3s * var(--spd)) linear infinite; }
@keyframes fx-flicker { 0%, 89%, 100% { opacity: 1; } 91% { opacity: .35; } 93% { opacity: 1; } 95% { opacity: .55; } }

html.fx-paused .edge * { animation-play-state: paused !important; }
html.fx-paused .edge .fx-dot, html.fx-paused .edge .fx-dot-halo { display: none; }

/* ---------- Figurinhas no quadro ---------- */
.sticker {
  position: absolute; left: 0; top: 0; line-height: 1; cursor: grab; user-select: none; -webkit-user-select: none;
  filter: drop-shadow(0 3px 4px rgba(0, 0, 0, .22));
}
.sticker.selected { outline: 2px dashed var(--accent); outline-offset: 6px; border-radius: 10px; }
.sticker.moving { cursor: grabbing; }

/* ---------- Painéis flutuantes ---------- */
.floating {
  position: absolute; top: 12px; z-index: 12; overflow: auto; max-height: calc(100% - 24px);
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-lg);
}
.library { left: 12px; width: 292px; padding: 12px 14px 18px; overflow-x: hidden; }
.panel { right: 12px; width: 264px; padding: 14px; }
.panel.closed { display: none; }

.lib-head { display: flex; align-items: center; justify-content: space-between; }
.lib-tip { color: var(--muted); font-size: 12px; margin: 4px 0 12px; }
.lib-sec { display: none; }
.library[data-tab="models"] [data-sec="models"],
.library[data-tab="labels"] [data-sec="labels"],
.library[data-tab="stickers"] [data-sec="stickers"] { display: block; }
.lib-sec h4, .label-form h4, .panel h4, .popover h4 {
  margin: 0 0 8px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
}
.lib-sec .fill-bar { margin-bottom: 14px; }
.model-group h5 { margin: 14px 0 8px; font-size: 12px; font-weight: 600; }
.model-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.pal-model {
  border: 1px solid var(--border); background: var(--surface-2); border-radius: 10px; padding: 8px 6px 6px;
  display: flex; flex-direction: column; align-items: center; gap: 4px; cursor: grab; user-select: none; touch-action: none;
}
.pal-model:hover { border-color: var(--accent); }
.pal-model .pv { height: 60px; display: flex; align-items: center; justify-content: center; width: 100%; pointer-events: none; overflow: hidden; }
.pal-model small { font-size: 11px; color: var(--muted); }
.node.preview { position: relative; transform: scale(.66); pointer-events: none; --fs: 13px; flex: none; }
.node.preview.shape-star, .node.preview.shape-heart { transform: scale(.5); }
.node.preview.shape-image { width: 120px; }
.node.preview.shape-sticky { min-width: 110px; min-height: 80px; }
.node.preview.shape-diamond, .node.preview.shape-cloud, .node.preview.shape-cylinder { transform: scale(.55); }
.node.preview.shape-circle { transform: scale(.5); }

.label-list { display: flex; flex-wrap: wrap; gap: 6px; }
.pal-label { cursor: grab; padding: 4px 10px; font-size: 12px; user-select: none; touch-action: none; }
.pal-label:hover { filter: brightness(1.1); }
.pal-label .lab-del {
  border: 0; background: rgba(255,255,255,.25); color: #fff; width: 16px; height: 16px; border-radius: 50%;
  padding: 0; font-size: 11px; line-height: 16px; cursor: pointer;
}
.label-form { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; }
.label-form input { border: 1px solid var(--border); background: var(--surface-2); border-radius: 8px; padding: 7px 9px; }
.label-form input:focus { outline: none; border-color: var(--accent); }
.label-colors { display: flex; flex-wrap: wrap; gap: 6px; }
.label-colors button { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--border); cursor: pointer; }
.label-colors button.active { box-shadow: 0 0 0 2px var(--accent); }

.sticker-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
.pal-sticker {
  font-size: 28px; aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
  border-radius: 10px; cursor: grab; user-select: none; touch-action: none;
}
.pal-sticker:hover { background: var(--surface-2); transform: scale(1.12); }
.pal-ghost { position: fixed; left: 0; top: 0; pointer-events: none; z-index: 300; opacity: .9; }

/* Painel de formatação */
.panel-empty { color: var(--muted); }
.panel .panel-body, .panel .panel-sticker, .panel .panel-draw, .panel .panel-link { display: none; }
.panel.has-selection .panel-body, .panel.has-sticker .panel-sticker, .panel.has-draw .panel-draw, .panel.has-link .panel-link { display: block; }
.panel.has-selection .panel-empty, .panel.has-sticker .panel-empty, .panel.has-draw .panel-empty, .panel.has-link .panel-empty { display: none; }
.seg.seg-3 { grid-template-columns: repeat(3, 1fr); }
.seg.fmt button { font-size: 15px; font-family: Georgia, "Times New Roman", serif; }
.field-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; font-size: 12px; color: var(--muted); }
.field-row .seg { flex: 1; max-width: 170px; }
.model-current { display: flex; align-items: center; gap: 10px; }
.model-current .pv { width: 96px; height: 62px; flex: none; display: flex; align-items: center; justify-content: center; overflow: hidden; background: var(--surface-2); border-radius: 10px; border: 1px solid var(--border); }
.model-current strong { display: block; font-size: 13px; margin-bottom: 6px; }
.model-picker { margin-top: 10px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; max-height: 320px; overflow: auto; padding: 2px; }
.model-picker button {
  border: 1px solid var(--border); background: var(--surface-2); border-radius: 8px; padding: 4px 2px 3px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 1px; min-width: 0;
}
.model-picker button:hover { border-color: var(--accent); }
.model-picker button.active { border-color: var(--accent); background: var(--accent-soft); }
.model-picker .pv { height: 40px; width: 100%; display: flex; align-items: center; justify-content: center; overflow: hidden; pointer-events: none; }
.model-picker .pv .node.preview { transform: scale(.42); }
.model-picker small { font-size: 10px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.panel .seg[data-hidden] { display: none; }
.panel-title { font-weight: 700; margin-bottom: 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.panel section { padding: 12px 0; border-top: 1px solid var(--border); }
.panel .fill-bar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.field { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.field select { width: 150px; color: var(--text); }
.swatches { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.swatches button { aspect-ratio: 1; border-radius: 50%; border: 2px solid var(--surface); cursor: pointer; box-shadow: 0 0 0 1px var(--border); }
.swatches button.auto { background: conic-gradient(#E8590C, #F08C00, #2F9E44, #1C7ED6, #AE3EC9, #E8590C); }
.swatches button.active { box-shadow: 0 0 0 2px var(--accent); }
.custom-color { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; color: var(--muted); font-size: 12px; }
.custom-color input { width: 34px; height: 24px; padding: 0; border: 1px solid var(--border); border-radius: 6px; background: none; cursor: pointer; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.seg.seg-4 { grid-template-columns: repeat(4, 1fr); }
.seg button { border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 6px; cursor: pointer; font-size: 12px; }
.seg button.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.icons { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; }
.icons button { border: 1px solid transparent; background: none; border-radius: 6px; padding: 4px 0; font-size: 16px; cursor: pointer; }
.icons button:hover { background: var(--surface-2); }
.icons button.active { border-color: var(--accent); background: var(--accent-soft); }
.panel textarea { width: 100%; resize: vertical; border: 1px solid var(--border); border-radius: 8px; padding: 8px; background: var(--surface-2); }
.panel textarea:focus { outline: none; border-color: var(--accent); }
#stickerPreview { font-size: 20px; margin-left: 6px; }
#stickerSize { width: 100%; accent-color: var(--accent); }
.node-labels { display: flex; flex-wrap: wrap; gap: 6px; }
.node-labels .muted { font-size: 12px; }
.node-labels .label-chip button {
  border: 0; background: rgba(255,255,255,.25); color: #fff; width: 15px; height: 15px; border-radius: 50%;
  padding: 0; font-size: 10px; line-height: 15px; cursor: pointer;
}

/* ---------- Menu de conectores ---------- */
.popover {
  position: fixed; z-index: 150; width: 380px; max-width: calc(100vw - 24px); max-height: calc(100vh - 80px); overflow: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-lg); padding: 14px;
}
.popover h4:not(:first-child) { margin-top: 14px; }
.popover .btn.wide { margin-top: 4px; }
.opt-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.opt {
  border: 1px solid var(--border); background: var(--surface-2); border-radius: 10px; padding: 6px 8px 5px;
  cursor: pointer; display: flex; flex-direction: column; gap: 2px; text-align: left;
}
.opt:hover { border-color: var(--accent); }
.opt.active { border-color: var(--accent); background: var(--accent-soft); }
.opt small { font-size: 11.5px; color: var(--muted); }
.opt.active small { color: var(--accent); font-weight: 600; }
.fx-svg { width: 100%; height: 30px; overflow: visible; display: block; }

/* ---------- Zoom e dica ---------- */
.zoombar {
  position: absolute; right: 14px; bottom: 14px; display: flex; align-items: center; gap: 2px; padding: 3px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow);
}
.zoom-label { border: 0; background: none; min-width: 52px; font-size: 12px; font-variant-numeric: tabular-nums; cursor: pointer; border-radius: 6px; height: 30px; }
.zoom-label:hover { background: var(--surface-2); }
.hint {
  position: absolute; left: 50%; top: 14px; transform: translateX(-50%); font-size: 12.5px; color: var(--text); z-index: 9;
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 7px 14px; pointer-events: none;
  box-shadow: var(--shadow-lg); white-space: nowrap;
}

/* ---------- Gaveta de mapas ---------- */
.drawer {
  width: 260px; flex: none; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; z-index: 15;
}
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 12px; border-bottom: 1px solid var(--border); }
.map-list { list-style: none; margin: 0; padding: 6px; overflow: auto; flex: 1; }
.map-list li { display: flex; align-items: center; border-radius: 8px; }
.map-list li.current { background: var(--accent-soft); }
.map-list li:hover:not(.current) { background: var(--surface-2); }
.map-open { flex: 1; min-width: 0; text-align: left; border: 0; background: none; padding: 8px 10px; cursor: pointer; }
.map-open strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.map-open small { color: var(--muted); font-size: 11px; }
.map-list .icon-btn { width: 30px; height: 30px; opacity: 0; }
.map-list li:hover .icon-btn { opacity: .7; }
.drawer-foot { font-size: 11px; color: var(--muted); padding: 10px 12px; margin: 0; border-top: 1px solid var(--border); }

/* ---------- Menu de contexto ---------- */
.ctx {
  position: fixed; z-index: 200; min-width: 210px; padding: 5px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow-lg);
}
.ctx button {
  width: 100%; display: flex; justify-content: space-between; gap: 16px; border: 0; background: none;
  padding: 7px 10px; border-radius: 6px; text-align: left; cursor: pointer;
}
.ctx button:hover { background: var(--accent-soft); }
.ctx button:disabled { opacity: .4; cursor: default; background: none; }
.ctx kbd { color: var(--muted); font-family: inherit; font-size: 12px; }
.ctx hr { border: 0; border-top: 1px solid var(--border); margin: 4px 2px; }

/* ---------- Ajuda ---------- */
dialog {
  border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--text);
  padding: 20px 24px; max-width: 580px; width: calc(100% - 32px); box-shadow: var(--shadow-lg);
}
dialog::backdrop { background: rgba(0, 0, 0, .35); }
dialog h3 { margin-top: 0; }
dialog table { width: 100%; border-collapse: collapse; }
dialog td { padding: 6px 4px; border-bottom: 1px solid var(--border); vertical-align: top; }
dialog td:first-child { white-space: nowrap; padding-right: 16px; }
kbd { background: var(--surface-2); border: 1px solid var(--border); border-radius: 4px; padding: 1px 5px; font-size: 12px; font-family: inherit; }
dialog form { text-align: right; margin-top: 12px; }

/* ---------- Login ---------- */
.auth {
  position: fixed; inset: 0; z-index: 500; display: flex; align-items: center; justify-content: center; padding: 16px;
  background-color: var(--bg);
  background-image: radial-gradient(var(--grid) 1.2px, transparent 1.2px); background-size: 22px 22px;
}
.auth-card {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: var(--shadow-lg); padding: 28px 26px 22px; display: flex; flex-direction: column; gap: 12px;
}
.auth-logo { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--accent); }
.auth-logo span { color: var(--text); }
.auth-card h2 { margin: 6px 0 0; font-size: 22px; }
.auth-card #authSub { margin: 0 0 4px; }
.auth-field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; }
.auth-field input {
  height: 42px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); padding: 0 12px; font-size: 15px; font-weight: 400;
}
.auth-field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.auth-msg { margin: 0; min-height: 18px; font-size: 13px; color: #e03131; }
.auth-msg.ok { color: var(--muted); }
.auth-card .btn.primary { height: 42px; justify-content: center; font-weight: 600; font-size: 15px; }
.auth-links { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; }
.linkish { border: 0; background: none; color: var(--accent); cursor: pointer; padding: 4px 0; font-size: 13px; }
.linkish:hover { text-decoration: underline; }
.status[data-sync="offline"] { color: #f08c00; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

/* ---------- Responsivo ---------- */
@media (max-width: 760px) {
  .zoombar { bottom: 70px; }
  .drawbar .draw-opts { position: absolute; bottom: 52px; left: 50%; transform: translateX(-50%); }
}
@media (max-width: 900px) {
  .topbar { padding: 0 8px; gap: 6px; }
  .pill-history { display: none; }
  .icon-btn.boxed { display: none; }
  .drawer { position: absolute; left: 0; top: 0; bottom: 0; box-shadow: var(--shadow-lg); }
}
@media (max-width: 640px) {
  .topbar { overflow-x: auto; }
  .tb-left .doc-meta { display: none; }
  .tb-left { flex: none; }
  .pill { padding: 2px; }
  .icon-btn { width: 30px; }
  .library, .panel { left: 8px; right: 8px; width: auto; }
}
