/**
 * Shell de documentação (tema escuro, grid, sidebar, TOC) — alinhado ao modelo
 * de safenodemvp/functions-documentation.php, sem dependências Tailwind/SafeNode.
 */
:root {
  --doc-ref-header-h: 64px;
  --bg-primary: #000000;
  --bg-secondary: #050505;
  --bg-tertiary: #0a0a0a;
  --bg-card: #080808;
  --bg-hover: #111111;
  --bg-elevated: #0d0d0d;
  --border-subtle: rgba(255, 255, 255, 0.05);
  --border-light: rgba(255, 255, 255, 0.08);
  --border-focus: rgba(255, 255, 255, 0.15);
  --text-primary: #fafafa;
  --text-secondary: #a1a1aa;
  --text-muted: #52525b;
  --success: #10b981;
  --success-bg: rgba(16, 185, 129, 0.1);
  --glow-primary: rgba(255, 255, 255, 0.03);
  --glow-intense: rgba(255, 255, 255, 0.06);
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
}
*::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
*::-webkit-scrollbar-track {
  background: transparent;
}
*::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--doc-ref-header-h) + 1.5rem);
}
body.doc-ref {
  font-family: Inter, system-ui, -apple-system, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-secondary);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
body.doc-ref img {
  max-width: 100%;
  height: auto;
  display: block;
}
body.doc-ref a {
  color: inherit;
}
body.doc-ref button {
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
}

.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--text-primary), var(--text-secondary));
  z-index: 9999;
  transition: width 0.1s linear;
  width: 0;
}
.bg-grid {
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.02) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.02) 1px, transparent 1px);
  background-size: 64px 64px;
  mask-image: radial-gradient(ellipse 80% 50% at 50% 0%, black 70%, transparent 100%);
  pointer-events: none;
  z-index: 0;
}
.bg-glow {
  position: fixed;
  top: -50%;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  height: 100%;
  background: radial-gradient(ellipse 60% 40% at 50% 0%, rgba(255, 255, 255, 0.04), transparent 70%);
  pointer-events: none;
  z-index: 0;
}

.doc-ref-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--doc-ref-header-h);
  z-index: 100;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 1px solid var(--border-subtle);
}
.doc-ref-header-inner {
  max-width: 100%;
  height: 100%;
  padding: 0 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
@media (min-width: 640px) {
  .doc-ref-header-inner {
    padding: 0 1.5rem;
  }
}
.doc-ref-header-left {
  display: flex;
  align-items: center;
  gap: 1rem;
  min-width: 0;
}
.doc-ref-breadcrumb {
  display: none;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: var(--text-muted);
}
@media (min-width: 640px) {
  .doc-ref-breadcrumb {
    display: flex;
  }
}
.doc-ref-breadcrumb span.sep {
  color: var(--text-muted);
}
.doc-ref-breadcrumb span.current {
  color: var(--text-primary);
}
.doc-ref-brand {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  text-decoration: none;
  color: var(--text-primary);
  font-weight: 600;
  font-size: 0.875rem;
}
.doc-ref-brand-icon {
  width: 1.75rem;
  height: 1.75rem;
  color: var(--text-primary);
  flex-shrink: 0;
}
.doc-ref-brand-icon svg {
  width: 100%;
  height: 100%;
}
.doc-ref-brand-icon img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.doc-ref-brand span.light {
  font-weight: 500;
  color: var(--text-secondary);
}
.doc-ref-header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}
.doc-ref-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem 0.75rem;
  border-radius: 0.5rem;
  font-size: 0.8125rem;
  font-weight: 500;
  text-decoration: none;
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
  background: var(--bg-tertiary);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.doc-ref-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border-light);
}
.doc-ref-btn-primary {
  background: var(--text-primary);
  color: var(--bg-primary);
  border-color: transparent;
}
.doc-ref-btn-primary:hover {
  filter: brightness(0.95);
  color: var(--bg-primary);
}
.doc-ref-menu-toggle {
  display: flex;
  padding: 0.5rem;
  margin-left: -0.5rem;
  border-radius: 0.5rem;
  color: var(--text-secondary);
  transition: background 0.15s;
}
.doc-ref-menu-toggle:hover {
  background: rgba(255, 255, 255, 0.05);
}
@media (min-width: 1024px) {
  .doc-ref-menu-toggle {
    display: none;
  }
}

.doc-ref-sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  top: var(--doc-ref-header-h);
  background: rgba(0, 0, 0, 0.5);
  z-index: 45;
}
.doc-ref-sidebar-backdrop.is-open {
  display: block;
}
@media (min-width: 1024px) {
  .doc-ref-sidebar-backdrop {
    display: none !important;
  }
}

.doc-ref-sidebar {
  position: fixed;
  top: var(--doc-ref-header-h);
  left: 0;
  width: 260px;
  height: calc(100vh - var(--doc-ref-header-h));
  overflow-y: auto;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-subtle);
  padding: 1.5rem 0;
  z-index: 50;
}
@media (max-width: 1023px) {
  .doc-ref-sidebar {
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    background: var(--bg-primary);
  }
  .doc-ref-sidebar.is-open {
    transform: translateX(0);
  }
}

.doc-ref-sidebar-pill {
  margin: 0 1rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-radius: 0.5rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-primary);
}
.doc-ref-sidebar-pill .badge {
  margin-left: auto;
  font-size: 0.625rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
  background: rgba(119, 123, 180, 0.15);
  color: #a5b4fc;
  border: 1px solid rgba(119, 123, 180, 0.25);
}

.doc-ref-nav-section {
  padding: 0 1.25rem;
  margin-bottom: 0.5rem;
  margin-top: 1.5rem;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}
.doc-ref-nav-section:first-of-type {
  margin-top: 0;
}
.doc-ref-nav-link {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.5rem 1.25rem;
  color: var(--text-secondary);
  font-size: 0.8125rem;
  font-weight: 450;
  text-decoration: none;
  transition: all 0.15s ease;
  border-left: 2px solid transparent;
  margin: 1px 0;
}
.doc-ref-nav-link:hover {
  color: var(--text-primary);
  background: var(--glow-primary);
}
.doc-ref-nav-link.is-active {
  color: var(--text-primary);
  background: var(--glow-intense);
  border-left-color: var(--text-primary);
}
.doc-ref-nav-link svg {
  width: 11px;
  height: 11px;
  opacity: 0.7;
  flex-shrink: 0;
}
.doc-ref-nav-link.is-active svg {
  opacity: 1;
}

.doc-ref-toc {
  position: fixed;
  top: var(--doc-ref-header-h);
  right: 0;
  width: 220px;
  height: calc(100vh - var(--doc-ref-header-h));
  overflow-y: auto;
  padding: 1.5rem 1rem;
  border-left: 1px solid var(--border-subtle);
  background: var(--bg-secondary);
  z-index: 40;
}
.doc-ref-toc-title {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 1rem;
}
.doc-ref-toc-link {
  display: block;
  padding: 0.375rem 0.75rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-decoration: none;
  transition: all 0.15s ease;
  border-left: 1px solid transparent;
  margin-left: -1px;
}
.doc-ref-toc-link:hover {
  color: var(--text-secondary);
}
.doc-ref-toc-link.is-active {
  color: var(--text-primary);
  border-left-color: var(--text-primary);
  background: var(--glow-primary);
}
.doc-ref-toc-link.level-3 {
  padding-left: 1.25rem;
}

.doc-ref-main {
  margin-left: 260px;
  margin-right: 220px;
  /* Header fixo 64px — conteúdo começa abaixo da barra + margem (documentation.php também define #doc-ref-main) */
  padding: calc(64px + 2.75rem) 3rem 6rem;
  max-width: calc(100% - 480px);
  position: relative;
  z-index: 1;
}
.doc-ref-main-inner {
  max-width: 720px;
  margin: 0 auto;
}

.doc-ref-hero-title {
  font-size: 2.25rem;
  font-weight: 800;
  letter-spacing: -0.035em;
  line-height: 1.15;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
  background: linear-gradient(180deg, var(--text-primary) 0%, var(--text-secondary) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.doc-ref-kicker {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.doc-ref-footnote {
  margin-top: 1.5rem;
  padding: 0 1.25rem 2rem;
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--text-muted);
}
.doc-ref-footnote code {
  font-family: var(--mono);
  font-size: 0.6875rem;
  padding: 0.1rem 0.3rem;
  border-radius: 4px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
}
.doc-ref-footnote strong {
  color: var(--text-secondary);
}

/* Markdown dentro do tema escuro */
.md-content > h1:first-child {
  display: none;
}
.md-content h1 {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  margin: 1.5em 0 0.5em;
}
.md-content h2 {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 1.35em 0 0.45em;
  padding-top: 0.25rem;
  scroll-margin-top: calc(var(--doc-ref-header-h) + 1.25rem);
}
.md-content h3 {
  font-size: 1.05rem;
  font-weight: 600;
  margin: 1.1em 0 0.35em;
  color: var(--text-primary);
  scroll-margin-top: calc(var(--doc-ref-header-h) + 1.25rem);
}
.md-content h4,
.md-content h5,
.md-content h6 {
  font-size: 1rem;
  font-weight: 600;
  margin: 1em 0 0.3em;
  color: var(--text-primary);
}
.md-content p {
  margin: 0.65em 0;
  line-height: 1.65;
}
.md-content p strong,
.md-content li strong {
  color: var(--text-primary);
}
.md-content a {
  color: var(--text-primary);
  text-decoration: underline;
  text-underline-offset: 2px;
  font-weight: 500;
}
.md-content a:hover {
  opacity: 0.9;
}
.md-content ul,
.md-content ol {
  margin: 0.65em 0 0.65em 1.35em;
}
.md-content li {
  margin: 0.35em 0;
}
.md-content li::marker {
  color: var(--text-muted);
}
.md-content hr {
  border: none;
  border-top: 1px solid var(--border-subtle);
  margin: 1.75em 0;
}
.md-content blockquote {
  margin: 1em 0;
  padding: 12px 16px;
  border-left: 3px solid var(--border-focus);
  background: var(--glow-primary);
  border-radius: 0 8px 8px 0;
}
.md-content pre {
  margin: 1em 0;
  padding: 1rem 1.15rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 0.8125rem;
  line-height: 1.65;
}
.md-content code {
  font-family: var(--mono);
  font-size: 0.88em;
}
.md-content pre code {
  font-size: 0.8125rem;
  color: var(--text-primary);
}
.md-content :not(pre) > code {
  background: var(--bg-tertiary);
  padding: 0.125rem 0.375rem;
  border-radius: 5px;
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  font-size: 0.8125rem;
}

.md-table-wrap {
  overflow-x: auto;
  margin: 1em 0;
}
.md-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}
.md-table th,
.md-table td {
  border: 1px solid var(--border-subtle);
  padding: 0.625rem 0.875rem;
  text-align: left;
}
.md-table th {
  background: var(--bg-tertiary);
  font-weight: 600;
  color: var(--text-primary);
}
.md-table td {
  color: var(--text-secondary);
}

@media (max-width: 1280px) {
  .doc-ref-toc {
    display: none;
  }
  .doc-ref-main {
    margin-right: 0;
    max-width: calc(100% - 260px);
  }
}
@media (max-width: 1023px) {
  .doc-ref-main {
    margin-left: 0;
    max-width: 100%;
    padding: calc(64px + 1.75rem) 1.25rem 4rem;
  }
  .doc-ref-hero-title {
    font-size: 1.75rem;
  }
}
