/*
 * The docs at docs.ownbase.site, on top of site.css. scripts/generate-docs-site.mjs
 * writes the pages from the guides in docs/. The header stays at the top; under
 * it, the guides on the left, the page in the middle, its headings on the
 * right. Both side columns fit the window under the header and scroll on their
 * own, without handing the scroll on to the page. Narrower, the headings go
 * above the page, and on a phone the guides fold away and the header scrolls.
 */

.docs-body {
  --link: #a8430b;
  /* The header's height, and where the side columns stop under it. */
  --head: 72px;
  --stick: calc(var(--head) + 24px);
}

.docs-body .guide-head {
  position: sticky;
  top: 0;
  z-index: 10;
}
.docs-body .guide-head .nav {
  height: var(--head);
}
.nav-links a[aria-current="page"] {
  color: #fff;
  background: rgb(255 255 255 / 0.12);
}

.docs {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr) 220px;
  grid-template-areas: "side main toc";
  gap: 48px;
  align-items: start;
  padding-block: 40px var(--section);
}
/*
 * The search box stays put and the list of guides under it takes the rest of
 * the window, scrolling inside itself. No overflow on the column itself: the
 * search results open wider than it.
 */
.docs-side {
  grid-area: side;
  position: sticky;
  top: var(--stick);
  display: flex;
  flex-direction: column;
  max-height: calc(100dvh - var(--stick) - 24px);
}
.docs-main {
  grid-area: main;
  min-width: 0;
  max-width: 780px;
}
.docs-toc {
  grid-area: toc;
  position: sticky;
  top: var(--stick);
  max-height: calc(100dvh - var(--stick) - 24px);
  overflow-y: auto;
  overscroll-behavior: contain;
  font-size: 14px;
}

/* Search. Results open over the page, wider than the column they start in. */
.docs-search {
  position: relative;
  flex: none;
  margin-bottom: 16px;
}
.docs-search input {
  width: 100%;
  height: 44px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 15px;
}
.docs-search input:focus-visible {
  outline-offset: 0;
}
.docs-status:empty {
  display: none;
}
.docs-status {
  margin-top: 8px;
  color: var(--ink-3);
  font-size: 14px;
  line-height: 1.4;
}
.docs-results {
  position: absolute;
  z-index: 5;
  top: 52px;
  left: 0;
  width: min(560px, calc(100vw - 2 * var(--gutter)));
  max-height: min(70vh, 640px);
  overflow-y: auto;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 18px 48px rgb(29 27 51 / 0.18);
}
.docs-hit-page + .docs-hit-page {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--line);
}
.docs-hit-title {
  padding: 6px 10px 2px;
  color: var(--ink-3);
  font-size: 13px;
  font-weight: 600;
}
.docs-results a {
  display: block;
  padding: 8px 10px;
  border-radius: 6px;
  text-decoration: none;
}
.docs-results a:hover,
.docs-results a:focus-visible {
  background: var(--fog);
}
.docs-hit-heading {
  display: block;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.35;
}
.docs-snippet {
  display: block;
  margin-top: 2px;
  color: var(--ink-2);
  font-size: 14px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}
.docs-snippet mark {
  background: rgb(255 210 122 / 0.6);
  color: inherit;
}

/*
 * The guides, one fold each, the open page's guide unfolded. The list scrolls
 * inside the column; on a phone docs.js folds it under the Guides button.
 */
.docs-nav {
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 4px;
}
.docs-fold + .docs-fold {
  margin-top: 2px;
}
.docs-fold > summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 6px;
  color: var(--ink);
  font-size: 15px;
  font-weight: 620;
  line-height: 1.35;
  list-style: none;
  cursor: pointer;
}
.docs-fold > summary::-webkit-details-marker {
  display: none;
}
.docs-fold > summary::before {
  content: "";
  flex: none;
  width: 7px;
  height: 7px;
  border-right: 1.5px solid var(--ink-3);
  border-bottom: 1.5px solid var(--ink-3);
  transform: rotate(-45deg);
  transition: transform 0.15s ease;
}
.docs-fold[open] > summary::before {
  transform: rotate(45deg);
}
.docs-fold > summary:hover {
  background: rgb(29 27 51 / 0.06);
}
.docs-fold-list {
  margin: 2px 0 10px 13px;
  padding-left: 8px;
  border-left: 1px solid var(--line);
}
/* A guide's groups: quieter than a guide, with their sections under them. */
.docs-group > summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  border-radius: 6px;
  color: var(--ink-2);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
  list-style: none;
  cursor: pointer;
}
.docs-group > summary::-webkit-details-marker {
  display: none;
}
.docs-group > summary::before {
  content: "";
  flex: none;
  width: 5px;
  height: 5px;
  border-right: 1.5px solid var(--ink-3);
  border-bottom: 1.5px solid var(--ink-3);
  transform: rotate(-45deg);
  transition: transform 0.15s ease;
}
.docs-group[open] > summary::before {
  transform: rotate(45deg);
}
.docs-group > summary:hover {
  color: var(--ink);
  background: rgb(29 27 51 / 0.06);
}
.docs-group ul {
  margin: 0 0 6px 12px;
}
.docs-group a {
  font-size: 14.5px;
}
.docs-nav a,
.docs-toc a {
  display: block;
  padding: 5px 10px;
  border-radius: 6px;
  color: var(--ink-2);
  font-size: 15px;
  line-height: 1.35;
  text-decoration: none;
}
.docs-nav a:hover,
.docs-toc a:hover {
  color: var(--ink);
  background: rgb(29 27 51 / 0.06);
}
.docs-nav a[aria-current="page"] {
  background: #fff;
  color: var(--ink);
  font-weight: 600;
  box-shadow: inset 3px 0 0 var(--host);
}
.docs-toc-title {
  margin: 0 0 6px 10px;
  color: var(--ink-3);
  font-size: 13px;
  font-weight: 650;
}
.docs-toc a {
  font-size: 14px;
}
.docs-toc .toc-4 a {
  padding-left: 22px;
}

/* The page. */
.docs-crumb {
  margin-bottom: 12px;
  color: var(--ink-3);
  font-size: 14px;
}
.docs-crumb a {
  color: inherit;
  text-underline-offset: 3px;
}
.doc {
  color: var(--ink-2);
  font-size: 16.5px;
  line-height: 1.65;
}
.doc :where(h1, h2, h3, h4, h5) {
  margin: 0;
  color: var(--ink);
  font-weight: 650;
  line-height: 1.2;
  letter-spacing: -0.02em;
  scroll-margin-top: calc(var(--head) + 16px);
  text-wrap: balance;
}
.doc h1 {
  font-size: clamp(32px, 4vw, 44px);
  letter-spacing: -0.035em;
}
.doc h2 {
  margin-top: 48px;
  font-size: clamp(23px, 2.2vw, 28px);
}
.doc h3 {
  margin-top: 36px;
  font-size: 20px;
}
.doc :where(h4, h5) {
  margin-top: 28px;
  font-size: 17px;
}
.doc-anchor {
  margin-left: 0.35em;
  color: var(--ink-3);
  font-weight: 500;
  text-decoration: none;
  opacity: 0;
}
:where(h1, h2, h3, h4, h5):hover > .doc-anchor,
.doc-anchor:focus-visible {
  opacity: 1;
}
.doc :where(p, ul, ol, pre, blockquote, .doc-table) {
  margin: 16px 0 0;
}
.docs-lede {
  color: var(--ink-2);
  font-size: 18px;
}
.doc a {
  color: var(--link);
  text-underline-offset: 3px;
}
.doc strong {
  color: var(--ink);
  font-weight: 620;
}
.doc :where(ul, ol) {
  padding-left: 1.4em;
}
.doc ul {
  list-style: disc;
}
.doc ol {
  list-style: decimal;
}
.doc li + li {
  margin-top: 6px;
}
.doc li > :where(p, ul, ol, pre, .doc-table):first-child {
  margin-top: 0;
}
.doc li::marker {
  color: var(--ink-3);
}
/*
 * Unlike the landing page's short commands, these can be long: let them wrap,
 * inside a word only when nothing else fits, so table columns do not shrink
 * to break --storage-limit-mb after its dashes.
 */
.doc :where(p, li, td, th, h1, h2, h3, h4) code {
  white-space: normal;
  overflow-wrap: break-word;
}
.doc :where(h1, h2, h3, h4, td, th) code {
  font-size: 0.86em;
  padding: 0.12em 0.38em;
  border-radius: 4px;
  background: rgb(29 27 51 / 0.07);
}
.doc pre {
  overflow-x: auto;
  padding: 16px 18px;
  border-radius: 8px;
  background: var(--deep);
  color: #e9e8f2;
  font-size: 14px;
  line-height: 1.6;
  tab-size: 2;
}
.doc blockquote {
  margin-left: 0;
  padding-left: 16px;
  border-left: 3px solid var(--line);
}
.doc-table {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}
.doc table {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
  line-height: 1.5;
}
.doc :where(th, td) {
  /* Narrow columns would stack a word to a line; the box scrolls instead. */
  min-width: 14ch;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}
.doc th {
  color: var(--ink);
  font-weight: 620;
  background: #fff;
}
.doc tr:last-child td {
  border-bottom: 0;
}
.doc .align-right {
  text-align: right;
}
.doc .align-center {
  text-align: center;
}
.docs-list {
  columns: 2 260px;
  column-gap: 32px;
}
/* A guide's overview: its sections under their groups, side by side. */
.docs-groups {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px 32px;
}
.doc .docs-groups h3 {
  margin-top: 20px;
  color: var(--ink-3);
  font-size: 14px;
  font-weight: 650;
  letter-spacing: 0;
}
.doc .docs-groups ul {
  margin-top: 8px;
  padding-left: 0;
  list-style: none;
}
.doc .docs-groups li + li {
  margin-top: 4px;
}

/* The home page: one card per guide, the whole card a link to it. */
.docs-guides {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
  margin-top: 32px;
}
.docs-guide {
  position: relative;
  padding: 20px 22px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
}
.docs-guide:hover {
  border-color: var(--ink-3);
}
.doc .docs-guide h2 {
  margin: 0;
  font-size: 20px;
}
.docs-guide h2 a {
  color: var(--ink);
  text-decoration: none;
}
.docs-guide h2 a::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
}
.docs-guide h2 a:focus-visible {
  outline: none;
}
.docs-guide:has(a:focus-visible) {
  outline: 2px solid var(--host);
  outline-offset: 2px;
}
.doc .docs-guide p {
  margin-top: 8px;
  font-size: 15px;
  line-height: 1.5;
}
.doc .docs-guide-count {
  color: var(--ink-3);
  font-size: 14px;
}

.docs-pager {
  display: flex;
  gap: 16px;
  margin-top: 56px;
}
.docs-pager a {
  flex: 1 1 0;
  min-width: 0;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  font-weight: 600;
  line-height: 1.35;
  text-decoration: none;
}
.docs-pager a:hover {
  border-color: var(--ink-3);
}
.docs-pager span {
  display: block;
  margin-bottom: 2px;
  color: var(--ink-3);
  font-size: 13px;
  font-weight: 500;
}
.docs-next {
  margin-left: auto;
  text-align: right;
}
.docs-source {
  margin-top: 24px;
  color: var(--ink-3);
  font-size: 14px;
}
.docs-source a {
  color: inherit;
  text-underline-offset: 3px;
}

/* Headings above the page once there is no room beside it. */
@media (max-width: 1200px) {
  .docs {
    grid-template-columns: 240px minmax(0, 1fr);
    grid-template-areas:
      "side toc"
      "side main";
    gap: 0 40px;
  }
  .docs-side {
    grid-row: 1 / span 2;
  }
  .docs-toc {
    position: static;
    max-height: none;
    max-width: 780px;
    margin-bottom: 32px;
    padding: 14px 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--paper);
  }
  .docs-toc ul {
    columns: 2 220px;
  }
}

@media (max-width: 860px) {
  /* A phone's window is short: the header scrolls away with the page. */
  .docs-body {
    --head: 0px;
  }
  .docs-body .guide-head {
    position: static;
  }
  .docs-body .guide-head .nav {
    height: 72px;
  }
  .docs {
    display: block;
    padding-top: 20px;
  }
  .docs-side {
    position: static;
    display: block;
    max-height: none;
    margin-bottom: 28px;
  }
  /* The [hidden] attribute shows and hides these, so neither sets display. */
  .docs-nav-toggle {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--paper);
    color: var(--ink);
    font: inherit;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
  }
  .docs-nav-toggle::after {
    content: "";
    float: right;
    width: 7px;
    height: 7px;
    margin: 6px 4px 0 0;
    border-right: 1.5px solid var(--ink-3);
    border-bottom: 1.5px solid var(--ink-3);
    transform: rotate(45deg);
  }
  .docs-nav-toggle[aria-expanded="true"]::after {
    margin-top: 9px;
    transform: rotate(-135deg);
  }
  .docs-nav {
    overflow: visible;
    margin-top: 8px;
    padding: 8px 4px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--paper);
  }
  .docs-results {
    width: 100%;
  }
  .docs-pager {
    flex-direction: column;
  }
  .docs-next {
    margin-left: 0;
  }
}
