:root {
  --green-dark: #2c4a2e;
  --green-mid: #4a7c4e;
  --green-light: #e8f0e8;
  --ink: #1a1a1a;
  --rule: #c8d8c8;
  --paper: #fafcfa;
  --scan-bg: #f0f0ec;
  --search-h: 44px;     /* desktop single-row bar height */
  --sidebar-w: 220px;   /* unified nav sidebar width */
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: Georgia, serif; background: var(--scan-bg); color: var(--ink); }

/* SEARCH BAR */
#search-bar {
  position: sticky; top: 0; z-index: 200;
  background: var(--green-dark); color: #fff;
  display: flex; align-items: center; gap: 8px;
  padding: 6px 16px; font-family: sans-serif; font-size: 0.85rem;
}
/* Top row: logo + nav toggle */
.sb-top {
  display: flex; align-items: center; gap: 8px; flex-shrink: 0;
}
/* Search row: input + count + nav buttons */
.sb-search {
  display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0;
}
.site-title { color: #fff; text-decoration: none; font-weight: bold; white-space: nowrap; }
#search-input {
  flex: 1; padding: 5px 10px; border-radius: 4px; border: none;
  font-size: 0.9rem; background: #fff; color: var(--ink); min-width: 0;
}
#search-count { color: #cdc; font-size: 0.8rem; white-space: nowrap; min-width: 60px; }
.s-btn {
  background: var(--green-mid); color: #fff; border: none;
  padding: 5px 10px; border-radius: 4px; cursor: pointer; font-size: 0.85rem;
}
.s-btn:hover { background: #5a9c5e; }

/* NAV TOGGLE BUTTON (mobile only — hidden on desktop) */
.nav-toggle-btn {
  display: none;   /* shown only on mobile via media query */
  background: rgba(255,255,255,0.15);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.25);
  padding: 5px 11px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
  font-family: sans-serif;
  white-space: nowrap;
  flex-shrink: 0;
  line-height: 1;
}
.nav-toggle-btn:hover { background: rgba(255,255,255,0.25); }
.nav-toggle-btn.open { background: rgba(255,255,255,0.28); border-color: rgba(255,255,255,0.5); }

/* SECTION LAYOUT — sidebar + content */
.section-layout {
  display: flex;
  align-items: flex-start;
  max-width: 1100px;
  margin: 0 auto;
  padding: 0;
}
.section-layout .page-wrap {
  flex: 1;
  min-width: 0;
  margin: 24px 0;
}

/* UNIFIED NAV SIDEBAR */
.toc-sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  position: sticky;
  top: var(--search-h);
  max-height: calc(100vh - var(--search-h));
  overflow-y: auto;
  background: #fff;
  border-right: 1px solid var(--rule);
  flex-shrink: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--rule) transparent;
}

/* PREV / NEXT STRIP */
.nav-pn-strip {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  background: var(--green-light);
  border-bottom: 1px solid var(--rule);
}
.nav-pn {
  color: var(--green-dark);
  text-decoration: none;
  font-size: 0.74rem;
  font-weight: 600;
  font-family: sans-serif;
  line-height: 1.4;
  max-width: 48%;
}
.nav-pn:hover { text-decoration: underline; }
.nav-pn-next { text-align: right; margin-left: auto; }

/* SECTION GROUPS */
.nav-group { border-bottom: 1px solid var(--green-light); }
.nav-group:last-child { border-bottom: none; }
.nav-group-label {
  font-size: 0.61rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #aaa;
  padding: 8px 12px 3px;
}
.nav-item {
  display: block;
  padding: 5px 12px;
  color: #555;
  text-decoration: none;
  font-size: 0.77rem;
  font-family: sans-serif;
  line-height: 1.35;
}
.nav-item:hover { background: var(--green-light); color: var(--green-dark); }
.nav-item-active {
  background: var(--green-light);
  color: var(--green-dark);
  font-weight: 600;
  border-left: 3px solid var(--green-mid);
  padding-left: 9px;
}

/* ARTICLE HEADINGS — injected by JS under current section */
.toc-articles {
  list-style: none;
  padding: 2px 0 6px;
  margin: 0;
  background: #f4f9f4;
  border-top: 1px solid var(--green-light);
}
.tsa-item {
  border-left: 3px solid transparent;
}
.tsa-item.active {
  border-left-color: var(--green-mid);
  background: var(--green-light);
}
.tsa-link {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 4px;
  padding: 3px 10px 3px 16px;
  text-decoration: none;
  color: #666;
  font-family: sans-serif;
  font-size: 0.7rem;
  line-height: 1.35;
}
.tsa-item.active .tsa-link { color: var(--green-dark); font-weight: 600; }
.tsa-link:hover { color: var(--green-dark); background: var(--green-light); }
.tsa-label { flex: 1; }
.tsa-pg { color: #bbb; font-size: 0.63rem; white-space: nowrap; }
.tsa-item.tsa-starred .tsa-pg::before { content: '\2605 '; color: var(--green-mid); }

/* Sidebar backdrop (mobile) */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 149;
}
.sidebar-backdrop.open { display: block; }

/* PAGE WRAP */
.page-wrap { max-width: 860px; margin: 24px auto; background: #fff; padding: 36px 40px; border-radius: 4px; box-shadow: 0 1px 6px rgba(0,0,0,0.10); }
.doc-header { font-family: sans-serif; font-size: 0.78rem; color: #888; margin-bottom: 20px; }
.doc-header a { color: var(--green-dark); text-decoration: none; }

/* SECTION MAP — static in-page contents table */
.section-map {
  border: 1px solid var(--rule);
  border-radius: 4px;
  margin-bottom: 28px;
  overflow: hidden;
  font-family: sans-serif;
}
.section-map-hdr {
  background: var(--green-light);
  padding: 8px 14px;
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--green-dark);
  border-bottom: 1px solid var(--rule);
}
.section-map-tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}
.section-map-tbl tr { border-bottom: 1px solid var(--green-light); }
.section-map-tbl tr:last-child { border-bottom: none; }
.section-map-tbl td { padding: 5px 14px; vertical-align: baseline; }
.sm-article a { color: var(--ink); text-decoration: none; }
.sm-article a:hover { color: var(--green-dark); text-decoration: underline; }
.sm-pg { white-space: nowrap; text-align: right; }
.sm-pg a { color: var(--green-mid); text-decoration: none; font-size: 0.75rem; }
.sm-star { color: var(--green-mid); font-size: 0.8rem; }

/* DOCUMENT BODY */
.doc-body { line-height: 1.75; font-size: 0.97rem; }
.doc-body p { margin-bottom: 14px; text-align: justify; }
.doc-body h2 { font-size: 1rem; text-align: center; margin: 28px 0 16px; text-transform: uppercase; letter-spacing: 0.04em; }
.doc-body h4 { font-size: 0.97rem; margin: 20px 0 8px; }

/* PAGE ROW — two-column gutter layout (sections/) */
.page-row {
  display: flex;
  gap: 0;
  border-top: 1px solid var(--rule);
  margin-top: 0;
}
.page-row:first-of-type { border-top: none; }

.pg-gutter {
  width: 56px;
  min-width: 56px;
  padding: 20px 12px 20px 0;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  border-right: 2px solid var(--green-light);
  margin-right: 20px;
}
.pg-num {
  font-family: sans-serif;
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--green-mid);
  letter-spacing: 0.04em;
  text-align: right;
  line-height: 1;
}
.pg-scan-btn {
  background: var(--green-light);
  border: 1px solid var(--rule);
  color: var(--green-dark);
  padding: 3px 6px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.68rem;
  font-family: sans-serif;
  white-space: nowrap;
  line-height: 1.4;
}
.pg-scan-btn:hover { background: var(--rule); }
.pg-scan-btn.showing { background: var(--green-mid); color: #fff; border-color: var(--green-mid); }

.pg-content {
  flex: 1;
  padding: 20px 0;
  min-width: 0;
}
.pg-text { line-height: 1.75; font-size: 0.97rem; }
.pg-text p { margin-bottom: 14px; text-align: justify; }
.pg-text h2 { font-size: 1rem; text-align: center; margin: 28px 0 16px; text-transform: uppercase; letter-spacing: 0.04em; }
.pg-text h4 { font-size: 0.97rem; margin: 20px 0 8px; }

.pg-scan-view img { max-width: 100%; border: 1px solid var(--rule); display: block; }
.doc-title-block { text-align: center; margin-bottom: 28px; }
.doc-title-block h1 { font-size: 1.1rem; font-style: italic; line-height: 1.5; }
.doc-subtitle { font-style: italic; font-size: 0.9rem; margin-top: 6px; }
.sub-items { margin-left: 28px; border-left: 2px solid var(--rule); padding-left: 16px; margin-bottom: 14px; }
.sub-items p { margin-bottom: 10px; }
.doc-items { margin-left: 20px; margin-bottom: 14px; }
.doc-items li { display: flex; gap: 12px; margin-bottom: 10px; list-style: none; }
.item-num { min-width: 28px; font-weight: bold; }

/* SIGNATURE BLOCKS */
.sig-block { margin: 24px 0 8px; font-family: 'Courier New', monospace; font-size: 0.88rem; }
.sig-line { border-bottom: 1px solid var(--ink); margin: 20px 0 4px; }
.sig-label { font-size: 0.82rem; color: #555; }

/* SCAN TOGGLE (legacy -- pages/ files) */
.scan-toggle-wrap { margin-top: 28px; }
.scan-toggle-btn {
  background: var(--green-light); border: 1px solid var(--rule);
  color: var(--green-dark); padding: 7px 14px; border-radius: 4px;
  cursor: pointer; font-size: 0.85rem; font-family: sans-serif;
}
.scan-toggle-btn:hover { background: var(--rule); }
.scan-image-wrap { display: none; margin-top: 12px; }
.scan-image-wrap img { max-width: 100%; border: 1px solid var(--rule); }

/* MAP / IMAGE PAGES */
.map-page-wrap { margin: 8px 0 16px; }
.map-page-label { font-family: sans-serif; font-size: 0.82rem; color: #666; margin-bottom: 10px; font-style: italic; }
.map-page-img img { max-width: 100%; border: 1px solid var(--rule); }
.hidden-ocr { display: none; }

/* INDEX / TOC */
.toc-section { margin-bottom: 32px; }
.toc-section h2 { font-family: sans-serif; font-size: 0.95rem; color: var(--green-dark); border-bottom: 2px solid var(--green-light); padding-bottom: 6px; margin-bottom: 12px; }
.toc-list { list-style: none; }
.toc-list li a {
  display: flex; align-items: baseline; gap: 8px;
  padding: 7px 4px; text-decoration: none; color: var(--ink);
  border-bottom: 1px solid var(--green-light); font-size: 0.88rem;
  font-family: sans-serif;
}
.toc-list li a:hover { background: var(--green-light); }
.toc-list li a span:first-child { min-width: 54px; font-weight: bold; color: var(--green-dark); }
.pg { margin-left: auto; color: #aaa; font-size: 0.78rem; min-width: 24px; text-align: right; }
.tag { background: var(--green-light); color: var(--green-dark); font-size: 0.72rem; padding: 1px 6px; border-radius: 3px; white-space: nowrap; }
.tag-map { background: #e8eef5; color: #2a4a6e; }

/* SEARCH HIGHLIGHTS */
mark { background: #ffe066; color: var(--ink); border-radius: 2px; }
mark.current { background: #ff9900; }

/* TOC DOC (inside pages) */
.toc-doc { font-family: 'Courier New', monospace; font-size: 0.88rem; line-height: 1.8; }
.toc-doc .toc-article { font-weight: bold; margin-top: 18px; margin-bottom: 4px; }
.toc-doc .toc-entry { display: flex; gap: 0; margin-left: 24px; }
.toc-doc .toc-entry .te-title { flex: 1; }
.toc-doc .toc-entry .te-pg { white-space: nowrap; }

/* VIEW TOGGLE (index page) */
.view-toggle {
  display: flex;
  gap: 8px;
  margin: 0 0 20px;
}
.view-btn {
  font-family: sans-serif;
  font-size: 0.85rem;
  padding: 6px 16px;
  border-radius: 4px;
  border: 1px solid var(--rule);
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}
.view-btn:hover { background: var(--green-light); }
.view-btn-active {
  background: var(--green-dark);
  color: #fff;
  border-color: var(--green-dark);
}

/* MOBILE: sidebar becomes off-canvas overlay, toggle button appears */
@media (max-width: 960px) {
  .nav-toggle-btn { display: flex; }

  .toc-sidebar {
    position: fixed;
    left: 0;
    top: var(--search-h);
    bottom: 0;
    width: 280px;
    max-height: none;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    z-index: 150;
    box-shadow: none;
  }
  .toc-sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0,0,0,0.18);
  }

  .section-layout { padding: 0; }
  .section-layout .page-wrap { margin: 12px auto; }
}

@media (max-width: 600px) {
  :root { --search-h: 80px; }

  /* Search bar -- two explicit rows */
  #search-bar { flex-wrap: wrap; gap: 0; padding: 0; }
  .sb-top {
    width: 100%; display: flex; align-items: center;
    padding: 8px 12px; gap: 8px;
  }
  .sb-search {
    width: 100%; flex-basis: 100%;
    padding: 6px 12px 8px; gap: 6px;
    border-top: 1px solid rgba(255,255,255,0.12);
  }

  /* Page wrap -- tighten everything */
  .page-wrap { padding: 12px 14px; margin: 8px; }
  .section-layout .page-wrap { margin: 8px; }
  .doc-header { margin-bottom: 12px; font-size: 0.74rem; }

  /* Page row -- flip gutter to a horizontal strip above content */
  .page-row { flex-direction: column; }
  .pg-gutter {
    flex-direction: row;
    width: auto; min-width: auto;
    padding: 6px 0 8px;
    border-right: none;
    border-bottom: 1px solid var(--green-light);
    margin-right: 0;
    align-items: center;
    justify-content: flex-start;
    gap: 10px;
  }
  .pg-num { font-size: 0.72rem; text-align: left; }
  .pg-content { padding: 10px 0 0; }
}
