/* ==========================================================================
   Document — Reading view layout and typography
   ========================================================================== */

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

/* Main Content */
.document-content {
  flex: 1;
  min-width: 0;
  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 anchors — scroll offset for fixed navbar */
.heading-anchor {
  scroll-margin-top: calc(var(--menu-height) + 16px);
}

.document-section[id] {
  scroll-margin-top: calc(var(--menu-height) + 16px);
}

.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;
}

.document-not-found-link {
  color: var(--primary-color);
  font-weight: 500;
}

/* --------------------------------------------------------------------------
   Responsive: Mobile
   -------------------------------------------------------------------------- */

@media (max-width: 1023px) {
  .document-view {
    flex-direction: column;
    padding: 0;
    overflow-x: hidden;
  }

  .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;
  }
}
