@layer components {
  .main {
    display: flex;
    flex-direction: column;
    padding: var(--block-space-double) var(--inline-space-double);
    gap: var(--inline-space-double);
    margin-inline: auto;
    max-inline-size: var(--main-width);

    @media (width >= 860px) {
      flex-direction: row;
    }
  }

  /* Listing pages (products index, category pages): a header area that sits
     above the filter toggle on mobile, while the sidebar keeps its top
     alignment next to the header on desktop. */
  .main--listing {
    display: grid;
    grid-template:
      "header"
      "sidebar"
      "content"
      / 1fr;

    @media (width >= 860px) {
      grid-template:
        "sidebar header" auto
        "sidebar content" 1fr
        / var(--sidebar-width) 1fr;
    }
  }

  .main__header {
    display: flex;
    flex-direction: column;
    gap: var(--block-space);
    grid-area: header;
  }

  .main__header .page-title {
    margin-block-end: 0;
  }

  /* Let the results turbo-frame participate in the listing grid as if its
     children were direct grid items. */
  .main--listing > turbo-frame {
    display: contents;
  }

  .main--listing .sidebar {
    grid-area: sidebar;
  }

  .main--listing .content {
    grid-area: content;
  }

  .sidebar {
    inline-size: 100%;

    @media (width >= 860px) {
      inline-size: var(--sidebar-width);
    }
  }

  .content {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    gap: var(--block-space-double);
  }
}
