<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>$if(title)$$title$$else$Document$endif$</title>
  
  <!-- Document metadata for JavaScript -->
  $if(revision)$<meta name="revision" content="$revision$">$endif$
  $if(generation_time)$<meta name="generation_time" content="$generation_time$">$endif$
  
  <!-- Embedded CSS -->
  <style>
/*
* ZDDC Document Viewer Template
* Enhanced responsive layout with TOC navigation
*/

/* CSS Variables for theming - Soft Light Theme */
:root {
  --primary-color: #2563eb;
  --primary-color-dark: #1d4ed8;
  --text-color: #4b5563;
  --text-secondary: #6b7280;
  --text-primary: #1f2937;
  --bg-primary: #f8fafc;
  --bg-secondary: #f1f5f9;
  --border-color: #d1d5db;
  --hover-bg: #e2e8f0;
  --active-bg: rgba(37, 99, 235, 0.1);
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --sidebar-width: 280px;
  --header-height: 120px;
  --content-max-width: 900px;
}

/* Dark mode variables - Standard Dark Theme */
@media (prefers-color-scheme: dark) {
  :root {
    --primary-color: #60a5fa;
    --primary-color-dark: #3b82f6;
    --text-color: #d1d5db;
    --text-secondary: #9ca3af;
    --text-primary: #f9fafb;
    --bg-primary: #111827;
    --bg-secondary: #1f2937;
    --border-color: #374151;
    --hover-bg: #374151;
    --active-bg: rgba(96, 165, 250, 0.2);
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
  }
}

/* Reset and base styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  line-height: 1.6;
  color: var(--text-color);
  background: var(--bg-secondary);
  height: 100vh;
  overflow-x: hidden;
}

@media print {
  body {
    height: auto !important;
    overflow: visible !important;
  }
}

/* App Container - Modern CSS Grid Layout */
.app-container {
  height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  grid-template-areas: "sidebar main";
}

@media (max-width: 768px) {
  .app-container {
    grid-template-columns: 1fr;
    grid-template-areas: "main";
  }
}

/* Content wrapper - Grid area */
.content-wrapper {
  grid-area: main;
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-width: min(900px, 100%);
  margin: 0;
  container-type: inline-size;
}

/* Content page simplified */
.content-page {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.header-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
}

/* Sidebar Navigation - Grid area */
#sidebar {
  grid-area: sidebar;
  height: 100vh;
  background: var(--bg-primary);
  border-inline-end: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

@media (max-width: 768px) {
  #sidebar {
    position: fixed;
    inset: 0;
    z-index: 1000;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
    background: var(--bg-primary);
  }
  
  #sidebar.mobile-open {
    transform: translateX(0);
  }
  
  .content-wrapper {
    max-width: none;
  }
  
  /* Ensure mobile TOC uses light theme colors */
  #sidebar .sidebar-header {
    background: var(--bg-secondary);
    color: var(--text-primary);
  }
  
  #sidebar .toc a {
    color: var(--text-primary);
  }
  
  #sidebar .toc a:hover {
    background: var(--hover-bg);
  }
}

/* Document Header - Flex Row Layout */
.document-header {
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-color);
  padding: 1rem;
  margin-bottom: 0;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-shrink: 0;
}

.mobile-menu-container {
  display: none;
  flex-shrink: 0;
}

@media (max-width: 768px) {
  .mobile-menu-container {
    display: flex;
    align-items: center;
  }
  
  .mobile-menu-toggle {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 0.75rem;
    border-radius: 0.5rem;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.2s ease;
    line-height: 1;
  }
  
  .mobile-menu-toggle:hover {
    background: var(--primary-color-dark);
    transform: scale(1.05);
    margin: 0;
  }
}

.header-content {
  flex: 1;
  min-width: 0;
}

.sidebar-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.sidebar-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-secondary);
}

.toc-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.toc-level-selector {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}


.toc-level-selector select {
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--border-color);
  border-radius: 0.25rem;
  background: var(--bg-primary);
  color: var(--text-color);
  font-size: 0.9rem;
}

/* TOC Container */
.toc-container {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 0;
  scrollbar-width: thin;
  scrollbar-color: var(--border-color) transparent;
  position: relative;
}

.toc-container::-webkit-scrollbar {
  width: 6px;
}

.toc-container::-webkit-scrollbar-track {
  background: transparent;
}

.toc-container::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 3px;
}

/* Scroll Progress Indicator */
.scroll-progress {
  width: 100%;
  height: 3px;
  background: var(--border-color);
  margin-bottom: 20px;
}

.scroll-progress-bar {
  height: 100%;
  background: var(--primary-color);
  width: 0%;
  transition: width 0.1s ease;
}

/* TOC Styling */
.toc ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.toc ul ul {
  padding-left: 1.25rem;
  margin-top: 0.25rem;
  border-left: 2px solid var(--border-color);
  margin-left: 0.5rem;
}

.toc li {
  margin: 0;
}

.toc a {
  display: block;
  padding: 0.375rem 0.75rem;
  color: var(--text-color);
  text-decoration: none;
  border-radius: 4px;
  transition: all 0.2s ease;
  font-size: 0.9rem;
  line-height: 1.3;
}

.toc li li a {
  border-left: none;
}

.toc a:hover {
  background: var(--hover-bg);
  color: var(--primary-color);
}

.toc a.active {
  background: var(--active-bg);
  color: var(--primary-color);
  border-left-color: var(--primary-color);
  font-weight: 500;
}

/* Content Page Container - Simplified */
.content-page {
  flex: 1;
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Document Content */
.document-content {
  flex: 1;
  padding: 0.5rem 2rem 2rem 2rem;
  max-width: var(--content-max-width);
  margin: 0 auto;
  overflow-y: auto;
  position: relative;
}

/* Document Header */
.document-header {
  border-bottom: 1px solid var(--border-color);
  padding: 0.75rem 2rem;
  background: var(--bg-primary);
}

.header-content {
  max-width: var(--content-max-width);
  margin: 0 auto;
}

.header-line {
  margin: 0;
  line-height: 1.3;
}

/* Header line hierarchy */
.client-project {
  font-size: 1.2rem;
  color: var(--text-color);
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.document-title {
  font-size: 2.2rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

.metadata-line {
  font-size: 0.9rem;
  color: var(--text-secondary);
  font-weight: 400;
}

.draft-status {
  color: #dc3545;
  font-weight: bold;
  margin-left: 0.5rem;
}

/* Print-only elements - hidden on screen */
.print-header,
.print-footer {
  display: none;
}

/* Mobile menu backdrop */
@media (max-width: 768px) {
  .mobile-menu-container {
    display: flex;
    align-items: center;
  }

  #sidebar.mobile-open::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: -1;
  }
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
  color: var(--text-primary);
  font-weight: 600;
  line-height: 1.25;
  margin-top: 1em;
  margin-bottom: 0.5em;
}

/* Remove top margin from first heading in content */
.document-content h1:first-child,
.document-content h2:first-child,
.document-content h3:first-child,
.document-content h4:first-child,
.document-content h5:first-child,
.document-content h6:first-child {
  margin-top: 0;
}

h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }
h4 { font-size: 1.125rem; }
h5 { font-size: 1rem; }
h6 { font-size: 0.875rem; }

p {
  margin: 1rem 0;
  color: var(--text-color);
}

/* Lists */
ol, ul {
  margin: 1rem 0;
  padding-left: 2rem;
}

ol {
  list-style-type: decimal;
}

ul {
  list-style-type: disc;
}

li {
  margin: 0.25rem 0;
  color: var(--text-color);
}

/* Nested lists */
ol ol, ul ul, ol ul, ul ol {
  margin: 0.25rem 0;
  padding-left: 1.5rem;
}

ul ul {
  list-style-type: circle;
}

ul ul ul {
  list-style-type: square;
}

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  font-size: 0.9rem;
}

th, td {
  padding: 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

/* Print styles */
@media print {
  /* Hide online-only elements */
  .sidebar,
  .mobile-menu-toggle,
  .scroll-progress,
  .document-header {
    display: none !important;
  }

  /* Show print-only elements */
  .print-header {
    display: block !important;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: white;
    border-bottom: 1pt solid #000;
    padding: 12pt 0.5in;
    z-index: 1000;
    margin: 0;
  }

  .print-footer {
    display: flex !important;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-top: 1pt solid #000;
    padding: 8pt 0.5in;
    z-index: 1000;
    justify-content: space-between;
    align-items: center;
    margin: 0;
  }

  /* Print header styling */
  .print-header .client-project {
    font-size: 12pt;
    color: #333;
    font-weight: 600;
    margin: 0 0 4pt 0;
    line-height: 1.2;
  }

  .print-header .document-title {
    font-size: 16pt;
    color: #000;
    font-weight: 700;
    margin: 0;
    line-height: 1.2;
  }

  /* Print footer styling */
  .print-footer .footer-left,
  .print-footer .footer-right {
    font-size: 10pt;
    color: #666;
    margin: 0;
  }
  
  /* Page counter for print */
  .print-footer .page-number::after {
    content: counter(page);
  }
  
  @page {
    margin: 1in;
    size: letter;
    counter-increment: page;
  }
  
  .draft-line {
    margin-top: 4pt;
    font-size: 10pt;
  }

  /* Layout adjustments */
  html, body {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
  }

  .app-container {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
  }

  .content-wrapper {
    margin-left: 0 !important;
    width: 100% !important;
    /* The screen layout caps content-wrapper at 900px; in print, the
       printable area is page-width minus @page margins (~6.5in =
       ~624px for letter at 96dpi), which is narrower than 900px BUT
       chromium's --print-to-pdf renders at the full page width and
       only clips at print time — so without max-width:none the
       element extends past the right margin. */
    max-width: none !important;
  }

  .content-page {
    max-width: none !important;
    width: 100% !important;
    padding: 0 !important;
  }

  .document-content {
    margin-top: 80pt !important;
    margin-bottom: 50pt !important;
    padding: 0 0.5in !important;
    border-left: none !important;
    min-height: calc(100vh - 130pt) !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
  }

  /* Wide content that wouldn't otherwise wrap: tables, code blocks,
     long URLs in inline code. Force them to stay within the
     printable area instead of running off the right edge. */
  pre, code, table, blockquote, img, video {
    max-width: 100% !important;
    overflow-wrap: break-word !important;
    word-wrap: break-word !important;
  }
  pre {
    white-space: pre-wrap !important;
    word-break: break-word !important;
  }
  table {
    table-layout: fixed !important;
    width: 100% !important;
  }

  /* Fix list formatting in print */
  ol, ul {
    padding-left: 2rem !important;
  }

  li {
    margin: 0.25rem 0 !important;
  }

  /* Typography for print */
  body {
    font-size: 12pt !important;
    line-height: 1.4 !important;
    color: #000 !important;
    background: white !important;
  }

  /* Page breaks */
  h1, h2, h3, h4, h5, h6 {
    page-break-after: avoid;
    page-break-inside: avoid;
    margin-top: 0.5em;
  }

  p, li {
    orphans: 3;
    widows: 3;
    page-break-inside: avoid;
  }
  
  /* Prevent content cutoff */
  * {
    box-sizing: border-box;
  }
  
  /* Ensure proper spacing at page breaks */
  h1:first-child, h2:first-child, h3:first-child {
    margin-top: 0;
    padding-top: 0.5em;
  }
  
  /* Table print formatting */
  table {
    page-break-inside: avoid;
  }

  thead {
    display: table-header-group;
  }

  tbody {
    display: table-row-group;
  }

  tr {
    page-break-inside: avoid;
  }

  th, td {
    padding: 8pt 6pt !important;
    vertical-align: top;
  }

  a {
    color: #000 !important;
    text-decoration: underline !important;
  }
}

/* Diff styling for pandiff output */
u {
  background-color: #d4edda;
  color: #155724;
  text-decoration: none;
  padding: 0.1em 0.2em;
  border-radius: 0.2em;
}


/*
 * Legal-style heading numbering for ZDDC documents.
 * Gated by the `numbered` body class, which the per-doctype templates add when
 * the document's YAML front matter sets `numbering: true` (default: off).
 */
body.numbered .document-content { counter-reset: h1-counter; }

body.numbered h1 { counter-reset: h2-counter h3-counter h4-counter h5-counter h6-counter; counter-increment: h1-counter; }
body.numbered h1::before { content: counter(h1-counter) ". "; font-weight: bold; color: var(--primary-color); }

body.numbered h2 { counter-reset: h3-counter h4-counter h5-counter h6-counter; counter-increment: h2-counter; }
body.numbered h2::before { content: counter(h1-counter) "." counter(h2-counter) " "; font-weight: bold; color: var(--primary-color); }

body.numbered h3 { counter-reset: h4-counter h5-counter h6-counter; counter-increment: h3-counter; }
body.numbered h3::before { content: counter(h1-counter) "." counter(h2-counter) "." counter(h3-counter) " "; font-weight: bold; color: var(--primary-color); }

body.numbered h4 { counter-reset: h5-counter h6-counter; counter-increment: h4-counter; }
body.numbered h4::before { content: counter(h1-counter) "." counter(h2-counter) "." counter(h3-counter) "." counter(h4-counter) " "; font-weight: bold; color: var(--primary-color); }

body.numbered h5 { counter-reset: h6-counter; counter-increment: h5-counter; }
body.numbered h5::before { content: counter(h1-counter) "." counter(h2-counter) "." counter(h3-counter) "." counter(h4-counter) "." counter(h5-counter) " "; font-weight: bold; color: var(--primary-color); }

body.numbered h6 { counter-increment: h6-counter; }
body.numbered h6::before { content: counter(h1-counter) "." counter(h2-counter) "." counter(h3-counter) "." counter(h4-counter) "." counter(h5-counter) "." counter(h6-counter) " "; font-weight: bold; color: var(--primary-color); }

/* TOC numbering to match document headings */
body.numbered .toc { counter-reset: toc-h1; }
body.numbered .toc ul { list-style: none; }
body.numbered .toc > ul > li { counter-increment: toc-h1; counter-reset: toc-h2 toc-h3 toc-h4 toc-h5 toc-h6; }
body.numbered .toc > ul > li > a::before { content: counter(toc-h1) ". "; font-weight: bold; color: var(--primary-color); margin-right: 0.25em; }
body.numbered .toc > ul > li > ul > li { counter-increment: toc-h2; counter-reset: toc-h3 toc-h4 toc-h5 toc-h6; }
body.numbered .toc > ul > li > ul > li > a::before { content: counter(toc-h1) "." counter(toc-h2) " "; font-weight: bold; color: var(--primary-color); margin-right: 0.25em; }
body.numbered .toc > ul > li > ul > li > ul > li { counter-increment: toc-h3; counter-reset: toc-h4 toc-h5 toc-h6; }
body.numbered .toc > ul > li > ul > li > ul > li > a::before { content: counter(toc-h1) "." counter(toc-h2) "." counter(toc-h3) " "; font-weight: bold; color: var(--primary-color); margin-right: 0.25em; }

body.numbered h1::before, body.numbered h2::before, body.numbered h3::before,
body.numbered h4::before, body.numbered h5::before, body.numbered h6::before { margin-right: 0.5em; }

@media print {
  body.numbered h1::before, body.numbered h2::before, body.numbered h3::before,
  body.numbered h4::before, body.numbered h5::before, body.numbered h6::before { color: #000 !important; }
}

/* Visual heading hierarchy that accompanies the numbered/legal look. */
body.numbered h1 { border-bottom: 2px solid var(--primary-color); padding-bottom: 0.3em; margin-top: 1em; }
body.numbered h1:first-of-type { margin-top: 0.5em; }
body.numbered h2 { border-bottom: 1px solid var(--border-color); padding-bottom: 0.2em; margin-top: 1.5em; }
body.numbered h3 { margin-top: 1.2em; }
body.numbered h4, body.numbered h5, body.numbered h6 { margin-top: 1em; }

/*
 * Doctype-specific layout. `doctype` comes from the document's YAML front matter
 * (report | specification | letter); the per-doctype template sets `doc-<name>`.
 * A letter has no TOC sidebar and flows as a normal single column.
 */
body.doc-letter { height: auto; overflow: visible; }
body.doc-letter .content-wrapper { margin: 0 auto; max-width: var(--content-max-width); }


  </style>
  
  $for(header-includes)$
  $header-includes$
  $endfor$
</head>
