/*
 * Page shells.
 *
 * Two shells share the global header (base/site-chrome.css) and footer:
 *
 *   - `.app-shell`  — catalog + component pages: a centered grid with a sticky
 *     sidebar rail and a scrolling content column (the document scrolls, the
 *     header + sidebar stick). Below `--breakpoint` it collapses to one column
 *     and the sidebar becomes a modal off-canvas drawer (dogfooded
 *     stimeo--sidebar: focus trap, scroll lock, background inert).
 *   - `.page-shell` — landing + single-column content pages: header / main /
 *     footer stacked, the page owns its own max-width.
 *
 * INERT CONTRACT: stimeo--sidebar's FocusTrap makes every body-level child that
 * does NOT contain the panel `inert` while the drawer is open. So the panel must
 * stay inside its own body-level wrapper (`.layout`), and the header, main, and
 * footer must be separate body-level children — which the grid areas below place
 * side by side without nesting main inside `.layout`.
 */

body {
  margin: 0;
}

/* ── App shell (catalog / component) ──────────────────────────────────── */
/* 4-column gutter grid centers the sidebar+content block at --shell-max while
   the header/footer span full width (their own inner wrappers re-cap content). */
.app-shell {
  display: grid;
  grid-template-columns:
    minmax(1.75rem, 1fr)
    var(--sidebar-width)
    minmax(0, calc(var(--shell-max) - var(--sidebar-width) - var(--shell-gap)))
    minmax(1.75rem, 1fr);
  grid-template-rows: auto 1fr auto;
  grid-template-areas:
    "header  header  header  header"
    ".       sidebar main    ."
    "footer  footer  footer  footer";
  column-gap: var(--shell-gap);
  min-height: 100dvh;
  background: var(--surface-page);
}

.app-shell > .site-header {
  grid-area: header;
}

.app-shell > .layout {
  grid-area: sidebar;
  min-width: 0;
}

.app-shell > .content {
  grid-area: main;
  min-width: 0;
}

.app-shell > .site-footer {
  grid-area: footer;
}

:root {
  --shell-gap: 2.5rem;
}

/* `.layout` is the stimeo--sidebar root; it stretches the sidebar row so the
   sticky panel inside has room to release at the bottom of a long page. */
.layout {
  display: block;
  min-width: 0;
}

/* Mobile top bar (hamburger) — shown only in overlay mode (media query below). */
.layout__bar {
  display: none;
}

.layout__nav-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  color: var(--color-text);
  background: var(--surface-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.layout__nav-toggle:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 1px;
}

.layout__nav-toggle-icon {
  position: relative;
  display: block;
  width: 1rem;
  height: 2px;
  background: currentColor;
}

.layout__nav-toggle-icon::before,
.layout__nav-toggle-icon::after {
  content: "";
  position: absolute;
  left: 0;
  display: block;
  width: 1rem;
  height: 2px;
  background: currentColor;
}

.layout__nav-toggle-icon::before {
  top: -5px;
}

.layout__nav-toggle-icon::after {
  top: 5px;
}

/* Backdrop (shown only while the overlay drawer is open). Sits above the sticky
   header so the whole page reads as "behind the modal". */
.layout__backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgb(15 23 42 / 0.5);
  opacity: 1;
  transition: opacity var(--duration-base) var(--ease-out);
}

.layout__backdrop[data-state="closed"] {
  opacity: 0;
}

.layout__backdrop[hidden] {
  display: none;
}

/* ── Sidebar (panel) ──────────────────────────────────────────────────── */
/* Sticky rail that scrolls independently below the sticky header. */
.sidebar {
  position: sticky;
  top: var(--header-h);
  align-self: start;
  max-height: calc(100dvh - var(--header-h));
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 1.875rem 0.25rem 2.5rem;
}

.sidebar__title {
  margin: 0 0 0.75rem;
  padding: 0 0.625rem;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: var(--tracking-eyebrow);
  color: var(--color-text-subtle);
}

/* Quick links (catalog index + shared styles), above the category groups. */
.sidebar__quicklinks {
  margin-bottom: 0.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-default);
}

.sidebar__quicklink {
  display: block;
  padding: 0.4rem 0.625rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: var(--weight-semibold);
  color: var(--color-text-muted);
  text-decoration: none;
}

.sidebar__quicklink:hover {
  color: var(--color-text);
  background: var(--color-primary-soft);
}

.sidebar__quicklink[aria-current="page"] {
  color: var(--color-primary);
}

.sidebar__quicklink:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* Expand all / collapse all toolbar (shared by sidebar and main). */
.toolbar {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.toolbar--end {
  justify-content: flex-end;
}

.toolbar__btn {
  flex: 1 1 auto;
  padding: 0.3rem 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  font-weight: var(--weight-semibold);
  color: var(--color-text-muted);
  background: transparent;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.toolbar--end .toolbar__btn {
  flex: 0 0 auto;
}

.toolbar__btn:hover {
  color: var(--color-text);
  border-color: var(--border-strong);
}

.toolbar__btn:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 1px;
}

/* Sidebar nav (collapsible per category via stimeo--accordion). */
.sidebar__nav ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.sidebar__category {
  margin: 0;
}

.sidebar__category-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  width: 100%;
  padding: 0.45rem 0.625rem;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  color: var(--color-text-subtle);
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.sidebar__category-trigger:hover {
  color: var(--color-text-muted);
}

.sidebar__category-trigger:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: -2px;
}

.sidebar__category-icon {
  flex: none;
  width: 0.45rem;
  height: 0.45rem;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg);
  transition: transform var(--duration-fast) var(--ease-out);
}

.sidebar__category-trigger[aria-expanded="true"] .sidebar__category-icon {
  transform: rotate(45deg);
}

.sidebar__category-panel {
  margin: 0.125rem 0 0.5rem;
}

.sidebar__link {
  display: block;
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  color: var(--color-text-muted);
  text-decoration: none;
}

.sidebar__link:hover {
  background: var(--color-primary-soft);
  color: var(--color-text);
}

.sidebar__link[aria-current="page"] {
  background: var(--color-primary);
  color: var(--color-on-primary);
  font-weight: var(--weight-semibold);
}

/* ── Main content column ──────────────────────────────────────────────── */
.content {
  min-width: 0;
}

.content__inner {
  padding: 2.25rem 0 4.5rem;
}

/* ── Single-column shell (landing / docs) ─────────────────────────────── */
.page-shell {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  background: var(--surface-page);
}

.page-shell > main {
  flex: 1 0 auto;
}

/* Centered content container for the prose / form pages. */
.page {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 3rem 1.75rem 4.5rem;
}

.page--narrow {
  max-width: 42rem;
}

.page--mid {
  max-width: 48rem;
}

/* ── Responsive: mobile (<768px) ──────────────────────────────────────── */
@media (max-width: 768px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 1fr auto;
    grid-template-areas:
      "header"
      "sidebar"
      "main"
      "footer";
    column-gap: 0;
  }

  /* Before JS / no-JS fallback (inline): stack the sidebar on top. */
  .sidebar[data-mode="inline"] {
    position: static;
    max-height: 42dvh;
    padding: 1rem;
    border-bottom: 1px solid var(--border-default);
  }

  /* JS enabled (overlay): show the hamburger bar. */
  .layout:has(.sidebar[data-mode="overlay"]) .layout__bar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0.9rem;
    border-bottom: 1px solid var(--border-default);
    background: var(--surface-sidebar);
  }

  .layout__bar-label {
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    font-weight: var(--weight-semibold);
    text-transform: uppercase;
    letter-spacing: var(--tracking-wide);
    color: var(--color-text-subtle);
  }

  /* overlay: modal off-canvas drawer that slides in from the left. */
  .sidebar[data-mode="overlay"] {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 60;
    align-self: stretch;
    max-height: none;
    width: min(18rem, 85vw);
    padding: 1.25rem 1rem;
    background: var(--surface-sidebar);
    border-right: 1px solid var(--border-default);
    box-shadow: 6px 0 24px rgb(15 23 42 / 0.18);
    transform: translateX(-100%);
    transition: transform var(--duration-slow) var(--ease-out);
  }

  .sidebar[data-mode="overlay"][data-state="open"] {
    transform: translateX(0);
  }

  .sidebar[data-mode="overlay"][hidden] {
    display: none;
  }

  .content__inner {
    padding: 1.5rem 1.25rem 3rem;
  }

  .page {
    padding: 2.25rem 1.25rem 3.5rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar,
  .layout__backdrop {
    transition: none;
  }
}

@media (max-width: 400px) {
  .content__inner {
    padding: 1.25rem 1rem 2.5rem;
  }
}
