/* ============ Tokens ============ */
:root {
  --bg: #f5f3ee;
  --surface: #ffffff;
  --surface-2: #faf8f4;
  --text: #171c26;
  --muted: #5d6472;
  --border: #e4dfd5;
  --shadow: 0 1px 2px rgba(23, 28, 38, 0.06), 0 4px 14px rgba(23, 28, 38, 0.06);
  --shadow-forte: 0 12px 40px rgba(23, 28, 38, 0.18);
  --central: #14284b;
  --central-2: #1f3d6e;
  --central-text: #ffffff;
  --link: #1d5fa8;
  --foco: #1d5fa8;

  --st-documentado: #0f766e;
  --st-investigacao: #c2410c;
  --st-indireta: #64748b;
  --st-anulado: #b91c1c;
  --erro: #d61f1f;

  --g-master: #e3ecfd;   --a-master: #2456c9;
  --g-inss: #eee8fc;     --a-inss: #6d3fd1;
  --g-imoveis: #e2f5e7;  --a-imoveis: #15803d;
  --g-milicia: #fdeedd;  --a-milicia: #c2570c;
  --g-marielle: #fce8f1; --a-marielle: #be185d;
  --g-alerj: #dcf4f0;    --a-alerj: #0f766e;
  --g-farao: #e0f1fb;    --a-farao: #0369a1;
  --g-refit: #fbf1d3;    --a-refit: #a16207;

  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --gutter: 16px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1219; --surface: #151c26; --surface-2: #111821; --text: #e8edf3; --muted: #9ba6b4; --border: #263140;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 14px rgba(0,0,0,.25); --shadow-forte: 0 12px 40px rgba(0,0,0,.5);
    --central: #2b5594; --central-2: #3a68ad; --link: #82b6f0; --foco: #82b6f0;
    --st-documentado: #2dd4bf; --st-investigacao: #fb923c; --st-indireta: #94a3b8; --st-anulado: #f87171; --erro: #ff6b6b;
    --g-master: #172540; --a-master: #7ea6f5; --g-inss: #221c3b; --a-inss: #b39cf5; --g-imoveis: #14291c; --a-imoveis: #6ad08f;
    --g-milicia: #2f2013; --a-milicia: #f5a262; --g-marielle: #33172a; --a-marielle: #f37fb4; --g-alerj: #10302b; --a-alerj: #5fd4c2;
    --g-farao: #10283a; --a-farao: #6cc1f0; --g-refit: #2e2610; --a-refit: #e7c15a;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1219; --surface: #151c26; --surface-2: #111821; --text: #e8edf3; --muted: #9ba6b4; --border: #263140;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 14px rgba(0,0,0,.25); --shadow-forte: 0 12px 40px rgba(0,0,0,.5);
  --central: #2b5594; --central-2: #3a68ad; --link: #82b6f0; --foco: #82b6f0;
  --st-documentado: #2dd4bf; --st-investigacao: #fb923c; --st-indireta: #94a3b8; --st-anulado: #f87171; --erro: #ff6b6b;
  --g-master: #172540; --a-master: #7ea6f5; --g-inss: #221c3b; --a-inss: #b39cf5; --g-imoveis: #14291c; --a-imoveis: #6ad08f;
  --g-milicia: #2f2013; --a-milicia: #f5a262; --g-marielle: #33172a; --a-marielle: #f37fb4; --g-alerj: #10302b; --a-alerj: #5fd4c2;
  --g-farao: #10283a; --a-farao: #6cc1f0; --g-refit: #2e2610; --a-refit: #e7c15a;
}

/* ============ Base (mobile first) ============ */
* { box-sizing: border-box; }
html, body { margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
body.travado { overflow: hidden; }
a { color: var(--link); }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--foco); outline-offset: 2px; }

.app { max-width: 1600px; margin: 0 auto; }

/* ============ Topo ============ */
.topo { padding: 18px var(--gutter) 6px; }
.topo h1 {
  font-family: var(--serif);
  font-weight: 800;
  font-size: clamp(36px, 10vw, 56px);
  line-height: 1;
  letter-spacing: -0.02em;
  margin: 4px 0 8px;
}
.linha-fina { margin: 0; color: var(--muted); font-size: 16px; max-width: 62ch; }

.numeros { list-style: none; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 16px 0 0; padding: 0; }
.numeros li {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 6px 12px; font-size: 13px; color: var(--muted); line-height: 1.25;
}
.numeros b { display: block; font-family: var(--serif); font-size: 22px; color: var(--text); }

.aviso {
  margin: 10px var(--gutter) 12px;
  font-size: 13px;
  color: var(--muted);
}
.aviso a { font-weight: 600; text-decoration: none; white-space: nowrap; }

/* ============ Controles ============ */
.controles {
  display: flex; flex-direction: column; gap: 10px;
  padding: 0 var(--gutter) 12px;
}
.chips {
  display: flex; gap: 6px;
  overflow-x: auto; scrollbar-width: none;
  margin: 0 calc(-1 * var(--gutter)); padding: 2px var(--gutter);
}
.chips::-webkit-scrollbar { display: none; }
.chips button {
  flex: none;
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 600;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 14px 7px 12px;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.chips button[aria-pressed="false"] { opacity: .45; box-shadow: none; }
.chips button[aria-pressed="false"] span { text-decoration: line-through; }
.chips svg { flex: none; }


/* ============ Mapa ============ */
.mapa-bloco {
  position: relative;
  margin: 0 var(--gutter) 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.mapa-scroll { overflow: hidden; position: relative; scrollbar-width: none; }
.mapa-scroll::-webkit-scrollbar { display: none; }
.mapa-tamanho { position: relative; }
.mapa-camada { position: absolute; top: 0; left: 0; transform-origin: 0 0; }

.mapa-camada svg { position: absolute; inset: 0; overflow: visible; }
.aresta { fill: none; stroke-width: 2.2; stroke-linecap: round; transition: opacity .2s, stroke-width .2s; }
.aresta.documentado { stroke: var(--st-documentado); }
.aresta.investigacao { stroke: var(--st-investigacao); stroke-dasharray: 8 5; }
.aresta.indireta { stroke: var(--st-indireta); stroke-dasharray: 3 5; }
.aresta.anulado { stroke: var(--st-anulado); stroke-dasharray: 1 5; stroke-width: 2.6; }
.aresta.secundaria { opacity: .22; }
.aresta-alvo { fill: none; stroke: transparent; stroke-width: 16; cursor: pointer; pointer-events: stroke; }
.oculta { display: none; }

.grupo {
  position: absolute;
  background: var(--gcor);
  border-radius: 16px;
  border: 1px solid color-mix(in srgb, var(--acor) 18%, transparent);
}
.grupo-titulo {
  position: absolute; top: 9px; left: 14px; right: 14px;
  font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--acor);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.no {
  position: absolute;
  width: 208px; height: 52px;
  display: flex; flex-direction: column; justify-content: center; align-items: flex-start;
  gap: 1px;
  padding: 0 12px 0 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  text-align: left;
  cursor: pointer;
  transition: opacity .2s, transform .15s, box-shadow .15s, border-color .15s;
}
.no:hover { transform: translateY(-1px); box-shadow: var(--shadow-forte); border-color: color-mix(in srgb, var(--foco) 45%, var(--border)); }
.no .nome { font-weight: 700; font-size: 13.5px; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: calc(100% - 26px); }
.no .sub { font-size: 11.5px; color: var(--muted); line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.no .pontos { position: absolute; top: 7px; right: 8px; display: flex; gap: 3px; }
.ponto { width: 7px; height: 7px; border-radius: 50%; }
.ponto.documentado { background: var(--st-documentado); }
.ponto.investigacao { background: var(--st-investigacao); }
.ponto.indireta { background: var(--st-indireta); }
.ponto.anulado { background: var(--st-anulado); }
.no.apuracao { border-style: dashed; background: var(--surface-2); box-shadow: none; }
.no.apuracao .nome { font-style: italic; color: var(--muted); }

.no.central {
  width: 290px; height: 74px;
  background: linear-gradient(160deg, var(--central-2), var(--central));
  border: none; color: var(--central-text);
  align-items: center; text-align: center; padding: 0 14px;
  box-shadow: 0 8px 24px rgba(20, 40, 75, .35);
}
.no.central .nome { font-family: var(--serif); font-size: 22px; font-weight: 800; letter-spacing: -.01em; }
.no.central .sub { color: rgba(255,255,255,.8); font-size: 12px; }

.foco .no:not(.ativo) { opacity: .28; }
.foco .grupo { opacity: .7; }
.foco .aresta:not(.ativo) { opacity: .06; }
.foco .aresta.ativo { stroke-width: 3.4; opacity: 1; }
.no.selecionado { outline: 3px solid var(--foco); outline-offset: 2px; }

/* Controles do mapa */
.mapa-botoes { display: none; position: absolute; right: 12px; bottom: 12px; flex-direction: column; gap: 6px; z-index: 3; }
.mapa-botoes button {
  width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); box-shadow: var(--shadow); font-size: 18px; font-weight: 600; cursor: pointer;
}
.explorar {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); z-index: 3;
  background: var(--central); color: #fff; border: none; border-radius: 999px;
  padding: 11px 20px; font-weight: 700; font-size: 14.5px; box-shadow: var(--shadow-forte); cursor: pointer;
  white-space: nowrap;
}
.explorar::after { content: "  ⤢"; }
.sair-tela-cheia {
  display: none; position: absolute; top: calc(12px + env(safe-area-inset-top)); left: 12px; z-index: 3;
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px;
  padding: 8px 16px; font-weight: 700; box-shadow: var(--shadow); cursor: pointer;
}
.mapa-bloco.previa .mapa-scroll::after {
  content: ""; position: absolute; inset: auto 0 0 0; height: 70px;
  background: linear-gradient(transparent, var(--surface));
  pointer-events: none;
}

.mapa-bloco.tela-cheia {
  position: fixed; inset: 0; margin: 0; border-radius: 0; border: none; z-index: 40;
  display: flex; flex-direction: column;
}
.mapa-bloco.tela-cheia .mapa-scroll { flex: 1; overflow: auto; -webkit-overflow-scrolling: touch; }
.mapa-bloco.tela-cheia .mapa-botoes { display: flex; bottom: calc(16px + env(safe-area-inset-bottom)); }
.mapa-bloco.tela-cheia .sair-tela-cheia { display: block; }
.mapa-bloco.tela-cheia .explorar { display: none; }

/* ============ Lista (mobile) ============ */
.lista { padding: 0 var(--gutter) 8px; }
.lista-grupo { margin-bottom: 22px; }
.lista-grupo h2 {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--acor); margin: 0 0 8px;
}
.lista-grupo h2::before { content: ""; width: 10px; height: 10px; border-radius: 3px; background: var(--acor); }
.lista-grupo ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.cartao {
  width: 100%;
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 4px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--acor);
  border-radius: 12px;
  padding: 12px 14px;
  text-align: left; cursor: pointer;
  box-shadow: var(--shadow);
}
.cartao .nome { font-weight: 700; font-size: 15.5px; line-height: 1.25; }
.cartao .sub { grid-column: 1; font-size: 13px; color: var(--muted); }
.cartao .seta { grid-row: 1 / span 3; grid-column: 2; color: var(--muted); font-size: 20px; }
.cartao .badges { grid-column: 1; display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.cartao.apuracao { border-style: dashed; border-left-style: solid; box-shadow: none; }

/* ============ Selos de status ============ */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11.5px; font-weight: 700;
  padding: 2px 9px 2px 7px;
  border-radius: 999px;
  border: 1.5px solid currentColor;
  white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.documentado { color: var(--st-documentado); }
.badge.investigacao { color: var(--st-investigacao); border-style: dashed; }
.badge.indireta { color: var(--st-indireta); border-style: dashed; }
.badge.anulado { color: var(--st-anulado); border-style: dotted; }

.painel-conteudo::-webkit-scrollbar { width: 8px; }
.painel-conteudo::-webkit-scrollbar-track { background: transparent; }
.painel-conteudo::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; border: 2px solid var(--surface); }

/* ============ Painel (mobile: gaveta de baixo) ============ */
.painel {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
  max-height: 88vh; max-height: 88dvh;
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  box-shadow: var(--shadow-forte);
  transform: translateY(105%);
  transition: transform .28s cubic-bezier(.2,.8,.2,1);
  display: flex; flex-direction: column;
}
.painel.aberto { transform: none; }
.painel-alca { width: 40px; height: 5px; border-radius: 3px; background: var(--border); margin: 8px auto 0; flex: none; }
.painel-fechar {
  position: absolute; top: 10px; right: 12px;
  width: 36px; height: 36px; border-radius: 50%; border: none;
  background: var(--surface-2); font-size: 22px; line-height: 1; cursor: pointer; z-index: 2;
}
.painel-conteudo {
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  scrollbar-width: thin; scrollbar-color: var(--border) transparent;
  padding: 10px 20px calc(28px + env(safe-area-inset-bottom));
}
.veu { position: fixed; inset: 0; background: rgba(10, 14, 20, .45); z-index: 50; opacity: 0; pointer-events: none; transition: opacity .25s; }
.veu.aberto { opacity: 1; pointer-events: auto; }

.painel .grupo-tag { font-size: 11.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--acor, var(--muted)); margin-top: 6px; }
.painel h2 { font-family: var(--serif); font-size: 28px; line-height: 1.1; letter-spacing: -.01em; margin: 4px 44px 6px 0; }
.painel .desc { color: var(--muted); margin: 0; }

.nota-mapa {
  margin: 14px 0 0;
  padding: 2px 0 2px 12px;
  border-left: 3px solid var(--border);
  font-size: 13.5px;
  color: var(--muted);
}
.caixa-apuracao {
  margin: 16px 0 4px;
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 14px;
  background: var(--surface-2);
  border: 1px dashed var(--border);
}
.caixa-apuracao b { display: block; }

.ligacao { border-top: 1px solid var(--border); padding-top: 18px; margin-top: 18px; }
.ligacao:first-of-type { margin-top: 20px; }
.ligacao h3 { margin: 10px 0 8px; font-size: 16px; line-height: 1.3; }
.ligacao h3 button { all: unset; cursor: pointer; color: var(--link); font-weight: 700; }
.ligacao h3 button:focus-visible { outline: 2px solid var(--foco); }
.ligacao p { margin: 0 0 10px; }
.outro-lado {
  font-size: 14px; color: var(--muted);
  padding-left: 12px; border-left: 3px solid var(--border);
}
.outro-lado b { color: var(--text); }
.fontes-titulo { font-size: 11.5px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 14px 0 6px; }
.fontes { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.fontes a {
  display: block; text-decoration: none; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 9px 12px;
}
.fontes a:hover { border-color: var(--link); }
.fontes .veiculo { display: block; font-size: 11.5px; font-weight: 700; color: var(--muted); }
.fontes .titulo { font-size: 14px; font-weight: 600; color: var(--link); line-height: 1.35; }
.fontes .titulo::after { content: " ↗"; font-weight: 400; }
.verificado { font-size: 12px; color: var(--muted); margin-top: 10px; }

/* ============ Rodapé ============ */
.rodape {
  display: flex; justify-content: center; gap: 10px;
  padding: 14px var(--gutter) calc(24px + env(safe-area-inset-bottom));
  font-size: 13px; color: var(--muted);
}
.rodape a { color: var(--muted); font-weight: 600; text-decoration: none; }
.rodape a:hover { color: var(--link); }

/* ============ Páginas de texto ============ */
.pagina { max-width: 720px; margin: 0 auto; padding: 24px var(--gutter) 48px; }
.pagina h1 { font-family: var(--serif); font-size: 36px; line-height: 1.1; letter-spacing: -0.02em; margin: 14px 0 14px; }
.pagina h2 { font-family: var(--serif); font-size: 22px; margin-top: 30px; }
.pagina .voltar { font-weight: 600; text-decoration: none; }
.pagina table { border-collapse: collapse; width: 100%; font-size: 14px; }
.pagina td, .pagina th { border-bottom: 1px solid var(--border); padding: 8px 6px; text-align: left; vertical-align: top; }

/* ============ Desktop ============ */
@media (min-width: 900px) {
  :root { --gutter: 28px; }
  body.pagina-mapa { height: 100vh; overflow: hidden; }
  .app { height: 100vh; display: flex; flex-direction: column; transition: padding-right .28s; }
  .topo { padding-top: 20px; display: grid; grid-template-columns: 1fr auto; column-gap: 32px; align-items: end; }
  .topo h1 { grid-column: 1; grid-row: 1; font-size: 52px; margin: 0 0 6px; }
  .linha-fina { grid-column: 1; grid-row: 2; max-width: none; }
  .numeros { grid-column: 2; grid-row: 1 / span 2; margin: 0; grid-template-columns: repeat(3, auto); justify-content: end; align-self: center; }
  .aviso { margin-top: 12px; }
  .controles { flex-direction: row; align-items: center; justify-content: space-between; }
  .chips { overflow: visible; margin: 0; padding: 0; flex-wrap: wrap; }

  .mapa-bloco { flex: 1; min-height: 0; margin-bottom: 0; display: flex; }
  .rodape { padding: 8px var(--gutter) 12px; }
  .mapa-scroll { flex: 1; overflow: auto; cursor: grab; }
  .mapa-bloco .mapa-botoes { display: flex; }
  .explorar, .lista, .mapa-bloco.previa .mapa-scroll::after { display: none; }


  .painel {
    left: auto; top: 16px; right: 16px; bottom: 16px;
    width: 440px; max-height: none;
    border-radius: 16px;
    border: 1px solid var(--border);
    transform: translateX(calc(100% + 24px));
  }
  .painel-alca { display: none; }
  .painel-conteudo { padding: 22px 26px 30px; }
  .veu { display: none; }
  body.com-painel .app { padding-right: 460px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ============ Imagem de prévia (?og) ============ */
.modo-og .aviso, .modo-og .controles, .modo-og .rodape, .modo-og .mapa-botoes, .modo-og .numeros { display: none !important; }
