/* ─────────────────────────────────────────────────────────────────────────────
   BPG app shell — the shared sidebar + shell layout.

   Every colour here resolves to a token from theme.css (the canonical set in
   BPG.Platform.Core, served alongside this file as
   /_content/BPG.Shell.Web/bpg-shell/css/theme.css). There are no literal hex
   values below except where a token genuinely does not exist for the job, and
   each of those says why. That is the whole point: a host that adopts this
   sidebar cannot end up off-brand, and dark mode comes for free because the
   tokens already flip.

   Load order: theme.css, then this file, then the host's page styles.
   ───────────────────────────────────────────────────────────────────────────── */

/* Shell-local geometry. Not colour, so not theme tokens — but named here rather
   than scattered so the collapsed rail width is stated once. */
:root {
  --bpg-shell-width: 260px;
  --bpg-shell-width-collapsed: 64px;
  --bpg-shell-radius: 8px;
  --bpg-shell-gap: 2px;
  --bpg-shell-transition: 160ms ease;
}

/* ── The shell container ──────────────────────────────────────────────────── */

.bpg-shell {
  display: flex;
  /* dvh, not vh: vh resolves against iOS Safari's LARGE viewport, so a shell
     sized in vh is taller than the visible area whenever chrome is showing. */
  min-height: 100dvh;
  background: var(--bg-primary);
  color: var(--text-primary);
}

/* The page area beside the sidebar. min-width:0 is load-bearing: without it a
   wide child (a table, the calendar's timeline) forces the flex item wider than
   the viewport and the whole page scrolls sideways instead of the child. */
.bpg-shell__main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* ── Full-height app pages ────────────────────────────────────────────────────
   Opt-in for a page whose content is an app that owns its own scrolling — the
   packaged calendar, the Better Pages hub — rather than a document the page
   scrolls as a whole.

   Why it is needed. The rules above solve the HORIZONTAL axis only: `min-width:
   0` lets a wide child overflow inside itself instead of widening the page.
   Vertically there was no equivalent, so `.bpg-shell__main` kept its automatic
   minimum size of `min-content` and refused to shrink below its content. A
   24-hour calendar grid is ~1550px tall, so `__main` grew to 1550px, the inner
   `overflow-y:auto` pane inherited a height equal to its own content, and there
   was nothing left to scroll — while `body{overflow:hidden}` from the calendar's
   own sheet stopped the page scrolling either. Net effect on a phone: the grid
   could not be scrolled at all.

   `height` (not `min-height`) is the point: the shell has to take the viewport's
   height rather than grow past it, so a definite height propagates down the
   flex chain to the pane that scrolls. `min-height:0` on both boxes is what
   permits shrinking below content once that height is definite.

   Only pages that hand their whole main column to such an app should set this —
   on an ordinary document page it would clip content instead of scrolling it.
   `Pages/BetterPages/Index.cshtml` predates this and pins `.bp-shell` to
   100dvh itself, which is the same fix applied one level lower. */
.bpg-shell--app {
  height: 100dvh;
  min-height: 0;
}

.bpg-shell--app > .bpg-shell__main {
  min-height: 0;
}

/* ── Sidebar ──────────────────────────────────────────────────────────────── */

.bpg-shell-sidebar {
  flex: 0 0 var(--bpg-shell-width);
  width: var(--bpg-shell-width);
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-light);
  /* Sticks for its own height so long nav lists scroll independently of the page. */
  position: sticky;
  top: 0;
  /* dvh for the same reason as .bpg-shell: with vh the sidebar's far edge sits
     below the fold behind the browser chrome, taking its footer with it. */
  height: 100dvh;
  transition: flex-basis var(--bpg-shell-transition), width var(--bpg-shell-transition);
}

.bpg-shell-sidebar[data-collapsed="true"] {
  flex-basis: var(--bpg-shell-width-collapsed);
  width: var(--bpg-shell-width-collapsed);
}

/* Collapsed rail: icons only. Labels are hidden with width:0 + overflow rather
   than display:none so they stay in the accessibility tree — a screen reader
   still reads the link name in the collapsed state. */
.bpg-shell-sidebar[data-collapsed="true"] .bpg-shell-nav__label,
.bpg-shell-sidebar[data-collapsed="true"] .bpg-shell-nav__badge,
.bpg-shell-sidebar[data-collapsed="true"] .bpg-shell-brand__name,
.bpg-shell-sidebar[data-collapsed="true"] .bpg-shell-user__text,
.bpg-shell-sidebar[data-collapsed="true"] .bpg-shell-profile__caret,
.bpg-shell-sidebar[data-collapsed="true"] .bpg-shell-nav__heading {
  width: 0;
  overflow: hidden;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
}

/* The label is still in the row at width 0 (for screen readers), so in the rail it
   must neither grow (its flex: 1 pushed the icon to the item's left padding) nor
   keep the item's gap (half a gap more): either puts an item's icon left of the
   rail's centre, out of line with the section rail links, which have no label.
   The nav's items only: the profile panel's rows share these classes and stay
   labelled in every state (see "The panel is always labelled"). */
.bpg-shell-sidebar[data-collapsed="true"] .bpg-shell-nav .bpg-shell-nav__item {
  gap: 0;
}

.bpg-shell-sidebar[data-collapsed="true"] .bpg-shell-nav .bpg-shell-nav__label {
  flex: 0 0 0;
}

.bpg-shell-sidebar[data-collapsed="true"] .bpg-shell-nav__item {
  justify-content: center;
}

/* The rail's brand row has room for one control, and the toggle is the one that
   expands it: the 28px brand mark beside it overlapped it in 64px. The brand is
   a link home, which the open sidebar still shows. */
.bpg-shell-sidebar[data-collapsed="true"] .bpg-shell-brand {
  display: none;
}

.bpg-shell-sidebar[data-collapsed="true"] .bpg-shell-sidebar__brand {
  justify-content: center;
  padding-left: 0;
  padding-right: 0;
}

/* ── Brand ────────────────────────────────────────────────────────────────── */

.bpg-shell-sidebar__brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.875rem 0.75rem;
  border-bottom: 1px solid var(--border-light);
  min-height: 56px;
}

.bpg-shell-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  min-width: 0;
  text-decoration: none;
  color: var(--text-primary);
  font-weight: 600;
}

.bpg-shell-brand__logo {
  height: 28px;
  width: auto;
  max-width: 100%;
}

.bpg-shell-brand__mark {
  flex: 0 0 28px;
  height: 28px;
  border-radius: var(--bpg-shell-radius);
  background: var(--brand-blue);
  color: var(--text-inverse);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  text-transform: uppercase;
}

.bpg-shell-brand__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: opacity var(--bpg-shell-transition);
}

.bpg-shell-sidebar__toggle {
  flex: 0 0 auto;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-tertiary);
  padding: 0.25rem 0.375rem;
  border-radius: var(--bpg-shell-radius);
  font-size: 1rem;
  line-height: 1;
}

.bpg-shell-sidebar__toggle:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* ── Nav ──────────────────────────────────────────────────────────────────── */

.bpg-shell-nav {
  flex: 1;
  /* A flex item's automatic minimum size is zero once overflow is not visible,
     so this is what lets a long nav scroll inside the sidebar rather than
     growing past it and pushing the footer off the bottom. */
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  /* Reaching the end of the nav must not start scrolling the page behind the
     drawer — on a phone that reads as the drawer having jumped. */
  overscroll-behavior: contain;
  padding: 0.5rem 0.5rem 1rem;
}

.bpg-shell-nav__section + .bpg-shell-nav__section {
  margin-top: 1rem;
}

.bpg-shell-nav__heading {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 0.375rem 0.625rem;
  transition: opacity var(--bpg-shell-transition);
}

/* ── Collapsible sections ─────────────────────────────────────────────────── */

/* A collapsible section is a <details>; its heading is the <summary>. The UA
   disclosure triangle is suppressed twice over — `list-style: none` for engines
   that draw it as the summary's list marker, and the -webkit pseudo-element for
   older WebKit — because the caret on the right is the affordance. */

.bpg-shell-nav__section--group > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  cursor: pointer;
  list-style: none;
  border-radius: var(--bpg-shell-radius);
  /* Comfortable for a thumb without making the heading look like a nav row. */
  min-height: 32px;
}

.bpg-shell-nav__section--group > summary::-webkit-details-marker {
  display: none;
}

.bpg-shell-nav__section--group > summary:hover {
  background: var(--bg-hover);
  color: var(--text-secondary);
}

.bpg-shell-nav__section--group > summary:focus-visible {
  outline: 2px solid var(--input-focus-border);
  outline-offset: -2px;
}

.bpg-shell-nav__heading-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bpg-shell-nav__caret {
  flex: 0 0 auto;
  font-size: 0.625rem;
  line-height: 1;
  /* Points down when open, right when closed — rotated rather than swapped so
     there is one glyph to keep consistent. */
  transform: rotate(-90deg);
  transition: transform var(--bpg-shell-transition);
}

.bpg-shell-nav__section--group[open] > summary .bpg-shell-nav__caret {
  transform: rotate(0deg);
}

/* Collapsed rail (desktop collapse and the tablet rail alike): there are no
   headings to click, so the toggle goes away and every section renders open.
   Without the second half a section the user had closed would take its icons
   with it into the rail, where nothing can reopen them.

   Both spellings are needed. Engines that still hide a closed <details> with
   the UA's `display: none` on non-summary children are beaten by the author
   `display: flex`; engines that hide it with `content-visibility` on
   ::details-content (Chrome 131+) ignore that rule entirely and need the
   pseudo-element one. */
.bpg-shell-sidebar[data-collapsed="true"] .bpg-shell-nav__section--group > summary {
  display: none;
}

.bpg-shell-sidebar[data-collapsed="true"] .bpg-shell-nav__section--group > .bpg-shell-nav__list {
  display: flex;
}

.bpg-shell-sidebar[data-collapsed="true"] .bpg-shell-nav__section--group::details-content {
  content-visibility: visible;
}

/* ── Section rail entries (0.9.0-alpha) ───────────────────────────────────────
   A section the host gave an icon (ShellNavSection.LucideIcon / Icon) is ONE
   entry in a rail, BetterGather's sidebar-groups pattern: the partial renders a
   .bpg-shell-nav__rail-link inside it, and in a rail that link replaces the
   section's heading and its list. Anywhere else (the expanded sidebar, the
   tablet overlay, the phone drawer) the link is display:none and the section
   is exactly what it was.

   Its own class rather than .bpg-shell-nav__item, so nothing that looks up
   "the first nav item" (the drawer's focus-on-open, a host's own script) can
   land on a link that is hidden at that width. The look is copied from the item.

   The rail rules are stated for the desktop collapse here, scoped to >= 768px so
   the phone drawer can never inherit them, and again for the tablet rail in its
   media block below. */
.bpg-shell-nav__rail-link {
  display: none;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 0.5rem 0.625rem;
  border-radius: var(--bpg-shell-radius);
  text-decoration: none;
  color: var(--text-secondary);
  font-size: 0.875rem;
  line-height: 1.25;
}

.bpg-shell-nav__rail-link:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.bpg-shell-nav__rail-link:focus-visible {
  outline: 2px solid var(--input-focus-border);
  outline-offset: -2px;
}

.bpg-shell-nav__rail-link.is-active {
  background: var(--bg-hover);
  color: var(--text-link);
  font-weight: 600;
  box-shadow: inset 2px 0 0 0 var(--brand-blue);
}

@media (min-width: 768px) {
  .bpg-shell-sidebar[data-collapsed="true"] .bpg-shell-nav__section--railed > .bpg-shell-nav__rail-link {
    display: flex;
  }

  /* Two classes on the section, so this outranks the "every section open in the
     rail" rule above that shows a group's list. */
  .bpg-shell-sidebar[data-collapsed="true"] .bpg-shell-nav__section.bpg-shell-nav__section--railed > .bpg-shell-nav__heading,
  .bpg-shell-sidebar[data-collapsed="true"] .bpg-shell-nav__section.bpg-shell-nav__section--railed > .bpg-shell-nav__list {
    display: none;
  }

  /* One icon per section reads as one list, so consecutive section icons sit at
     the item gap rather than the 1rem that separates sections with headings. */
  .bpg-shell-sidebar[data-collapsed="true"] .bpg-shell-nav__section--railed + .bpg-shell-nav__section--railed {
    margin-top: var(--bpg-shell-gap);
  }

  /* BetterGather's rail shows no scrollbar either: in 64px a scrollbar takes a
     quarter of the width and shoves the icons off-centre. The nav still scrolls.
     Only a rail with section icons, which is short: a rail of one icon per item
     (the Portal's) can be long, and there the scrollbar says there is more. */
  .bpg-shell-sidebar[data-collapsed="true"] .bpg-shell-nav:has(.bpg-shell-nav__section--railed) {
    scrollbar-width: none;
  }

  .bpg-shell-sidebar[data-collapsed="true"] .bpg-shell-nav:has(.bpg-shell-nav__section--railed)::-webkit-scrollbar {
    display: none;
  }
}

.bpg-shell-nav__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--bpg-shell-gap);
}

.bpg-shell-nav__item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  width: 100%;
  padding: 0.5rem 0.625rem;
  border-radius: var(--bpg-shell-radius);
  text-decoration: none;
  color: var(--text-secondary);
  font-size: 0.875rem;
  line-height: 1.25;
  /* Buttons in the footer share this class, so neutralise the UA button look. */
  background: none;
  border: none;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
}

/* Hosts gate an item they won't show this person by setting `hidden` on it (or on
   its <li>, which needs nothing here). [hidden] is a UA rule, so the author
   display:flex above would beat it and leave a gated link on screen. Same weight
   as the scrim's rule below. */
.bpg-shell-nav__item[hidden] {
  display: none !important;
}

.bpg-shell-nav__item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.bpg-shell-nav__item:focus-visible {
  outline: 2px solid var(--input-focus-border);
  outline-offset: -2px;
}

/* Active item. The left bar rather than a heavy fill: the sidebar sits next to a
   dense calendar, and a saturated block competes with the page content. */
.bpg-shell-nav__item.is-active {
  background: var(--bg-hover);
  color: var(--text-link);
  font-weight: 600;
  box-shadow: inset 2px 0 0 0 var(--brand-blue);
}

.bpg-shell-nav__icon {
  flex: 0 0 1.25rem;
  text-align: center;
  font-size: 0.9375rem;
  line-height: 1.25rem;
}

/* Lucide sprite icons, rendered when the host sets ShellNav.IconSpriteUrl. Sized
   here rather than by BPG.Icons.Web's lc.css, because a host may not load that
   stylesheet, and an unsized <svg> is 300x150. Two classes deep so a .lc rule
   (0,0,1,0) loaded after this file cannot resize them. No colour is set: every
   Lucide symbol strokes in currentColor, so an icon follows its row's text colour
   (muted, hover, active, dark mode) exactly as the glyph did.

   In a nav row the svg is 1rem square, centred in the same 1.25rem box the text
   glyph sits in, so a sprite host's rows and rail are the same size as a text
   host's. */
.bpg-shell-sidebar .bpg-shell-nav__svg {
  display: block;
  width: 1rem;
  height: 1rem;
  flex: none;
  vertical-align: middle;
}

.bpg-shell-sidebar .bpg-shell-nav__icon > .bpg-shell-nav__svg {
  margin: 0.125rem auto;
}

/* The carets keep their glyph's footprint, so the heading and the profile chip
   do not grow. They still rotate as a whole (the transform is on the span). */
.bpg-shell-sidebar .bpg-shell-nav__caret > .bpg-shell-nav__svg,
.bpg-shell-sidebar .bpg-shell-profile__caret > .bpg-shell-nav__svg {
  width: 0.875rem;
  height: 0.875rem;
}

/* The brand-row toggle: the same visual weight as the 1rem glyph it replaces. */
.bpg-shell-sidebar .bpg-shell-sidebar__toggle .bpg-shell-nav__svg {
  width: 1.125rem;
  height: 1.125rem;
}

/* The toggle's chevron (0.9.0-alpha) points the way the sidebar will move: left
   while it is open, right while it is a rail. The partial renders both and this
   picks one, so the first paint is right before bpg-shell.js runs. The rail
   states are the desktop collapse here and the tablet rail in its media block;
   the phone drawer keeps the left chevron, where the button closes the drawer. */
.bpg-shell-sidebar__toggle-icon {
  display: block;
}

.bpg-shell-sidebar__toggle-icon--expand {
  display: none;
}

@media (min-width: 768px) {
  .bpg-shell-sidebar[data-collapsed="true"] .bpg-shell-sidebar__toggle-icon--collapse {
    display: none;
  }

  .bpg-shell-sidebar[data-collapsed="true"] .bpg-shell-sidebar__toggle-icon--expand {
    display: block;
  }
}

.bpg-shell-nav__label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: opacity var(--bpg-shell-transition);
}

.bpg-shell-nav__badge {
  flex: 0 0 auto;
  font-size: 0.6875rem;
  font-weight: 600;
  padding: 0.0625rem 0.375rem;
  border-radius: 999px;
  background: var(--bg-tertiary);
  color: var(--text-tertiary);
  border: 1px solid var(--border-light);
}

/* ── Footer ───────────────────────────────────────────────────────────────── */

.bpg-shell-sidebar__footer {
  border-top: 1px solid var(--border-light);
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: var(--bpg-shell-gap);
}

.bpg-shell-user {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.625rem;
  min-width: 0;
}

.bpg-shell-user__avatar {
  flex: 0 0 1.75rem;
  height: 1.75rem;
  border-radius: 999px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-light);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
}

.bpg-shell-user__text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  transition: opacity var(--bpg-shell-transition);
}

.bpg-shell-user__name {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bpg-shell-user__email {
  font-size: 0.6875rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Profile drop-up ──────────────────────────────────────────────────────────
   BetterGather / BetterRoofing's account menu: the user chip is the toggle, and
   settings, theme and sign out live in a panel that opens UPWARD over the nav,
   so the footer costs one row instead of five. */

.bpg-shell-profile {
  position: relative;
}

.bpg-shell-profile__chip {
  list-style: none;
  cursor: pointer;
  border-radius: var(--bpg-shell-radius);
}

.bpg-shell-profile__chip::-webkit-details-marker {
  display: none;
}

.bpg-shell-profile__chip:hover,
.bpg-shell-profile[open] > .bpg-shell-profile__chip {
  background: var(--bg-hover);
}

.bpg-shell-profile__chip:focus-visible {
  outline: 2px solid var(--input-focus-border);
  outline-offset: -2px;
}

.bpg-shell-profile__chip .bpg-shell-user__text {
  flex: 1;
}

.bpg-shell-profile__caret {
  flex: 0 0 auto;
  font-size: 0.75rem;
  color: var(--text-muted);
  transition: transform var(--bpg-shell-transition);
}

.bpg-shell-profile[open] .bpg-shell-profile__caret {
  transform: rotate(180deg);
}

/* min-width, not just left/right: in the 64px collapsed rail the panel would
   otherwise be as narrow as the rail. It grows to the right, over the page. */
.bpg-shell-profile__panel {
  position: absolute;
  left: 0;
  bottom: calc(100% + 0.375rem);
  width: 100%;
  min-width: 15rem;
  z-index: 60;
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: calc(var(--bpg-shell-radius) * 2);
  box-shadow: var(--shadow-xl);
  overflow: hidden;
}

.bpg-shell-profile__header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem;
  border-bottom: 1px solid var(--border-light);
  min-width: 0;
}

.bpg-shell-profile__avatar {
  flex: 0 0 2.75rem;
  height: 2.75rem;
  border-radius: 999px;
  background: var(--brand-blue);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: 600;
}

.bpg-shell-profile__identity {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.bpg-shell-profile__name {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bpg-shell-profile__email {
  font-size: 0.75rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bpg-shell-profile__body {
  display: flex;
  flex-direction: column;
  gap: var(--bpg-shell-gap);
  padding: 0.375rem;
}

.bpg-shell-profile__divider {
  height: 1px;
  margin: 0.25rem 0.375rem;
  background: var(--border-light);
}

/* The panel is always labelled, whatever state the rail is in: it opens over
   the page, so it has the room the rail does not. */
.bpg-shell-sidebar .bpg-shell-profile__panel .bpg-shell-nav__label {
  width: auto;
  overflow: hidden;
  opacity: 1;
  pointer-events: auto;
}

.bpg-shell-sidebar .bpg-shell-profile__panel .bpg-shell-nav__item {
  justify-content: flex-start;
}

/* ─────────────────────────────────────────────────────────────────────────────
   Responsive model — ported from BetterGather's unified chrome, one markup,
   three layouts. Breakpoints are stated here and in bpg-shell.js and MUST agree:

     <= 767px          phone. Sidebar is an off-canvas drawer, opened by the
                       hamburger in .bpg-shell-navbar (or wherever the page's
                       [data-app-nav-slot] docked it). Scrim + body scroll lock.
     768px – 900px     tablet. Sidebar is a 64px icon rail in flow; expanding it
                       overlays the page (position: fixed) behind a scrim rather
                       than reflowing a cramped viewport.
     >= 901px          desktop. Full sidebar in flow, collapsible, persisted.
   ───────────────────────────────────────────────────────────────────────────── */

/* ── Hamburger bar (phone only) ───────────────────────────────────────────── */

/* Hidden by default; the phone media block shows it. When bpg-shell.js has
   docked the toggle into a page-provided [data-app-nav-slot], the emptied bar
   must not keep costing a row. */
.bpg-shell-navbar {
  display: none;
}

body.bpg-shell-nav-docked .bpg-shell-navbar {
  display: none !important;
}

/* The toggle hides by CLASS, not by where it sits, so a docked button
   disappears from the host toolbar on wider screens without the slot owner
   doing anything. */
.bpg-shell-navbar__toggle {
  display: none;
  align-items: center;
  justify-content: center;
  /* 44px: minimum comfortable touch target. */
  width: 44px;
  height: 44px;
  padding: 0;
  background: none;
  border: none;
  border-radius: var(--bpg-shell-radius);
  cursor: pointer;
  color: var(--text-primary);
}

.bpg-shell-navbar__toggle:hover {
  background: var(--bg-hover);
}

.bpg-shell-navbar__toggle:focus-visible {
  outline: 2px solid var(--input-focus-border);
  outline-offset: -2px;
}

/* Three bars drawn from the middle one; no icon font, no sprite dependency. */
.bpg-shell-navbar__bars {
  position: relative;
  display: block;
  width: 18px;
  height: 2px;
  background: currentColor;
  border-radius: 1px;
}

.bpg-shell-navbar__bars::before,
.bpg-shell-navbar__bars::after {
  content: "";
  position: absolute;
  left: 0;
  width: 18px;
  height: 2px;
  background: currentColor;
  border-radius: 1px;
}

.bpg-shell-navbar__bars::before { top: -6px; }
.bpg-shell-navbar__bars::after  { top: 6px; }

/* ── Scrim (phone drawer + tablet rail overlay) ───────────────────────────── */

.bpg-shell-scrim {
  position: fixed;
  inset: 0;
  background: var(--overlay-bg);
  z-index: 40;
  border: 0;
  padding: 0;
}

/* [hidden] is a UA-stylesheet rule, so any author rule setting display wins over
   it. Say it once, here, with the same weight — otherwise the scrim above stays
   painted over the whole page while `hidden` is set. */
.bpg-shell-scrim[hidden] {
  display: none !important;
}

/* ── Phone: off-canvas drawer ─────────────────────────────────────────────── */

@media (max-width: 767px) {
  /* The hamburger bar stacks above the page instead of sitting beside it. */
  .bpg-shell {
    flex-direction: column;
  }

  .bpg-shell-navbar {
    display: flex;
    align-items: center;
    flex: 0 0 auto;
    padding: 0.25rem 0.5rem;
    /* Keep the bar out of a phone notch / status area. */
    padding-top: calc(0.25rem + env(safe-area-inset-top, 0px));
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-light);
  }

  .bpg-shell-navbar__toggle {
    display: flex;
  }

  .bpg-shell-sidebar {
    position: fixed;
    z-index: 50;
    left: 0;
    top: 0;
    /* Never the whole screen: the scrim peeking through is what tells you the
       page is still behind the drawer. Same clamp BetterGather uses. */
    flex-basis: auto;
    width: min(85dvw, 300px);
    /* Off-canvas by default; bpg-shell.js slides it in. Kept mounted rather
       than display:none so the transition has something to run on and focus can
       be moved into it — visibility keeps the closed drawer out of hit-testing
       and the accessibility tree (bpg-shell.js also sets `inert`). */
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform var(--bpg-shell-transition),
                visibility 0s linear var(--bpg-shell-transition);
    box-shadow: var(--shadow-xl);
    padding-left: env(safe-area-inset-left, 0px);
  }

  .bpg-shell-sidebar[data-open="true"] {
    transform: translateX(0);
    visibility: visible;
    transition: transform var(--bpg-shell-transition);
  }

  /* The collapsed rail is a desktop affordance only — on a drawer it would give
     you a 64px overlay with no labels, which is strictly worse than closed. */
  .bpg-shell-sidebar[data-collapsed="true"] {
    width: min(85dvw, 300px);
  }

  .bpg-shell-sidebar[data-collapsed="true"] .bpg-shell-nav__label,
  .bpg-shell-sidebar[data-collapsed="true"] .bpg-shell-nav__badge,
  .bpg-shell-sidebar[data-collapsed="true"] .bpg-shell-brand__name,
  .bpg-shell-sidebar[data-collapsed="true"] .bpg-shell-user__text,
  .bpg-shell-sidebar[data-collapsed="true"] .bpg-shell-profile__caret,
  .bpg-shell-sidebar[data-collapsed="true"] .bpg-shell-nav__heading {
    width: auto;
    overflow: visible;
    opacity: 1;
    pointer-events: auto;
  }

  .bpg-shell-sidebar[data-collapsed="true"] .bpg-shell-nav__item {
    justify-content: flex-start;
  }

  .bpg-shell-sidebar[data-collapsed="true"] .bpg-shell-nav .bpg-shell-nav__item {
    gap: 0.625rem;
  }

  .bpg-shell-sidebar[data-collapsed="true"] .bpg-shell-nav .bpg-shell-nav__label {
    flex: 1;
  }

  .bpg-shell-sidebar[data-collapsed="true"] .bpg-shell-brand {
    display: flex;
  }

  .bpg-shell-sidebar[data-collapsed="true"] .bpg-shell-sidebar__brand {
    justify-content: flex-start;
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }

  /* A drawer is never a rail, so the collapsed-rail overrides above must not
     reach it — the section headings are the only way to collapse a section on a
     phone, which is where the nav is longest and collapsing matters most. */
  .bpg-shell-sidebar[data-collapsed="true"] .bpg-shell-nav__section--group > summary {
    display: flex;
  }

  /* In a drawer the collapse chevron is meaningless; the brand-row button
     becomes a close control (bpg-shell.js relabels it). */

  /* Touch tap targets: the desktop 30px row is too small for a thumb. */
  .bpg-shell-nav__item {
    padding-top: 0.6875rem;
    padding-bottom: 0.6875rem;
    min-height: 44px;
  }

  .bpg-page {
    padding: 1rem;
  }

  /* The page must not scroll behind an open drawer. */
  body.bpg-shell-drawer-open {
    overflow: hidden;
  }
}

/* ── Tablet: icon rail, expands as an overlay ─────────────────────────────── */

@media (min-width: 768px) and (max-width: 900px) {
  /* Rail by default REGARDLESS of data-collapsed: the server renders
     data-collapsed="false", and if the script never runs the rail must still be
     the resting state — an unclosable fixed overlay is the failure mode this
     avoids. Only the script-set data-overlay expands it. */
  .bpg-shell-sidebar {
    flex-basis: var(--bpg-shell-width-collapsed);
    width: var(--bpg-shell-width-collapsed);
  }

  .bpg-shell-sidebar:not([data-overlay="true"]) .bpg-shell-nav__label,
  .bpg-shell-sidebar:not([data-overlay="true"]) .bpg-shell-nav__badge,
  .bpg-shell-sidebar:not([data-overlay="true"]) .bpg-shell-brand__name,
  .bpg-shell-sidebar:not([data-overlay="true"]) .bpg-shell-user__text,
  .bpg-shell-sidebar:not([data-overlay="true"]) .bpg-shell-profile__caret,
  .bpg-shell-sidebar:not([data-overlay="true"]) .bpg-shell-nav__heading {
    width: 0;
    overflow: hidden;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
  }

  .bpg-shell-sidebar:not([data-overlay="true"]) .bpg-shell-nav__item {
    justify-content: center;
  }

  .bpg-shell-sidebar:not([data-overlay="true"]) .bpg-shell-nav .bpg-shell-nav__item {
    gap: 0;
  }

  .bpg-shell-sidebar:not([data-overlay="true"]) .bpg-shell-nav .bpg-shell-nav__label {
    flex: 0 0 0;
  }

  /* The rail shows the toggle alone, as the collapsed desktop rail does. */
  .bpg-shell-sidebar:not([data-overlay="true"]) .bpg-shell-brand {
    display: none;
  }

  .bpg-shell-sidebar:not([data-overlay="true"]) .bpg-shell-sidebar__brand {
    justify-content: center;
    padding-left: 0;
    padding-right: 0;
  }

  /* The rail has no headings either, so its sections must not stay closed —
     same reasoning (and the same two spellings) as the collapsed desktop rail
     above. */
  .bpg-shell-sidebar:not([data-overlay="true"]) .bpg-shell-nav__section--group > summary {
    display: none;
  }

  .bpg-shell-sidebar:not([data-overlay="true"]) .bpg-shell-nav__section--group > .bpg-shell-nav__list {
    display: flex;
  }

  .bpg-shell-sidebar:not([data-overlay="true"]) .bpg-shell-nav__section--group::details-content {
    content-visibility: visible;
  }

  /* A section with an icon is one rail entry here too (see "Section rail
     entries" above). */
  .bpg-shell-sidebar:not([data-overlay="true"]) .bpg-shell-nav__section--railed > .bpg-shell-nav__rail-link {
    display: flex;
  }

  .bpg-shell-sidebar:not([data-overlay="true"]) .bpg-shell-nav__section.bpg-shell-nav__section--railed > .bpg-shell-nav__heading,
  .bpg-shell-sidebar:not([data-overlay="true"]) .bpg-shell-nav__section.bpg-shell-nav__section--railed > .bpg-shell-nav__list {
    display: none;
  }

  .bpg-shell-sidebar:not([data-overlay="true"]) .bpg-shell-nav__section--railed + .bpg-shell-nav__section--railed {
    margin-top: var(--bpg-shell-gap);
  }

  .bpg-shell-sidebar:not([data-overlay="true"]) .bpg-shell-nav:has(.bpg-shell-nav__section--railed) {
    scrollbar-width: none;
  }

  .bpg-shell-sidebar:not([data-overlay="true"]) .bpg-shell-nav:has(.bpg-shell-nav__section--railed)::-webkit-scrollbar {
    display: none;
  }

  /* The rail's toggle expands it, so it points right; the overlay's collapses. */
  .bpg-shell-sidebar:not([data-overlay="true"]) .bpg-shell-sidebar__toggle-icon--collapse {
    display: none;
  }

  .bpg-shell-sidebar:not([data-overlay="true"]) .bpg-shell-sidebar__toggle-icon--expand {
    display: block;
  }

  /* Expanded: slide over the page rather than reflowing it. The rail's 64px
     stays reserved in flow (this element leaves it), which is fine — the page
     behind is dimmed by the scrim while the overlay is up. */
  .bpg-shell-sidebar[data-overlay="true"] {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 50;
    width: var(--bpg-shell-width);
    height: 100dvh;
    box-shadow: var(--shadow-xl);
  }
}

@media (min-width: 901px) {
  /* The scrim must never appear on desktop, whatever state the script left it
     in on a resize. */
  .bpg-shell-scrim {
    display: none;
  }
}

/* Respect a reduced-motion preference: the slide and collapse are decoration. */
@media (prefers-reduced-motion: reduce) {
  .bpg-shell-sidebar,
  .bpg-shell-nav__label,
  .bpg-shell-brand__name,
  .bpg-shell-user__text,
  .bpg-shell-profile__caret,
  .bpg-shell-nav__heading {
    transition: none;
  }
}

/* ─────────────────────────────────────────────────────────────────────────────
   Page primitives.

   The small set of things every BPG app page needs — a header, a card, a table,
   a button, a form field, an empty state — expressed once in tokens. These live
   in the shell rather than in each host because the alternative is what the
   Portal had: a private palette per app, and three definitions of "a card".

   Namespaced .bpg-* so they cannot collide with a host's existing classes, and
   deliberately unopinionated about layout beyond spacing.
   ───────────────────────────────────────────────────────────────────────────── */

.bpg-page {
  padding: 1.5rem;
  max-width: 1200px;
  width: 100%;
}

.bpg-page__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

.bpg-page__title {
  font-size: 1.375rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.bpg-page__subtitle {
  font-size: 0.875rem;
  color: var(--text-tertiary);
  margin: 0.25rem 0 0;
}

.bpg-breadcrumb {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.bpg-breadcrumb a {
  color: var(--text-link);
  text-decoration: none;
}

.bpg-breadcrumb a:hover {
  text-decoration: underline;
}

/* ── Card ─────────────────────────────────────────────────────────────────── */

.bpg-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: 12px;
  padding: 1rem 1.125rem;
  box-shadow: var(--shadow-sm);
}

.bpg-card + .bpg-card {
  margin-top: 0.75rem;
}

.bpg-card__title {
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 0.25rem;
  font-size: 0.9375rem;
}

.bpg-card__meta {
  font-size: 0.8125rem;
  color: var(--text-tertiary);
}

.bpg-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 0.75rem;
}

/* A card that is a link should not look like body text. */
a.bpg-card {
  display: block;
  text-decoration: none;
  color: inherit;
}

a.bpg-card:hover {
  border-color: var(--border-medium);
  box-shadow: var(--shadow-md);
}

/* ── Swatch ───────────────────────────────────────────────────────────────── */

/* Programs carry a host-chosen hex colour, so this one is set inline from data —
   the only place a literal colour legitimately reaches the DOM. */
.bpg-swatch {
  display: inline-block;
  width: 0.625rem;
  height: 0.625rem;
  border-radius: 3px;
  margin-right: 0.375rem;
  vertical-align: baseline;
}

/* ── Table ────────────────────────────────────────────────────────────────── */

/* Wrapper, not the table: a wide table must scroll inside its own box rather
   than making the whole page scroll sideways. */
.bpg-table-wrap {
  overflow-x: auto;
  /* Horizontal-only. Without an explicit overflow-y, `overflow-x: auto` forces
     overflow-y to auto as well, producing a redundant vertical scrollbar on a
     wrapper whose height is already content-driven. */
  overflow-y: hidden;
  border: 1px solid var(--border-light);
  border-radius: 12px;
  background: var(--bg-secondary);
}

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

.bpg-table th,
.bpg-table td {
  text-align: left;
  padding: 0.625rem 0.875rem;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-secondary);
  white-space: nowrap;
}

.bpg-table th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  background: var(--bg-tertiary);
}

.bpg-table tr:last-child td {
  border-bottom: none;
}

.bpg-table tbody tr:hover td {
  background: var(--bg-hover);
}

.bpg-table a {
  color: var(--text-link);
  text-decoration: none;
}

.bpg-table a:hover {
  text-decoration: underline;
}

/* ── Status pill ──────────────────────────────────────────────────────────── */

.bpg-pill {
  display: inline-block;
  font-size: 0.6875rem;
  font-weight: 600;
  padding: 0.125rem 0.5rem;
  border-radius: 999px;
  background: var(--bg-tertiary);
  color: var(--text-tertiary);
  border: 1px solid var(--border-light);
  /* a pill is one line; wrapped, its rounded background splits across two line boxes */
  white-space: nowrap;
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */

.bpg-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 0.875rem;
  border-radius: var(--bpg-shell-radius);
  font-size: 0.875rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  border: 1px solid transparent;
  background: var(--btn-secondary-bg);
  color: var(--btn-secondary-text);
}

.bpg-btn:hover {
  background: var(--btn-secondary-hover);
}

.bpg-btn--primary {
  background: var(--btn-primary-bg);
  color: var(--btn-primary-text);
}

.bpg-btn--primary:hover {
  background: var(--btn-primary-hover);
}

.bpg-btn--danger {
  background: var(--btn-danger-bg);
  color: var(--btn-danger-text);
}

.bpg-btn--danger:hover {
  background: var(--btn-danger-hover);
}

.bpg-btn:focus-visible {
  outline: 2px solid var(--input-focus-border);
  outline-offset: 2px;
}

/* ── Forms ────────────────────────────────────────────────────────────────── */

.bpg-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-end;
}

.bpg-field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0;
}

.bpg-field__label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-tertiary);
}

.bpg-input,
.bpg-select,
.bpg-textarea {
  padding: 0.4375rem 0.625rem;
  border-radius: var(--bpg-shell-radius);
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--text-primary);
  font-size: 0.875rem;
  font-family: inherit;
}

.bpg-input:focus,
.bpg-select:focus,
.bpg-textarea:focus {
  outline: none;
  border-color: var(--input-focus-border);
  box-shadow: 0 0 0 3px var(--input-focus-ring);
}

.bpg-textarea {
  min-height: 5rem;
  resize: vertical;
}

/* ── Empty + error states ─────────────────────────────────────────────────── */

.bpg-empty {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--text-muted);
  font-size: 0.875rem;
  border: 1px dashed var(--border-medium);
  border-radius: 12px;
}

.bpg-alert {
  padding: 0.625rem 0.875rem;
  border-radius: var(--bpg-shell-radius);
  border: 1px solid var(--border-medium);
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  font-size: 0.875rem;
  margin-bottom: 1rem;
}
