.layout-app {
  overflow: hidden;
}

.app-shell {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  grid-template-areas: "sidebar content";
  height: 100vh;
  min-height: 0;
  overflow: hidden;
}

.app-shell > .app-sidebar {
  grid-area: sidebar;
}

.app-shell > .app-content {
  grid-area: content;
}

.app-sidebar {
  background: var(--color-shell);
  color: var(--color-surface);
  border-right: 1px solid var(--shell-line);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  min-height: 0;
  overflow-y: auto;
  padding: var(--space-4) var(--space-3);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-1) var(--space-3);
  margin-bottom: var(--space-4);
  color: var(--color-surface);
}

.sidebar-brand__name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.25rem;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.sidebar-brand__page-title {
  display: none;
}

.sidebar-brand[data-sidebar-toggle] {
  cursor: pointer;
}

.sidebar-brand__icon {
  display: none;
  margin-left: auto;
  font-size: 1.2rem;
  line-height: 1;
  color: var(--color-surface);
  opacity: 0.9;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* Links: one row style, current page marked by a crimson bar */
.side-link {
  display: block;
  position: relative;
  padding: 0.5rem var(--space-3);
  border-radius: var(--radius);
  color: var(--shell-text);
  font-size: 0.92rem;
  text-decoration: none;
}

.side-link:hover,
.side-link:focus-visible {
  background: var(--shell-hover);
  color: var(--color-surface);
  text-decoration: none;
}

.side-link--active,
.side-link--active:hover,
.side-link--active:focus-visible {
  background: var(--shell-line);
  color: var(--color-surface);
  font-weight: 600;
}

.side-link--active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.4rem;
  bottom: 0.4rem;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--color-accent-bright);
}

/* Collapsible groups: a small heading, items indented under a hairline */
.side-group {
  margin-top: var(--space-3);
}

.side-group + .side-link {
  margin-top: var(--space-3);
  padding-top: 0.5rem;
}

.side-group__toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0.4rem var(--space-3);
  border: 0;
  background: transparent;
  color: var(--shell-text-mute);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  text-align: left;
}

.side-group__toggle::after {
  content: "";
  width: 0.4rem;
  height: 0.4rem;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg);
  transition: transform 0.15s ease;
}

.side-group__toggle[aria-expanded="true"]::after {
  transform: rotate(-135deg);
}

.side-group__toggle:hover,
.side-group__toggle.is-current {
  color: var(--color-surface);
}

.side-group__toggle:focus-visible {
  outline: 2px solid var(--color-accent-bright);
  outline-offset: -2px;
}

.side-group__items {
  margin-left: var(--space-3);
  padding-left: var(--space-1);
  border-left: 1px solid var(--shell-line);
}

.side-group__items .side-link--active::before {
  left: -5px;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: var(--space-4);
  border-top: 1px solid var(--shell-line);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.sidebar-user {
  padding: 0 var(--space-3);
  color: var(--shell-text-mute);
  font-size: 0.8rem;
  overflow-wrap: anywhere;
}

.sidebar-logout-trigger {
  margin: 0 var(--space-3);
  border-color: var(--shell-line-strong);
  background: transparent;
  color: var(--shell-text);
  white-space: nowrap;
}

.sidebar-logout-trigger:hover {
  background: var(--shell-hover);
  border-color: var(--shell-line-strong);
  color: var(--color-surface);
}


.app-content {
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  background: var(--color-paper);
}

.content-main {
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: var(--layout-page-max-width);
  margin: 0 auto;
  padding: 1.25rem;
}

/* ── Mobile (≤992px): native document scrolling ─────────────────────────────
 *
 * Desktop (above) uses a fixed-height shell (.app-shell @ 100vh) with the
 * .app-content as an inner overflow:auto scroll region. That same pattern on
 * mobile breaks inside an INSTALLED PWA (display:standalone): the shell's
 * 100dvh can resolve taller than the actually-visible viewport (system UI
 * overlaps it), so the bottom of the inner scroll area — the pagination —
 * lands below the screen and cannot be scrolled into view. It works in a
 * normal mobile browser only because the browser chrome makes dvh behave.
 *
 * Fix: on mobile, abandon the inner-scroll pattern entirely and let the
 * DOCUMENT scroll natively. The browser/PWA owns the scroll region, so the
 * bottom is always reachable in every display mode. The sidebar collapses to
 * a sticky top bar so the menu toggle stays reachable while scrolling.
 * ──────────────────────────────────────────────────────────────────────────── */
@media (max-width: 992px) {
  .layout-app {
    overflow: visible;
  }

  .app-shell {
    display: flex;
    flex-direction: column;
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    overflow: visible;
  }

  .app-sidebar {
    position: sticky;
    top: 0;
    z-index: 1020;
    height: auto;
    overflow: visible;
    border-right: 0;
    border-bottom: 1px solid var(--shell-line);
    padding-bottom: 0.9rem;
  }

  .app-sidebar > :not(.sidebar-brand) {
    display: none;
  }

  .app-sidebar.is-open > .sidebar-nav,
  .app-sidebar.is-open > .sidebar-footer {
    display: flex;
  }

  .sidebar-brand {
    width: 100%;
  }

  .sidebar-brand__icon {
    display: inline-block;
  }

  .sidebar-brand__name:has(+ .sidebar-brand__page-title) {
    display: none;
  }

  .sidebar-brand__page-title {
    display: block;
  }

  .app-content {
    flex: 1;
    min-height: 0;
    overflow: visible;
  }

  /* Generous bottom padding keeps pagination clear of any system bar; the
     safe-area inset is added on top when the platform reports one. */
  .content-main {
    padding: 1rem 1rem max(4rem, calc(2rem + env(safe-area-inset-bottom, 0px)));
  }

}
