/*
 * mad-help.css — Ajuda do app (manual do sistema, fórum #227).
 * Só tokens --mad-* (claro/escuro e todos os temas seguem sozinhos).
 */

/* ── /app/ajuda: grade (árvore | conteúdo | sumário) ─────────────────────── */
.mad-help {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  gap: 28px;
  align-items: start;
}
.mad-help--page:has(.mad-help-toc) {
  grid-template-columns: 240px minmax(0, 1fr) 200px;
}
.mad-help-nav,
.mad-help-toc {
  position: sticky;
  top: 12px;
  max-height: calc(100vh - 140px);
  overflow-y: auto;
}
.mad-help-nav { display: flex; flex-direction: column; gap: 14px; }
.mad-help-nav-section { display: flex; flex-direction: column; gap: 2px; }
.mad-help-nav-title,
.mad-help-toc-title {
  font-size: var(--mad-text-xs, 12px);
  font-weight: 650;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--mad-text-subtle, var(--mad-text-muted));
  padding: 0 10px 4px;
}
.mad-help-nav-link,
.mad-help-toc-link {
  display: block;
  padding: 6px 10px;
  border-radius: var(--mad-radius-sm, 6px);
  color: var(--mad-text-muted);
  font-size: var(--mad-text-sm, 13.5px);
  text-decoration: none;
  line-height: 1.35;
}
.mad-help-nav-link:hover,
.mad-help-toc-link:hover { background: var(--mad-bg-hover, var(--mad-bg-muted)); color: var(--mad-text); text-decoration: none; }
.mad-help-nav-link.is-active {
  background: var(--mad-primary-subtle);
  color: var(--mad-primary-ink, var(--mad-primary));
  font-weight: 600;
}
.mad-help-toc { border-left: 1px solid var(--mad-border); padding-left: 6px; }
.mad-help-toc-link { padding: 4px 10px; font-size: var(--mad-text-xs, 12.5px); }
.mad-help-toc-link.lvl-3 { padding-left: 22px; }

/* Busca */
.mad-help-search {
  position: relative;
  display: flex;
  align-items: center;
}
.mad-help-search svg,
.mad-help-search i {
  position: absolute;
  left: 10px;
  width: 15px;
  height: 15px;
  color: var(--mad-text-subtle, var(--mad-text-muted));
  pointer-events: none;
}
.mad-help-search input {
  width: 100%;
  height: 36px;
  padding: 0 10px 0 32px;
  border: 1px solid var(--mad-border);
  border-radius: var(--mad-radius-md, 8px);
  background: var(--mad-bg);
  color: var(--mad-text);
  font-size: var(--mad-text-sm, 13.5px);
  outline: none;
}
.mad-help-search input:focus { border-color: var(--mad-primary); box-shadow: 0 0 0 3px var(--mad-focus-ring, var(--mad-primary-subtle)); }

.mad-help-results { display: flex; flex-direction: column; gap: 8px; }
.mad-help-results-head { font-size: var(--mad-text-sm, 13px); color: var(--mad-text-muted); margin-bottom: 4px; }
.mad-help-result {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 14px;
  border: 1px solid var(--mad-border);
  border-radius: var(--mad-radius-md, 8px);
  background: var(--mad-bg);
  text-decoration: none;
  color: var(--mad-text);
}
.mad-help-result:hover { border-color: var(--mad-primary); text-decoration: none; }
.mad-help-result-section { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--mad-text-subtle, var(--mad-text-muted)); }
.mad-help-result-title { font-weight: 600; }
.mad-help-result-snippet { font-size: var(--mad-text-sm, 13px); color: var(--mad-text-muted); }

/* Índice: cartões por seção */
.mad-help-sections {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}
.mad-help-card {
  border: 1px solid var(--mad-border);
  border-radius: var(--mad-radius-lg, 12px);
  background: var(--mad-bg);
  overflow: hidden;
}
.mad-help-card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--mad-border);
  background: var(--mad-bg-subtle, var(--mad-bg-muted));
}
.mad-help-card-title { font-weight: 650; color: var(--mad-text); }
.mad-help-card-count { font-size: var(--mad-text-xs, 12px); color: var(--mad-text-muted); }
.mad-help-card-list { list-style: none; margin: 0; padding: 6px; }
.mad-help-card-list a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--mad-radius-sm, 6px);
  color: var(--mad-text);
  text-decoration: none;
  font-size: var(--mad-text-sm, 13.5px);
}
.mad-help-card-list a:hover { background: var(--mad-bg-hover, var(--mad-bg-muted)); text-decoration: none; }
.mad-help-card-list svg,
.mad-help-card-list i { width: 15px; height: 15px; color: var(--mad-text-subtle, var(--mad-text-muted)); flex-shrink: 0; }

.mad-help-empty { min-height: 40vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; text-align: center; }
.mad-help-empty .mad-empty-desc { max-width: 440px; color: var(--mad-text-muted); }
.mad-help-loading { padding: 24px 0; color: var(--mad-text-muted); text-align: center; }

/* Navegação anterior/próxima */
.mad-help-pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 32px;
  padding-top: 20px;
  border-top: 1px solid var(--mad-border);
}
.mad-help-pager-link {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 14px;
  border: 1px solid var(--mad-border);
  border-radius: var(--mad-radius-md, 8px);
  text-decoration: none;
  color: var(--mad-text);
}
.mad-help-pager-link.is-next { text-align: right; align-items: flex-end; }
.mad-help-pager-link:hover { border-color: var(--mad-primary); text-decoration: none; }
.mad-help-pager-link .lbl { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--mad-text-muted); }
.mad-help-pager-link .lbl svg { width: 13px; height: 13px; }
.mad-help-pager-link .ttl { font-weight: 600; }

/* ── Texto do manual (página e cortina) ──────────────────────────────────── */
.mad-help-prose {
  color: var(--mad-text);
  font-size: 15px;
  line-height: 1.65;
  max-width: 820px;
  overflow-wrap: anywhere;
}
.mad-help-prose > :first-child { margin-top: 0; }
.mad-help-prose h1, .mad-help-prose h2, .mad-help-prose h3, .mad-help-prose h4 {
  color: var(--mad-text);
  line-height: 1.3;
  font-weight: 650;
  scroll-margin-top: 16px;
}
.mad-help-prose h1 { font-size: 1.6em; margin: 0 0 .6em; }
.mad-help-prose h2 { font-size: 1.3em; margin: 1.8em 0 .6em; padding-bottom: .3em; border-bottom: 1px solid var(--mad-border); }
.mad-help-prose h3 { font-size: 1.1em; margin: 1.5em 0 .5em; }
.mad-help-prose h4 { font-size: 1em; margin: 1.3em 0 .4em; }
.mad-help-prose p, .mad-help-prose ul, .mad-help-prose ol, .mad-help-prose table, .mad-help-prose pre, .mad-help-prose blockquote { margin: 0 0 1em; }
.mad-help-prose ul, .mad-help-prose ol { padding-left: 1.4em; }
.mad-help-prose li { margin: .25em 0; }
.mad-help-prose li > input[type="checkbox"] { margin-right: .4em; vertical-align: -1px; }
.mad-help-prose a { color: var(--mad-primary); text-decoration: underline; text-underline-offset: 2px; }
.mad-help-prose a:not([href]) { color: inherit; text-decoration: none; cursor: default; }
.mad-help-prose a.mad-doc-anchor {
  margin-left: .35em;
  color: var(--mad-text-subtle, var(--mad-text-muted));
  text-decoration: none;
  opacity: 0;
  font-weight: 400;
}
.mad-help-prose h2:hover .mad-doc-anchor,
.mad-help-prose h3:hover .mad-doc-anchor,
.mad-help-prose h4:hover .mad-doc-anchor { opacity: 1; }
.mad-help-prose code {
  font-size: .88em;
  padding: .12em .38em;
  border-radius: 4px;
  background: var(--mad-bg-muted);
  border: 1px solid var(--mad-border);
}
.mad-help-prose pre {
  padding: 12px 14px;
  border-radius: var(--mad-radius-md, 8px);
  background: var(--mad-bg-muted);
  border: 1px solid var(--mad-border);
  overflow-x: auto;
}
.mad-help-prose pre code { padding: 0; border: 0; background: none; }
.mad-help-prose img {
  display: block;
  max-width: 100%;
  height: auto;
  border: 1px solid var(--mad-border);
  border-radius: var(--mad-radius-md, 8px);
  margin: .5em 0;
}
/* Print com os números do Studio por cima (x/y em % da imagem): a figura tem
   o tamanho da imagem, e os marcadores acompanham quando ela encolhe. */
.mad-help-prose .mad-help-figure {
  position: relative;
  display: inline-block;
  max-width: 100%;
  margin: .5em 0;
  padding: 0;
  vertical-align: top;
  line-height: 0;
}
.mad-help-prose figure.mad-help-figure { display: block; width: fit-content; }
.mad-help-prose .mad-help-figure > img { margin: 0; }
.mad-help-marker {
  position: absolute;
  transform: translate(-50%, -50%);
  display: grid;
  place-items: center;
  box-sizing: border-box;
  height: 22px;
  min-width: 22px;
  padding: 0 4px;
  border-radius: 999px;
  /* Azul fixo como no Studio: o --mad-primary do tema pode ser quase preto
     (claro) ou quase branco (escuro) e o número sumia. Branco sobre #2563eb
     = 5,2:1 nos dois temas. */
  background: var(--mad-help-marker-bg, #2563eb);
  color: var(--mad-help-marker-fg, #fff);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  box-shadow: 0 0 0 2px #fff, 0 2px 6px rgba(0, 0, 0, .35);
  user-select: none;
  cursor: default;
}
.mad-help-prose table {
  width: 100%;
  border-collapse: collapse;
  font-size: .93em;
  display: block;
  overflow-x: auto;
}
.mad-help-prose th, .mad-help-prose td {
  padding: 8px 10px;
  border: 1px solid var(--mad-border);
  text-align: left;
  vertical-align: top;
}
.mad-help-prose thead th { background: var(--mad-bg-subtle, var(--mad-bg-muted)); font-weight: 600; }
.mad-help-prose hr { border: 0; border-top: 1px solid var(--mad-border); margin: 1.6em 0; }

/* Citação comum e callouts (data-callout = contrato com a prévia do Studio) */
.mad-help-prose blockquote {
  padding: 10px 14px;
  border-left: 3px solid var(--mad-border-strong, var(--mad-border));
  color: var(--mad-text-muted);
  background: transparent;
}
.mad-help-prose blockquote > :last-child { margin-bottom: 0; }
.mad-help-prose blockquote[data-callout] {
  color: var(--mad-text);
  border-radius: 0 var(--mad-radius-md, 8px) var(--mad-radius-md, 8px) 0;
}
.mad-help-prose blockquote[data-callout="tip"] {
  border-left-color: var(--mad-success);
  background: var(--mad-success-subtle);
}
.mad-help-prose blockquote[data-callout="warning"] {
  border-left-color: var(--mad-warning);
  background: var(--mad-warning-subtle);
}
.mad-help-prose blockquote[data-callout="note"] {
  border-left-color: var(--mad-info);
  background: var(--mad-info-subtle);
}
.mad-help-prose blockquote[data-callout] > p:first-child > strong:first-child { font-weight: 700; }
.mad-help-prose blockquote[data-callout="tip"] > p:first-child > strong:first-child { color: var(--mad-success); }
.mad-help-prose blockquote[data-callout="warning"] > p:first-child > strong:first-child { color: var(--mad-warning-text, var(--mad-warning)); }
.mad-help-prose blockquote[data-callout="note"] > p:first-child > strong:first-child { color: var(--mad-info); }

/* ── Cortina do botão ? ──────────────────────────────────────────────────── */
.mad-help-overlay[hidden] { display: none !important; }
.mad-help-overlay { z-index: calc(var(--mad-z-overlay, 1010) + 20); }
/* Tela em gaveta/modal: o ? fica no cabeçalho dela; o do <mad-page-header>
   de dentro (se a tela tiver) some para não repetir. */
.mad-drawer:has(> .mad-drawer-header [data-mad-help-screen]) .mad-drawer-body .mad-page-help-btn,
.mad-modal:has(> .mad-modal-header [data-mad-help-screen]) .mad-modal-body .mad-page-help-btn { display: none; }
.mad-overlay-help-btn { margin-left: auto; }
.mad-drawer-header .mad-overlay-help-btn + .mad-btn,
.mad-modal-header .mad-overlay-help-btn + .mad-btn { margin-left: 4px; }
.mad-help-drawer { width: 560px; }
.mad-help-drawer .mad-help-prose { font-size: 14.5px; }
.mad-help-context-page + .mad-help-context-page {
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid var(--mad-border);
}
.mad-help-context-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.mad-help-context-section { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--mad-text-subtle, var(--mad-text-muted)); }
.mad-help-context-title { margin: 2px 0 0; font-size: 18px; font-weight: 650; color: var(--mad-text); }
.mad-help-context-foot {
  margin-top: 24px;
  padding-top: 14px;
  border-top: 1px solid var(--mad-border);
  font-size: var(--mad-text-sm, 13px);
}
.mad-help-context-foot a { display: inline-flex; align-items: center; gap: 6px; color: var(--mad-primary); text-decoration: none; }
.mad-help-context .mad-help-empty { min-height: 50vh; }

/* Botão ? no cabeçalho da tela */
.mad-page-help-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--mad-border);
  border-radius: var(--mad-radius-full, 999px);
  background: var(--mad-bg);
  color: var(--mad-text-muted);
  cursor: pointer;
  flex-shrink: 0;
}
.mad-page-help-btn:hover { color: var(--mad-primary); border-color: var(--mad-primary); }
.mad-page-help-btn svg { width: 16px; height: 16px; }

/* ── Responsivo ──────────────────────────────────────────────────────────── */
@media (max-width: 1100px) {
  .mad-help--page:has(.mad-help-toc) { grid-template-columns: 220px minmax(0, 1fr); }
  .mad-help-toc { display: none; }
}
@media (max-width: 760px) {
  .mad-help, .mad-help--page:has(.mad-help-toc) { grid-template-columns: minmax(0, 1fr); }
  .mad-help-nav, .mad-help-toc { position: static; max-height: none; }
  .mad-help--page .mad-help-nav-section { display: none; }
  .mad-help-drawer { width: 100vw; }
  .mad-help-pager { grid-template-columns: 1fr; }
}
