/* Documentation pages. Uses site.css (tokens, header, footer and the .prose text styles). */

.docs-shell {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  gap: 64px;
  align-items: start;
  padding-top: 48px;
}

/* Sidebar: sticky topic list under the header */
.docs-sidebar {
  position: sticky;
  top: 88px;
  max-height: calc(100vh - 112px);
  overflow-y: auto;
  padding: 4px 8px 24px 0;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.docs-nav-toggle {
  display: none;
}

.docs-sidebar-home {
  display: block;
  margin: 0 0 1.4rem;
  padding: 0.5rem 0.8rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: none;
}

.docs-sidebar-section + .docs-sidebar-section {
  margin-top: 1.4rem;
}

.docs-sidebar-heading {
  margin: 0 0 0.4rem;
  padding: 0 0.8rem;
  color: var(--faint);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.docs-sidebar-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.docs-sidebar-link {
  position: relative;
  display: block;
  padding: 0.38rem 0.8rem;
  border-radius: 10px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.4;
  text-decoration: none;
  transition: color 0.15s ease, background 0.15s ease;
}

.docs-sidebar-home:hover,
.docs-sidebar-link:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
}

.docs-sidebar-home.active {
  border-color: rgba(245, 146, 30, 0.45);
  background: var(--accent-soft);
}

.docs-sidebar-link.active {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

.docs-sidebar-link.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.55rem;
  bottom: 0.55rem;
  width: 2px;
  border-radius: 2px;
  background: var(--accent);
}

/* Content column: comfortable line length; tables with many columns may use
   the full column width. */
.docs-content {
  min-width: 0;
}

.docs-content > * {
  max-width: 760px;
}

.docs-content > .docs-scroll-table:has(th:nth-child(5)) {
  max-width: none;
}

.docs-content > h1:first-child {
  padding-bottom: 1.25rem;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--line);
}

.docs-content hr + h2 {
  margin-top: 0;
}

/* Inline code stays on one line on wide screens ("{{" never ends a line alone)
   and keeps its frame on every line when it has to wrap. */
.docs-content :not(pre) > code {
  white-space: nowrap;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}

.docs-content strong > code {
  font-weight: 400;
}

/* Reserve the diagram's height before it loads (1024 x 1536). */
.docs-content img[src$="/Incoming-Data-Flow-Diagram.jpg"] {
  display: block;
  width: min(100%, 26rem);
  height: auto;
  aspect-ratio: 2 / 3;
}

/* Tables and code blocks scroll sideways inside their frame; the edge that hides
   more content fades (classes set by setupDocsScrollCues in docs/page.html). */
.docs-scroll {
  position: relative;
  margin: 1.4em 0;
  --scroll-fade: var(--bg);
}

.docs-scroll-code {
  --scroll-fade: var(--surface);
}

.docs-scroll::before,
.docs-scroll::after {
  content: "";
  position: absolute;
  z-index: 1;
  top: 1px;
  bottom: 1px;
  width: 48px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.docs-scroll::before {
  left: 1px;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  background: linear-gradient(to right, var(--scroll-fade) 15%, transparent);
}

.docs-scroll::after {
  right: 1px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: linear-gradient(to left, var(--scroll-fade) 15%, transparent);
}

.docs-scroll.can-scroll-left::before,
.docs-scroll.can-scroll-right::after {
  opacity: 1;
}

.docs-scroll > pre {
  margin: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.docs-scroll-x {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

/* Full-width tables so right edges line up; the frame lives on .docs-scroll-x. */
.docs-content table {
  display: table;
  width: 100%;
  max-width: none;
  margin: 0;
  overflow: visible;
  border: 0;
  border-radius: 0;
}

.docs-content td:first-child {
  min-width: 6rem;
}

/* Tables with five or more columns hold short values: let them fit the column. */
.docs-content table:has(th:nth-child(5)) th,
.docs-content table:has(th:nth-child(5)) code {
  white-space: normal;
}

.docs-content table:has(th:nth-child(5)) td:not(:first-child) {
  min-width: 0;
}

.docs-content table:has(th:nth-child(5)) :is(th, td) {
  padding: 0.6rem 0.75rem;
  font-size: 0.86rem;
}

/* Previous / next topic at the end of each page */
.docs-pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 4rem;
  padding-top: 2rem;
  border-top: 1px solid var(--line);
}

.prose .docs-pager-link {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  padding: 18px 22px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  text-decoration: none;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.prose .docs-pager-link:hover {
  border-color: rgba(245, 146, 30, 0.45);
  background: var(--surface-2);
}

.docs-pager-next {
  grid-column: 2;
  text-align: right;
}

.docs-pager-caption {
  color: var(--faint);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.docs-pager-prev .docs-pager-caption::before {
  content: "\2190\00a0\00a0";
}

.docs-pager-next .docs-pager-caption::after {
  content: "\00a0\00a0\2192";
}

.docs-pager-title {
  font-weight: 600;
  line-height: 1.4;
}

@media (max-width: 900px) {
  .docs-shell {
    grid-template-columns: minmax(0, 1fr);
    gap: 32px;
    padding-top: 24px;
  }

  .docs-sidebar {
    position: static;
    max-height: none;
    overflow: visible;
    padding: 0;
  }

  .docs-nav {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
  }

  .docs-nav-toggle {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 14px 18px;
    cursor: pointer;
    list-style: none;
    font-size: 0.95rem;
  }

  .docs-nav-toggle::-webkit-details-marker {
    display: none;
  }

  .docs-nav-toggle::after {
    content: "";
    flex: 0 0 auto;
    width: 8px;
    height: 8px;
    margin: 0 2px 4px auto;
    border-right: 1.5px solid var(--muted);
    border-bottom: 1.5px solid var(--muted);
    transform: rotate(45deg);
    transition: transform 0.15s ease;
  }

  .docs-nav[open] .docs-nav-toggle::after {
    margin-bottom: -4px;
    transform: rotate(-135deg);
  }

  .docs-nav-label {
    flex: 0 0 auto;
    color: var(--faint);
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.14em;
    text-transform: uppercase;
  }

  .docs-nav-current {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text);
    font-weight: 600;
  }

  .docs-nav-body {
    padding: 6px 10px 16px;
    border-top: 1px solid var(--line);
  }

  .docs-sidebar-home {
    margin: 10px 0 1.2rem;
  }

  .docs-content > * {
    max-width: none;
  }
}

@media (max-width: 680px) {
  .docs-pager {
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
    margin-top: 3rem;
  }

  .docs-pager-next {
    grid-column: auto;
  }

  .docs-content :not(pre) > code {
    white-space: normal;
    overflow-wrap: anywhere;
  }

  /* Phones: two- and three-column tables fit the screen; wider ones scroll.
     Values may break anywhere; headers and the first column hold names, so
     their words stay whole. */
  .docs-content th,
  .docs-content td {
    padding: 0.6rem 0.7rem;
  }

  .docs-content th {
    white-space: normal;
  }

  .docs-content td:first-child,
  .docs-content td:not(:first-child) {
    min-width: 0;
  }

  .docs-content td:not(:first-child) {
    overflow-wrap: anywhere;
  }

  /* Four or more columns would be too narrow to read: they keep whole words and
     scroll sideways instead. */
  .docs-content table:has(th:nth-child(4)) :is(th, td, code) {
    overflow-wrap: break-word;
  }

  .docs-content table:has(th:nth-child(4)) td {
    min-width: 8rem;
  }

  .docs-content table:has(th:nth-child(5)) td:not(:first-child) {
    min-width: 4.5rem;
  }
}
