/*
 * App shell, docs/design.md §3: the frame is a size container; navigation, top bar and page
 * padding switch on its width (drawer from 1200px, rail from 600px, bottom bar below).
 */
.frame {
  container-type: inline-size;
  container-name: app;
}

.app {
  display: grid;
  grid-template-columns: 272px minmax(0, 1fr);
  grid-template-rows: auto 1fr;
  min-height: 100dvh;
}

.page {
  width: 100%;
  max-width: var(--page-max);
  margin: 0 auto;
  padding: var(--page-pad);
}

/* Navigation: drawer */
.nav {
  position: sticky;
  top: 0;
  grid-row: 1 / span 2;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  padding-bottom: 8px;
  overflow-y: auto;
  background: var(--nav);
  color: var(--nav-fg);
}

.nav__brand:link,
.nav__brand:visited {
  color: inherit;
  text-decoration: none;
}

.nav__brand:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.nav__brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 22px 16px;
  border-bottom: 1px solid var(--nav-line);
}

.nav__logo {
  width: 34px;
  height: auto;
}

.nav__brand-text {
  display: flex;
  flex-direction: column;
}

.nav__name {
  color: var(--white);
  font-family: var(--f-display);
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -.01em;
}

.nav__line {
  margin-top: 4px;
  color: var(--nav-dim);
  font-size: 11px;
  letter-spacing: .35em;
  text-transform: uppercase;
}

.nav__heading {
  padding: 20px 16px 6px;
  color: var(--nav-dim);
  font-size: 11px;
  letter-spacing: .35em;
  text-transform: uppercase;
}

/* Cross-tenant scope */
.nav__group--platform .nav__heading {
  color: var(--accent);
}

.nav__item {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  height: 40px;
  padding: 0 16px 0 13px;
  border: 0;
  border-left: 3px solid transparent;
  background: none;
  color: var(--nav-fg);
  font: 14px var(--f-body);
  text-decoration: none;
  cursor: pointer;
  transition: background-color var(--duration-fast) var(--ease), color var(--duration-fast) var(--ease);
}

.nav__item .ms {
  opacity: .8;
}

.nav__item:hover {
  background: var(--nav-hover);
  color: var(--white);
}

.nav__item[aria-current="page"] {
  border-left-color: var(--accent);
  background: var(--nav-active);
  color: var(--white);
  font-weight: 600;
}

.nav__item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.nav__label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* The badge of Tasks (§3.2): a lime pill, right aligned in the drawer, top right in the rail and the bottom bar. */
.nav__badge {
  flex: none;
  margin-left: auto;
  padding: 1px 7px;
  border-radius: var(--radius-pill);
  background: var(--lime);
  color: var(--on-lime);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.4;
}

.nav__more {
  display: none;
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  height: 64px;
  padding: 0 20px;
  border-bottom: var(--border);
  background: var(--bg);
}

.topbar__tenant {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  font-family: var(--f-display);
  font-size: 1.2rem;
  font-weight: 400;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* AI view control (#689): "AI connected" with "Disconnect", while the window is connected. */
.ai-view {
  display: flex;
  flex: none;
  gap: 8px;
  align-items: center;
  margin-left: auto;
}

.ai-view[hidden] {
  display: none;
}

.avatar {
  display: grid;
  flex: none;
  place-items: center;
  width: 36px;
  height: 36px;
  margin-left: auto;
  padding: 0;
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--nav);
  color: var(--white);
  font-family: var(--f-display);
  font-size: .8rem;
  cursor: pointer;
}

.avatar:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

/* User menu: a popover in the top layer, placed under the avatar (14px + 46px from the top). */
.umenu {
  position: absolute;
  inset: 60px 20px auto auto;
  width: 290px;
  max-width: calc(100vw - 24px);
  max-height: calc(100dvh - 72px);
  margin: 0;
  padding: 0 0 4px;
  overflow-y: auto;
  border: var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--fg);
  box-shadow: var(--shadow-popover);
  /* Opens with a fade and a 4px drop, closes with a fade only (#2376). */
  opacity: 0;
  transition: opacity var(--duration-fast) var(--ease-in), display var(--duration-fast) allow-discrete,
    overlay var(--duration-fast) allow-discrete;
}

.umenu:popover-open {
  opacity: 1;
  transition: opacity var(--duration-fast) var(--ease-out), transform var(--duration-fast) var(--ease-out),
    display var(--duration-fast) allow-discrete, overlay var(--duration-fast) allow-discrete;
}

@starting-style {
  .umenu:popover-open {
    opacity: 0;
    transform: translateY(-4px);
  }
}

.umenu__who {
  display: flex;
  flex-direction: column;
  padding: 14px 16px;
  border-bottom: var(--border);
  overflow-wrap: anywhere;
}

.umenu__label {
  padding: 12px 16px 4px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: .35em;
  text-transform: uppercase;
}

.umenu form {
  margin: 0;
}

.umenu__row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 16px;
  border: 0;
  background: none;
  color: var(--fg);
  font: 14px var(--f-body);
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  transition: background-color var(--duration-fast) var(--ease);
}

.umenu__row:hover {
  background: var(--surface);
}

.umenu__row:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: -2px;
}

.umenu__row[aria-current="true"] {
  font-weight: 600;
  cursor: default;
}

.umenu__row[aria-current="true"]:hover {
  background: none;
}

.umenu__check {
  margin-left: auto;
  color: var(--blue);
}

.umenu__divider {
  height: 1px;
  margin: 4px 0;
  background: var(--line);
}

/* "More" sheet of the bottom bar: all groups */
.nav-sheet {
  position: fixed;
  inset: auto 0 0;
  width: 100%;
  max-width: none;
  max-height: 80dvh;
  margin: 0;
  padding: 8px 0 calc(8px + env(safe-area-inset-bottom));
  overflow-y: auto;
  border: 0;
  background: var(--nav);
  color: var(--nav-fg);
  /* A bottom sheet: slides up from the bottom edge and back down (#2376). */
  transform: translateY(100%);
  transition: transform var(--duration) var(--ease-in), display var(--duration) allow-discrete,
    overlay var(--duration) allow-discrete;
}

.nav-sheet::backdrop {
  background: rgba(10, 10, 10, .4);
  opacity: 0;
  transition: opacity var(--duration) var(--ease-in), display var(--duration) allow-discrete,
    overlay var(--duration) allow-discrete;
}

.nav-sheet:popover-open {
  transform: none;
  transition: transform var(--duration-swap) var(--ease-out), display var(--duration-swap) allow-discrete,
    overlay var(--duration-swap) allow-discrete;
}

.nav-sheet:popover-open::backdrop {
  opacity: 1;
  transition: opacity var(--duration-swap) var(--ease-out), display var(--duration-swap) allow-discrete,
    overlay var(--duration-swap) allow-discrete;
}

@starting-style {
  .nav-sheet:popover-open {
    transform: translateY(100%);
  }

  .nav-sheet:popover-open::backdrop {
    opacity: 0;
  }
}

/* Rail: 600-1199px */
@container app (max-width: 1199px) {
  .app {
    grid-template-columns: 84px minmax(0, 1fr);
  }

  .page {
    --page-pad: 28px 24px 64px;
  }

  .nav .nav__brand {
    justify-content: center;
    padding: 18px 0;
  }

  .nav .nav__brand-text,
  .nav .nav__heading {
    display: none;
  }

  .nav .nav__group + .nav__group::before {
    content: "";
    display: block;
    height: 1px;
    margin: 6px 14px;
    background: var(--nav-line);
  }

  .nav .nav__item {
    position: relative;
    flex-direction: column;
    gap: 2px;
    width: auto;
    height: auto;
    margin: 1px 8px;
    padding: 8px 4px;
    border-left: 0;
    border-radius: var(--radius-rail);
    font-size: 11px;
    line-height: 1.2;
    text-align: center;
  }

  .nav .nav__item[aria-current="page"] {
    background: var(--nav-active-compact);
  }

  .nav .nav__badge {
    position: absolute;
    top: 2px;
    right: 6px;
  }

  .nav .nav__label {
    max-width: 68px;
  }
}

/* Bottom bar: below 600px */
@container app (max-width: 599px) {
  .app {
    --bottom-bar-height: 64px;

    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto 1fr auto;
  }

  .page {
    --page-pad: 20px 16px 40px;
  }

  .nav {
    top: auto;
    bottom: 0;
    z-index: 5;
    grid-row: 3;
    flex-direction: row;
    height: auto;
    min-height: calc(var(--bottom-bar-height) + env(safe-area-inset-bottom, 0px));
    padding: 0 0 env(safe-area-inset-bottom);
    overflow: visible;
    border-top: 1px solid var(--nav-line);
  }

  /* The toast floats 24px above the bottom bar instead of covering it. */
  .app .toast {
    bottom: calc(var(--bottom-bar-height) + 24px + env(safe-area-inset-bottom, 0px));
  }

  .nav:not(:has(.nav__item)),
  .nav .nav__brand,
  .nav .nav__item:not(.nav__item--primary, .nav__more) {
    display: none;
  }

  .nav .nav__group {
    display: contents;
  }

  .nav .nav__group + .nav__group::before {
    content: none;
  }

  .nav .nav__item {
    flex: 1;
    min-width: 0;
    margin: 6px 2px;
    padding: 6px 0;
  }

  .nav .nav__more {
    display: flex;
  }

  .topbar {
    gap: 8px;
    padding: 0 12px;
  }

  .umenu {
    inset: 60px 12px auto auto;
  }
}

/* Help (#1213): the handbook page of the current view, right before the avatar. */
.topbar__help {
  display: grid;
  flex: none;
  place-items: center;
  width: 36px;
  height: 36px;
  margin-left: auto;
  border-radius: var(--radius-pill);
  color: var(--muted);
  text-decoration: none;
}

.topbar__help:hover {
  background: var(--surface);
  color: var(--fg);
}

.topbar__help:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

.topbar__help + .avatar {
  margin-left: 0;
}

/* Report a problem (#1230): before help; on a phone only its icon, its name stays the link's label. */
.topbar__problem {
  flex: none;
  margin-left: auto;
}

.topbar__problem + .dlg + .topbar__help {
  margin-left: 0;
}

@container app (max-width: 599px) {
  .topbar__problem-label {
    display: none;
  }
}

/* #1907: the dry-run notice above the frame on every page while ONESHOT_DRY_RUN is on. */
.dry-run-notice {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 0;
  padding: 8px 16px;
  background: var(--lime);
  color: var(--on-lime);
  font-weight: 600;
  text-align: center;
}
