/* Documentation site theme. It loads style.css first for the shared colour
   variables and themes, then overrides the app's global layout. */

html {
  /* Scale the whole document from the reader's browser/device font size (the
     `1rem` base) and the app's own text-size preference, so every rem-based
     size follows both instead of only the inheriting body text. */
  font-size: calc(1rem * var(--app-font-scale, 1));
}
/* Anchor jumps clear the sticky header through the target's own margin. A scroll-padding on the
   page made the browser treat the header's own controls as covered and scroll the page on
   every keystroke or focus in them. */
[id] {
  scroll-margin-top: 5rem;
}

/* Respect the reader's motion preference: anchor jumps and scroll-spy animate
   only when they have not asked their OS to reduce motion. */
@media (prefers-reduced-motion: no-preference) {
  html {
    scroll-behavior: smooth;
  }
}

body {
  height: auto;
  min-height: 100%;
  background: var(--color-primary);
  color: var(--color-text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  /* Explicit so the app's body rule (loaded from /style.css first) cannot scale
     the already-scaled root a second time. */
  font-size: 1rem;
  line-height: 1.65;
}

.doc-skip {
  position: absolute;
  left: -9999px;
  top: 0;
  padding: 0.5em 1em;
  background: var(--surface-chip);
  color: var(--color-text);
  z-index: 10;
}
.doc-skip:focus {
  left: 0.5rem;
  top: 0.5rem;
}

.doc-header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.65rem 1.25rem;
  background: var(--color-footer);
  border-bottom: 1px solid var(--border-soft);
}

.doc-brand {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  white-space: nowrap;
  text-decoration: none;
  color: var(--color-text-strong);
}
.doc-brand:hover {
  text-decoration: none;
  filter: none;
}
.doc-brand-name {
  font-weight: 700;
}
.doc-brand-tag {
  color: var(--color-text-muted);
  font-size: 0.9em;
}

.doc-header-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.doc-lang {
  display: flex;
  gap: 0.25rem;
}
.doc-lang a {
  padding: 0.15em 0.5em;
  border-radius: 4px;
  text-decoration: none;
  color: var(--color-text-muted);
  font-size: 0.9em;
}
.doc-lang a:hover {
  background: var(--surface-link-hover);
}
.doc-lang a.is-active {
  color: var(--color-text-strong);
  background: var(--surface-chip);
}

.doc-app {
  padding: 0.3em 0.75em;
  border: 1px solid var(--border-chip);
  border-radius: 6px;
  background: var(--surface-chip);
  color: var(--color-text-strong);
  text-decoration: none;
  font-size: 0.9em;
  white-space: nowrap;
}
.doc-app:hover {
  background: var(--surface-chip-hover);
  text-decoration: none;
  filter: none;
}

/* Static client-side search: input in the header, results in a dropdown. */
.doc-search {
  position: relative;
}
.doc-search-input {
  width: 14rem;
  max-width: 40vw;
  padding: 0.35em 0.7em;
  border: 1px solid var(--border-chip);
  border-radius: 6px;
  background: var(--surface-chip);
  color: var(--color-text);
  font: inherit;
  font-size: inherit;
}
.doc-search-input::placeholder {
  color: var(--color-text-muted);
}
.doc-search-input:focus {
  outline: none;
  border-color: var(--color-operator);
  background: var(--surface-chip-hover);
}
.doc-search-results {
  position: absolute;
  top: calc(100% + 0.4em);
  right: 0;
  z-index: 10;
  width: min(26rem, calc(100vw - 2rem));
  max-height: 22rem;
  overflow-y: auto;
  margin: 0;
  padding: 0.3em;
  list-style: none;
  background: var(--color-surface);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  box-shadow: 0 10px 30px var(--shadow-modal, rgba(0, 0, 0, 0.4));
}
.doc-search-result {
  display: block;
  padding: 0.45em 0.6em;
  border-radius: 5px;
  text-decoration: none;
  color: var(--color-text);
}
.doc-search-result:hover,
.doc-search-result.is-active {
  background: var(--surface-chip);
  text-decoration: none;
  filter: none;
}
.doc-search-title {
  display: block;
  color: var(--color-text-strong);
  font-weight: 600;
}
.doc-search-page {
  display: block;
  color: var(--color-text-muted);
  font-size: 0.85em;
}
.doc-search-empty {
  padding: 0.6em;
  color: var(--color-text-muted);
  font-size: 0.9em;
}

.doc-layout {
  display: grid;
  grid-template-columns: 16rem minmax(0, 1fr);
  gap: 2.5rem;
  max-width: 78rem;
  margin: 0 auto;
  /* Bottom space lives on .doc-main, not here: the sticky sidebar is clamped to
     the grid area, which excludes this container's padding. */
  padding: 1.5rem 1.25rem 0;
  align-items: start;
}

.doc-sidebar {
  position: sticky;
  /* Match the sidebar's natural top (header + the layout's top padding) so it
     pins immediately instead of drifting on the first scroll. */
  top: calc(var(--doc-header-height, 3.5rem) + 1.5rem);
  max-height: calc(100vh - var(--doc-header-height, 3.5rem) - 3rem);
  max-height: calc(100dvh - var(--doc-header-height, 3.5rem) - 3rem);
  overflow-y: auto;
  /* Keep a sidebar scroll from chaining into the page behind it. */
  overscroll-behavior: contain;
  font-size: 0.94em;
}

.doc-nav > ul {
  list-style: none;
  margin: 0;
  padding: 0;
}
.doc-nav-item > a {
  display: block;
  padding: 0.3em 0.6em;
  border-radius: 5px;
  color: var(--color-text);
  text-decoration: none;
}
.doc-nav-item > a:hover {
  background: var(--surface-link-hover);
  text-decoration: none;
  filter: none;
}
.doc-nav-item.is-active > a {
  color: var(--color-text-strong);
  background: var(--surface-chip);
  /* Keep the left edge square so the accent bar is not clipped by the radii. */
  border-radius: 0 5px 5px 0;
  box-shadow: inset 2px 0 0 var(--color-operator);
}
.doc-nav-sub {
  list-style: none;
  margin: 0.2em 0 0.6em;
  padding: 0 0 0 1em;
  border-left: 1px solid var(--border-soft);
}
.doc-nav-sub a {
  display: block;
  padding: 0.15em 0.5em;
  color: var(--color-text-muted);
  text-decoration: none;
  font-size: 0.92em;
}
.doc-nav-sub a:hover {
  color: var(--color-text);
  text-decoration: none;
}
.doc-nav-sub a.is-active {
  color: var(--color-text-strong);
  font-weight: 600;
}
.doc-nav-sub-title {
  padding: 0.3em 0.5em 0.15em;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.72em;
  color: var(--color-text-muted);
}

.doc-menu-toggle {
  display: none;
}

.doc-main {
  min-width: 0;
  /* Extends the grid area so the sticky sidebar can reach the page bottom. */
  padding-bottom: 4rem;
}

.doc-content {
  max-width: 46rem;
  font-size: 1.02rem;
}
.doc-content h1 {
  margin: 0 0 0.6em;
  font-size: 1.9em;
  line-height: 1.25;
  color: var(--color-text-strong);
}
.doc-content h2 {
  margin: 1.8em 0 0.5em;
  padding-bottom: 0.2em;
  font-size: 1.3em;
  line-height: 1.3;
  color: var(--color-text-strong);
  border-bottom: 1px solid var(--border-soft);
}
.doc-content h3 {
  margin: 1.4em 0 0.4em;
  font-size: 1.08em;
  color: var(--color-text-strong);
}
/* A per-heading link that appears on hover/focus, so a section can be linked
   and shared by its anchor. */
.doc-content .doc-anchor {
  margin-left: 0.35em;
  color: var(--color-text-muted);
  text-decoration: none;
  opacity: 0;
  transition: opacity 0.12s ease;
}
.doc-content h2:hover .doc-anchor,
.doc-content h3:hover .doc-anchor,
.doc-content .doc-anchor:focus-visible {
  opacity: 1;
}
.doc-content .doc-anchor:hover {
  color: var(--color-operator);
  text-decoration: none;
  filter: none;
}
@media (hover: none) {
  .doc-content .doc-anchor {
    opacity: 1;
  }
}
.doc-content p,
.doc-content li {
  margin: 0.55em 0;
}
.doc-content ul,
.doc-content ol {
  padding-left: 1.4em;
}
.doc-content a {
  color: var(--color-link);
}
.doc-content blockquote {
  margin: 0.8em 0;
  padding: 0.2em 1em;
  border-left: 3px solid var(--border-strong);
  color: var(--color-text-muted);
}
.doc-content code {
  padding: 0.12em 0.35em;
  background: var(--surface-code);
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
}
.doc-content pre {
  margin: 0.8em 0;
  padding: 0.8em 1em;
  background: var(--surface-code);
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  overflow-x: auto;
}
.doc-content pre code {
  padding: 0;
  background: transparent;
  font-size: 0.9em;
}
/* A table can be wider than a phone viewport (the Reference page's shortcuts
   table); let it scroll inside its own box instead of widening the page. */
.doc-table {
  max-width: 100%;
  margin: 0.8em 0 1.2em;
  overflow-x: auto;
}
.doc-content table {
  width: 100%;
  margin: 0;
  border-collapse: collapse;
  font-size: 0.94em;
}
.doc-content th,
.doc-content td {
  padding: 0.4em 0.7em;
  border-bottom: 1px solid var(--border-table);
  text-align: left;
  vertical-align: top;
}
.doc-content th {
  color: var(--color-text-strong);
}
.doc-content td:first-child,
.doc-content th:first-child {
  white-space: nowrap;
}

.doc-example {
  margin: 1em 0;
  border: 1px solid var(--border-chip);
  border-radius: 8px;
  background: var(--surface-chip);
  overflow: hidden;
}
.doc-example .doc-code {
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  /* Match the editor's input surface. */
  background: var(--color-primary);
}
.doc-example .doc-code code {
  display: block;
  font-size: 0.92em;
  line-height: 1.6;
}
/* Match the editor's number sidebar: a distinct column with a divider. Long
   lines scroll horizontally; the number column stays pinned while they do. */
.doc-line {
  display: flex;
  width: max-content;
  min-width: 100%;
}
.doc-line-number {
  position: sticky;
  left: 0;
  z-index: 1;
  flex: 0 0 auto;
  box-sizing: border-box;
  width: calc(var(--doc-gutter, 1ch) + 1.6em);
  padding: 0.15em 0.7em 0.15em 0.9em;
  background: var(--color-surface);
  border-right: 1px solid var(--border-strong);
  color: var(--color-text-muted);
  text-align: right;
  user-select: none;
}
.doc-line-content {
  padding: 0.15em 1em;
  white-space: pre;
}
/* Token colours reused from the app's highlighting */
.doc-example .variable {
  color: var(--color-variable);
}
.doc-example .number {
  color: var(--color-number);
}
.doc-example .operator {
  color: var(--color-operator);
}
.doc-example .currency {
  color: var(--color-currency);
}
.doc-example .title {
  color: var(--color-title);
}
.doc-example .tag {
  background: var(--color-tag-bg);
  color: var(--color-tag-text);
  border-radius: 3px;
  padding: 0 0.25em;
}
.doc-example .comment {
  color: var(--color-dim);
}
.doc-example .line {
  white-space: pre;
}

.doc-example-result {
  padding: 0 1em 0.3em;
  color: var(--color-text-muted);
  font-size: 0.85em;
}

.doc-example-actions {
  display: flex;
  gap: 0.5rem;
  padding: 0.6em 1em;
  border-top: 1px solid var(--border-soft);
  background: var(--surface-nav);
}
.doc-action {
  padding: 0.3em 0.7em;
  border: 1px solid var(--border-chip);
  border-radius: 5px;
  background: var(--surface-chip);
  color: var(--color-text);
  font: inherit;
  font-size: 0.85em;
  cursor: pointer;
}
.doc-action:hover {
  background: var(--surface-chip-hover);
}
.doc-action-primary {
  color: var(--color-text-strong);
  border-color: var(--color-operator);
}

/* Scoped to beat `.doc-content ul`, which adds a list indent. */
.doc-content .doc-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
  gap: 0.9rem;
  list-style: none;
  margin: 1.4em 0 0;
  padding: 0;
}
/* Drop the prose list spacing so the grid gap is equal both ways. */
.doc-content .doc-cards > li {
  margin: 0;
}
.doc-cards a {
  display: block;
  height: 100%;
  padding: 0.9em 1em;
  border: 1px solid var(--border-chip);
  border-radius: 8px;
  background: var(--surface-chip);
  text-decoration: none;
}
.doc-cards a:hover {
  background: var(--surface-chip-hover);
  text-decoration: none;
  filter: none;
}
.doc-card-title {
  display: block;
  color: var(--color-text-strong);
  font-weight: 600;
}
.doc-card-desc {
  display: block;
  margin-top: 0.25em;
  color: var(--color-text-muted);
  font-size: 0.9em;
}

.doc-footer {
  max-width: 46rem;
  margin-top: 3rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-soft);
  color: var(--color-text-muted);
  font-size: 0.9em;
}

@media (max-width: 900px) {
  .doc-layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 1rem;
    padding-top: 1rem;
  }
  .doc-menu-toggle {
    display: block;
    justify-self: start;
    padding: 0.4em 0.9em;
    border: 1px solid var(--border-chip);
    border-radius: 6px;
    background: var(--surface-chip);
    color: var(--color-text);
    font: inherit;
    cursor: pointer;
  }
  /* The drawer is a real overlay below the sticky header: fixed, slide-in,
     with a dimmed backdrop. `--doc-header-height` is set by docs.js so the
     header (and its Menu button) stays visible above the drawer. */
  .doc-sidebar {
    position: fixed;
    top: var(--doc-header-height, 3.5rem);
    left: 0;
    bottom: 0;
    z-index: 6;
    width: min(88vw, 22rem);
    max-height: none;
    padding: 1rem 1rem 2rem;
    background: var(--color-primary);
    border-right: 1px solid var(--border-strong);
    overflow-y: auto;
    overscroll-behavior: contain;
    transform: translateX(-100%);
    visibility: hidden;
  }
  .doc-sidebar.is-open {
    transform: translateX(0);
    visibility: visible;
  }
  /* Sits below the header (z-index 5) so the Menu button stays clickable, and
     below the drawer so it is not dimmed. */
  .doc-backdrop {
    position: fixed;
    inset: 0;
    z-index: 4;
    background: rgba(0, 0, 0, 0.45);
    opacity: 0;
    visibility: hidden;
  }
  .doc-backdrop.is-open {
    opacity: 1;
    visibility: visible;
  }
  /* Lock the page behind the drawer. */
  html.doc-menu-open {
    overflow: hidden;
  }
  @media (prefers-reduced-motion: no-preference) {
    /* Visibility flips at once when opening (so the drawer is focusable), and
       only after the slide when closing (so it does not vanish mid-animation). */
    .doc-sidebar {
      transition:
        transform 0.2s ease,
        visibility 0s 0.2s;
    }
    .doc-sidebar.is-open {
      transition:
        transform 0.2s ease,
        visibility 0s;
    }
    .doc-backdrop {
      transition:
        opacity 0.2s ease,
        visibility 0s 0.2s;
    }
    .doc-backdrop.is-open {
      transition:
        opacity 0.2s ease,
        visibility 0s;
    }
  }
  .doc-header {
    flex-wrap: nowrap;
  }
  /* Keep the bar one row: the tag is the first thing to go. */
  .doc-brand-tag {
    display: none;
  }
  .doc-header-actions {
    /* docs.js reparents this into the drawer on phones; stack it above the nav. */
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid var(--border-soft);
  }
  .doc-search,
  .doc-search-input {
    width: 100%;
    max-width: none;
  }
  .doc-search-results {
    /* Inline below the box: an absolute dropdown would be clipped by the
       drawer's own scroll area. */
    position: static;
    width: auto;
    max-height: 12rem;
  }
}

.doc-not-found {
  max-width: 40rem;
  margin: 4rem auto;
  padding: 0 1rem;
}
