/*
 * @kurthlabs/design-docs: the docs page over Kurth Labs Design's static.css (loaded first). Semantic tokens only, no raw
 * colours, no url() or @import. Unlayered, so these rules beat static.css's layers; the touch floors stay its own.
 * Phone first: one column with the nav and "On this page" as disclosures; a sidebar from 64rem, the
 * "On this page" column from 80rem.
 */

.m-docs [hidden] { display: none !important; }

.m-docs { min-height: 100vh; }

.m-docs-skip {
  position: absolute;
  top: -200px;
  left: 8px;
  z-index: 40;
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 10px 14px;
  border: 1px solid var(--m-border-strong);
  border-radius: var(--m-radius-md);
  background: var(--m-bg-elevated);
  color: var(--m-text);
}
.m-docs-skip:focus { top: 8px; }

/* ── Top bar ── */

.m-docs-top {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 60px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--m-border);
  background: var(--m-bg);
}
.m-docs-brand { display: inline-flex; flex: 0 1 auto; align-items: center; gap: 8px; min-width: 0; min-height: 44px; color: var(--m-text); }
.m-docs-brand .m-brand { min-width: 0; }
.m-docs-brand-tag { flex: none; color: var(--m-text-muted); font-size: 0.875rem; }
.m-docs-search { position: relative; flex: 1 1 12rem; min-width: 0; max-width: 28rem; margin-left: auto; }
.m-docs-search-input { width: 100%; }
.m-docs-search-results {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  left: 0;
  z-index: 30;
  max-height: min(60vh, 28rem);
  overflow: auto;
  padding: 4px;
  border: 1px solid var(--m-border);
  border-radius: var(--m-radius-md);
  background: var(--m-bg-elevated);
  box-shadow: var(--m-shadow-popover);
  list-style: none;
}
.m-docs-search-option a {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  min-height: 44px;
  padding: 6px 10px;
  border-radius: var(--m-radius-sm);
}
.m-docs-search-option[aria-selected="true"] a { background: var(--m-accent-soft); }
.m-docs-search-option a:hover { background: var(--m-surface-hover); }
.m-docs-search-title { color: var(--m-text); font-weight: 600; }
.m-docs-search-meta { color: var(--m-text-muted); font-size: 0.8125rem; }
.m-docs-search-meta:empty { display: none; }
.m-docs-search-empty { padding: 12px 10px; color: var(--m-text-muted); }
.m-docs-search-open { display: none; flex: none; width: 44px; min-height: 44px; margin-left: auto; padding: 0; justify-content: center; }
/* Under 600px the brand keeps the row: search is a button that opens the field over the bar. */
@media (max-width: 37.5rem) {
  .m-docs-search-open { display: inline-flex; }
  .m-docs-search { display: none; }
  .m-docs-top[data-search-open] .m-docs-search {
    position: absolute;
    top: 8px;
    right: 16px;
    left: 16px;
    z-index: 25;
    display: block;
    max-width: none;
    margin: 0;
  }
  .m-docs-top[data-search-open] .m-docs-search-input { min-height: 44px; background: var(--m-bg); }
}
.m-docs-theme { flex: none; width: 44px; min-height: 44px; padding: 0; justify-content: center; }
.m-docs-icon { width: 20px; height: 20px; }
.m-docs-icon-sun,
.m-docs-theme[data-scheme="dark"] .m-docs-icon-moon { display: none; }
.m-docs-theme[data-scheme="dark"] .m-docs-icon-sun { display: block; }

/* ── Nav ── */

.m-docs-navbox { border-bottom: 1px solid var(--m-border); background: var(--m-bg); }
.m-docs-navbox-summary,
.m-docs-tocbox-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 16px;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}
.m-docs-navbox-summary::-webkit-details-marker,
.m-docs-tocbox-summary::-webkit-details-marker { display: none; }
.m-docs-navbox-summary::after,
.m-docs-tocbox-summary::after {
  content: "";
  flex: none;
  width: 8px;
  height: 8px;
  margin: 0 4px 4px auto;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  transition: transform var(--m-dur-2) var(--m-ease-out);
}
details[open] > .m-docs-navbox-summary::after,
details[open] > .m-docs-tocbox-summary::after { margin-bottom: -4px; transform: rotate(-135deg); }
.m-docs-navbox-current { min-width: 0; overflow: hidden; color: var(--m-text-muted); font-weight: 400; text-overflow: ellipsis; white-space: nowrap; }
.m-docs-navbox .m-docs-nav { padding: 0 8px 16px; }

.m-docs-nav-group + .m-docs-nav-group { margin-top: 16px; }
.m-docs-nav-title {
  padding: 0 8px 4px;
  color: var(--m-text-subtle);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: var(--m-label-tracking);
  text-transform: var(--m-label-case);
}
.m-docs-nav-list,
.m-docs-toc-list { list-style: none; }
.m-docs-nav-link,
.m-docs-out {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 4px 8px;
  border-radius: var(--m-radius-sm);
  color: var(--m-text-muted);
}
.m-docs-nav > .m-docs-out:first-of-type { margin-top: 16px; }
.m-docs-out { color: var(--m-accent); }
.m-docs-nav-link:hover { background: var(--m-surface-hover); color: var(--m-text); }
.m-docs-nav-link[aria-current="page"] { background: var(--m-accent-soft); color: var(--m-text); font-weight: 600; }

/* ── Layout ── */

.m-docs-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 32px;
  max-width: 90rem;
  margin: 0 auto;
  padding: 24px 16px 48px;
}
.m-docs-sidebar,
.m-docs-toc { display: none; }
.m-docs-main { min-width: 0; }
.m-docs-main:focus { outline: none; box-shadow: none; }

@media (min-width: 64rem) {
  .m-docs-navbox { display: none; }
  .m-docs-layout { grid-template-columns: 15rem minmax(0, 1fr); padding: 32px 24px 64px; }
  .m-docs-sidebar { position: sticky; top: 76px; display: block; align-self: start; max-height: calc(100vh - 92px); overflow: auto; }
  .m-docs-nav-link,
  .m-docs-out { min-height: 36px; }
}
@media (min-width: 80rem) {
  .m-docs-layout { grid-template-columns: 15rem minmax(0, 1fr) 13rem; }
  .m-docs-toc { position: sticky; top: 76px; display: block; align-self: start; max-height: calc(100vh - 92px); overflow: auto; }
  .m-docs-tocbox { display: none; }
}
@media (min-width: 64rem) and (pointer: coarse) {
  .m-docs-nav-link,
  .m-docs-out,
  .m-docs-toc-link { min-height: 44px; }
}

/* ── Content ── */

.m-docs-header { max-width: 76ch; margin-bottom: 24px; }
.m-docs-title {
  font-family: var(--m-font-display);
  font-size: calc(1.875rem * var(--m-type-scale, 1));
  font-weight: var(--m-heading-weight);
  line-height: 1.15;
  letter-spacing: var(--m-heading-tracking);
  text-transform: var(--m-heading-case);
}
.m-docs-summary { margin-top: 8px; color: var(--m-text-muted); font-size: calc(1.0625rem * var(--m-type-scale, 1)); }
.m-docs-badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
/* Ids and versions are data: mono, never re-cased or wrapped. The owner badge reads as a sentence. */
.m-docs-id,
.m-docs-data { font-family: var(--m-font-mono); letter-spacing: 0; text-transform: none; white-space: nowrap; }
.m-docs-plain { letter-spacing: 0; text-transform: none; }

/* The standards index: a table from 600px, a stacked list below. */
.m-prose .m-docs-index-list { display: none; padding: 0; list-style: none; }
.m-docs-index-item { padding: 12px 0; border-bottom: 1px solid var(--m-border); }
.m-prose .m-docs-index-title { display: inline-flex; align-items: center; min-height: 44px; font-weight: 600; }
.m-docs-index-item .m-docs-badges { margin-top: 2px; }
@media (max-width: 37.5rem) {
  .m-prose .m-docs-index-table { display: none; }
  .m-prose .m-docs-index-list { display: block; }
}
.m-docs-content { font-size: calc(0.9375rem * var(--m-type-scale, 1)); }
.m-docs-content :is(h2, h3, h4) { scroll-margin-top: 76px; }
/* Tables scroll inside themselves (static.css makes them blocks); a flag or name in the first column never breaks. */
.m-docs-content td:first-child code { white-space: nowrap; }

.m-docs-code { position: relative; margin: 0 0 12px; }
.m-prose .m-docs-code pre { margin: 0; }
/* The Copy button sits in a strip above the code, so a long line scrolls beneath it, never under it. */
.m-docs-code:has(.m-docs-copy) pre { padding-top: 40px; }
.m-docs-copy {
  position: absolute;
  top: 4px;
  right: 4px;
  min-height: 32px;
  padding: 0 10px;
  background: var(--m-bg-elevated);
  font-size: 0.75rem;
}
@media (pointer: coarse) {
  .m-docs-code:has(.m-docs-copy) pre { padding-top: 52px; }
  .m-docs-copy { min-height: 44px; }
}

.m-docs-tocbox { margin: 0 0 24px; border: 1px solid var(--m-border); border-radius: var(--m-radius-md); background: var(--m-bg-elevated); }
.m-docs-tocbox-summary { padding: 0 12px; }
.m-docs-tocbox nav { padding: 0 12px 8px; }
.m-docs-toc-title { margin-bottom: 4px; color: var(--m-text-subtle); font-size: 0.75rem; font-weight: 600; letter-spacing: var(--m-label-tracking); text-transform: var(--m-label-case); }
.m-docs-toc-link { display: flex; align-items: center; min-height: 44px; color: var(--m-text-muted); font-size: 0.875rem; }
.m-docs-toc .m-docs-toc-link { min-height: 32px; padding: 2px 0; }
.m-docs-toc-link:hover { color: var(--m-text); }
.m-docs-toc-3 { padding-left: 12px; }

/* Copy-link anchors: always shown on touch; on a mouse, shown while the heading or rule is hovered or focused. */
.m-prose .m-docs-anchor {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  min-height: 32px;
  margin-left: 4px;
  border-radius: var(--m-radius-sm);
  color: var(--m-text-subtle);
  font-family: var(--m-font-mono);
  font-size: 0.9em;
  font-weight: 400;
  text-decoration: none;
  vertical-align: middle;
}
.m-prose .m-docs-anchor:hover { background: var(--m-surface-hover); color: var(--m-accent); }
@media (pointer: coarse) {
  .m-prose .m-docs-anchor { min-width: 44px; min-height: 44px; margin-block: -10px; }
}
@media (hover: hover) and (pointer: fine) {
  .m-prose .m-docs-anchor { opacity: 0; }
  .m-prose :is(h2, h3, h4, h5, h6, .m-docs-rule):is(:hover, :focus-within) > .m-docs-anchor,
  .m-prose .m-docs-anchor:focus-visible { opacity: 1; }
}

/* A page that opens with an example: the first code block, before any prose, reads as the lead. */
.m-docs-content > .m-docs-code:first-child pre { border-left: 3px solid var(--m-accent); background: var(--m-bg-elevated); }
.m-docs-content > .m-docs-code:first-child pre code { font-size: calc(0.84375rem * var(--m-type-scale, 1)); }

.m-docs-meta { margin-top: 8px; font-size: 0.875rem; }
.m-docs-md-link { display: inline-flex; align-items: center; min-height: 44px; color: var(--m-text-muted); text-decoration: underline; text-underline-offset: 2px; }
.m-docs-md-link:hover { color: var(--m-accent); }
@media (max-width: 30rem) {
  .m-docs-brand-tag { display: none; }
}

/* ── Standards: numbered rules ── */

.m-prose .m-docs-rules { padding-left: 0; list-style: none; }
.m-prose .m-docs-rule {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: start;
  gap: 4px 12px;
  margin: 0 0 12px;
  padding: 12px;
  border: 1px solid var(--m-border);
  border-radius: var(--m-radius-md);
  background: var(--m-bg-elevated);
  scroll-margin-top: 76px;
}
.m-prose .m-docs-rule-num { color: var(--m-text-muted); font-family: var(--m-font-mono); font-size: 0.75rem; line-height: 2.1; white-space: nowrap; }
.m-prose .m-docs-rule > .m-docs-anchor { margin: -4px -4px 0 0; }
.m-docs-rule-body > :last-child { margin-bottom: 0; }
@media (max-width: 37.5rem) {
  .m-prose .m-docs-rule { grid-template-columns: minmax(0, 1fr) auto; }
  .m-docs-rule-body { grid-column: 1 / -1; grid-row: 2; }
}
.m-docs-rule-body :is(.m-docs-code, blockquote) { margin-top: 8px; }
.m-docs-rule-key { letter-spacing: 0.04em; }
.m-docs-rule-key[data-level="must"] { color: var(--m-accent); }
.m-docs-rule-key[data-level="should"],
.m-docs-rule-key[data-level="may"] { color: var(--m-text-muted); }

/* ── Pager and footer ── */

.m-docs-pager { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; max-width: 76ch; margin-top: 40px; }
.m-docs-pager-link {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 44px;
  padding: 10px 14px;
  border: 1px solid var(--m-border);
  border-radius: var(--m-radius-md);
  color: var(--m-text);
}
.m-docs-pager-link:hover { border-color: var(--m-border-strong); background: var(--m-surface-hover); }
.m-docs-pager-next { grid-column: 2; text-align: right; }
.m-docs-pager-dir { color: var(--m-text-muted); font-size: 0.75rem; }
.m-docs-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 0 16px;
  max-width: 76ch;
  margin-top: 40px;
  padding-top: 8px;
  border-top: 1px solid var(--m-border);
  font-size: 0.875rem;
}
.m-docs-footer a { display: inline-flex; align-items: center; min-height: 44px; color: var(--m-text-muted); }
.m-docs-footer a:hover { color: var(--m-text); text-decoration: underline; }

@media (prefers-reduced-motion: reduce) {
  .m-docs-navbox-summary::after,
  .m-docs-tocbox-summary::after { transition: none; }
}
