/* layout.css — the shell grid, header, sidebar, TOC rail, mobile drawer.
 *
 * The grid columns are declared HERE, not by JS, so the sidebar column exists
 * at first paint and the injected chrome merely fills it. That is what keeps a
 * JS-injected shell from shifting the layout under the reader.
 */

:root {
  --sidebar-w: 17rem;
  --toc-w: 13rem;
  --header-h: 3.5rem;
  --content-max: 48rem;
}

/* ---- skip link --------------------------------------------------------- */

.skip {
  position: absolute;
  left: var(--sp-4);
  top: -6rem;
  z-index: 60;
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  padding: var(--sp-2) var(--sp-4);
  text-decoration: none;
  transition: top var(--dur-fast) var(--ease-out);
}
.skip:focus { top: var(--sp-3); }

/* ---- header ------------------------------------------------------------ */

.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 0 var(--sp-5);
  background: var(--topbar-bg);
  backdrop-filter: blur(var(--blur-glass));
  border-bottom: 1px solid var(--border);
}

.site-header .brand {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-family: var(--font-display);
  font-weight: var(--fw-bold);
  color: var(--text-primary);
  text-decoration: none;
  white-space: nowrap;
}
.site-header .brand .mark {
  width: 1.5rem; height: 1.5rem;
  border-radius: var(--r-sm);
  background: var(--grad-accent);
  display: grid; place-items: center;
  color: var(--on-solid);
  font-size: var(--fs-xs);
  font-weight: var(--fw-extra);
}
.site-header .brand .sub {
  color: var(--text-tertiary);
  font-weight: var(--fw-regular);
  font-size: var(--fs-sm);
}

.site-header .spacer { flex: 1; }

.hbtn {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  height: 2rem;
  padding: 0 var(--sp-3);
  background: var(--bg-surface);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  font: inherit;
  font-size: var(--fs-sm);
  cursor: pointer;
}
.hbtn:hover { color: var(--text-primary); border-color: var(--border-strong); }
.hbtn kbd { font-size: 0.7rem; }

.nav-toggle { display: none; }

/* ---- the shell grid ---------------------------------------------------- */

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--toc-w);
  gap: var(--sp-8);
  max-width: 90rem;
  margin: 0 auto;
  padding: var(--sp-6) var(--sp-5) var(--sp-12);
  align-items: start;
}

main { min-width: 0; max-width: var(--content-max); }

/* ---- sidebar ----------------------------------------------------------- */

.site-sidebar {
  position: sticky;
  top: calc(var(--header-h) + var(--sp-6));
  max-height: calc(100vh - var(--header-h) - var(--sp-10));
  overflow-y: auto;
  font-size: var(--fs-sm);
  padding-right: var(--sp-2);
}
.site-sidebar .area {
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
  font-weight: var(--fw-semibold);
  margin: var(--sp-5) 0 var(--sp-2);
}
.site-sidebar .area:first-child { margin-top: 0; }
.site-sidebar ul { list-style: none; margin: 0 0 var(--sp-2); padding: 0; }
.site-sidebar li { margin: 0; }
.site-sidebar a {
  display: block;
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-sm);
  color: var(--text-secondary);
  text-decoration: none;
  border-left: 2px solid transparent;
}
.site-sidebar a:hover { background: var(--row-hover); color: var(--text-primary); }
/* The current page. Text is --text-primary, NOT --accent-deep: on the tinted
 * background, accent-deep resolves to purple-on-purple in the dark theme and
 * fails contrast outright. The accent still carries the state through the
 * background and the left border, which is where it is safe. Checked in both
 * themes -- light never certifies dark. */
.site-sidebar a[aria-current="page"] {
  background: var(--soft-primary-bg);
  color: var(--text-primary);
  font-weight: var(--fw-semibold);
  border-left-color: var(--accent);
}

/* ---- on-this-page rail ------------------------------------------------- */

.site-toc {
  position: sticky;
  top: calc(var(--header-h) + var(--sp-6));
  max-height: calc(100vh - var(--header-h) - var(--sp-10));
  overflow-y: auto;
  font-size: var(--fs-xs);
  border-left: 1px solid var(--border);
  padding-left: var(--sp-4);
}
.site-toc .toc-title {
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
  font-weight: var(--fw-semibold);
  margin-bottom: var(--sp-3);
}
.site-toc ul { list-style: none; margin: 0; padding: 0; }
.site-toc a {
  display: block;
  padding: var(--sp-1) 0;
  color: var(--text-tertiary);
  text-decoration: none;
  line-height: var(--lh-snug);
}
.site-toc a:hover { color: var(--text-primary); }
.site-toc a.active { color: var(--accent-deep); font-weight: var(--fw-medium); }
.site-toc .lvl3 { padding-left: var(--sp-3); }

/* ---- footer ------------------------------------------------------------ */

.site-footer {
  grid-column: 1 / -1;
  margin-top: var(--sp-10);
  padding-top: var(--sp-5);
  border-top: 1px solid var(--border);
  font-size: var(--fs-xs);
  color: var(--text-tertiary);
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2) var(--sp-5);
  align-items: baseline;
}
.site-footer a { color: var(--text-secondary); }
.site-footer .prov { margin-left: auto; }
.site-footer .prov.stale { color: var(--soft-warning-fg); }

/* ---- breakpoints ------------------------------------------------------- */

/* 1024–1279: drop the on-this-page rail; the sidebar stays. */
@media (max-width: 79.99rem) {
  .shell { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); gap: var(--sp-6); }
  .site-toc { display: none; }
}

/* Narrow phones. The accessibility rule requires reflow to 320px with no
 * horizontal scroll, and at that width the header's full contents -- menu,
 * wordmark, "Search Ctrl K", "System" -- are about 80px too wide. Shed the
 * labels rather than the controls: every button keeps an accessible name. */
@media (max-width: 26rem) {
  .site-header { padding: 0 var(--sp-3); gap: var(--sp-2); }
  .site-header .brand .sub { display: none; }
  #search-btn kbd, #search-btn .lbl { display: none; }
  #search-btn { padding: 0 var(--sp-2); }
  #theme-btn { padding: 0 var(--sp-2); font-size: 0; }        /* glyph only */
  #theme-btn span { font-size: var(--fs-sm); }
}

/* below 1024: the sidebar becomes an off-canvas drawer. Staff consoles are
 * desktop-first, but documentation gets read on phones. */
@media (max-width: 63.99rem) {
  .shell { grid-template-columns: minmax(0, 1fr); padding: var(--sp-5) var(--sp-4) var(--sp-10); }
  main { max-width: none; }
  .nav-toggle { display: inline-flex; }

  .site-sidebar {
    position: fixed;
    inset: var(--header-h) auto 0 0;
    width: min(20rem, 84vw);
    max-height: none;
    z-index: 45;
    background: var(--bg-surface);
    border-right: 1px solid var(--border);
    box-shadow: var(--shadow-xl);
    padding: var(--sp-5);
    transform: translateX(-100%);
    transition: transform var(--dur-base) var(--ease-out);
  }
  .site-sidebar[data-open="true"] { transform: translateX(0); }

  .nav-scrim {
    position: fixed;
    inset: var(--header-h) 0 0 0;
    background: var(--scrim);
    z-index: 44;
  }
}
