/* Face humana — navegação.
 *
 * Três zonas fixas e uma coluna de leitura: topo (onde estou + buscar),
 * lateral esquerda (o corpus), lateral direita (este documento), centro (o
 * texto). Nada do que serve para navegar rola junto com o texto.
 */

:root {
  --fg: #1a1a1a;
  --muted: #6b7280;
  --bg: #ffffff;
  --accent: #1d4ed8;
  --accent-soft: #eef2ff;
  --border: #e5e7eb;
  --surface: #f9fafb;
  --obrig: #b91c1c;
  --rec: #b45309;
  --sidebar: 17rem;
  --outline: 16rem;
  --header-h: 3.25rem;
}

* { box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--fg);
  background: var(--bg);
  margin: 0;
  line-height: 1.6;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
code { font-size: 0.9em; }

/* ------------------------------------------------------------------ topo */

header.site {
  position: sticky; top: 0; z-index: 30; background: var(--bg);
  border-bottom: 1px solid var(--border);
  min-height: var(--header-h);
  display: flex; align-items: center; gap: 0.9rem;
  padding: 0.4rem 1rem;
}
header.site .brand { font-weight: 700; white-space: nowrap; }
header.site .brand a { color: var(--fg); }

/* Trilha: onde o leitor está, e — em documento longo — em que seção ele está
   agora (atualizada pelo scroll, ver ui.js). */
nav.crumbs {
  display: flex; align-items: center; gap: 0.35rem; min-width: 0;
  font-size: 0.85rem; color: var(--muted); white-space: nowrap;
}
nav.crumbs a { color: var(--muted); }
nav.crumbs a:hover { color: var(--accent); }
nav.crumbs .sep { opacity: 0.5; }
nav.crumbs .here { color: var(--fg); font-weight: 600; }
nav.crumbs .at-section {
  overflow: hidden; text-overflow: ellipsis; max-width: 22rem;
}
@media (max-width: 1100px) { nav.crumbs .at-section { display: none; } }

/* Busca: no topo, com resultado na própria página. A tela /search continua
   existindo para a lista inteira, mas deixou de ser o caminho obrigatório. */
.finder { position: relative; margin-left: auto; }
.finder input[type=search] {
  width: 22rem; max-width: 42vw;
  padding: 0.38rem 0.6rem; border: 1px solid var(--border);
  border-radius: 7px; font-size: 0.9rem; background: var(--surface);
}
.finder input[type=search]:focus {
  outline: 2px solid var(--accent-soft); border-color: var(--accent);
  background: var(--bg);
}
.finder .hint {
  position: absolute; right: 0.55rem; top: 50%; transform: translateY(-50%);
  font-size: 0.7rem; color: var(--muted); border: 1px solid var(--border);
  border-radius: 4px; padding: 0 0.25rem; pointer-events: none; background: var(--bg);
}
.finder input:focus ~ .hint, .finder input:not(:placeholder-shown) ~ .hint { display: none; }

.finder-results {
  position: absolute; right: 0; top: calc(100% + 0.35rem);
  width: 34rem; max-width: 88vw; max-height: 70vh; overflow: auto;
  background: var(--bg); border: 1px solid var(--border); border-radius: 9px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12); padding: 0.3rem;
}
.finder-results[hidden] { display: none; }
.finder-results .row {
  display: block; padding: 0.4rem 0.55rem; border-radius: 6px; color: var(--fg);
}
.finder-results .row:hover, .finder-results .row.active {
  background: var(--accent-soft); text-decoration: none;
}
.finder-results .row .title { font-weight: 600; font-size: 0.9rem; }
.finder-results .row .meta { font-size: 0.75rem; color: var(--muted); }
.finder-results .row .snippet {
  font-size: 0.8rem; color: var(--muted);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.finder-results .empty, .finder-results .all {
  padding: 0.45rem 0.6rem; font-size: 0.8rem; color: var(--muted);
}

.nav-toggle {
  display: none; background: var(--bg); border: 1px solid var(--border);
  border-radius: 7px; padding: 0.3rem 0.6rem; font: inherit; font-size: 0.85rem;
  cursor: pointer;
}

/* -------------------------------------------------------------- esqueleto */

.shell {
  display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr);
  gap: 2rem; max-width: 100rem; margin: 0 auto; padding: 1.25rem 1.25rem 4rem;
  align-items: start;
}
.shell.with-outline {
  grid-template-columns: var(--sidebar) minmax(0, 1fr) var(--outline);
}
@media (max-width: 1250px) {
  .shell.with-outline { grid-template-columns: var(--sidebar) minmax(0, 1fr); }
  .shell.with-outline .outline { display: none; }
  .shell.with-outline .outline-inline { display: block; }
}
@media (max-width: 900px) {
  .shell, .shell.with-outline { grid-template-columns: 1fr; gap: 1rem; }
  .nav-toggle { display: block; }
  .finder input[type=search] { width: 11rem; }
  .sidebar {
    display: none; position: static; max-height: none;
    border-right: 0; border-bottom: 1px solid var(--border);
    padding: 0 0 0.75rem;
  }
  .sidebar.open { display: block; }
}

/* ------------------------------------------------- lateral de documentos */

.sidebar {
  position: sticky; top: calc(var(--header-h) + 0.75rem); align-self: start;
  font-size: 0.875rem; max-height: calc(100vh - var(--header-h) - 1.5rem);
  overflow: auto; border-right: 1px solid var(--border); padding-right: 0.75rem;
}
.sidebar .group { margin-bottom: 1.1rem; }
.sidebar .group > h3 {
  font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); margin: 0 0 0.35rem;
}
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar li { margin: 0.1rem 0; }
.sidebar li a {
  display: block; padding: 0.3rem 0.5rem; border-radius: 6px; color: var(--fg);
  line-height: 1.3;
}
.sidebar li a:hover { background: var(--surface); text-decoration: none; }
.sidebar li a[aria-current="page"] {
  background: var(--accent-soft); box-shadow: inset 2px 0 0 var(--accent);
}
.sidebar .name { font-weight: 600; }
.sidebar li a[aria-current="page"] .name { color: var(--accent); }
.sidebar .sub, .sidebar .count {
  display: block; font-size: 0.75rem; color: var(--muted); font-weight: 400;
}
.sidebar .foot { font-size: 0.72rem; color: var(--muted); padding: 0 0.5rem; }

/* ------------------------------------------------- sumário do documento */

.outline {
  position: sticky; top: calc(var(--header-h) + 0.75rem); align-self: start;
  font-size: 0.82rem; max-height: calc(100vh - var(--header-h) - 1.5rem);
  overflow: auto; border-left: 1px solid var(--border); padding-left: 0.85rem;
}
.outline h3, .outline-inline h3 {
  font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); margin: 0 0 0.45rem;
}
.outline-inline { display: none; margin: 0 0 1.5rem; font-size: 0.875rem; }
.outline ul, .outline-inline ul { list-style: none; margin: 0; padding: 0; }
.outline li, .outline-inline li { margin: 0.1rem 0; }
.outline a, .outline-inline a {
  color: var(--fg); display: block; padding: 0.12rem 0.4rem; border-radius: 5px;
  border-left: 2px solid transparent;
}
.outline a:hover, .outline-inline a:hover { color: var(--accent); text-decoration: none; }
/* Seção em que o leitor está agora (ui.js). */
.outline a.active, .outline-inline a.active {
  color: var(--accent); background: var(--accent-soft);
  border-left-color: var(--accent); font-weight: 600;
}
.outline li.l3 a, .outline-inline li.l3 a { padding-left: 1rem; }
.outline li.l4 a, .outline-inline li.l4 a { padding-left: 1.75rem; }
.outline li.l5 a, .outline-inline li.l5 a { padding-left: 2.5rem; }
.outline .lv {
  display: inline-block; width: 0.45rem; height: 0.45rem; border-radius: 50%;
  margin-right: 0.35rem; vertical-align: middle;
}
.outline .lv.obrigatorio, .outline-inline .lv.obrigatorio { background: var(--obrig); }
.outline .lv.recomendado, .outline-inline .lv.recomendado { background: var(--rec); }
.outline .lv.permitido, .outline-inline .lv.permitido { background: var(--muted); }

/* ---------------------------------------------------------------- rótulos */

.badge {
  display: inline-block; font-size: 0.68rem; font-weight: 700;
  text-transform: uppercase; padding: 0.05rem 0.32rem; border-radius: 4px;
  vertical-align: middle; letter-spacing: 0.02em;
}
.badge.obrigatorio { color: #fff; background: var(--obrig); }
.badge.recomendado { color: #fff; background: var(--rec); }
.badge.permitido { color: #fff; background: var(--muted); }
.badge.narrative, .badge.deprecated, .badge.superseded, .badge.section {
  color: var(--muted); background: var(--surface); border: 1px solid var(--border);
}

.chips { display: flex; gap: 0.4rem; flex-wrap: wrap; margin: 0.5rem 0 1.25rem; }
.chips a {
  font-size: 0.8rem; padding: 0.2rem 0.6rem; border: 1px solid var(--border);
  border-radius: 999px; color: var(--fg); background: var(--bg);
}
.chips a:hover { border-color: var(--accent); text-decoration: none; }
.chips a[aria-current="true"] {
  background: var(--fg); color: var(--bg); border-color: var(--fg);
}

/* ----------------------------------------------------- corpo do documento */

.markdown-body { max-width: 52rem; }
.markdown-body table {
  display: block; width: fit-content; max-width: 100%; overflow-x: auto;
}
.markdown-body :is(h1, h2, h3, h4, h5, h6)[id] {
  scroll-margin-top: calc(var(--header-h) + 1rem);
}
.markdown-body :is(h2, h3, h4)[id]::after {
  content: " #"; color: var(--border); font-weight: 400;
}
/* Ponto de pouso de âncora antiga (render._alias_anchor): invisível, mas com o
   mesmo recuo, senão o link antigo para atrás do cabeçalho fixo. */
.anchor-alias {
  display: block; height: 0; scroll-margin-top: calc(var(--header-h) + 1rem);
}
/* Referência cruzada resolvida (xref.py): '(UNISCALE §21)' clicável. */
.markdown-body a[href*="#"] { text-underline-offset: 2px; }

.doc-head {
  border-bottom: 1px solid var(--border); margin-bottom: 1.25rem;
  padding-bottom: 0.75rem;
}
.doc-head h1 { margin: 0 0 0.3rem; font-size: 1.65rem; line-height: 1.25; }
.doc-head .lead { color: var(--muted); margin: 0 0 0.4rem; }
.doc-head .facts { font-size: 0.8rem; color: var(--muted); }
.doc-foot {
  margin-top: 2.5rem; border-top: 1px solid var(--border); padding-top: 1rem;
  font-size: 0.9rem;
}
.pager { display: flex; gap: 1rem; justify-content: space-between; margin-top: 1rem; }
.pager a { display: block; max-width: 48%; }

.card {
  border: 1px solid var(--border); border-radius: 9px; padding: 0.85rem 1rem;
  margin: 0.6rem 0;
}
.card:hover { border-color: var(--accent); }
.card h3 { margin: 0 0 0.2rem; font-size: 1.05rem; }
.card p { margin: 0.15rem 0; }
.grid-cards {
  display: grid; gap: 0.75rem;
  grid-template-columns: repeat(auto-fill, minmax(19rem, 1fr));
}

table.rules { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
table.rules td, table.rules th {
  border-bottom: 1px solid var(--border); padding: 0.35rem 0.5rem;
  text-align: left; vertical-align: top;
}
table.rules tr:hover td { background: var(--surface); }
