/* ==========================================================================
   Document View — Two-column layout with sidebar and content
   ========================================================================== */

.document-view {
  display: flex;
  gap: 32px;
  min-height: calc(100vh - var(--menu-height));
  padding: 0 40px;
  padding-top: 32px;
  max-width: 1400px;
  margin: 0 auto;
}

/* Sidebar Overlay (mobile) */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.4);
  z-index: 200;
  border: none;
}

.sidebar-overlay--visible {
  display: block;
}

/* Sidebar */
.document-sidebar {
  position: sticky;
  top: calc(var(--menu-height) + 32px);
  width: var(--sidebar-width);
  height: fit-content;
  max-height: calc(100vh - var(--menu-height) - 64px);
  flex-shrink: 0;
  overflow-y: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  background-color: var(--bg-color);
  box-shadow: var(--shadow-sm);
}

/* Custom scrollbar for sidebar */
.document-sidebar::-webkit-scrollbar {
  width: 8px;
}

.document-sidebar::-webkit-scrollbar-track {
  background: transparent;
  margin: 12px 0;
}

.document-sidebar::-webkit-scrollbar-thumb {
  background-color: var(--neutral-60);
  border-radius: 10px;
  border: 2px solid var(--bg-color);
}

.document-sidebar::-webkit-scrollbar-thumb:hover {
  background-color: var(--neutral-300);
}

.sidebar-header {
  display: none;
}

.sidebar-close {
  padding: 8px;
  color: var(--text-secondary);
}

.sidebar-close:hover {
  color: var(--text-color);
}

.sidebar-content {
  padding: 20px;
  padding-bottom: 40px;
}

.sidebar-back-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.8rem;
  color: var(--primary-color);
  margin-bottom: 16px;
}

.sidebar-back-link:hover {
  text-decoration: underline;
}

/* Main Content */
.document-content {
  flex: 1;
  min-width: 0;
  max-width: 900px;
  padding: 40px 48px;
  background-color: var(--bg-color);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  margin-bottom: 40px;
}

/* Sections */
.document-section {
  margin-bottom: 32px;
}

.document-section h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--primary-color);
}

.document-section h2 {
  font-size: 1.25rem;
  font-weight: 600;
  margin-top: 24px;
  margin-bottom: 12px;
}

.document-section h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-top: 20px;
  margin-bottom: 10px;
}

.document-section h4 {
  font-size: 1rem;
  font-weight: 600;
  margin-top: 16px;
  margin-bottom: 8px;
}

.document-section p {
  margin-bottom: 12px;
}

.document-section ul,
.document-section ol {
  margin-bottom: 12px;
}

.document-section li {
  margin-bottom: 4px;
}

/* Front page section */
.document-section--frontpage {
  margin-bottom: 40px;
  padding-bottom: 32px;
  border-bottom: 1px solid var(--border-color);
}

.document-section--frontpage .frontpage {
  text-align: center;
}

/* Tables */
.table-wrapper {
  margin: 20px 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background-color: var(--bg-color);
}

.document-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  table-layout: auto;
}

.document-table th,
.document-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
  text-align: left;
  vertical-align: top;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.document-table th {
  background-color: var(--bg-secondary);
  font-weight: 600;
}

.document-table thead td {
  background-color: var(--bg-secondary);
  font-weight: 600;
}

.document-table tr:last-child td,
.document-table tr:last-child th {
  border-bottom: none;
}

.document-table tbody tr:nth-child(even) td {
  background-color: var(--neutral-20);
}

/* Images */
.document-section img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
  margin: 12px 0;
}



.heading-anchor-button {
  position: absolute;
  left: -28px;
  top: 50%;
  transform: translateY(-50%);
  padding: 4px;
  color: var(--text-muted);
  opacity: 0;
  transition: opacity var(--transition-fast), color var(--transition-fast);
  border-radius: var(--radius-sm);
}

h1:hover .heading-anchor-button,
h2:hover .heading-anchor-button,
h3:hover .heading-anchor-button,
[data-slug]:hover .heading-anchor-button {
  opacity: 1;
}

.heading-anchor-button:hover {
  color: var(--primary-color);
  background-color: var(--primary-color-light);
}

.heading-anchor-button--copied {
  opacity: 1;
  color: #10B981;
}

/* Document not found */
.document-not-found {
  text-align: center;
  padding: 80px 24px;
}

.document-not-found h1 {
  font-size: 1.25rem;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

.back-link {
  color: var(--primary-color);
  font-weight: 500;
}

/* ==========================================================================
   Floating TOC button (mobile only)
   ========================================================================== */

.toc-fab {
  display: none;
}

/* Responsive: Mobile */
@media (max-width: 1023px) {
  .toc-fab {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 199;
    padding: 10px 18px;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-secondary);
    background-color: var(--white);
    border: 1px solid var(--neutral-40);
    border-radius: 100px;
    box-shadow: 0 2px 12px rgba(18, 27, 44, 0.12), 0 1px 3px rgba(18, 27, 44, 0.08);
    cursor: pointer;
    transition: all var(--transition-fast);
  }

  .toc-fab:active {
    transform: scale(0.96);
  }
  .document-view {
    flex-direction: column;
    padding: 0;
    overflow-x: hidden;
  }

  .document-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: 100%;
    z-index: 300;
    height: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    border: none;
    border-radius: 0;
    box-shadow: none;
    opacity: 0;
    transform: translateY(100%);
    transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1),
                opacity 0.35s cubic-bezier(0.32, 0.72, 0, 1);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  .document-sidebar--open {
    opacity: 1;
    transform: translateY(0);
  }

  .sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-light);
    position: sticky;
    top: 0;
    background-color: var(--bg-color);
    z-index: 1;
  }

  .sidebar-header-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-color);
  }

  .sidebar-content {
    padding: 20px;
    padding-bottom: 80px;
  }

  .document-content {
    max-width: 100%;
    padding: 20px 16px;
    margin: 0 10px 20px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    background-color: var(--bg-color);
    overflow-x: hidden;
    font-size: 0.875rem;
    line-height: 1.55;
  }

  /* Force long words/URLs to break */
  .document-content * {
    overflow-wrap: break-word;
    word-break: break-word;
  }

  /* Scale down front page title — API injects inline font-size:36px */
  .document-section--frontpage span[style*="font-size"] {
    font-size: 1.25rem !important;
  }

  .document-section--frontpage {
    margin-bottom: 24px;
    padding-bottom: 20px;
  }

  .document-section {
    margin-bottom: 20px;
  }

  .document-section h1 {
    font-size: 1.1rem;
    margin-bottom: 10px;
    padding-bottom: 6px;
  }

  .document-section h2 {
    font-size: 1rem;
    margin-top: 16px;
    margin-bottom: 8px;
  }

  .document-section h3 {
    font-size: 0.9375rem;
    margin-top: 14px;
    margin-bottom: 6px;
  }

  .document-section h4 {
    font-size: 0.875rem;
    margin-top: 12px;
    margin-bottom: 6px;
  }

  .document-section p {
    margin-bottom: 8px;
  }

  .document-section ul,
  .document-section ol {
    margin-bottom: 8px;
    padding-left: 1.25em;
  }

  .document-section li {
    margin-bottom: 3px;
  }

  /* Tables: allow horizontal scroll, don't force word breaks */
  .table-wrapper {
    margin: 12px 0;
  }

  .document-table {
    font-size: 0.75rem;
    width: max-content;
    min-width: 100%;
  }

  .document-table th,
  .document-table td {
    padding: 8px 10px;
    word-break: normal;
    overflow-wrap: normal;
  }

  .document-table th {
    white-space: nowrap;
  }

  .heading-anchor-button {
    position: relative;
    left: auto;
    top: auto;
    transform: none;
    opacity: 0.5;
    margin-left: 8px;
    display: inline-flex;
    vertical-align: middle;
  }
}
