@layer pw-ui {
  .pw-frame-nav-item {
    position: relative;
    isolation: isolate;
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 32px;
    min-width: 0;
    width: 100%;
    border: 0;
    border-radius: 8px;
    padding: 6px 8px;
    background: transparent;
    color: inherit;
    font: inherit;
    font-size: 14px;
    font-weight: 500;
    line-height: 20px;
    cursor: pointer;
    text-decoration: none;
    text-align: start;
    transition: color 150ms ease-out;
  }
  /* Backgrounds fade by opacity on layers: Chromium runs background-color transitions on the
     compositor, and an item repainted mid-fade shows its starting color for a frame as the fade
     ends, flashing the highlight back to the item just left. */
  .pw-frame-nav-item::before,
  .pw-frame-nav-item::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: -1;
    border-radius: inherit;
    opacity: 0;
    pointer-events: none;
    transition: opacity 150ms ease-out;
  }
  .pw-frame-nav-item::before {
    background: var(--theme-sidebar-hover, var(--theme-hover));
  }
  .pw-frame-nav-item::after {
    background: var(--theme-sidebar-active-bg, var(--theme-accent-subtle));
  }
  .pw-frame-nav-item:hover,
  :where(.pw-frame-nav-row:hover, .pw-frame-nav-page:hover) > .pw-frame-nav-item,
  :where(.pw-frame-nav-row:hover > .pw-frame-nav-page) > .pw-frame-nav-item {
    /* Halfway from the sidebar's text to full contrast: a translucent text gains half its missing opacity. */
    color: oklch(
      from var(--theme-sidebar-text, var(--theme-app)) calc(l + (l - 0.5) * 0.5) c h /
      calc(alpha + (1 - alpha) * 0.5)
    );
  }
  .pw-frame-nav-item:hover::before,
  :where(.pw-frame-nav-row:hover, .pw-frame-nav-page:hover) > .pw-frame-nav-item::before,
  :where(.pw-frame-nav-row:hover > .pw-frame-nav-page) > .pw-frame-nav-item::before {
    opacity: 1;
  }
  .pw-frame-nav-item:is([aria-current], [data-selected]) {
    color: var(--theme-sidebar-active-text, var(--theme-accent));
  }
  .pw-frame-nav-item:is([aria-current], [data-selected])::before {
    opacity: 0;
  }
  .pw-frame-nav-item:is([aria-current], [data-selected])::after {
    opacity: 1;
  }
  .pw-frame-nav-item:is(:disabled, [aria-disabled]) {
    opacity: 0.5;
    cursor: not-allowed;
  }
  .pw-frame-nav-icon {
    display: flex;
    flex: 0 0 18px;
    align-items: center;
    justify-content: center;
  }
  .pw-frame-nav-icon svg {
    width: 18px;
    height: 18px;
  }
  .pw-frame-nav-label {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .pw-frame-nav-item:has(> .pw-frame-nav-text) {
    align-items: flex-start;
  }
  .pw-frame-nav-item:has(> .pw-frame-nav-text) > .pw-frame-nav-icon {
    height: 20px;
  }
  .pw-frame-nav-text {
    display: flex;
    flex: 1;
    flex-direction: column;
    min-width: 0;
  }
  .pw-frame-nav-detail {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    overflow: hidden;
    font-size: 11px;
    font-weight: 400;
    line-height: 16px;
    white-space: nowrap;
    color: color-mix(in oklch, currentColor 70%, transparent);
  }
  .pw-frame-nav-badge {
    flex-shrink: 0;
    font-size: 12px;
    font-variant-numeric: tabular-nums;
  }
  .pw-frame-nav-row {
    position: relative;
  }
  :where(.pw-frame-nav-row) > :is(.pw-frame-nav-item, .pw-frame-nav-group-heading) {
    padding-inline-end: 32px;
  }
  .pw-frame-nav-action {
    position: absolute;
    inset-block: 0;
    inset-inline-end: 6px;
    display: flex;
    align-items: center;
    opacity: 0;
    transition: opacity 150ms ease-out;
  }
  .pw-frame-nav-row:is(:hover, :focus-within) > .pw-frame-nav-action {
    opacity: 1;
  }
  /* Without hover, a hidden action could only be found by accident. */
  @media (hover: none) {
    .pw-frame-nav-action {
      opacity: 1;
    }
  }
  .pw-frame-nav-group-heading {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    border: 0;
    border-radius: 6px;
    padding: 6px 8px;
    background: transparent;
    color: var(--theme-sidebar-text, var(--theme-muted-text-color));
    font: inherit;
    font-size: 11px;
    font-weight: 500;
    line-height: 16px;
    text-align: start;
  }
  button.pw-frame-nav-group-heading {
    cursor: pointer;
  }
  .pw-frame-nav-group-count {
    flex-shrink: 0;
    font-weight: 400;
    font-variant-numeric: tabular-nums;
    opacity: 0.7;
  }
  .pw-frame-nav-group-chevron {
    width: 12px;
    height: 12px;
    flex-shrink: 0;
    transition: transform 200ms ease-out;
  }
  [data-panel-open] > .pw-frame-nav-group-chevron {
    transform: rotate(90deg);
  }
  .pw-frame-nav-group-row > .pw-frame-nav-group-chevron {
    opacity: 0.6;
  }
  /* A group with its own page: the link fills the row, and its toggle sits at the row's end. */
  .pw-frame-nav-page {
    position: relative;
  }
  :where(.pw-frame-nav-page) > .pw-frame-nav-item {
    padding-inline-end: 28px;
  }
  :where(.pw-frame-nav-row) > .pw-frame-nav-page > .pw-frame-nav-item {
    padding-inline-end: 52px;
  }
  .pw-frame-nav-group-toggle {
    position: absolute;
    inset-block: 0;
    inset-inline-end: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    border: 0;
    border-radius: 6px;
    padding: 0;
    background: transparent;
    color: inherit;
    opacity: 0.6;
    cursor: pointer;
  }
  :where(.pw-frame-nav-row) > .pw-frame-nav-page > .pw-frame-nav-group-toggle {
    inset-inline-end: 26px;
  }
  .pw-frame-nav-group-toggle:hover {
    opacity: 1;
  }
  .pw-frame-nav-group-items {
    display: grid;
    /* An auto column grows to the longest label, pushing each row's action out of the sidebar. */
    grid-template-columns: minmax(0, 1fr);
  }
  /* Nested items keep their group's icon column, as top-level items do, so nesting costs
     the sidebar no width; --pw-frame-nav-indent steps them in where a tree needs it. */
  .pw-frame-nav-group-nested {
    margin-inline-start: var(--pw-frame-nav-indent, 0px);
  }
  .pw-frame-nav-group {
    padding-block: 4px;
  }
  .pw-frame-nav-subgroup {
    padding-block: 0;
  }
  /* A flyout is a popover, not the sidebar, so its items take the popover's colors. */
  .pw-frame-nav-flyout {
    --theme-sidebar-text: var(--theme-app);
    --theme-sidebar-hover: var(--theme-hover);
    --theme-sidebar-active-bg: var(--theme-accent-subtle);
    --theme-sidebar-active-text: var(--theme-accent);
    min-width: 220px;
    padding: 6px;
  }
  [data-sidebar-mode="rail"] .pw-frame-nav-item {
    padding-inline: 0;
    justify-content: center;
    height: 40px;
  }
  /* A page's list made for a panel beside it, such as its conversations, as the navigation: its
     text one step brighter than the navigation's items, as a hovered item's is, and its secondary
     text that at 70%, as an item's second line is, with the theme's tokens for both pointed at
     these so what the page renders in its rows follows. */
  .pw-frame-list {
    --theme-app: var(--pw-frame-ink-strong);
    --theme-muted-text-color: color-mix(in oklab, var(--theme-app) 70%, transparent);
    --theme-hover: var(--pw-frame-hover);
    --theme-focus: var(--theme-app);
    --theme-border: color-mix(in oklch, var(--pw-frame-ink) 20%, transparent);
    /* A field, such as the list's search, is a tint of the navigation rather than a page's
       light or dark box. */
    --theme-input-bg: color-mix(in oklab, var(--pw-frame-ink) 8%, transparent);
    --theme-border-field: color-mix(in oklab, var(--pw-frame-ink) 22%, transparent);
    --theme-border-strong: color-mix(in oklab, var(--pw-frame-ink) 40%, transparent);
    --theme-placeholder: color-mix(in oklab, var(--theme-app) 55%, transparent);
    /* The theme's warning text is made for its panels; pulled toward the navigation's text, it
       reads on a navigation of either lightness. Oklab, so the mix keeps the warning's hue rather
       than turning through green or pink on its way to the text's. */
    --theme-warning-text: color-mix(in oklab, var(--theme-warning) 60%, var(--theme-app));
  }
  .pw-frame-list [data-sidebar-row][data-selected] {
    --theme-app: var(--pw-frame-active-ink-strong);
    --theme-muted-text-color: color-mix(in oklab, var(--theme-app) 70%, transparent);
    --theme-focus: var(--pw-frame-active-ink);
  }
  /* The row draws its own ring on its highlight's edge. */
  .pw-frame-list [data-sidebar-row] > :not([aria-haspopup="menu"]):focus-visible {
    outline: none;
  }
  /* What starts a new item and searches stays in view while the rows scroll under it. */
  .pw-frame-list-top {
    position: sticky;
    top: 0;
    z-index: 1;
    padding-block-end: 4px;
    background: var(--pw-frame-bg);
  }
  .pw-frame-list-footer {
    position: sticky;
    bottom: 0;
    padding-block-start: 4px;
    background: var(--pw-frame-bg);
  }
  .pw-frame-list-rail {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 4px;
    padding-block: 4px;
  }
  /* A tonal thumb rather than the active fill: the switch picks which list shows, and the
     navigation's fill stays for the page that is open in it. */
  .pw-frame-nav-switch {
    display: grid;
    grid-auto-columns: minmax(0, 1fr);
    grid-auto-flow: column;
    gap: 2px;
    margin-block-end: 8px;
    border-radius: 8px;
    padding: 2px;
    background: color-mix(in oklch, var(--pw-frame-ink, var(--theme-app)) 8%, transparent);
  }
  .pw-frame-nav-switch-item {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-width: 0;
    height: 28px;
    border-radius: 6px;
    padding-inline: 8px;
    color: inherit;
    font-size: 13px;
    font-weight: 500;
    line-height: 20px;
    text-decoration: none;
    transition:
      background-color 150ms ease-out,
      color 150ms ease-out;
  }
  .pw-frame-nav-switch-item:hover {
    background: var(--pw-frame-hover, var(--theme-hover));
    color: var(--pw-frame-ink-strong, var(--theme-app));
  }
  .pw-frame-nav-switch-item[aria-current] {
    background: color-mix(in oklch, var(--pw-frame-ink, var(--theme-app)) 18%, transparent);
    /* Full contrast: the sidebar's text pushed all the way to white or black. */
    color: oklch(from var(--pw-frame-ink, var(--theme-app)) calc(l + (l - 0.5)) c h / 1);
  }
  .pw-frame-sidebar .pw-frame-nav-switch-item:focus-visible,
  .pw-frame-drawer .pw-frame-nav-switch-item:focus-visible {
    outline-offset: 0;
  }
  .pw-frame-nav-switch-icon {
    display: flex;
    flex-shrink: 0;
  }
  .pw-frame-nav-switch-icon svg {
    width: 16px;
    height: 16px;
  }
  .pw-frame-nav-switch-item > .pw-frame-nav-label {
    flex: 0 1 auto;
  }
  .pw-frame-nav-switch-badge {
    flex-shrink: 0;
    font-size: 12px;
    font-variant-numeric: tabular-nums;
  }
  .pw-frame-nav-switch-rail {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    margin-block-end: 8px;
    border-block-end: 1px solid
      color-mix(in oklch, var(--pw-frame-ink, var(--theme-app)) 15%, transparent);
    padding-block-end: 8px;
  }
  @media (prefers-reduced-motion: reduce) {
    .pw-frame-nav-item,
    .pw-frame-nav-item::before,
    .pw-frame-nav-item::after,
    .pw-frame-nav-action,
    .pw-frame-nav-group-chevron,
    .pw-frame-nav-switch-item {
      transition: none;
    }
  }
}
