:root {
  --roxo: #9b59b6;
  --roxo-escuro: #8e44ad;
  --roxo-claro: #f3eaf8;
  --azul: #2c3e50;
  --cinza: #7f8c8d;
  --cinza-claro: #ecf0f1;
  --branco: #fdfdfd;
  --laranja: #f39c12;
  --verde: #10b981;
  --vermelho: #e74c3c;
  --sombra: 0 2px 12px rgba(44, 62, 80, 0.08);
  --sombra-hover: 0 4px 20px rgba(44, 62, 80, 0.15);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--branco);
  color: var(--azul);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--roxo); text-decoration: none; }
a:hover { color: var(--roxo-escuro); }

.topbar {
  background: white;
  border-bottom: 1px solid var(--cinza-claro);
  padding: 16px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--sombra);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 18px;
  color: var(--azul);
}

.logo-mark {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--roxo), var(--roxo-escuro));
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: bold;
}

.nav { display: flex; gap: 16px; }
.nav a { padding: 8px 14px; border-radius: 6px; font-weight: 500; }
.nav a:hover { background: var(--cinza-claro); }
.nav a.ativo { background: var(--roxo); color: white; }

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 24px;
}

.hero {
  text-align: center;
  margin-bottom: 40px;
}
.hero h1 {
  font-size: 36px;
  font-weight: 800;
  margin-bottom: 12px;
  background: linear-gradient(135deg, var(--roxo), var(--roxo-escuro));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.hero p { color: var(--cinza); font-size: 17px; max-width: 640px; margin: 0 auto; }

.card {
  background: white;
  border-radius: 16px;
  box-shadow: var(--sombra);
  padding: 32px;
  margin-bottom: 24px;
}

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 2px solid var(--cinza-claro);
  margin-bottom: 24px;
}
.tab {
  padding: 12px 20px;
  cursor: pointer;
  font-weight: 500;
  color: var(--cinza);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.2s;
}
.tab:hover { color: var(--roxo); }
.tab.ativa {
  color: var(--roxo);
  border-bottom-color: var(--roxo);
}

.tab-content { display: none; }
.tab-content.ativa { display: block; }

label {
  display: block;
  font-weight: 500;
  margin-bottom: 8px;
  color: var(--azul);
}

input[type="text"], input[type="url"], textarea, select {
  width: 100%;
  padding: 12px 16px;
  border: 1.5px solid var(--cinza-claro);
  border-radius: 10px;
  font-family: inherit;
  font-size: 15px;
  transition: border-color 0.2s;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--roxo);
}
textarea {
  resize: vertical;
  min-height: 160px;
  font-family: 'JetBrains Mono', 'Consolas', monospace;
}

.file-drop {
  border: 2px dashed var(--cinza-claro);
  border-radius: 10px;
  padding: 32px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
}
.file-drop:hover, .file-drop.dragging {
  border-color: var(--roxo);
  background: var(--roxo-claro);
}
.file-drop.com-arquivo { border-color: var(--verde); background: rgba(16, 185, 129, 0.05); }

.row { display: flex; gap: 16px; align-items: end; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 200px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border: none;
  border-radius: 10px;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  font-family: inherit;
}
.btn-primary {
  background: linear-gradient(135deg, var(--roxo), var(--roxo-escuro));
  color: white;
}
.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: var(--sombra-hover);
}
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-secondary {
  background: var(--cinza-claro);
  color: var(--azul);
}
.btn-secondary:hover { background: #d5dbdb; }
.btn-ghost { background: transparent; color: var(--roxo); }
.btn-ghost:hover { background: var(--roxo-claro); }
.btn-danger { background: var(--vermelho); color: white; }
.btn-grande { padding: 16px 36px; font-size: 17px; }

.modos-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px;
  margin-top: 8px;
}
.modo-chip {
  padding: 10px 14px;
  border: 1.5px solid var(--cinza-claro);
  border-radius: 10px;
  cursor: pointer;
  text-align: center;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s;
  background: white;
}
.modo-chip:hover { border-color: var(--roxo); }
.modo-chip.selecionado {
  background: var(--roxo);
  color: white;
  border-color: var(--roxo);
}
.modo-chip .desc { font-size: 11px; opacity: 0.7; display: block; margin-top: 2px; }

.loading {
  display: none;
  text-align: center;
  padding: 40px;
}
.loading.ativo { display: block; }
.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--cinza-claro);
  border-top-color: var(--roxo);
  border-radius: 50%;
  animation: girar 1s linear infinite;
  margin: 0 auto 16px;
}
@keyframes girar { to { transform: rotate(360deg); } }

.galeria-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
}
.mapa-card {
  background: white;
  border-radius: 12px;
  box-shadow: var(--sombra);
  overflow: hidden;
  transition: all 0.2s;
  cursor: pointer;
  border: 1px solid var(--cinza-claro);
}
.mapa-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--sombra-hover);
}
.mapa-card-header {
  padding: 16px;
  border-bottom: 1px solid var(--cinza-claro);
}
.mapa-card-titulo {
  font-weight: 600;
  font-size: 15px;
  margin-bottom: 4px;
}
.mapa-card-meta {
  font-size: 12px;
  color: var(--cinza);
  display: flex;
  gap: 8px;
}
.modo-tag {
  display: inline-block;
  padding: 2px 8px;
  background: var(--roxo-claro);
  color: var(--roxo-escuro);
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
}
.mapa-card-acoes {
  padding: 12px 16px;
  display: flex;
  gap: 8px;
}
.mapa-card-acoes .btn { flex: 1; padding: 6px 10px; font-size: 12px; }

.editor-wrap {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 16px;
  height: calc(100vh - 70px);
  padding: 16px;
  transition: grid-template-columns 0.3s ease;
  position: relative;
}
.editor-wrap.recolhido {
  grid-template-columns: 0 1fr;
  gap: 0;
  padding-left: 0;
}
.editor-wrap.recolhido .editor-painel-esq {
  display: none;
}
.btn-toggle-painel {
  position: fixed;
  top: 80px;
  left: 16px;
  z-index: 60;
  background: white;
  border: 1.5px solid var(--cinza-claro);
  border-radius: 8px;
  width: 36px;
  height: 36px;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--sombra);
  transition: all 0.2s;
  color: var(--azul);
}
.btn-toggle-painel:hover {
  border-color: var(--roxo);
  color: var(--roxo);
  transform: scale(1.05);
}
.editor-wrap:not(.recolhido) .btn-toggle-painel {
  left: calc(380px + 16px - 18px);
  background: var(--roxo);
  color: white;
  border-color: var(--roxo);
}

/* === Outliner — editor hierárquico === */
.outliner {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  line-height: 1.45;
  background: white;
}
.ol-vazio {
  color: var(--cinza);
  font-style: italic;
  padding: 12px;
  text-align: center;
}
.ol-no {
  position: relative;
}
.ol-linha {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 6px;
  border-radius: 6px;
  transition: background 0.1s;
  position: relative;
  min-height: 28px;
}
.ol-linha:hover {
  background: rgba(155, 89, 182, 0.04);
}
.ol-linha:focus-within {
  background: var(--roxo-claro);
}
.ol-toggle {
  width: 14px;
  height: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--cinza);
  cursor: pointer;
  font-size: 9px;
  flex-shrink: 0;
  opacity: 0.5;
  transition: transform 0.15s, opacity 0.1s;
  padding: 0;
}
.ol-toggle:hover { opacity: 1; }
.ol-no.recolhido > .ol-linha .ol-toggle {
  transform: rotate(-90deg);
}
.ol-no.sem-filhos > .ol-linha .ol-toggle {
  visibility: hidden;
}
.ol-bolinha {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--roxo);
  flex-shrink: 0;
  margin-right: 2px;
}
.ol-no.tipo-h1 > .ol-linha .ol-bolinha {
  width: 12px;
  height: 12px;
  box-shadow: 0 0 0 3px rgba(155,89,182,0.15);
}
.ol-no.tipo-h2 > .ol-linha .ol-bolinha {
  width: 10px;
  height: 10px;
}
.ol-texto {
  flex: 1;
  outline: none;
  padding: 3px 6px;
  border-radius: 4px;
  caret-color: var(--roxo);
  word-break: break-word;
  min-height: 1em;
}
.ol-texto:focus {
  background: white;
  box-shadow: inset 0 0 0 1.5px var(--roxo);
}
.ol-texto:empty::before {
  content: 'Vazio — comece a digitar';
  color: var(--cinza);
  font-style: italic;
  pointer-events: none;
}
.ol-no.tipo-h1 > .ol-linha .ol-texto {
  font-weight: 700;
  font-size: 16px;
  color: var(--azul);
}
.ol-no.tipo-h2 > .ol-linha .ol-texto {
  font-weight: 600;
  font-size: 14.5px;
}
.ol-acoes {
  display: none;
  gap: 2px;
}
.ol-linha:hover .ol-acoes,
.ol-linha:focus-within .ol-acoes {
  display: flex;
}
.ol-acao-btn {
  width: 22px;
  height: 22px;
  border: none;
  background: transparent;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--cinza);
  transition: all 0.1s;
  font-weight: bold;
  padding: 0;
}
.ol-acao-btn:hover {
  background: var(--roxo);
  color: white;
}
.ol-acao-btn.perigo:hover {
  background: var(--vermelho);
}
.ol-filhos {
  margin-left: 16px;
  padding-left: 8px;
  border-left: 1px solid var(--cinza-claro);
  position: relative;
}
.ol-no.recolhido > .ol-filhos {
  display: none;
}
.atalhos-hint {
  padding: 8px 14px;
  font-size: 11px;
  color: var(--cinza);
  border-top: 1px solid var(--cinza-claro);
  background: #fafafa;
  line-height: 1.6;
}
.atalhos-hint kbd {
  display: inline-block;
  padding: 1px 5px;
  background: white;
  border: 1px solid var(--cinza-claro);
  border-radius: 3px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: var(--azul);
  font-weight: 600;
  margin: 0 1px;
}

/* === Toolbar de ações no mapa === */
.toolbar-acoes {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%) translateY(-150%);
  display: flex;
  gap: 6px;
  background: white;
  padding: 8px 10px;
  border-radius: 12px;
  box-shadow: 0 6px 24px rgba(44, 62, 80, 0.15);
  border: 1px solid var(--cinza-claro);
  z-index: 20;
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s;
  align-items: center;
  opacity: 0;
  pointer-events: none;
}
.toolbar-acoes.ativo {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
  pointer-events: auto;
}
.toolbar-info {
  font-size: 12px;
  padding: 0 10px 0 4px;
  border-right: 1px solid var(--cinza-claro);
  display: flex;
  flex-direction: column;
  max-width: 200px;
}
.toolbar-info .label {
  font-size: 10px;
  color: var(--cinza);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 500;
}
.toolbar-info .nome {
  font-size: 13px;
  font-weight: 600;
  color: var(--azul);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}
.toolbar-botoes {
  display: flex;
  gap: 4px;
}
.toolbar-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border: none;
  background: transparent;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--azul);
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}
.toolbar-btn:hover {
  background: var(--roxo-claro);
  color: var(--roxo-escuro);
}
.toolbar-btn.danger:hover {
  background: rgba(231, 76, 60, 0.1);
  color: var(--vermelho);
}
.toolbar-btn .icone {
  font-size: 14px;
}
.toolbar-divider {
  width: 1px;
  background: var(--cinza-claro);
  margin: 0 2px;
}

/* === Hover/clique nos nós do mapa SVG === */
g.markmap-node {
  cursor: pointer;
  transition: opacity 0.15s;
}
g.markmap-node:hover circle {
  stroke-width: 3px;
  stroke: var(--roxo) !important;
  filter: drop-shadow(0 0 4px rgba(155, 89, 182, 0.5));
}

/* Flash de destaque quando clica no mapa e foca no outliner */
.ol-linha.destaque-flash {
  animation: flashDestaque 0.7s ease;
}
@keyframes flashDestaque {
  0%   { background: rgba(155, 89, 182, 0.25); }
  100% { background: transparent; }
}

/* Controles flutuantes do mapa */
.mapa-controles {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  gap: 4px;
  z-index: 5;
}
.btn-mapa {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--cinza-claro);
  background: white;
  cursor: pointer;
  font-size: 18px;
  color: var(--azul);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--sombra);
  transition: all 0.15s;
}
.btn-mapa:hover {
  border-color: var(--roxo);
  color: var(--roxo);
  transform: scale(1.05);
}

/* Dica de uso no canto */
.mapa-hint-uso {
  position: absolute;
  bottom: 10px;
  left: 12px;
  right: 12px;
  background: rgba(255, 255, 255, 0.95);
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 11.5px;
  color: var(--cinza);
  box-shadow: var(--sombra);
  pointer-events: none;
  text-align: center;
  backdrop-filter: blur(4px);
}
.mapa-hint-uso kbd {
  display: inline-block;
  padding: 1px 5px;
  background: var(--cinza-claro);
  border-radius: 3px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  font-weight: 600;
  color: var(--azul);
  margin: 0 1px;
}

.mapa-hint kbd {
  display: inline-block;
  padding: 1px 6px;
  background: var(--cinza-claro);
  border-radius: 4px;
  font-family: monospace;
  font-size: 11px;
  color: var(--azul);
  font-weight: 600;
}
.editor-painel {
  background: white;
  border-radius: 12px;
  box-shadow: var(--sombra);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.editor-titulo {
  padding: 12px 16px;
  border-bottom: 1px solid var(--cinza-claro);
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.editor-textarea {
  flex: 1;
  border: none;
  padding: 16px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  resize: none;
  background: #fafafa;
}
.editor-textarea:focus { outline: none; }
.preview-iframe {
  flex: 1;
  width: 100%;
  border: none;
}
.editor-acoes {
  padding: 12px 16px;
  border-top: 1px solid var(--cinza-claro);
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.editor-acoes .btn { padding: 8px 14px; font-size: 13px; }

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--azul);
  color: white;
  padding: 14px 20px;
  border-radius: 10px;
  box-shadow: var(--sombra-hover);
  transform: translateX(120%);
  transition: transform 0.3s;
  z-index: 1000;
}
.toast.ativo { transform: translateX(0); }
.toast.sucesso { background: var(--verde); }
.toast.erro { background: var(--vermelho); }

.diagnostico {
  margin-top: 16px;
  padding: 16px;
  background: var(--roxo-claro);
  border-radius: 10px;
  font-size: 14px;
}
.diagnostico h3 {
  font-size: 14px;
  text-transform: uppercase;
  color: var(--roxo-escuro);
  margin-bottom: 8px;
}
.diagnostico ul { padding-left: 20px; margin-bottom: 12px; }
.diagnostico li { margin-bottom: 4px; }

.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--cinza);
}

@media (max-width: 768px) {
  .editor-wrap {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr;
  }
  .hero h1 { font-size: 28px; }
}
