:root {
  --bg: #f4f4f5;
  --panel: #ffffff;
  --ink: #18181b;
  --muted: #71717a;
  --line: #e4e4e7;
  --accent: #2563eb;
  --edited: #d97706;
  --artifact: #7c3aed;
  --site: #2d6235;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #18181b;
    --panel: #27272a;
    --ink: #f4f4f5;
    --muted: #a1a1aa;
    --line: #3f3f46;
    --accent: #60a5fa;
    --edited: #fbbf24;
    --artifact: #a78bfa;
    --site: #1d3f24;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* --- barra superior --- */

.bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.brand { font-weight: 650; letter-spacing: -0.01em; }

.tag {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 8px;
}

.spacer { flex: 1; }

.button, button {
  font: inherit;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
}

.button:hover, button:hover { border-color: var(--accent); }
button:disabled { opacity: 0.4; cursor: default; border-color: var(--line); }

.group { display: inline-flex; align-items: center; gap: 6px; }
.group span { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 60px; text-align: center; }

.check { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); cursor: pointer; }

/* --- aviso --- */

.notice {
  padding: 8px 14px;
  background: color-mix(in srgb, var(--edited) 12%, var(--panel));
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  font-size: 13px;
}

/* --- layout --- */

main {
  flex: 1;
  display: flex;
  min-height: 0;
}

.stage {
  flex: 1;
  overflow: auto;
  padding: 24px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.empty { max-width: 46ch; margin-top: 12vh; text-align: center; }
.empty h1 { font-size: 20px; font-weight: 600; margin: 0 0 10px; }
.empty p { margin: 0 0 10px; }
.muted { color: var(--muted); font-size: 13px; }

/* --- página --- */

.page {
  position: relative;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.16), 0 8px 28px rgba(0,0,0,.10);
}

.page canvas { display: block; }

.layer {
  position: absolute;
  inset: 0;
  /* A camada é transparente a cliques; só as linhas capturam. Sem isto, um
     clique em qualquer lugar da página roubaria o foco da linha em edição. */
  pointer-events: none;
}

/* --- linhas de texto --- */

.tl {
  position: absolute;
  /* O recuo cresce a área de clique sem mover o texto: a margem negativa
     devolve exatamente o que o padding empurrou. Uma linha de 8pt tem oito
     pixels de altura a 100%, e acertá-la com o mouse era questão de sorte. */
  margin: -3px -1px;
  padding: 3px 2px;
  white-space: pre;
  color: #111;
  font-family: Georgia, "Times New Roman", serif;
  line-height: 1;
  pointer-events: auto;
  cursor: text;
  border-radius: 2px;
  outline: none;
  /* O texto é reposicionado pela baseline reconstruída; a origem do elemento
     fica no topo da caixa, então subimos aproximadamente uma altura de ascendente. */
  transform-origin: left top;
}

.tl.moving {
  cursor: grabbing;
  background: color-mix(in srgb, var(--edited) 30%, transparent);
  box-shadow: 0 0 0 1px var(--edited);
}

.tl:hover { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.tl:focus { background: color-mix(in srgb, var(--accent) 18%, transparent); box-shadow: 0 0 0 1px var(--accent); }

.tl.artifact { color: #444; }
.tl.edited { background: color-mix(in srgb, var(--edited) 22%, transparent); }

.boxes .tl { box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 40%, transparent); }
.boxes .tl.artifact { box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--artifact) 50%, transparent); }

.hide-artifacts .tl.artifact { display: none; }

/* Quais linhas a gravação alcança. Fica atrás de um interruptor porque é
 * andaime de desenvolvimento, não parte do documento — mas enquanto a edição
 * não alcançar tudo, é a informação que decide onde mexer. */
.savable-marks .tl.savable { box-shadow: inset 0 -2px 0 #16a34a; }
.savable-marks .tl.unsavable { box-shadow: inset 0 -2px 0 var(--artifact); opacity: 0.75; }

/* --- painel lateral --- */

.side {
  width: 320px;
  border-left: 1px solid var(--line);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.panel.grow { flex: 1; min-height: 0; display: flex; flex-direction: column; }

.panel h2 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 0 0 8px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.count {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 7px;
  font-size: 11px;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
}

dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; font-size: 13px; }
dt { color: var(--muted); }
dd { margin: 0; font-variant-numeric: tabular-nums; }
dd.warn { color: var(--edited); font-weight: 600; }

.lines { margin: 0; padding: 0 0 0 2px; list-style: none; overflow: auto; flex: 1; font-size: 12px; }
.lines li {
  padding: 3px 6px;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lines li:hover { background: var(--bg); }
.lines li.artifact { color: var(--artifact); }
.lines li.edited { color: var(--edited); font-weight: 600; }

.edits { max-height: 190px; overflow: auto; font-size: 12px; }
.edits .row { padding: 5px 0; border-bottom: 1px dashed var(--line); }
.edits .row:last-child { border-bottom: 0; }
.edits .before { color: var(--muted); text-decoration: line-through; }
.edits .after { color: var(--edited); }
.edits .blocked {
  color: var(--muted);
  font-style: italic;
  border-left: 2px solid var(--artifact);
  padding-left: 6px;
  margin-top: 3px;
}

/* A troca "todas as páginas / só esta" de uma edição de mobiliário. Parece
   link porque é uma escolha secundária dentro de uma linha de texto, e não uma
   ação da barra. */
.edits button.link {
  background: none;
  border: 0;
  padding: 0;
  color: var(--edited);
  text-decoration: underline;
  font: inherit;
  cursor: pointer;
}
.edits button.link:focus-visible { outline: 2px solid var(--edited); outline-offset: 2px; }

/* O parágrafo aberto para edição. A borda diz "isto é uma unidade só"; o
   fundo continua transparente porque o vetor por baixo não tem texto. */
.paragrafo {
  position: absolute;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  outline: 1px dashed var(--edited);
  outline-offset: 2px;
  z-index: 5;
  cursor: text;
}
.paragrafo:focus { outline-style: solid; }

/* Aviso permanente de que o editor está mandando arquivos ao servidor. Não
   some sozinho: quem abre um documento tem de saber que ele está sendo
   guardado. */
.depuracao {
  background: #7a1f1f;
  color: #fff;
  font-size: 13px;
  padding: 6px 12px;
}
.depuracao a { color: #fff; font-weight: 600; }

/* --- toast --- */

.toast {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13px;
  box-shadow: 0 4px 16px rgba(0,0,0,.25);
}

/* --- barra de fonte --- */

/* Uma regra de autor com `display` vence o `[hidden]` do navegador, que é regra
 * de agente do usuário. Sem isto as duas barras flutuantes aparecem antes de
 * haver linha em foco ou tabela selecionada — e o `hidden` no HTML dá a
 * impressão de que estão escondidas. */
.fontbar[hidden], .tablebar[hidden] { display: none; }

.fontbar {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 6px 24px rgba(0,0,0,.20);
  z-index: 10;
}

.fontbar .fb-label {
  font-size: 12px;
  color: var(--muted);
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding-right: 4px;
  border-right: 1px solid var(--line);
  margin-right: 2px;
}

.fontbar select, .fontbar input {
  font: inherit;
  font-size: 13px;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 3px 6px;
}
.fontbar input { width: 62px; }
.fontbar button.on { background: var(--accent); color: #fff; border-color: var(--accent); }

/* --- listas de fontes e imagens --- */

.fonts { font-size: 12px; max-height: 172px; overflow: auto; }
.fonts .item { padding: 5px 0; border-bottom: 1px dashed var(--line); }
.fonts .item:last-child { border-bottom: 0; }
.fonts .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fonts .meta { color: var(--muted); }
.fonts .flag {
  display: inline-block;
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 0 4px;
  margin-right: 3px;
  font-size: 11px;
}
.fonts .flag.warn { border-color: var(--edited); color: var(--edited); }
.fonts .flag.good { border-color: var(--accent); color: var(--accent); }

/* --- classificação de mobiliário de página --- */

.tl.furniture { color: #444; }
.boxes .tl.furniture { box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--artifact) 50%, transparent); }
.hide-artifacts .tl.furniture { display: none; }
.lines li.furniture { color: var(--artifact); }

.fontbar .fb-add { padding: 3px 8px; font-size: 12px; }
.fontbar select { max-width: 220px; }

/* --- tabelas ---
 *
 * A camada da grade cobre a página inteira e é transparente a eventos: só as
 * alças recebem clique. Sem isso a grade roubaria o clique do texto, e editar
 * uma célula — a coisa mais óbvia a se fazer numa tabela — deixaria de
 * funcionar. */

.tablelayer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.tgrid {
  position: absolute;
  outline: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
}

.tgrid-v, .tgrid-h {
  position: absolute;
  background: color-mix(in srgb, var(--accent) 28%, transparent);
}

.tgrid-v { top: 0; bottom: 0; width: 1px; }
.tgrid-h { left: 0; right: 0; height: 1px; }

/* As alças ficam fora da tabela — coluna acima, fileira à esquerda — porque
 * dentro dela está o texto. */
.thandle {
  position: absolute;
  pointer-events: auto;
  padding: 0;
  border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
  border-radius: 3px;
  background: color-mix(in srgb, var(--accent) 12%, var(--panel));
  color: var(--accent);
  font: 600 10px/1 ui-sans-serif, system-ui, sans-serif;
  cursor: pointer;
}

.thandle:hover { background: color-mix(in srgb, var(--accent) 28%, var(--panel)); }
.thandle.on { background: var(--accent); color: #fff; border-color: var(--accent); }

.thandle-col { height: 13px; }
.thandle-row { width: 13px; }

/* Célula cuja fileira ou coluna o usuário removeu. Continua no DOM, riscada, em
 * vez de sumir: a operação é reversível e ver o que saiu é o que permite
 * conferir que saiu a coisa certa. */
.tl.removed {
  opacity: 0.28;
  text-decoration: line-through;
  pointer-events: none;
}

.tablebar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-top: 1px solid var(--line);
  background: var(--panel);
  font-size: 12px;
}

.tablebar button {
  padding: 3px 8px;
  font-size: 12px;
  min-width: 30px;
}

.tablebar button:disabled { opacity: 0.35; cursor: default; }
.tablebar .tb-sep { width: 1px; height: 18px; background: var(--line); }
.tablebar .fb-label { margin-right: auto; }

/* Com os glifos do arquivo desenhados no canvas, a camada editável **fica** —
 * só o texto dela some. Esconder a camada inteira era o erro: quem liga a
 * fidelidade quer ver o documento como ele é, não perder a capacidade de
 * clicar nele. Texto transparente por cima do texto desenhado é o que dá as
 * duas coisas: o que se vê são os contornos do arquivo, e o que se clica
 * continua sendo a linha. */
.glyphs .tl { color: transparent; }
.glyphs .tl span { color: transparent; }
.glyphs .tl::selection, .glyphs .tl span::selection {
  /* A seleção precisa continuar visível mesmo com o texto transparente. */
  background: color-mix(in srgb, var(--accent) 35%, transparent);
}

/* --- navegacao entre as ferramentas do site -------------------------------
 *
 * As duas ferramentas moram no mesmo dominio e atacam o mesmo problema por
 * caminhos diferentes: o gerador troca os lancamentos de um extrato a partir de
 * uma planilha; o editor abre qualquer PDF e deixa mexer no texto. Quem chega
 * por uma precisa ver que a outra existe -- e a faixa e a mesma nas duas, para
 * que passar de uma para a outra nao pareca sair do site. */

.sitenav {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 14px;
  min-height: 40px;
  background: var(--site);
  color: #fff;
  font-size: 13px;
  overflow-x: auto;
}

.sitenav-brand {
  font-weight: 650;
  letter-spacing: 0.02em;
  margin-right: 12px;
  white-space: nowrap;
}

.sitenav a {
  color: rgba(255, 255, 255, 0.82);
  text-decoration: none;
  padding: 5px 10px;
  border-radius: 6px;
  white-space: nowrap;
}

.sitenav a:hover { background: rgba(255, 255, 255, 0.12); color: #fff; }
.sitenav a:focus-visible { outline: 2px solid #fff; outline-offset: 1px; }

.sitenav a[aria-current="page"] {
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  font-weight: 600;
}
