:root {
  --bg: #f6f7f9; --card: #fff; --texto: #1f2937; --suave: #6b7280; --borda: #e5e7eb;
  --primaria: #2563eb; --primaria-esc: #1d4ed8; --perigo: #dc2626;
  --side-w: 300px; --raio: 10px; --sombra: 0 1px 3px rgba(0,0,0,.08);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 16px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--texto); background: var(--bg); display: flex; }
button, input, textarea { font: inherit; color: inherit; }
a { color: var(--primaria); }

/* ---------- Sidebar ---------- */
.sidebar { width: var(--side-w); flex-shrink: 0; height: 100vh; position: sticky; top: 0; background: var(--card);
  border-right: 1px solid var(--borda); display: flex; flex-direction: column; z-index: 20; }
.sidebar-topo { padding: 16px; border-bottom: 1px solid var(--borda); display: grid; gap: 12px; }
.logo { font-weight: 700; font-size: 1.15rem; text-decoration: none; color: var(--texto); }
#busca { width: 100%; padding: 9px 12px; border: 1px solid var(--borda); border-radius: 8px; background: var(--bg); }
#busca:focus { outline: 2px solid var(--primaria); background: #fff; }
.arvore { flex: 1; overflow-y: auto; padding: 8px; }
.sidebar-rodape { padding: 12px; border-top: 1px solid var(--borda); }

.modulo { margin-bottom: 4px; }
.modulo-cab { display: flex; align-items: center; gap: 4px; border-radius: 8px; }
.modulo-cab:hover { background: var(--bg); }
.modulo-btn { flex: 1; display: flex; align-items: center; gap: 8px; text-align: left; background: none; border: 0; padding: 8px; cursor: pointer; font-weight: 600; min-width: 0; }
.modulo-btn .nome { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pontinho { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.seta { font-size: .7rem; color: var(--suave); transition: transform .15s; }
.modulo.aberto .seta { transform: rotate(90deg); }
.topicos { display: none; margin: 0 0 6px 18px; padding-left: 8px; border-left: 2px solid var(--borda); }
.modulo.aberto .topicos { display: block; }
.topico { display: flex; align-items: center; border-radius: 6px; }
.topico a { flex: 1; display: block; padding: 6px 8px; text-decoration: none; color: var(--texto); font-size: .93rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topico:hover { background: var(--bg); }
.topico.ativo { background: #eff6ff; }
.topico.ativo a { color: var(--primaria); font-weight: 600; }
.acoes-mini { display: none; gap: 2px; }
body.editando .acoes-mini { display: flex; }
.acoes-mini button, .icon-btn { background: none; border: 0; cursor: pointer; border-radius: 6px; padding: 2px 6px; color: var(--suave); }
.acoes-mini button:hover, .icon-btn:hover { background: var(--borda); color: var(--texto); }
.add-topico { display: none; margin: 4px 0 4px 8px; font-size: .88rem; }
body.editando .add-topico { display: inline-block; }
.edit-only { display: none; width: 100%; }
body.editando .edit-only { display: block; }
.vazio-side { padding: 16px; color: var(--suave); font-size: .92rem; }
.resultado { display: block; padding: 10px; border-radius: 8px; text-decoration: none; color: var(--texto); }
.resultado:hover { background: var(--bg); }
.resultado strong { display: block; }
.resultado small { color: var(--suave); display: block; }
.resultado .modtag { font-size: .75rem; font-weight: 600; }
mark { background: #fde68a; padding: 0 2px; border-radius: 3px; }

/* ---------- Principal ---------- */
.principal { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.barra { position: sticky; top: 0; z-index: 10; display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px 32px; background: rgba(246,247,249,.92); backdrop-filter: blur(6px); border-bottom: 1px solid var(--borda); }
.migalhas { color: var(--suave); font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toggle { display: flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; font-size: .9rem; font-weight: 600; flex-shrink: 0; }
.toggle input { display: none; }
.trilho { width: 40px; height: 22px; border-radius: 11px; background: #cbd5e1; position: relative; transition: background .2s; }
.bolinha { position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; background: #fff; border-radius: 50%; transition: transform .2s; }
.toggle input:checked + .trilho { background: var(--primaria); }
.toggle input:checked + .trilho .bolinha { transform: translateX(18px); }
.conteudo { width: 100%; max-width: 860px; margin: 0 auto; padding: 32px; }

.btn { background: var(--primaria); color: #fff; border: 0; padding: 9px 16px; border-radius: 8px; cursor: pointer; font-weight: 600; }
.btn:hover { background: var(--primaria-esc); }
.btn-sec { background: var(--card); color: var(--texto); border: 1px solid var(--borda); }
.btn-sec:hover { background: var(--bg); }
.btn-perigo { color: var(--perigo); }
.btn-peq { padding: 5px 10px; font-size: .88rem; }

/* Início */
.hero h1 { margin: 0 0 4px; }
.hero p { color: var(--suave); margin: 0 0 24px; }
.grade { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.card-mod { background: var(--card); border: 1px solid var(--borda); border-top-width: 4px; border-radius: var(--raio); padding: 16px; box-shadow: var(--sombra); }
.card-mod h3 { margin: 0 0 4px; }
.card-mod p { margin: 0 0 8px; color: var(--suave); font-size: .92rem; }
.card-mod ul { margin: 0; padding-left: 18px; font-size: .93rem; }

/* Tópico */
.topico-cab h1 { margin: 4px 0 6px; line-height: 1.25; }
.tag-mod { display: inline-block; font-size: .78rem; font-weight: 700; color: #fff; padding: 2px 10px; border-radius: 99px; }
.resumo { color: var(--suave); font-size: 1.05rem; margin: 0 0 4px; }
.meta { color: var(--suave); font-size: .82rem; margin-bottom: 24px; }
.input-titulo { width: 100%; font-size: 1.8rem; font-weight: 700; border: 1px dashed var(--borda); border-radius: 8px; padding: 6px 10px; background: #fff; }
.input-resumo { width: 100%; margin-top: 8px; border: 1px dashed var(--borda); border-radius: 8px; padding: 8px 10px; background: #fff; resize: vertical; }

.bloco { position: relative; margin-bottom: 16px; }
.bloco-texto { background: var(--card); border-radius: var(--raio); padding: 4px 20px; box-shadow: var(--sombra); }
.texto h2 { font-size: 1.4rem; margin: 1.1em 0 .4em; }
.texto h3 { font-size: 1.15rem; margin: 1em 0 .3em; }
.texto p, .texto div { margin: .5em 0; }
.texto ul, .texto ol { margin: .5em 0; padding-left: 24px; }
.aviso { background: #fef9c3; border-left: 4px solid #eab308; padding: 10px 14px; border-radius: 6px; margin: .8em 0 !important; }
.fig { margin: 0; text-align: center; }
.fig img { max-width: 100%; max-height: 520px; border-radius: var(--raio); border: 1px solid var(--borda); background: #fff; cursor: zoom-in; box-shadow: var(--sombra); }
.fig figcaption { color: var(--suave); font-size: .88rem; margin-top: 6px; }

/* Edição */
.editor { min-height: 70px; padding: 10px 4px; outline: none; }
body.editando .bloco { padding: 8px; border: 1px dashed var(--borda); border-radius: var(--raio); background: rgba(255,255,255,.5); }
body.editando .bloco-texto { padding: 8px; }
.bloco-barra { display: none; align-items: center; gap: 4px; flex-wrap: wrap; padding-bottom: 8px; margin-bottom: 8px; border-bottom: 1px solid var(--borda); }
body.editando .bloco-barra { display: flex; }
.bloco-barra .esp { flex: 1; }
.fmt { background: var(--bg); border: 1px solid var(--borda); border-radius: 6px; padding: 3px 9px; cursor: pointer; font-size: .85rem; }
.fmt:hover { background: var(--borda); }
.input-legenda { width: 100%; margin-top: 8px; padding: 6px 10px; border: 1px solid var(--borda); border-radius: 6px; text-align: center; }
.adicionar { display: none; gap: 8px; flex-wrap: wrap; margin-top: 24px; padding: 16px; border: 2px dashed var(--borda); border-radius: var(--raio); justify-content: center; align-items: center; }
body.editando .adicionar { display: flex; }
.adicionar small { color: var(--suave); width: 100%; text-align: center; }
.acoes-topico { display: none; gap: 8px; margin-top: 32px; }
body.editando .acoes-topico { display: flex; }
.estado-salvo { font-size: .78rem; color: var(--suave); margin-left: 6px; }
.vazio { text-align: center; color: var(--suave); padding: 48px 16px; }

/* Dialog, modal, toast */
dialog { border: 0; border-radius: 14px; padding: 24px; width: min(440px, 92vw); box-shadow: 0 20px 50px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog h3 { margin: 0 0 16px; }
dialog label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 12px; }
dialog input:not([type=color]), dialog textarea { width: 100%; margin-top: 4px; padding: 8px 10px; border: 1px solid var(--borda); border-radius: 8px; font-weight: 400; }
dialog input[type=color] { display: block; margin-top: 4px; width: 60px; height: 36px; border: 1px solid var(--borda); border-radius: 6px; padding: 2px; }
.dlg-acoes { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.modal-img { position: fixed; inset: 0; background: rgba(0,0,0,.85); z-index: 100; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px; cursor: zoom-out; }
.modal-img[hidden] { display: none; }
.modal-img img { max-width: 95vw; max-height: 85vh; border-radius: 8px; background: #fff; }
.modal-img p { color: #fff; margin: 12px 0 0; text-align: center; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #111827; color: #fff; padding: 10px 18px; border-radius: 8px; z-index: 200; font-size: .92rem; }
.toast[hidden] { display: none; }
.toast.erro { background: var(--perigo); }

/* ---------- Responsivo ---------- */
.menu-toggle { display: none; position: fixed; top: 8px; left: 8px; z-index: 30; background: var(--card); border: 1px solid var(--borda); font-size: 1.2rem; padding: 6px 12px; }
.overlay { display: none; }
@media (max-width: 860px) {
  .menu-toggle { display: block; }
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 30px rgba(0,0,0,.2); }
  body.menu-aberto .sidebar { transform: none; }
  body.menu-aberto .overlay { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 15; }
  .barra { padding: 12px 16px 12px 64px; }
  .conteudo { padding: 20px 16px; }
}
@media print {
  .sidebar, .barra, .menu-toggle, .adicionar, .acoes-topico { display: none !important; }
  body { background: #fff; }
  .bloco-texto { box-shadow: none; padding: 0; }
}
.editor:empty::before { content: attr(data-placeholder); color: var(--suave); }
kbd { background: var(--bg); border: 1px solid var(--borda); border-radius: 4px; padding: 0 5px; font-size: .8em; }
