/* Refract — Documentation layout.
   Extends css/style.css; loaded only on documentation pages. */

:root {
  --docs-sidebar-width: 232px;
  --docs-toc-width: 190px;
  --docs-max-width: 1280px;
  --docs-gutter: 2.5rem;
  --color-code-bg: #171717;
  --color-code-border: rgba(255, 255, 255, 0.06);

  /* Syntax tokens. Desaturated to sit with the rest of the palette rather than
     compete with it; applied at build time, so no highlighter ships. */
  --tok-kw: #9fb8d6;
  --tok-str: #a7c6ae;
  --tok-num: #d3bd97;
  --tok-com: #6b7076;
  --tok-fn: #bcb5d0;
  --tok-bi: #9ec6c8;
  --tok-op: #8b9098;
  --color-note: #5b7a9a;
  --color-tip: #4f8a6a;
  --color-warn: #a8843f;
}

/* ═══════════════════════════════════════════════════
   SHELL
   ═══════════════════════════════════════════════════ */

body.docs {
  background: var(--color-bg);
}

.docs-shell {
  display: grid;
  grid-template-columns: var(--docs-sidebar-width) minmax(0, 1fr) var(--docs-toc-width);
  gap: var(--docs-gutter);
  max-width: var(--docs-max-width);
  margin: 0 auto;
  padding: 0 1.5rem;
  align-items: start;
}

/* The shared header tracks the 980px marketing column; docs run wider, so
   widen it here to keep the logo flush with the sidebar. */
body.docs .site-header-inner {
  max-width: var(--docs-max-width);
}

/* style.css constrains `main`; docs pages manage their own width. */
body.docs main.docs-main {
  max-width: none;
  margin: 0;
  padding: 2.75rem 0 5rem;
  min-width: 0;
}

/* ═══════════════════════════════════════════════════
   SIDEBAR
   ═══════════════════════════════════════════════════ */

.docs-sidebar {
  position: sticky;
  top: var(--header-height);
  max-height: calc(100vh - var(--header-height));
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 2.75rem 0 3rem;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.12) transparent;
}

.docs-sidebar::-webkit-scrollbar {
  width: 6px;
}

.docs-sidebar::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}

.docs-sidebar-title {
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--color-text-tertiary);
  margin: 0 0 0.9rem;
  padding-left: 0.75rem;
}

.docs-filter {
  position: relative;
  margin-bottom: 1.25rem;
}

.docs-filter input {
  width: 100%;
  font-family: inherit;
  font-size: 0.8125rem;
  padding: 0.45rem 0.7rem;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.02);
  color: var(--color-text);
}

.docs-filter input::placeholder {
  color: var(--color-text-tertiary);
}

.docs-filter input:focus {
  outline: none;
  border-color: var(--color-logo-blue-light);
  box-shadow: 0 0 0 3px rgba(61, 81, 102, 0.3);
}

.docs-nav-group {
  margin-bottom: 1.35rem;
}

.docs-nav-group h3 {
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-tertiary);
  margin: 0 0 0.4rem;
  padding-left: 0.75rem;
}

.docs-nav-group ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.docs-nav-group li {
  margin: 0;
}

.docs-nav-group a {
  display: block;
  padding: 0.32rem 0.75rem;
  border-left: 2px solid transparent;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 0.875rem;
  line-height: 1.35;
  color: var(--color-text-muted);
  text-decoration: none;
  transition: color 0.18s ease, background 0.18s ease, border-color 0.18s ease;
}

.docs-nav-group a:hover {
  color: var(--color-text);
  background: rgba(255, 255, 255, 0.03);
}

.docs-nav-group a[aria-current="page"] {
  color: var(--color-text);
  border-left-color: var(--color-primary);
  background: rgba(91, 122, 154, 0.12);
}

/* The animated underline from style.css would fight the nav rows. */
.docs-sidebar a::after,
.docs-toc a::after,
.docs-pager a::after,
.docs-card::after {
  content: none !important;
}

.docs-nav-empty {
  display: none;
  padding: 0.4rem 0.75rem;
  font-size: 0.8125rem;
  color: var(--color-text-tertiary);
}

/* ═══════════════════════════════════════════════════
   TABLE OF CONTENTS
   ═══════════════════════════════════════════════════ */

.docs-toc {
  position: sticky;
  top: var(--header-height);
  max-height: calc(100vh - var(--header-height));
  overflow-y: auto;
  padding: 3.5rem 0 3rem;
  scrollbar-width: none;
}

.docs-toc::-webkit-scrollbar {
  display: none;
}

.docs-toc h2 {
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-tertiary);
  margin: 0 0 0.6rem;
  padding-left: 0.75rem;
}

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

.docs-toc li {
  margin: 0;
}

.docs-toc a {
  display: block;
  padding: 0.25rem 0.75rem;
  border-left: 2px solid var(--color-border);
  font-size: 0.8125rem;
  line-height: 1.35;
  color: var(--color-text-tertiary);
  text-decoration: none;
  transition: color 0.18s ease, border-color 0.18s ease;
}

.docs-toc a:hover {
  color: var(--color-text-muted);
}

.docs-toc a.is-active {
  color: var(--color-text);
  border-left-color: var(--color-primary);
}

/* ═══════════════════════════════════════════════════
   PAGE HEADER
   ═══════════════════════════════════════════════════ */

.docs-eyebrow {
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-primary);
  margin: 0 0 0.6rem;
}

.docs-main h1 {
  font-size: 2.25rem;
  margin-bottom: 0.6rem;
}

.docs-lead {
  font-size: 1.125rem;
  font-weight: 300;
  line-height: 1.55;
  color: var(--color-text-muted);
  margin: 0 0 2.5rem;
  max-width: 40em;
}

/* ═══════════════════════════════════════════════════
   BODY CONTENT
   ═══════════════════════════════════════════════════ */

.docs-body {
  max-width: 46em;
}

.docs-body section {
  scroll-margin-top: calc(var(--header-height) + 1.5rem);
  padding-top: 0.5rem;
}

.docs-body section + section {
  margin-top: 3.25rem;
  border-top: 1px solid var(--color-border);
  padding-top: 2.5rem;
}

.docs-body h2 {
  font-size: 1.5rem;
  margin: 0 0 1rem;
}

.docs-body h3 {
  font-size: 1.0625rem;
  font-weight: 500;
  margin: 2rem 0 0.6rem;
  color: var(--color-text);
  scroll-margin-top: calc(var(--header-height) + 1.5rem);
}

.docs-body h4 {
  font-size: 0.9375rem;
  font-weight: 500;
  letter-spacing: -0.01em;
  margin: 1.5rem 0 0.5rem;
  color: var(--color-text);
}

.docs-body p,
.docs-body li {
  font-size: 0.9375rem;
  line-height: 1.65;
}

.docs-body ul,
.docs-body ol {
  padding-left: 1.35rem;
}

.docs-body li {
  margin-bottom: 0.45rem;
}

.docs-body li > ul,
.docs-body li > ol {
  margin-top: 0.45rem;
  margin-bottom: 0.25rem;
}

.docs-body strong {
  color: var(--color-text);
  font-weight: 500;
}

.anchor {
  margin-left: 0.4rem;
  font-size: 0.75em;
  font-weight: 400;
  color: var(--color-text-tertiary);
  opacity: 0;
  transition: opacity 0.18s ease;
}

.docs-body h2:hover .anchor,
.docs-body h3:hover .anchor,
.anchor:focus {
  opacity: 1;
}

/* ═══════════════════════════════════════════════════
   CODE
   ═══════════════════════════════════════════════════ */

.docs-body code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  padding: 0.1em 0.35em;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.06);
  color: #d8dee6;
  white-space: nowrap;
}

.docs-body pre {
  margin: 1rem 0 1.4rem;
  padding: 0.9rem 1.1rem;
  overflow-x: auto;
  background: var(--color-code-bg);
  border: 1px solid var(--color-code-border);
  border-radius: var(--radius-sm);
  -webkit-overflow-scrolling: touch;
}

.docs-body pre code {
  display: block;
  padding: 0;
  background: none;
  font-size: 0.8125rem;
  line-height: 1.6;
  color: #cdd6e0;
  white-space: pre;
}

.code-block {
  margin: 1rem 0 1.4rem;
}

.code-block > .code-label {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-tertiary);
  padding: 0 0 0.35rem 0.15rem;
}

.code-block pre {
  margin: 0;
}

.tok-kw  { color: var(--tok-kw); }
.tok-str { color: var(--tok-str); }
.tok-num { color: var(--tok-num); }
.tok-com { color: var(--tok-com); font-style: italic; }
.tok-fn  { color: var(--tok-fn); }
.tok-bi  { color: var(--tok-bi); }
.tok-op  { color: var(--tok-op); }

kbd,
.kbd {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.82em;
  line-height: 1.45;
  /* Modifier glyphs (⇧⌘O) sit shoulder to shoulder without tracking. The right
     padding is trimmed by the same amount, since letter-spacing also adds a
     trailing gap after the last glyph and would otherwise skew the chip left. */
  letter-spacing: 0.09em;
  padding: 0.24em 0.44em 0.24em 0.53em;
  margin: 0.1em 0.04em;
  border-radius: 5px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-bottom-width: 2px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--color-text);
  white-space: nowrap;
}

/* Alternatives listed side by side — ⌘[ ⌘] — need more than a text space
   between them, or the two chips read as one. */
kbd + kbd,
.kbd + .kbd {
  margin-left: 0.3em;
}

/* ═══════════════════════════════════════════════════
   TABLES
   ═══════════════════════════════════════════════════ */

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 1rem 0 1.5rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
}

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

.doc-table th,
.doc-table td {
  text-align: left;
  vertical-align: top;
  padding: 0.72rem 0.95rem;
  border-bottom: 1px solid var(--color-border);
  color: var(--color-text-muted);
  line-height: 1.55;
}

.doc-table thead th {
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--color-text-tertiary);
  background: rgba(255, 255, 255, 0.02);
  white-space: nowrap;
}

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

.doc-table tbody th {
  font-weight: 500;
  color: var(--color-text);
  white-space: nowrap;
}

.doc-table code {
  white-space: nowrap;
}

.doc-table .col-narrow {
  width: 8.5rem;
}

.doc-table .center {
  text-align: center;
}

/* ═══════════════════════════════════════════════════
   CALLOUTS
   ═══════════════════════════════════════════════════ */

.callout {
  margin: 1.25rem 0;
  padding: 0.9rem 1.1rem;
  border-left: 3px solid var(--color-note);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: rgba(91, 122, 154, 0.08);
}

.callout > :last-child {
  margin-bottom: 0;
}

.callout p {
  font-size: 0.875rem;
  margin-bottom: 0.6rem;
}

.callout-label {
  display: block;
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-note);
  margin-bottom: 0.3rem;
}

.callout.tip {
  border-left-color: var(--color-tip);
  background: rgba(79, 138, 106, 0.08);
}

.callout.tip .callout-label {
  color: var(--color-tip);
}

.callout.warn {
  border-left-color: var(--color-warn);
  background: rgba(168, 132, 63, 0.08);
}

.callout.warn .callout-label {
  color: var(--color-warn);
}

/* ═══════════════════════════════════════════════════
   CARDS (documentation index)
   ═══════════════════════════════════════════════════ */

.docs-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 0.85rem;
  margin: 1.25rem 0 1.5rem;
}

.docs-card {
  display: block;
  padding: 1.1rem 1.2rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface-elevated);
  text-decoration: none;
  transition: border-color 0.22s ease, background 0.22s ease, transform 0.22s ease;
}

.docs-card:hover {
  border-color: var(--color-border-strong);
  background: #232323;
  transform: translateY(-1px);
}

.docs-card h3 {
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--color-text);
  margin: 0 0 0.3rem;
}

.docs-card p {
  font-size: 0.8125rem;
  line-height: 1.5;
  color: var(--color-text-muted);
  margin: 0;
}

/* ═══════════════════════════════════════════════════
   MISC BLOCKS
   ═══════════════════════════════════════════════════ */

.steps {
  counter-reset: step;
  list-style: none;
  padding-left: 0;
  margin: 1rem 0 1.5rem;
}

.steps > li {
  position: relative;
  counter-increment: step;
  padding-left: 2.1rem;
  margin-bottom: 0.85rem;
}

.steps > li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: 0.05rem;
  width: 1.45rem;
  height: 1.45rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 1px solid var(--color-border-strong);
  background: rgba(255, 255, 255, 0.03);
  font-size: 0.72rem;
  font-family: var(--font-mono);
  color: var(--color-text-muted);
}

.pill {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.12em 0.5em;
  border-radius: 980px;
  border: 1px solid var(--color-border-strong);
  background: rgba(255, 255, 255, 0.04);
  color: var(--color-text-muted);
  vertical-align: 0.08em;
  white-space: nowrap;
}

.pill.free { color: #9aa4ad; }
.pill.paid { color: #7fa3c4; border-color: rgba(127, 163, 196, 0.3); }

dl.opts {
  margin: 1rem 0 1.5rem;
}

dl.opts dt {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--color-text);
  margin-top: 1rem;
}

dl.opts dt:first-child {
  margin-top: 0;
}

dl.opts dd {
  margin: 0.25rem 0 0;
  padding-left: 0;
  font-size: 0.875rem;
  line-height: 1.6;
  color: var(--color-text-muted);
}

/* ═══════════════════════════════════════════════════
   PAGER
   ═══════════════════════════════════════════════════ */

.docs-pager {
  display: flex;
  gap: 0.85rem;
  margin-top: 3.5rem;
  padding-top: 1.75rem;
  border-top: 1px solid var(--color-border);
}

.docs-pager a {
  flex: 1 1 0;
  min-width: 0;
  padding: 0.85rem 1.1rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  text-decoration: none;
  transition: border-color 0.22s ease, background 0.22s ease;
}

.docs-pager a:hover {
  border-color: var(--color-border-strong);
  background: rgba(255, 255, 255, 0.02);
}

.docs-pager .dir {
  display: block;
  font-size: 0.6875rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-tertiary);
  margin-bottom: 0.2rem;
}

.docs-pager .label {
  display: block;
  font-size: 0.9375rem;
  color: var(--color-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.docs-pager .next {
  text-align: right;
  margin-left: auto;
}

/* ═══════════════════════════════════════════════════
   MOBILE NAV
   ═══════════════════════════════════════════════════ */

.docs-nav-toggle {
  display: none;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin: 1.25rem 0 0;
  padding: 0.6rem 0.9rem;
  font-family: inherit;
  font-size: 0.875rem;
  color: var(--color-text-muted);
  background: var(--color-surface-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.docs-nav-toggle[aria-expanded="true"] {
  color: var(--color-text);
}

/* ═══════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════ */

@media (max-width: 1180px) {
  .docs-shell {
    grid-template-columns: var(--docs-sidebar-width) minmax(0, 1fr);
    gap: 2rem;
  }
  .docs-toc {
    display: none;
  }
}

@media (max-width: 880px) {
  .docs-shell {
    display: block;
    padding: 0 1rem;
  }
  body.docs .site-header-inner {
    padding: 0 1rem;
  }
  .docs-nav-toggle {
    display: flex;
  }
  .docs-sidebar {
    position: static;
    max-height: none;
    overflow: visible;
    padding: 1rem 0 0;
  }
  /* Collapsing is only applied once the toggle is wired up, so the nav stays
     reachable when scripting is unavailable. */
  .docs-shell.js-nav .docs-sidebar {
    display: none;
  }
  .docs-shell.js-nav .docs-sidebar.is-open {
    display: block;
  }
  .docs-sidebar-title {
    display: none;
  }
  body.docs main.docs-main {
    padding: 1.75rem 0 3rem;
  }
  .docs-main h1 {
    font-size: 1.875rem;
  }
  .docs-lead {
    font-size: 1.0625rem;
    margin-bottom: 2rem;
  }
  .docs-pager {
    flex-direction: column;
  }
  .docs-pager .next {
    text-align: left;
  }
}

@media (prefers-reduced-motion: reduce) {
  .docs-card,
  .docs-nav-group a,
  .docs-toc a,
  .docs-pager a {
    transition: none;
  }
  .docs-card:hover {
    transform: none;
  }
}
