/* Cursor's grouped application shell. Scope every layout override to the
   signed-in shell so public and shared pages keep their compact header. */
body.app-navigation {
  --app-sidebar-width: 14rem;
  --app-header-height: calc(3.5rem + 1px);
  --app-phone-nav-height: calc(4rem + 1px);
}

/* Anchor navigation, browser focus scrolling and scrollIntoView must leave
   targets clear of the persistent header and phone actions. Safari 16 (the
   supported web floor) supports :has; public layouts do not get these offsets. */
html:has(> body.app-navigation) {
  scroll-padding-top: 4.5rem;
}

.app-navigation .top-nav.top-nav--grouped {
  position: sticky;
  top: 0;
  z-index: 50;
}

.app-navigation .top-nav--grouped .top-nav-inner {
  width: 100%;
  max-width: none;
}

.top-nav--grouped .app-sidebar,
.top-nav--grouped .mobile-primary-nav {
  display: none;
}

.top-nav--grouped .nav-group {
  min-width: 0;
  flex-shrink: 0;
}

.top-nav--grouped .nav-group + .nav-group {
  margin-top: 1.125rem;
}

.top-nav--grouped .nav-group-title {
  margin: 0 0 0.25rem;
  padding: 0 0.75rem;
  font-size: 0.6875rem;
  font-weight: 700;
  line-height: 1.5;
  letter-spacing: 0.075em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.top-nav--grouped .nav-group[data-current="true"] .nav-group-title {
  color: var(--color-accent);
}

.top-nav--grouped .nav-group-links {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

.top-nav--grouped .nav-group-links .nav-link {
  display: flex;
  align-items: center;
  min-width: 0;
  min-height: 2.75rem;
  padding: 0.5rem 0.75rem;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  line-height: 1.4;
  overflow-wrap: anywhere;
  text-decoration: none;
  color: var(--color-text-muted);
}

.top-nav--grouped .nav-group-links .nav-link:hover {
  background: var(--color-primary);
  color: var(--color-text);
}

.top-nav--grouped .nav-group-links .nav-link[aria-current] {
  background: color-mix(in srgb, var(--color-accent) 12%, var(--color-surface));
  color: var(--color-accent);
  font-weight: 600;
  box-shadow: inset 3px 0 0 var(--color-accent);
}

.top-nav--grouped :is(.nav-link, .mobile-primary-link, .mobile-more-button):focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

@media (min-width: 1024px) {
  .app-navigation .top-nav--grouped .top-nav-inner {
    padding-inline: 1.25rem;
  }

  .app-navigation .top-nav--grouped .app-sidebar {
    position: fixed;
    display: block;
    top: var(--app-header-height);
    bottom: 0;
    left: 0;
    width: var(--app-sidebar-width);
    padding: 1.125rem 0.75rem 1.5rem;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    scrollbar-width: thin;
    border-right: 1px solid var(--color-border-subtle);
    background: var(--color-surface);
  }

  .top-nav--grouped .app-sidebar .nav-group + .nav-group {
    margin-top: 0.75rem;
  }

  .top-nav--grouped .app-sidebar .nav-group-links .nav-link {
    min-height: 2.25rem;
    padding-block: 0.375rem;
  }

  .app-navigation #main.app-main {
    width: auto;
    min-width: 0;
    max-width: none;
    margin-inline-start: var(--app-sidebar-width);
    margin-inline-end: 0;
    padding-inline: clamp(1.25rem, 2.5vw, 2.5rem);
    padding-bottom: 2rem;
  }

  /* The Lab's run controls live inside this sticky bench on desktop. Its
     measured left edge already follows the main content beside the sidebar. */
  .app-navigation .pss .pss-bench {
    top: calc(var(--app-header-height) + 1rem);
  }
}

@media (max-width: 1023px) {
  html:has(> body.app-navigation) {
    scroll-padding-bottom: calc(5.5rem + env(safe-area-inset-bottom, 0px));
  }

  html:has(> body.app-navigation .top-nav-active-org) {
    scroll-padding-top: 7.25rem;
  }

  .app-navigation #main.app-main {
    min-width: 0;
    padding-bottom: calc(var(--app-phone-nav-height) + 1.5rem + env(safe-area-inset-bottom, 0px));
  }

  .app-navigation .top-nav--grouped .mobile-primary-nav {
    position: fixed;
    z-index: 70;
    right: 0;
    bottom: 0;
    left: 0;
    display: flex;
    min-height: var(--app-phone-nav-height);
    padding: 0.25rem max(0.375rem, env(safe-area-inset-right, 0px))
      calc(0.25rem + env(safe-area-inset-bottom, 0px)) max(0.375rem, env(safe-area-inset-left, 0px));
    border-top: 1px solid var(--color-border-subtle);
    background: var(--color-surface);
    box-shadow: 0 -4px 16px rgb(0 0 0 / 0.04);
  }

  .app-navigation .top-nav--grouped .mobile-primary-link,
  .app-navigation .top-nav--grouped .top-nav-menu-button.mobile-more-button {
    display: flex;
    flex: 1 1 0;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.125rem;
    min-width: 0;
    min-height: 3.5rem;
    width: auto;
    height: auto;
    padding: 0.25rem;
    border: 0;
    border-radius: 0.5rem;
    background: transparent;
    color: var(--color-text-muted);
    font-size: 0.75rem;
    font-weight: 500;
    line-height: 1.25;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
  }

  .top-nav--grouped .mobile-primary-nav .nav-item-icon {
    display: block;
    width: 1.25rem;
    height: 1.25rem;
    flex: 0 0 auto;
  }

  .top-nav--grouped .mobile-primary-nav .nav-item-icon svg {
    display: block;
    width: 100%;
    height: 100%;
  }

  .app-navigation .top-nav--grouped .mobile-primary-link:hover,
  .app-navigation .top-nav--grouped .top-nav-menu-button.mobile-more-button:hover {
    background: var(--color-primary);
    color: var(--color-text);
  }

  .app-navigation .top-nav--grouped .mobile-primary-link[aria-current],
  .app-navigation .top-nav--grouped .top-nav-menu-button.mobile-more-button[data-current="true"],
  .app-navigation .top-nav--grouped .top-nav-menu-button.mobile-more-button[aria-expanded="true"] {
    background: color-mix(in srgb, var(--color-accent) 10%, var(--color-surface));
    color: var(--color-accent);
  }

  .app-navigation .top-nav--grouped .top-nav-mobile-panel {
    position: fixed;
    z-index: 60;
    top: auto;
    right: 0;
    bottom: calc(var(--app-phone-nav-height) + env(safe-area-inset-bottom, 0px));
    left: 0;
    max-height: min(65vh, calc(100vh - 12rem), 36rem);
    max-height: min(65dvh, calc(100dvh - 12rem), 36rem);
    padding: 1rem 0.75rem 1.25rem;
    border: 1px solid var(--color-border-subtle);
    border-bottom: 0;
    border-radius: 0.875rem 0.875rem 0 0;
    background: var(--color-surface);
    box-shadow: 0 -8px 24px rgb(0 0 0 / 0.12);
  }

  .app-navigation .top-nav--grouped .top-nav-mobile-panel .nav-group-links .nav-link {
    padding: 0.625rem 0.75rem;
  }

  .app-navigation .top-nav--grouped .top-nav-org-menu {
    margin: 0 0.75rem 0.75rem;
    padding-bottom: 0.75rem;
  }

  /* Existing task actions remain above the app-wide navigation. Only the
     bottom navigation owns the home-indicator inset, so the Lab bar keeps
     its original 64px control area instead of counting that inset twice. */
  .app-navigation .pss .pss-runbar,
  .app-navigation [data-testid="sticky-commit"] {
    bottom: calc(var(--app-phone-nav-height) + env(safe-area-inset-bottom, 0px));
  }

  .app-navigation .pss .pss-runbar {
    height: 64px;
    padding-bottom: 0.625rem;
  }

  .app-navigation .pss {
    padding-bottom: 5rem;
  }

  .app-navigation .pss .pss-back {
    bottom: calc(var(--app-phone-nav-height) + 64px + env(safe-area-inset-bottom, 0px) + 0.75rem);
  }

  html:has(> body.app-navigation .pss) {
    scroll-padding-bottom: calc(9.5rem + env(safe-area-inset-bottom, 0px));
  }

  .app-navigation .pss :is(input, select, textarea, button, summary, a) {
    scroll-margin-bottom: 1rem;
  }
}

@media print {
  .app-navigation .top-nav--grouped {
    display: none;
  }

  .app-navigation #main.app-main {
    width: auto;
    max-width: none;
    margin-inline: 0;
    padding-bottom: 0;
  }
}
