/* Reset & base */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; color: #1a1a2e; background: #fafafa; line-height: 1.6; }
a { color: #2563eb; text-decoration: none; }
a:hover { text-decoration: underline; }

/* Topbar */
.topbar { display: flex; align-items: center; gap: 1rem; padding: .75rem 1.5rem; background: #1a1a2e; color: #fff; position: sticky; top: 0; z-index: 100; }
.search-form { display: flex; flex: 1; max-width: 400px; margin-left: auto; }
.search-form input { flex: 1; padding: .4rem .75rem; border: none; border-radius: 4px 0 0 4px; font-size: .9rem; }
.search-form button { padding: .4rem .75rem; background: #3b82f6; color: #fff; border: none; border-radius: 0 4px 4px 0; cursor: pointer; }
.nav-divider { border: none; border-top: 1px solid #334155; margin: .5rem .75rem; }
.nav-tags-link { display: block; padding: .45rem .75rem; color: #94a3b8; font-size: .85rem; text-decoration: none; }
.nav-tags-link:hover { color: #93c5fd; text-decoration: none; }
.nav-donate-link { display: block; padding: .45rem .75rem; color: #fb7185; font-size: .85rem; font-weight: 600; text-decoration: none; }
.nav-donate-link:hover { color: #f43f5e; text-decoration: none; }

/* Logo / nav toggle button */
.logo { background: none; border: none; cursor: pointer; color: #fff; font-weight: 700; font-size: 1.1rem; padding: 0; letter-spacing: .01em; white-space: nowrap; }
.logo:hover { color: #93c5fd; }

/* Dropdown wrapper — anchor for absolute positioning */
.nav-dropdown-wrapper { position: relative; }

/* Dropdown panel */
.nav-dropdown { position: absolute; top: calc(100% + .75rem); left: 0; width: 360px; max-height: 80vh; overflow-y: auto; background: #1e293b; border: 1px solid #334155; border-radius: 6px; padding: .75rem; z-index: 200; box-shadow: 0 8px 24px rgba(0,0,0,.4); }

/* L1: topic */
.nav-l1 { margin-bottom: .4rem; }
.nav-l1-summary { cursor: pointer; padding: .3rem .25rem; font-weight: 700; font-size: .85rem; color: #e2e8f0; list-style: none; display: flex; align-items: center; gap: .35rem; }
.nav-l1-summary::-webkit-details-marker { display: none; }
.nav-l1-summary::before { content: "▶"; font-size: .6rem; color: #64748b; transition: transform .15s; flex-shrink: 0; }
.nav-l1[open] > .nav-l1-summary::before { transform: rotate(90deg); }
.nav-l1-summary:hover { color: #93c5fd; }

/* L2: document type */
.nav-l2 { margin-left: .85rem; margin-bottom: .1rem; }
.nav-l2-summary { cursor: pointer; padding: .2rem .25rem; font-weight: 600; font-size: .75rem; color: #94a3b8; text-transform: uppercase; letter-spacing: .05em; list-style: none; display: flex; align-items: center; gap: .3rem; }
.nav-l2-summary::-webkit-details-marker { display: none; }
.nav-l2-summary::before { content: "▶"; font-size: .5rem; color: #475569; transition: transform .15s; flex-shrink: 0; }
.nav-l2[open] > .nav-l2-summary::before { transform: rotate(90deg); }
.nav-l2-summary:hover { color: #cbd5e1; }

/* L3: individual documents */
.nav-l3 { list-style: none; margin: .15rem 0 .25rem 1.2rem; padding: 0; }
.nav-l3 li { padding: .15rem 0; }
.nav-l3 li a { color: #94a3b8; font-size: .8rem; display: block; line-height: 1.4; padding-bottom: .1rem; }
.nav-l3 li a:hover { color: #e2e8f0; text-decoration: none; }
.nav-l3 li.nav-active a { color: #60a5fa; font-weight: 600; }

/* Layout — no sidebar, full width */
.layout { display: flex; min-height: calc(100vh - 50px); }
.content { flex: 1; padding: 1rem 1.5rem; min-width: 0; }

/* TOC sidebar (document pages only) */
.toc-sidebar { width: 160px; padding: .6rem .75rem; font-size: .68rem; background: #f8fafc; border-left: 2px solid #e2e8f0; overflow-y: auto; flex-shrink: 0; position: sticky; top: 50px; max-height: calc(100vh - 50px); align-self: flex-start; }
.toc-sidebar h3 { font-size: .7rem; font-weight: 700; color: #64748b; text-transform: uppercase; letter-spacing: .06em; margin-bottom: .5rem; }
.toc-sidebar ul { list-style: none; padding-left: 0; }
.toc-sidebar ul ul { padding-left: .5rem; border-left: 1px solid #e2e8f0; margin-left: .1rem; }
.toc-sidebar li { padding: .12rem 0; }
.toc-sidebar a { color: #64748b; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.35; }
.toc-sidebar a:hover { color: #2563eb; text-decoration: none; }

/* Breadcrumb */
.breadcrumb { font-size: .85rem; color: #64748b; margin-bottom: 1rem; }
.breadcrumb a { color: #64748b; }

/* Tables */
.doc-table { width: 100%; border-collapse: collapse; margin-top: 1rem; }
.doc-table th { text-align: left; padding: .5rem; border-bottom: 2px solid #e2e8f0; font-size: .8rem; color: #64748b; text-transform: uppercase; }
.doc-table td { padding: .5rem; border-bottom: 1px solid #f1f5f9; }
.doc-table tr:hover { background: #f8fafc; }

/* Badges & tags */
.badge { background: #e2e8f0; color: #475569; padding: .15rem .5rem; border-radius: 3px; font-size: .75rem; }
.tag { display: inline-block; background: #eff6ff; color: #2563eb; padding: .15rem .5rem; border-radius: 3px; font-size: .8rem; margin: .15rem .25rem .15rem 0; }
.tag:hover { background: #dbeafe; text-decoration: none; }
.count { color: #94a3b8; font-size: .8rem; }

/* Filters */
.filters { display: flex; gap: .5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.filters a { padding: .3rem .75rem; border-radius: 4px; font-size: .85rem; background: #f1f5f9; color: #475569; }
.filters a.active { background: #2563eb; color: #fff; }

/* Tag cloud */
.tag-cloud { display: flex; flex-wrap: wrap; gap: .5rem; }

/* Document */
.document header { margin-bottom: 1.5rem; }
.document h1 { font-size: 1.5rem; margin-bottom: .5rem; }
.meta { display: flex; gap: .75rem; align-items: center; font-size: .85rem; color: #64748b; margin-bottom: .5rem; }
.tags { margin-top: .5rem; }
.related { margin-top: 2rem; padding-top: 1rem; border-top: 1px solid #e2e8f0; }
.related h2 { font-size: 1.1rem; margin-bottom: .5rem; }
.related ul { list-style: none; }
.related li { padding: .25rem 0; }

/* Markdown body */
.markdown-body h1, .markdown-body h2, .markdown-body h3, .markdown-body h4 { margin: 1.5rem 0 .5rem; scroll-margin-top: 60px; }
.markdown-body h1 { font-size: 1.4rem; border-bottom: 1px solid #e2e8f0; padding-bottom: .3rem; }
.markdown-body h2 { font-size: 1.2rem; }
.markdown-body h3 { font-size: 1.05rem; }
.markdown-body p { margin: .5rem 0; }
.markdown-body ul, .markdown-body ol { margin: .5rem 0 .5rem 1.5rem; }
.markdown-body pre { background: #1e293b; color: #e2e8f0; padding: .5rem .75rem; border-radius: 6px; overflow-x: auto; margin: .25rem 0; font-size: .85rem; }
.markdown-body code { font-family: "SF Mono", Menlo, monospace; font-size: .85em; }
.markdown-body :not(pre) > code { background: #f1f5f9; padding: .15rem .35rem; border-radius: 3px; }
.markdown-body table { border-collapse: collapse; margin: .75rem 0; width: 100%; }
.markdown-body th, .markdown-body td { border: 1px solid #e2e8f0; padding: .4rem .75rem; text-align: left; }
.markdown-body th { background: #f8fafc; }
.markdown-body blockquote { border-left: 3px solid #e2e8f0; padding-left: 1rem; color: #64748b; margin: .75rem 0; }
.markdown-body img { max-width: 100%; }
.markdown-body .task-list-item { list-style: none; margin-left: -1.5rem; }
.markdown-body .task-list-item input { margin-right: .5rem; }

/* Pygments highlight */
.highlight { background: #1e293b; padding: .5rem .75rem; border-radius: 6px; overflow-x: auto; margin: .25rem 0; }

/* Disclaimer modal */
.disclaimer-backdrop {
  display: none; /* shown by JS only when needed */
  position: fixed; inset: 0; z-index: 9000;
  background: rgba(0, 0, 0, .72);
  align-items: center; justify-content: center;
  padding: 1.5rem;
}
.disclaimer-modal {
  background: #fff; border-radius: 8px;
  max-width: 640px; width: 100%;
  padding: 2rem 2rem 1.5rem;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
  display: flex; flex-direction: column; gap: 1.25rem;
}
.disclaimer-modal h2 {
  font-size: 1.1rem; font-weight: 700; color: #1a1a2e;
  margin: 0;
}
.disclaimer-text {
  font-size: .9rem; line-height: 1.65; color: #334155; margin: 0;
}
.disclaimer-btn {
  align-self: flex-end;
  background: #1a1a2e; color: #fff;
  border: none; border-radius: 5px;
  padding: .6rem 1.5rem; font-size: .9rem; font-weight: 600;
  cursor: pointer; transition: background .15s;
}
.disclaimer-btn:hover { background: #2563eb; }

/* Responsive */
@media (max-width: 768px) {
  .toc-sidebar { display: none; }
  .content { padding: 1rem; }
  .nav-dropdown { width: calc(100vw - 2rem); }
  .disclaimer-modal { padding: 1.5rem 1.25rem 1.25rem; }
  .disclaimer-btn { align-self: stretch; text-align: center; }

  /* Search bar drops to its own full-width row below the nav toggle */
  .topbar { flex-wrap: wrap; padding: .6rem 1rem; gap: .5rem; }
  .search-form { flex: 1 1 100%; max-width: 100%; margin-left: 0; }
  .search-form input { font-size: 1rem; padding: .5rem .75rem; }
  .search-form button { padding: .5rem .9rem; }
}
