/* Sidebar: off-canvas drawer (<768px), persistent sticky rail (≥768px), and
   the collapsed icon rail. Split out of style.css (large-file ratchet);
   linked from _layouts/root.html right after style.css, so it shares
   style.css's tokens and loads on every page. .app-layout / .app-main /
   .nav-backdrop stay in style.css. */

/* Mobile-first: an off-canvas drawer, opened by #nav-toggle (see forms.js),
   closed via the backdrop, Escape, or clicking a link. Becomes a persistent
   sticky rail at the tablet-and-up tier (bottom of this file). */
.sidebar {
  position: fixed;
  top: 0;
  left: -100%;
  width: 280px;
  max-width: 82vw;
  height: 100vh;
  z-index: 200;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: .5rem 0 2rem;
  overflow-y: auto;
  transition: left .22s ease;
}

.sidebar.open { left: 0; }

/* Drawer header: a title (mobile-only -- hidden at the ≥768px tier below,
   where it's redundant with the page's own heading) plus
   #sidebar-collapse-toggle, which the ≥768px tier repurposes into the rail
   collapse control (see style.css's `body[data-sidebar="collapsed"]`
   rules and forms.js's shared drawer/collapse-toggle handler). */
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  padding: .3rem .75rem .5rem;
}

.sidebar-header-title {
  font-size: .8rem;
  font-weight: 700;
  color: var(--muted);
}

.sidebar-collapse-toggle { flex-shrink: 0; }

/* Mobile-only drawer search -- .topnav-search is display:none below 768px
   (nothing else in the app lets a phone user search at all), restored to
   none at the ≥768px tier below where the topnav's own search takes over. */
.sidebar-search { padding: 0 1rem .5rem; }

.sidebar-search-input {
  width: 100%;
  padding: .45rem .6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: .875rem;
}

.sidebar-section { margin-bottom: .25rem; }

.sidebar-section-label {
  display: block;
  padding: .6rem .6rem .25rem;
  font-size: .95rem;
  font-weight: 900;
  color: var(--muted);
  cursor: default;
  text-decoration-line: overline;
}

/* Collapsible sidebar sections (native <details>/<summary> — no JS) */
.sidebar-section-group { margin-bottom: .25rem; }

.sidebar-section-group > summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: .65rem;
  min-height: var(--tap);
  margin: 0 .5rem;
  padding: .4rem .6rem;
  border-radius: var(--radius-lg);
  font-size: .9rem;
  font-weight: 500;
  color: var(--text);
  transition: background .12s, color .12s;
}

.sidebar-top-link {
  display: flex;
  align-items: center;
  gap: .65rem;
  min-height: var(--tap);
  margin: 0 .5rem;
  padding: .4rem .6rem;
  border-radius: var(--radius-lg);
  font-size: .9rem;
  font-weight: 500;
  color: var(--text);
  text-decoration: none;
  transition: background .12s, color .12s;
}

.sidebar-top-link:hover { background: var(--bg); }
.sidebar-top-link:focus-visible { outline: 2px solid var(--brand); outline-offset: -2px; }

.sidebar-top-link.active {
  background: color-mix(in srgb, var(--brand) 10%, transparent);
  color: var(--brand-text);
  font-weight: 600;
}

.sidebar-top-link.active > .sidebar-icon { color: var(--brand-text); }

.sidebar-section-group > summary:hover { background: var(--bg); }

.sidebar-section-group > summary:focus-visible,
.sidebar-link:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: -2px;
}

.sidebar-section-group > summary::-webkit-details-marker { display: none; }

.sidebar-icon {
  flex: none;
  width: 18px;
  height: 18px;
  color: var(--muted);
}

.sidebar-caret {
  flex: none;
  width: 14px;
  height: 14px;
  margin-left: auto;
  color: var(--muted);
  transition: transform .15s ease;
}

.sidebar-section-group[open] > summary { color: var(--brand-text); font-weight: 600; }
.sidebar-section-group[open] > summary > .sidebar-icon,
.sidebar-section-group[open] > summary > .sidebar-caret { color: var(--brand-text); }
.sidebar-section-group[open] > summary > .sidebar-caret { transform: rotate(180deg); }

/* Group body: indented under the parent icon along a thin guide line. */
.sidebar-section-group > .sidebar-section,
.sidebar-section-group > .sidebar-section-group {
  margin-left: 1.55rem;
  margin-bottom: 0;
  padding-left: .4rem;
  border-left: 1px solid var(--border);
}

/* A "More" group nested inside another (e.g. b2b-more inside b2b) --
   selector targets the structural nesting itself rather than a new class,
   so it needs no template-side marker. */
.sidebar-section-group .sidebar-section-group > summary {
  font-size: .8rem;
  color: var(--muted);
}

.sidebar-section-group .sidebar-section-group > summary > .sidebar-icon { width: 16px; height: 16px; }

.sidebar-link {
  display: flex;
  align-items: center;
  gap: .5rem;
  min-height: var(--tap);
  margin: 1px .5rem 1px 0;
  padding: .4rem .75rem;
  font-size: .875rem;
  color: var(--text);
  text-decoration: none;
  border-radius: var(--radius-lg);
  transition: background .12s, color .12s;
}

.sidebar-link:hover { background: var(--bg); color: var(--brand-text); }

.sidebar-link.active {
  background: color-mix(in srgb, var(--brand) 10%, transparent);
  color: var(--brand-text);
  font-weight: 600;
}

.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

@media (min-width: 768px) {
  .sidebar {
    position: sticky;
    top: var(--nav-h);
    left: auto;
    width: 220px;
    max-width: none;
    height: calc(100vh - var(--nav-h));
    transition: width .15s ease;
  }

  /* Drawer-only chrome: the title is redundant with the page's own heading
     once the sidebar is a persistent rail, and the search box is redundant
     with .topnav-search two lines below. */
  .sidebar-header-title,
  .sidebar-search { display: none; }

  /* Collapsible rail. User-initiated and reversible from a control that
     stays visible at every width -- unlike the viewport-driven hiding
     CLAUDE.md's "never hide a control to fix a fitting problem" rule
     targets (a media query deciding for the user, with no way back), this
     is a one-click, persisted *choice*, off by default. Scoped inside this
     ≥768px tier deliberately: outside it, this selector would also match
     the <768px off-canvas drawer, which must never collapse. */
  body[data-sidebar="collapsed"] .sidebar { width: 56px; }

  body[data-sidebar="collapsed"] .sidebar-link,
  body[data-sidebar="collapsed"] .sidebar-section-label {
    display: none;
  }

  body[data-sidebar="collapsed"] .sidebar-section-group > .sidebar-section { display: none; }

  body[data-sidebar="collapsed"] .sidebar-section-group > .sidebar-section-group {
    margin-left: 0;
    padding-left: 0;
    border-left: 0;
  }

  body[data-sidebar="collapsed"] .sidebar-section-group > summary {
    justify-content: center;
    width: 40px;
    min-height: 40px;
    margin: .15rem auto;
    padding: 0;
  }

  /* The label and caret are hidden (display:none also drops them from the
     accessibility tree, which is why global.html's `_group` macro puts the
     label on the <summary> itself via aria-label= -- an explicit aria-label
     wins over content-derived naming, so the accessible name survives
     regardless of collapse state). The sprite icon stays as the glyph. */
  body[data-sidebar="collapsed"] .sidebar-top-link > .sidebar-group-label,
  body[data-sidebar="collapsed"] .sidebar-section-group > summary > .sidebar-group-label,
  body[data-sidebar="collapsed"] .sidebar-section-group > summary > .sidebar-caret {
    display: none;
  }

  body[data-sidebar="collapsed"] .sidebar-top-link {
    justify-content: center;
    width: 40px;
    min-height: 40px;
    margin: .15rem auto;
    padding: 0;
  }

  body[data-sidebar="collapsed"] .sidebar-top-link > .sidebar-icon {
    width: 20px;
    height: 20px;
  }

  body[data-sidebar="collapsed"] .sidebar-section-group > summary > .sidebar-icon {
    width: 20px;
    height: 20px;
  }

  /* The group's links are hidden above, so mark "where am I" on the group's
     own summary. A group only renders open server-side (or via a saved
     preference) when it's the active one or the visitor chose to expand
     it, an acceptable proxy for "this is where you are." */
  body[data-sidebar="collapsed"] .sidebar-section-group[open] > summary {
    background: color-mix(in srgb, var(--brand) 12%, transparent);
  }
}
