.wiki-main {
  display: flex;
  height: calc(100vh - var(--header-height));
  margin-top: 0;
  padding-top: 0;
}

.wiki-sidebar {
  width: 280px;
  min-width: 280px;
  background-color: var(--clr-muted);
  border-right: 1px solid rgba(0, 0, 0, 0.08);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 1.5rem 1.25rem;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  background-color: var(--clr-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-header h2 {
  font-size: 1.1rem;
  margin: 0;
  color: var(--clr-primary);
}

/* TOC toggle button removed — TOC visible by default */

/* TOC Sidebar */
.toc-sidebar {
  width: 240px;
  min-width: 240px;
  max-width: 240px;
  background-color: var(--clr-light);
  border-right: 1px solid rgba(0, 0, 0, 0.08);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* legacy .visible class kept for compatibility */
.toc-sidebar.visible {
  width: 240px;
  min-width: 240px;
  max-width: 240px;
  border-right: 1px solid rgba(0, 0, 0, 0.08);
}

/* When viewing PDF, hide TOC with this helper class */
.toc-sidebar.pdf-hidden {
  width: 0 !important;
  min-width: 0 !important;
  max-width: 0 !important;
  border-right: none !important;
  overflow: hidden !important;
}

.toc-header {
  padding: 1rem 1rem;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  background-color: var(--clr-muted);
}

.toc-header h3 {
  font-size: 0.95rem;
  margin: 0;
  color: var(--clr-primary);
  white-space: nowrap;
}

.toc-nav {
  padding: 0.5rem 0;
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

.toc-empty {
  padding: 1rem;
  color: rgba(27, 29, 33, 0.5);
  font-size: 0.85rem;
  text-align: center;
  white-space: nowrap;
}

.toc-link {
  display: block;
  padding: 0.35rem 1rem;
  color: #333;
  text-decoration: none;
  font-size: 0.9rem;
  line-height: 1.4;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
  border-left: 3px solid transparent;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  text-overflow: unset;
}

.toc-link:hover {
  background-color: rgba(31, 79, 130, 0.08);
  color: var(--clr-primary);
}

.toc-link.active {
  border-left-color: var(--clr-secondary);
  color: var(--clr-secondary);
  font-weight: 400;
  background-color: rgba(20, 160, 152, 0.06);
}

/* Explicit sizes per heading level: h1 largest → h6 smallest */
.toc-link[data-level="1"] {
  padding-left: 0.5rem;
  font-size: 1rem;
  font-weight: 400;
}

.toc-link[data-level="2"] {
  padding-left: 1rem;
  font-size: 0.95rem;
  font-weight: 400;
}

.toc-link[data-level="3"] {
  padding-left: 1.75rem;
  font-size: 0.9rem;
  font-weight: 400;
}

.toc-link[data-level="4"] {
  padding-left: 2.5rem;
  font-size: 0.85rem;
  font-weight: 400;
}

.toc-link[data-level="5"] {
  padding-left: 3.25rem;
  font-size: 0.82rem;
  font-weight: 400;
}

.toc-link[data-level="6"] {
  padding-left: 4rem;
  font-size: 0.8rem;
  font-weight: 400;
}

.wiki-tree {
  padding: 0.75rem 0;
  flex: 1;
}

/* ==================== TREE SEARCH ==================== */
.tree-search-box {
  display: flex;
  align-items: center;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  background-color: var(--clr-muted);
  gap: 0.25rem;
}

#tree-search-input,
#tree-search-input-mobile {
  flex: 1;
  padding: 0.35rem 0.6rem;
  border: 1px solid rgba(0, 0, 0, 0.18);
  border-radius: 5px;
  font-size: 0.88rem;
  outline: none;
  background: #fff;
  color: #222;
  min-width: 0;
}

#tree-search-input:focus,
#tree-search-input-mobile:focus {
  border-color: var(--clr-primary);
  box-shadow: 0 0 0 2px rgba(31, 79, 130, 0.12);
}

.tree-search-clear {
  background: none;
  border: none;
  cursor: pointer;
  color: rgba(0, 0, 0, 0.45);
  font-size: 0.85rem;
  padding: 0.2rem 0.35rem;
  border-radius: 4px;
  line-height: 1;
  flex-shrink: 0;
  transition: color 0.15s, background 0.15s;
}

.tree-search-clear:hover {
  color: var(--clr-primary);
  background: rgba(31, 79, 130, 0.08);
}

.tree-search-result {
  flex-direction: column;
  align-items: flex-start !important;
  gap: 0.1rem !important;
}

.tree-search-highlight {
  background-color: #fff3a3;
  color: #333;
  border-radius: 2px;
  padding: 0 1px;
}

.tree-search-path {
  font-size: 0.75rem;
  color: rgba(0, 0, 0, 0.45);
  padding-left: 1.4rem;
  line-height: 1.2;
}


.tree-item {
  user-select: none;
}

.tree-folder,
.tree-file {
  padding: 0.5rem 1.25rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: background-color 0.15s ease;
  color: #000000;
}

.tree-folder:hover,
.tree-file:hover {
  background-color: rgba(31, 79, 130, 0.08);
}

.tree-file.active {
  background-color: var(--clr-secondary);
  color: var(--clr-light);
  font-weight: 500;
}

.tree-folder::before {
  content: '📁';
  font-size: 1rem;
}

.tree-folder.expanded::before {
  content: '📂';
}

.tree-file::before {
  content: '📄';
  font-size: 0.9rem;
}

.tree-children {
  display: none;
}

.tree-children.expanded {
  display: block;
}

.tree-children .tree-folder,
.tree-children .tree-file {
  padding-left: 2.25rem;
}

.tree-children .tree-children .tree-folder,
.tree-children .tree-children .tree-file {
  padding-left: 3.25rem;
}

.tree-children .tree-children .tree-children .tree-folder,
.tree-children .tree-children .tree-children .tree-file {
  padding-left: 4.25rem;
}

.wiki-content {
  flex: 1;
  overflow-y: auto;
  background-color: var(--clr-light);
  display: flex;
  flex-direction: column;
}

.content-wrapper {
  max-width: 820px;
  margin: 0 auto;
  padding: 2.5rem 2rem;
  width: 100%;
  box-sizing: border-box;
}

.content-wrapper:has(.excel-table-container) {
  max-width: 100%;
  padding: 2rem;
}

.content-wrapper:has(.pdf-viewer-container) {
  max-width: 100%;
  padding: 1rem 1.5rem;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
}

/* ==================== SEARCH BAR ==================== */
.search-bar {
  display: none;
  padding: 0.5rem 1rem;
  background: var(--clr-muted, #f5f5f5);
  border-bottom: 1px solid rgba(0,0,0,0.1);
  z-index: 100;
  flex-shrink: 0;
}

.search-bar.visible {
  display: block;
}

.search-bar-inner {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  max-width: 520px;
  margin: 0 auto;
}

#search-input {
  flex: 1;
  padding: 0.35rem 0.6rem;
  border: 1px solid rgba(0,0,0,0.2);
  border-radius: 5px;
  font-size: 0.9rem;
  outline: none;
  min-width: 0;
}

#search-input:focus {
  border-color: var(--clr-primary, #1f4f82);
  box-shadow: 0 0 0 2px rgba(31,79,130,0.12);
}

.search-counter {
  font-size: 0.8rem;
  color: rgba(0,0,0,0.55);
  white-space: nowrap;
  min-width: 3.5em;
  text-align: center;
}

.search-nav-btn,
.search-close-btn {
  background: none;
  border: 1px solid rgba(0,0,0,0.15);
  border-radius: 4px;
  cursor: pointer;
  padding: 0.25rem 0.45rem;
  font-size: 0.85rem;
  line-height: 1;
  color: var(--clr-primary, #1f4f82);
  transition: background 0.15s;
}

.search-nav-btn:hover,
.search-close-btn:hover {
  background: rgba(31,79,130,0.1);
}

.search-nav-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

/* Search highlight marks */
.search-highlight {
  background-color: #fff176;
  border-radius: 2px;
  padding: 0 1px;
}

.search-highlight.current {
  background-color: #ff9800;
  color: #fff;
  outline: 2px solid #ff9800;
}

.content-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

/* Loading overlay for large documents */
.content-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 0.5rem;
  background: rgba(255,255,255,0.85);
  z-index: 9999;
}

.content-loading .loading-ring {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 4px solid rgba(0,0,0,0.08);
  border-top-color: var(--clr-primary, #1f4f82);
  animation: spin 1s linear infinite;
}

.content-loading .loading-msg {
  font-size: 0.95rem;
  color: rgba(0,0,0,0.7);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.document-title {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--clr-primary);
  margin: 0;
}

.share-button {
  padding: 0.5rem 1rem;
  background-color: var(--clr-primary);
  color: var(--clr-light);
  border: none;
  border-radius: 6px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.share-button:hover {
  background-color: var(--clr-primary);
  opacity: 0.9;
}

.welcome-message {
  text-align: center;
  color: rgba(27, 29, 33, 0.6);
  padding: 4rem 2rem;
}

.welcome-message h1 {
  font-size: 1.75rem;
  margin-bottom: 0.75rem;
  color: var(--clr-primary);
}

.loading {
  padding: 1.25rem;
  text-align: center;
  color: rgba(27, 29, 33, 0.5);
}

/* Markdown content styles */
.markdown-content {
  line-height: 1.7;
  color: #000000;
}

.markdown-content h1 {
  font-size: 2rem;
  margin-top: 0;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid rgba(0, 0, 0, 0.08);
  color: var(--clr-primary);
}

.markdown-content h2 {
  font-size: 1.5rem;
  margin-top: 2rem;
  margin-bottom: 0.75rem;
  color: var(--clr-primary);
}

.markdown-content h3 {
  font-size: 1.25rem;
  margin-top: 1.5rem;
  margin-bottom: 0.6rem;
}

/* Smaller heading levels: ensure consistent scaling and weights */
.markdown-content h4 {
  font-size: 1.15rem;
  margin-top: 1.25rem;
  margin-bottom: 0.5rem;
  font-weight: 600;
}

.markdown-content h5 {
  font-size: 1.05rem;
  margin-top: 1rem;
  margin-bottom: 0.45rem;
  font-weight: 600;
}

.markdown-content h6 {
  font-size: 1rem; /* same as body text */
  margin-top: 0.75rem;
  margin-bottom: 0.4rem;
  font-weight: 600; /* bold but same size as body */
}

.markdown-content h1,
.markdown-content h2,
.markdown-content h3 {
  font-weight: 700;
}

.markdown-content p {
  margin-bottom: 1rem;
  color: #000000;
}

.markdown-content ul,
.markdown-content ol {
  margin-bottom: 1rem;
  padding-left: 1.75rem;
}

.markdown-content li {
  margin-bottom: 0.4rem;
  color: #000000;
}

.markdown-content code {
  background-color: rgba(31, 79, 130, 0.08);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 0.9em;
}

.markdown-content pre {
  background-color: var(--clr-dark);
  color: #e4e4e7;
  padding: 1rem;
  border-radius: 8px;
  overflow-x: auto;
  margin-bottom: 1rem;
}

.markdown-content pre code {
  background: none;
  padding: 0;
  color: inherit;
  font-size: 0.9rem;
}

.markdown-content blockquote {
  border-left: 4px solid var(--clr-secondary);
  margin: 1rem 0;
  padding-left: 1rem;
  color: rgba(27, 29, 33, 0.75);
  font-style: italic;
}

.markdown-content img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  margin: 1.5rem 0;
  cursor: pointer;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.markdown-content img:hover {
  opacity: 0.85;
  transform: scale(1.01);
}

.markdown-content a {
  color: var(--clr-secondary);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s ease;
}

.markdown-content a:hover {
  border-bottom-color: var(--clr-secondary);
}

.markdown-content a.wiki-link {
  color: var(--clr-secondary);
  font-weight: 500;
  border-bottom: 1px dotted var(--clr-secondary);
  cursor: pointer;
}

.markdown-content a.wiki-link:hover {
  border-bottom-style: solid;
  background-color: rgba(20, 160, 152, 0.08);
}

.markdown-content span.wiki-link-broken {
  color: #d32f2f;
  text-decoration: line-through;
  cursor: help;
  opacity: 0.7;
}

.markdown-content mark {
  background-color: #ffeb3b;
  color: inherit;
  padding: 0.1rem 0.2rem;
  border-radius: 3px;
}

.markdown-content hr {
  border: none;
  border-top: 2px solid rgba(0, 0, 0, 0.08);
  margin: 2rem 0;
}

.markdown-content table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1rem;
}

.markdown-content th,
.markdown-content td {
  border: 1px solid rgba(0, 0, 0, 0.12);
  padding: 0.5rem 0.75rem;
  text-align: left;
}

.markdown-content th {
  background-color: var(--clr-muted);
  font-weight: 600;
}

/* Excel file icon in tree */
.tree-file-excel::before {
  content: '📊' !important;
}

.tree-file-pdf::before {
  content: '📄' !important;
}

/* DOC/DOCX icon in tree */
.tree-file-doc::before {
  content: '📝' !important;
}

/* PDF file icon in tree */
.tree-file-pdf::before {
  content: '📄' !important;
  color: #c62828;
}

/* PDF viewer container */
.pdf-viewer-container {
  flex: 1;
  min-height: 0;
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 8px;
  overflow: hidden;
}

.pdf-iframe {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

/* PDF header actions (download + share) */
.pdf-header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.pdf-download-btn {
  display: inline-flex;
  align-items: center;
  padding: 0.4rem 0.9rem;
  border-radius: 6px;
  background-color: var(--clr-muted, #f0f0f0);
  color: var(--clr-primary, #1f4f82);
  font-size: 0.85rem;
  font-weight: 500;
  text-decoration: none;
  transition: background-color 0.15s ease;
  border: 1px solid rgba(0,0,0,0.08);
}

.pdf-download-btn:hover {
  background-color: rgba(31, 79, 130, 0.12);
}

/* Excel Sheet Tabs in TOC */
.excel-sheet-tab {
  display: block;
  width: 100%;
  padding: 0.5rem 1rem;
  background: none;
  border: none;
  border-left: 3px solid transparent;
  cursor: pointer;
  font-size: 0.85rem;
  color: #333;
  text-align: left;
  transition: all 0.15s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.excel-sheet-tab:hover {
  background-color: rgba(31, 79, 130, 0.08);
  color: var(--clr-primary);
}

.excel-sheet-tab.active {
  border-left-color: var(--clr-secondary);
  color: var(--clr-secondary);
  font-weight: 500;
  background-color: rgba(20, 160, 152, 0.06);
}

/* Excel Table Container */
.excel-table-container {
  overflow: auto;
  max-height: calc(100vh - 200px);
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 8px;
  width: 100%;
}

/* Excel Table */
.excel-table {
  border-collapse: collapse;
  font-size: 0.85rem;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  white-space: nowrap;
}

.excel-table td {
  border: 1px solid #d4d4d8;
  padding: 4px 8px;
  vertical-align: middle;
  max-width: 400px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.excel-table tr:first-child td {
  background-color: #f0f4f8;
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 1;
}

.excel-table tr:hover td {
  background-color: rgba(20, 160, 152, 0.04);
}

/* Mobile logo: show site + page title on wiki page */
.logo-desktop { display: inline; }
.logo-mobile  { display: none; }

/* Desktop: hide mobile-only elements */
.mobile-wiki-bar { display: none; }
.wiki-tree-toggle { display: none; }
.toc-mobile-toggle { display: none; }

@media (max-width: 768px) {
  .wiki-main {
    flex-direction: column;
  }

  /* Show full site title on mobile header */
  .logo-desktop { display: none; }
  .logo-mobile  { display: inline; }

  /* Mobile top bar: tree search + tree toggle + TOC toggle */
  .mobile-wiki-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.75rem;
    background: var(--clr-muted, #f5f5f5);
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    flex-shrink: 0;
    position: sticky;
    top: var(--header-height, 60px);
    z-index: 700;
    box-sizing: border-box;
  }

  .mobile-wiki-bar .tree-search-box {
    flex: 0;
    display: none;
  }

  /* Wiki sidebar: full-height overlay below header+bar */
  .wiki-sidebar {
    position: fixed !important;
    top: calc(var(--header-height, 60px) + 52px);
    left: 0;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    height: calc(100vh - var(--header-height, 60px) - 52px);
    max-height: none !important;
    z-index: 600;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    border-right: none !important;
    border-bottom: none !important;
    overflow-y: auto;
  }

  .wiki-sidebar.tree-open {
    transform: translateX(0);
  }

  /* Backdrop behind wiki-tree overlay */
  .wiki-tree-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 599;
  }

  .wiki-tree-backdrop.visible {
    display: block;
  }

  /* Tree toggle button */
  .wiki-tree-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.4rem 0.7rem;
    background: var(--clr-primary, #1f4f82);
    border: none;
    border-radius: 6px;
    font-size: 0.88rem;
    color: #fff;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    transition: background 0.15s;
  }

  .wiki-tree-toggle:hover,
  .wiki-tree-toggle.active {
    background: var(--clr-secondary, #14a098);
  }

  /* wiki-content fills remaining viewport height */
  .wiki-content {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    width: 100%;
  }

  .content-wrapper {
    padding: 1.5rem 1rem;
  }

  /* TOC: full-height overlay from right */
  .toc-sidebar {
    position: fixed !important;
    top: calc(var(--header-height, 60px) + 52px);
    right: 0;
    height: calc(100vh - var(--header-height, 60px) - 52px);
    width: 280px !important;
    min-width: 0 !important;
    max-width: 280px !important;
    z-index: 610;
    box-shadow: -4px 0 16px rgba(0, 0, 0, 0.18);
    transform: translateX(100%);
    transition: transform 0.25s ease;
    border-right: none !important;
    overflow-y: auto;
  }

  .toc-sidebar.mobile-open {
    transform: translateX(0);
  }

  /* Backdrop behind TOC panel */
  .toc-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 609;
  }

  .toc-backdrop.visible {
    display: block;
  }

  /* TOC toggle button: in mobile bar */
  .toc-mobile-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.4rem 0.7rem;
    background: var(--clr-muted, #f5f5f5);
    border: 1px solid rgba(0, 0, 0, 0.15);
    border-radius: 6px;
    font-size: 0.88rem;
    color: var(--clr-primary, #1f4f82);
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    transition: background 0.15s;
  }

  .toc-mobile-toggle:hover {
    background: rgba(31, 79, 130, 0.1);
  }
}

/* Image Modal Styles */
.image-modal {
  display: none;
  position: fixed;
  z-index: 10000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.9);
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.image-modal-content {
  position: relative;
  max-width: 95%;
  max-height: 95%;
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: scaleIn 0.2s ease;
}

@keyframes scaleIn {
  from {
    transform: scale(0.8);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

.image-modal-img {
  max-width: 100%;
  max-height: 90vh;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

@media (max-width: 768px) {
  .image-modal-img {
    max-height: 80vh;
  }
}
