/* Two-pane app shell: context rail on the left, workspace on the right. */
@layer components {
  :root {
    --shell-side-width: 15.5rem;
  }

  /* Two independent panes: wheel scrolls whichever side the pointer is over. */
  body.has-shell {
    display: flex;
    flex-direction: column;
    block-size: 100dvh;
    overflow: hidden;
  }

  .has-shell .site-header {
    /* Keep header above the rail and the mobile drawer. */
    position: relative;
    z-index: 30;
    flex-shrink: 0;
  }

  /* Use button.shell-open — body also gets .shell-open while the drawer is open. */
  button.shell-open {
    display: none;
    inline-size: 2.5rem;
    block-size: 2.5rem;
    min-block-size: 2.5rem;
    padding: 0;
    flex-shrink: 0;

    & svg { inline-size: 1.25rem; block-size: 1.25rem; margin: auto; }
  }

  .shell {
    display: grid;
    grid-template-columns: var(--shell-side-width) minmax(0, 1fr);
    align-items: stretch;
    flex: 1;
    min-block-size: 0;
    overflow: hidden;
  }

  .shell-backdrop {
    display: none;
  }

  .shell-side {
    box-sizing: border-box;
    z-index: 20;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    min-block-size: 0;
    padding: var(--space-4) var(--space-3) var(--space-5);
    background: var(--color-surface);
    border-inline-end: 1px solid var(--color-line);
    overflow: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
  }

  .shell-side-head {
    display: none;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    margin-block-end: var(--space-1);
  }

  .shell-side-label {
    margin: var(--space-3) 0 var(--space-1);
    padding-inline: var(--space-2);
    color: var(--color-text-muted);
    font-size: .75rem;
    font-weight: 600;
    letter-spacing: 0;
    text-transform: none;
  }

  .shell-list:first-child + .shell-side-label,
  .shell-side > .shell-side-label:first-child {
    margin-block-start: 0;
  }

  .shell-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
  }

  .shell-list a {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    min-block-size: 2rem;
    padding: .3rem var(--space-2);
    border-radius: var(--radius-s);
    color: var(--color-text-muted);
    text-decoration: none;
    font-size: .875rem;
    font-weight: 500;
    transition: background-color var(--duration), color var(--duration);

    &:hover { background: var(--color-surface-subtle); color: var(--color-text); }
    &[aria-current] {
      background: var(--color-accent-soft);
      color: var(--color-accent);
      font-weight: 600;
    }
    & span {
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
  }

  .shell-icon {
    inline-size: 1.125rem;
    block-size: 1.125rem;
    flex-shrink: 0;
    margin: 0;
  }

  .shell-empty {
    margin: 0;
    padding-inline: var(--space-2);
    font-size: .875rem;
  }

  .shell-archived {
    margin-block-start: var(--space-2);

    & summary {
      display: flex;
      align-items: center;
      gap: var(--space-2);
      min-block-size: 2rem;
      padding: .25rem var(--space-2);
      border-radius: var(--radius-m);
      color: var(--color-text-muted);
      font-size: .8125rem;
      font-weight: 600;
      cursor: pointer;
      list-style: none;

      &::-webkit-details-marker { display: none; }
      &::before {
        content: "";
        inline-size: .4rem;
        block-size: .4rem;
        border-block-end: 1.5px solid currentColor;
        border-inline-end: 1.5px solid currentColor;
        rotate: -45deg;
        translate: 0 -.05rem;
        transition: rotate .15s;
      }
    }
    &[open] > summary::before { rotate: 45deg; }
    & .shell-list { margin-block-start: 2px; }
    & a { color: var(--color-text-muted); opacity: .9; }
  }

  .shell-workspace {
    min-inline-size: 0;
    min-block-size: 0;
    overflow: auto;
    overscroll-behavior: contain;
  }

  .has-shell main {
    max-inline-size: min(var(--page-width), 100%);
    margin-inline: 0;
    padding-inline: var(--space-5);
  }

  @media (width < 56rem) {
    .has-shell main {
      padding-inline: max(var(--space-3), env(safe-area-inset-left, 0px)) max(var(--space-3), env(safe-area-inset-right, 0px));
    }
  }

  .page-head .lead { margin-block: var(--space-1) 0; }

  @media (width < 56rem) {
    button.shell-open { display: inline-grid; place-items: center; }

    .shell {
      grid-template-columns: 1fr;
    }

    .shell-backdrop {
      display: block;
      position: fixed;
      inset: 0;
      z-index: 40;
      background: var(--color-backdrop);
      border: 0;
      padding: 0;
      opacity: 0;
      pointer-events: none;
      transition: opacity .2s;
    }

    .shell-side {
      position: fixed;
      inset: 0 auto 0 0;
      z-index: 45;
      box-sizing: border-box;
      inline-size: min(20rem, calc(100vw - 2.5rem));
      block-size: 100dvh;
      max-block-size: 100dvh;
      padding-block-start: max(var(--space-4), env(safe-area-inset-top, 0px));
      padding-block-end: max(var(--space-5), env(safe-area-inset-bottom, 0px));
      padding-inline-start: max(var(--space-3), env(safe-area-inset-left, 0px));
      padding-inline-end: var(--space-3);
      translate: -105% 0;
      border-inline-end: 1px solid var(--color-line);
      box-shadow: var(--shadow-raised);
      transition: translate .22s cubic-bezier(.3, .7, .2, 1);
      /* Keep the full project list reachable under the sheet. */
      overflow-x: hidden;
      overflow-y: auto;
      -webkit-overflow-scrolling: touch;
      overscroll-behavior: contain;
      scrollbar-gutter: auto;
    }

    .shell-list a {
      min-block-size: 2.75rem;
      padding-block: .5rem;
    }

    /* On a phone the workspace is the only on-page scroll surface. */
    .shell-workspace { overflow: auto; }

    .shell-side-head {
      display: flex;
      position: sticky;
      inset-block-start: 0;
      z-index: 1;
      margin-block-end: var(--space-2);
      padding-block: var(--space-1) var(--space-2);
      background: var(--color-surface);
    }

    body.shell-open {
      overflow: hidden;

      /* Drawer must sit above the sticky site header (z-index 30). */
      & .site-header { z-index: 20; }
      & .shell-backdrop {
        opacity: 1;
        pointer-events: auto;
      }
      & .shell-side { translate: 0; }
      & button.shell-open { background: var(--color-accent-soft); color: var(--color-accent); }
    }

    @media (prefers-reduced-motion: reduce) {
      .shell-side, .shell-backdrop { transition: none; }
    }
  }
}
