html {
  overscroll-behavior: none;
}

body {
  --footer-height: calc((var(--block-space)) + 3.6em + var(--block-space));
  --navbar-height: 4.125em;
  --sidebar-width: 0vw;

  block-size: var(--app-height, 100dvh); /* fix height so grid and #main-content get definite size and main scrolls */
  display: grid;
  grid-template-areas:
    "nav sidebar"
    "main sidebar";
  grid-template-columns: 1fr var(--sidebar-width);
  grid-template-rows: min-content 1fr;
  height: var(--app-height, 100dvh); /* Chrome/WebKit: force fixed height so grid row gets definite size (min-height alone lets body grow) */
  max-block-size: var(--app-height, 100dvh);
  max-height: var(--app-height, 100dvh);
  min-block-size: 0;
  min-height: 0; /* Chrome/WebKit: grid row must shrink so main scroll works */
  overflow: hidden; /* clip so only #main-content and #sidebar scroll, not the document */

  &.sidebar {
    @media (min-width: 67.5rem) {
      --sidebar-width: 26vw;
    }
  }
}

#app-logo {
  display: none;

  @media (min-width: 67.5rem) {
    block-size: var(--footer-height);
    display: grid;
    filter: saturate(0);
    inline-size: 5vw;
    inset: auto auto 0 0;
    opacity: 0.5;
    padding-inline: 1vw;
    place-items: center;
    position: absolute;
    transition: opacity 500ms ease-in-out, filter 500ms ease-in-out;

    & img {
      block-size: auto;
      inline-size: 100%;
      max-inline-size: 2.75em;
    }

    &:hover {
      filter: none;
      opacity: 1;
    }
  }
}

#nav {
  grid-area: nav;
}

#main-content {
  align-content: start;
  background-color: var(--color-bg);
  display: flex;
  flex-direction: column;
  grid-area: main;
  min-block-size: 0; /* allow shrink so grid gives definite height */
  min-height: 0; /* Chrome/WebKit: flex child must shrink so #main-scroll gets bounded height */
  overflow: hidden; /* scroll happens in #main-scroll */
  position: relative;

  .sidebar & {
    justify-content: end;

    @media (min-width: 67.5rem) {
      border-inline: 1px solid var(--color-border-darker);
      margin-inline: 5vw 0;
    }

    /* Mobile: main content hidden by default, sidebar is home */
    @media (max-width: 67.4375rem) {
      opacity: 0;
      pointer-events: none;
      position: fixed;
      visibility: hidden;
    }
  }

  /* Mobile: show main content when in a room */
  .sidebar.in-room & {
    @media (max-width: 67.4375rem) {
      background-color: var(--color-bg);
      inset: 0;
      opacity: 1;
      pointer-events: auto;
      position: fixed;
      visibility: visible;
      z-index: 4;
    }
  }
}

/* Explicit scroll container so long pages (profile, account/edit, etc.) scroll */
.main-content__scroll {
  display: flex;
  flex-direction: column;
  flex: 1 1 0;
  height: 0; /* Chrome/WebKit: force flex item to take remaining space only */
  min-block-size: 0;
  min-height: 0;
  overflow-y: auto; /* scroll here when content overflows (e.g. account/edit); room page scrolls in .messages */
  -webkit-overflow-scrolling: touch;
}

/* Room page: .messages is direct child and becomes the scroll container */
.main-content__scroll > .messages {
  flex: 1 1 0;
  min-block-size: 0;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

#sidebar {
  grid-area: sidebar;
  position: relative;

  .sidebar & {
    -webkit-backdrop-filter: blur(66px);
    backdrop-filter: blur(66px);
    background-color: oklch(var(--lch-white) / 0.66);
    block-size: var(--app-height, 100dvh);
    max-block-size: var(--app-height, 100dvh);
    min-block-size: 0; /* allow grid item to shrink so inner scroll works */
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 3;

    /* Mobile: sidebar is HOME — full screen, solid background */
    @media (max-width: 67.4375rem) {
      background-color: var(--color-bg);
      block-size: var(--app-height, 100dvh);
      inline-size: 100vw;
      inset: 0;
      position: fixed;
    }
  }

  /* Constrain turbo-frame so .sidebar__container can scroll */
  .sidebar & > * {
    display: flex;
    flex-direction: column;
    flex: 1 1 0;
    min-block-size: 0;
    overflow: hidden;
  }
}

#footer {
  grid-area: footer;
  flex-shrink: 0;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
