/* =====================================================================
   CSS Custom Properties
   ===================================================================== */
:root {
    --topbar-height: 50px;
}

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

/* =====================================================================
   Skip link (accessibility — §9b)
   ===================================================================== */
.skip-link {
    position: absolute;
    left: -10000px;
    top: 0;
    width: 1px;
    height: 1px;
    overflow: hidden;
    z-index: 10000;
    background: #1a1a2e;
    color: #ffffff;
    padding: 0.5rem 1rem;
    font-size: 1rem;
    font-weight: 600;
    text-decoration: none;
    border-radius: 0 0 4px 4px;
}
.skip-link:focus {
    left: 0;
    width: auto;
    height: auto;
    overflow: visible;
}

/* =====================================================================
   Noscript notice (§9c)
   ===================================================================== */
.noscript-notice {
    background: #fef3c7;
    border: 1px solid #f59e0b;
    border-radius: 4px;
    padding: 0.75rem 1rem;
    margin: 0.75rem 1.5rem;
    font-size: 0.875rem;
    color: #78350f;
}

/* =====================================================================
   Topbar (§5a — topbar-inner wrapper; §5c — CSS var; §8b — flex-shrink)
   ===================================================================== */
.topbar {
    background: #1a1a2e;
    color: #fff;
    position: sticky;
    top: 0;
    z-index: 100;
    height: var(--topbar-height);
}
.topbar-inner {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0 1.5rem;
    height: 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 input:focus-visible {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25);
}
/* §5b — search button interactive states */
.search-form button { padding: .4rem .75rem; background: #3b82f6; color: #fff; border: none; border-radius: 0 4px 4px 0; cursor: pointer; transition: background .15s; }
.search-form button:hover { background: #2563eb; }
.search-form button:active { background: #1d4ed8; transform: translateY(1px); }
.search-form button:focus-visible { outline: 2px solid #93c5fd; outline-offset: 2px; border-radius: 0 4px 4px 0; }
.nav-divider { border: none; border-top: 1px solid #334155; margin: .5rem .75rem; }

/* §2d — utility nav link (Tags, About) */
.nav-utility-link {
    display: block;
    padding: .45rem .75rem;
    color: #94a3b8;
    font-size: .85rem;
    font-weight: 500;
    text-decoration: none;
    border-radius: 4px;
    transition: color .15s ease, background .15s ease;
}
.nav-utility-link:hover { color: #e2e8f0; background: rgba(255,255,255,0.08); text-decoration: none; }
/* Keep donate link pink for the Buy Me a Coffee CTA */
.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 (§2a — chevron rotation, hover state)
   ===================================================================== */
/* §8b — flex-shrink: 0 prevents logo from collapsing */
.logo { background: none; border: none; cursor: pointer; color: #fff; font-weight: 700; font-size: 1.1rem; padding: .25rem .4rem; letter-spacing: .01em; white-space: nowrap; flex-shrink: 0; border-radius: 4px; transition: color .15s, background .15s; }
.logo:hover { color: #93c5fd; background: rgba(255,255,255,0.08); }
.logo:focus-visible { outline: 2px solid #93c5fd; outline-offset: 2px; }

/* §2a — chevron rotation */
.logo-chevron {
    display: inline-block;
    transition: transform 0.2s ease;
    font-style: normal;
}
.logo[aria-expanded="true"] .logo-chevron {
    transform: rotate(180deg);
}

/* =====================================================================
   Dropdown wrapper & panel
   ===================================================================== */
.nav-dropdown-wrapper { position: relative; }
.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; }

/* §2c — active group highlight */
.nav-active-group { color: #60a5fa !important; background: rgba(37,99,235,0.10); border-radius: 4px; padding-left: 4px; }

/* 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; }
/* §2b — ellipsis on long nav doc links */
.nav-l3 li a { color: #94a3b8; font-size: .8rem; display: block; line-height: 1.4; padding-bottom: .1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-l3 li a:hover { color: #e2e8f0; text-decoration: none; }
.nav-l3 li.nav-active a { color: #60a5fa; font-weight: 600; }

/* =====================================================================
   Layout — single column, centred (§1a)
   ===================================================================== */
.layout { display: flex; min-height: calc(100vh - var(--topbar-height)); }
.content {
    flex: 1;
    padding: 1rem 1.5rem;
    min-width: 0;
    /* §1a — constrain reading width, centred */
    max-width: clamp(320px, 75ch, 800px);
    margin-left: auto;
    margin-right: auto;
    width: 100%;
}

/* =====================================================================
   Breadcrumb (§6c — aria-current styling handled inline in template)
   ===================================================================== */
.breadcrumb { font-size: .85rem; color: #64748b; margin-bottom: 1rem; }
.breadcrumb a { color: #64748b; }

/* =====================================================================
   Tables (§7a zebra, §7c fixed layout)
   ===================================================================== */
.doc-table { width: 100%; border-collapse: collapse; margin-top: 1rem; table-layout: fixed; }
.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; }
/* §7c — column widths for 3-column tables (topic, search has different widths set per-page) */
.doc-table.cols-3 th:nth-child(1) { width: auto; }
.doc-table.cols-3 th:nth-child(2) { width: 120px; }
.doc-table.cols-3 th:nth-child(3) { width: 100px; }
/* 4-column search table */
.doc-table.cols-4 th:nth-child(1) { width: auto; }
.doc-table.cols-4 th:nth-child(2) { width: 150px; }
.doc-table.cols-4 th:nth-child(3) { width: 110px; }
.doc-table.cols-4 th:nth-child(4) { width: 100px; }
/* 2-column index table */
.doc-table.cols-2 th:nth-child(1) { width: auto; }
.doc-table.cols-2 th:nth-child(2) { width: 90px; }
/* Subject cell: allow wrapping so long titles are fully visible */
.doc-table td:first-child { overflow: hidden; max-width: 0; }
.doc-table td:not(:first-child) { white-space: nowrap; }
/* §7a — zebra striping */
.doc-table tbody tr:nth-child(even) { background: #f8fafc; }
.doc-table tr:hover { background: #dbeafe !important; }

/* =====================================================================
   Badges & tags (§4c badge border, §6b tag cursor)
   ===================================================================== */
.badge { background: #f1f5f9; color: #475569; padding: .15rem .5rem; border-radius: 3px; font-size: .75rem; border: 1px solid #94a3b8; font-weight: 500; white-space: nowrap; }
.tag { display: inline-block; background: #eff6ff; color: #2563eb; padding: .15rem .5rem; border-radius: 3px; font-size: .8rem; margin: .15rem .25rem .15rem 0; cursor: pointer; transition: background .15s ease; }
.tag:hover { background: #dbeafe; text-decoration: none; }
.tag:focus-visible { outline: 2px solid #3b82f6; outline-offset: 2px; border-radius: 3px; }
/* §6e — smaller tag for related docs */
.tag-small { font-size: .7rem; padding: .1rem .35rem; margin: 0 .15rem; }
/* §9d — count contrast fix */
.count { color: #64748b; font-size: .8rem; }
/* §10a — topic hint subline in search results (Topic column removed) */
.topic-hint { display: block; font-size: .75rem; color: #94a3b8; margin-top: .1rem; }
.topic-hint a { color: #94a3b8; }
.topic-hint a:hover { color: #2563eb; }

/* =====================================================================
   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 page (§3a title size, §4e header border, §4b body colour applied globally)
   ===================================================================== */
/* §4e — header/body separator */
.document header { border-bottom: 1px solid #e2e8f0; padding-bottom: 1.25rem; margin-bottom: 1.75rem; }
/* §3a — document title */
.document h1 { font-size: 1.875rem; font-weight: 700; line-height: 1.2; margin-bottom: .625rem; color: #0f172a; }
.meta { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; font-size: .85rem; color: #64748b; margin-bottom: .5rem; }
.tags { margin-top: .5rem; }
/* =====================================================================
   Related Documents section (§6e redesign)
   ===================================================================== */
.related {
    margin-top: 2.5rem;
    padding-top: 1.25rem;
    border-top: 2px solid #e2e8f0;
}
.related h2 {
    font-size: 1rem;
    font-weight: 600;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.75rem;
}
.related ul {
    list-style: none;
}
.related li {
    padding: 0.625rem 0.5rem;
    border-bottom: 1px solid #f1f5f9;
    border-radius: 4px;
    transition: background 0.12s ease;
}
.related li:last-child {
    border-bottom: none;
}
.related li:hover {
    background: #f8fafc;
}
/* Document title link inside related list */
.related .doc-link {
    display: block;
    color: #1d4ed8;
    font-size: 0.9rem;
    font-weight: 500;
    line-height: 1.4;
    margin-bottom: 0.3rem;
}
.related .doc-link:hover {
    color: #1e40af;
    text-decoration: underline;
}
.related .doc-link:visited {
    color: #6d28d9;
}
.related .doc-link:visited:hover {
    color: #5b21b6;
}
/* Shared tags row — neutral gray chips, not the blue .tag style */
.related-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
}
/* Override .tag inside related-tags to use neutral gray */
.related-tags .tag,
.related-tags .tag-small {
    background: #f1f5f9;
    color: #64748b;
    border: 1px solid #cbd5e1;
    font-size: 0.7rem;
    padding: 0.1rem 0.4rem;
    margin: 0;
    border-radius: 3px;
    font-weight: 400;
    transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}
.related-tags .tag:hover,
.related-tags .tag-small:hover {
    background: #e2e8f0;
    color: #334155;
    border-color: #94a3b8;
    text-decoration: none;
}

/* =====================================================================
   Markdown body (§3b h1 demotion, §3d code line-height)
   ===================================================================== */
.markdown-body h1, .markdown-body h2, .markdown-body h3, .markdown-body h4 { margin: 1.5rem 0 .5rem; scroll-margin-top: calc(var(--topbar-height) + 12px); }
/* §3b — demote in-body h1 below page title */
.markdown-body h1 { font-size: 1.35rem; font-weight: 700; border-bottom: 1px solid #e2e8f0; padding-bottom: .3em; margin-bottom: .75rem; }
.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; }
/* §3d — tighter code line-height */
.markdown-body pre { background: #1e293b; color: #e2e8f0; padding: .5rem .75rem; border-radius: 6px; overflow-x: auto; margin: .25rem 0; font-size: .85rem; line-height: 1.45; tab-size: 4; }
.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; }
/* §4d — blockquote: blue callout style */
.markdown-body blockquote { border-left: 3px solid #3b82f6; background: #eff6ff; padding: .625rem 1rem; margin: .75rem 0; border-radius: 0 4px 4px 0; color: #334155; }
.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 toast — non-blocking bottom banner (UI-11)
   ===================================================================== */
.disclaimer-toast {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 1000;
  background: #1a1a2e;
  color: #e0e0e0;
  padding: 12px 20px;
  font-size: 0.82rem;
  line-height: 1.5;
  border-top: 2px solid #4a4a7a;
  display: flex;
  align-items: flex-start;
  gap: 16px;
  box-shadow: 0 -2px 12px rgba(0,0,0,0.4);
}
.disclaimer-toast-text { flex: 1; }
.disclaimer-toast-dismiss {
  flex-shrink: 0;
  background: #5a5a9a; color: #fff;
  border: none; border-radius: 4px;
  padding: 6px 14px; cursor: pointer;
  font-size: 0.8rem; white-space: nowrap;
  align-self: center;
}
.disclaimer-toast-dismiss:hover { background: #7a7abf; }

/* =====================================================================
   Site footer (UI-13)
   ===================================================================== */
.site-footer {
  margin-top: 3rem;
  padding: 1.25rem 1.5rem;
  border-top: 1px solid #e2e8f0;
  background: #f8fafc;
  font-size: 0.82rem;
  color: #64748b;
}
.site-footer-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.site-footer-links { display: flex; gap: 1.25rem; }
.site-footer-links a { color: #64748b; text-decoration: none; }
.site-footer-links a:hover { color: #1e293b; text-decoration: underline; }

/* =====================================================================
   Responsive — 1024px intermediate breakpoint (§8a)
   ===================================================================== */
@media (max-width: 1024px) {
  .topbar-inner { padding: 0 1rem; }
  .nav-dropdown { width: 300px; }
  .content { padding: 1rem; }
}

/* =====================================================================
   Responsive — 768px mobile
   ===================================================================== */
@media (max-width: 768px) {
  .content { padding: 1rem; }
  .nav-dropdown { width: calc(100vw - 2rem); }
  .disclaimer-toast { flex-direction: column; gap: 10px; padding: 12px 16px; }
  .disclaimer-toast-dismiss { align-self: stretch; text-align: center; }
  .site-footer-inner { flex-direction: column; align-items: flex-start; }

  /* Search bar drops to its own full-width row below the nav toggle */
  .topbar { height: auto; }
  .topbar-inner { flex-wrap: wrap; padding: .6rem 1rem; gap: .5rem; height: auto; }
  .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; }
}
