.pinot-base-layout {
  display: grid;
  /* minmax(0, 1fr): the content column may never grow wider than the space left by the sidebar */
  grid-template-columns: var(--sidebar-width, 280px) minmax(0, 1fr);
  grid-template-rows: calc(var(--wa-font-size-3xl) + var(--wa-space-m) * 2) minmax(0, 1fr);
  grid-template-areas:
        "sidebar-top header"
        "sidebar main";
  height: 100vh;
  overflow: hidden;
  /* The sidebar is a slightly tinted panel and the header floats above the page with a soft shadow: no hard lines */
  --lb-sidebar-background: color-mix(in srgb, var(--wa-color-surface-lowered) 55%, var(--wa-color-surface-default));

  > header {
    grid-area: header;
    min-inline-size: 0;
    padding: var(--wa-space-m);
    display: flex;
    align-items: center;
    gap: var(--wa-space-m);
    position: relative;
    z-index: 1;
    background: var(--wa-color-surface-default);
    box-shadow: var(--wa-shadow-s);
  }

  > main {
    grid-area: main;
    min-inline-size: 0;
    padding: var(--wa-space-m);
    overflow-y: auto;
  }

  > aside {
    grid-area: sidebar;
    display: flex;
    flex-direction: column;
    background: var(--lb-sidebar-background);
    overflow: hidden;

    .content {
      flex-grow: 1;
      overflow-y: auto;
      padding: var(--wa-space-m);
    }

    .bottom {
      padding: var(--wa-space-m);
      flex-shrink: 0;
    }
  }
}


.pinot-base-nav-top {
  padding: var(--wa-space-m);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  padding-inline: var(--wa-space-l);
  background: var(--lb-sidebar-background);
  grid-area: sidebar-top;
}

.pinot-base-header-brand {
  display: none;
}


.pinot-base-nav-toggle {
  display: none;
}

.pinot-base-nav {
  --wa-color-text-quiet: var(--wa-color-neutral-60);

  h2 {
    margin: var(--wa-space-l) 0 0;
    padding-inline: var(--wa-space-s);
    text-transform: uppercase;
    font-size: var(--wa-font-size-2xs);
    font-weight: var(--wa-font-weight-bold);
    letter-spacing: 0.08em;
    line-height: var(--wa-line-height-condensed);
    color: var(--wa-color-text-quiet);

    &:first-of-type {
      margin-top: 0;
    }
  }

  wa-button::part(base) {
    justify-content: flex-start;
    gap: var(--wa-space-xs);
    border: 0;
    border-radius: var(--wa-border-radius-m);
    font-size: var(--wa-font-size-s);
    font-weight: var(--wa-font-weight-semibold);
  }

  /* Idle items are quiet, the current page is a soft brand-colored tile */
  wa-button[appearance="plain"] {
    color: var(--wa-color-text-quiet);

    &:hover {
      color: var(--wa-color-text-normal);
    }
  }

  wa-button[appearance="filled"]::part(base) {
    font-weight: var(--wa-font-weight-bold);
  }
}

.pinot-base-header-user .wa-prose {
  display: none;
}

@media (max-width: 768px) {
  .pinot-base-layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
            "header"
            "main";

    aside {
      display: none;
    }
  }

  .pinot-base-nav-top {
    display: none;
  }

  .pinot-base-nav-toggle {
    display: block;
  }

  .pinot-base-header-brand {
    display: inline-flex;
  }

  /* Page title right next to the menu button */
  .pinot-base-layout > header {
    gap: var(--wa-space-2xs);
  }

  .pinot-base-header-brand {
    flex: none;
  }

  /* A page with its own title in the top bar leaves no room for the logo */
  .pinot-base-layout > header:has(.page-title) .pinot-base-header-brand {
    display: none;
  }
}

/* "Beta" in a nav button: a compact tag hanging on the button's top right corner, so a long label never has to make
   room for it (and no horizontal scrollbar appears). Same look for every nav item. */
.pinot-base-nav wa-button wa-badge {
  position: absolute;
  inset-block-start: calc(var(--wa-space-2xs) * -1);
  inset-inline-end: var(--wa-space-xs);
  translate: none;
  padding: 0 var(--wa-space-2xs);
  font-size: var(--wa-font-size-3xs);
  line-height: 1.5;
  pointer-events: none;
}

/* In the mobile drawer the user card fills the footer */
wa-drawer .bottom[slot="footer"] {
  flex: 1;
  min-inline-size: 0;
}

/* Page title in the top bar: same on every page (markup in templates/page_title.html) */
.page-title {
  min-inline-size: 0;
  margin: 0;
  overflow: hidden;
  font-size: var(--wa-font-size-l);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page-title-back {
  display: inline-flex;
  align-items: center;
  gap: var(--wa-space-xs);
  color: inherit;
  text-decoration: none;

  &:hover {
    color: var(--wa-color-brand-on-quiet);
  }
}

.page-badge {
  flex: none;
}

.page-subtitle {
  /* Takes what is left of the bar: the title keeps its width, the subtitle is the one that gets shortened */
  flex: 1 1 0;
  min-inline-size: 0;
  overflow: hidden;
  color: var(--wa-color-text-quiet);
  font-size: var(--wa-font-size-s);
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* On phones there is room for the title (and its badge), not for the subtitle */
@media (max-width: 40rem) {
  .page-subtitle {
    display: none;
  }
}
