@layer organisms {
  .ui-body.has-app-shell-sidebar {
    --app-shell-sidebar-expanded-width: 18.5rem;
    --app-shell-sidebar-collapsed-width: 5.5rem;
    --app-shell-sidebar-rail-width: var(--app-shell-sidebar-collapsed-width);
    --app-shell-sidebar-surface: linear-gradient(180deg, rgb(255 255 255 / 0.96), rgb(255 255 255 / 0.9));
    --app-shell-sidebar-border: color-mix(in srgb, var(--color-brand-primary) 14%, white);
    --app-shell-sidebar-shadow: 0 20px 38px rgb(15 23 42 / 0.1);
    --app-shell-sidebar-accent: color-mix(in srgb, white 76%, var(--color-brand-primary) 24%);
    --app-shell-sidebar-accent-strong: color-mix(in srgb, white 64%, var(--color-brand-primary) 36%);
    --app-shell-sidebar-featured: color-mix(in srgb, white 40%, #d95f02 60%);
    --app-shell-sidebar-featured-text: #5c2600;
  }

  .ui-shell__layout {
    display: block;
  }

  .ui-shell__layout--with-sidebar {
    display: grid;
    grid-template-columns: var(--app-shell-sidebar-rail-width) minmax(0, 1fr);
    align-items: stretch;
    min-height: calc(100dvh - 4rem);
    transition: grid-template-columns var(--transition-base);
  }

  .ui-body.is-app-shell-expanded .ui-shell__layout--with-sidebar {
    --app-shell-sidebar-rail-width: var(--app-shell-sidebar-expanded-width);
  }

  .ui-shell__main {
    min-width: 0;
    padding-inline-start: clamp(var(--space-3), 1vw, var(--space-5));
  }

  .ui-header__shell-trigger {
    display: inline-grid;
    place-items: center;
    width: 2.85rem;
    min-height: 2.85rem;
    border: var(--border-width) solid var(--ui-header-control-border);
    border-radius: var(--radius-md);
    background: rgb(255 255 255 / 0.14);
    color: var(--ui-header-text);
    box-shadow: 0 10px 24px rgb(15 23 42 / 0.12);
    transition:
      border-color var(--transition-fast),
      background var(--transition-fast),
      transform var(--transition-fast);
  }

  .ui-header__shell-trigger:hover,
  .ui-header__shell-trigger:focus-visible {
    border-color: rgb(255 255 255 / 0.86);
    background: rgb(255 255 255 / 0.24);
    transform: translateY(-1px);
  }

  .ui-header__shell-trigger img {
    width: 1.25rem;
    height: 1.25rem;
    filter: brightness(0) invert(1);
  }

  .app-shell-sidebar {
    position: sticky;
    top: 4rem;
    z-index: calc(var(--z-header) - 2);
    align-self: start;
    min-height: calc(100dvh - 4rem);
    padding: var(--space-3);
  }

  .app-shell-sidebar__surface {
    display: grid;
    grid-template-rows: auto 1fr;
    gap: var(--space-5);
    min-height: calc(100dvh - 4.75rem);
    padding: var(--space-3);
    border-right: var(--border-width) solid var(--app-shell-sidebar-border);
    border-radius: 0 1.4rem 1.4rem 0;
    background: var(--app-shell-sidebar-surface);
    box-shadow: var(--app-shell-sidebar-shadow);
    backdrop-filter: blur(14px);
    overflow: clip;
  }

  .app-shell-sidebar__header {
    display: grid;
  }

  .app-shell-sidebar__brand {
    display: grid;
    gap: var(--space-2);
    padding: var(--space-3);
    border: var(--border-width) solid color-mix(in srgb, var(--color-brand-primary) 12%, white);
    border-radius: 1.1rem;
    background: color-mix(in srgb, white 82%, var(--color-brand-primary) 18%);
    box-shadow: var(--shadow-sm);
  }

  .app-shell-sidebar__eyebrow,
  .app-shell-sidebar__section-title {
    margin: 0;
    color: var(--color-brand-secondary);
    font-size: var(--font-size-xs);
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }

  .app-shell-sidebar__title {
    color: var(--color-text);
    font: 700 1.18rem var(--font-secondary);
    line-height: 1.1;
  }

  .app-shell-sidebar__summary {
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
    line-height: 1.45;
    overflow-wrap: anywhere;
  }

  .app-shell-sidebar__sections {
    display: grid;
    align-content: start;
    gap: var(--space-5);
  }

  .app-shell-sidebar__section {
    display: grid;
    gap: var(--space-2);
  }

  .app-shell-sidebar__nav {
    display: grid;
    gap: var(--space-2);
  }

  .app-shell-sidebar__link {
    position: relative;
    display: grid;
    grid-template-columns: 2.5rem minmax(0, 1fr);
    align-items: center;
    gap: var(--space-3);
    width: 100%;
    min-height: 3rem;
    border: 0;
    border-radius: 1rem;
    background: transparent;
    color: var(--color-text);
    font: inherit;
    font-size: var(--font-size-sm);
    font-weight: 600;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
    padding: 0.45rem 0.7rem;
    transition:
      background var(--transition-fast),
      color var(--transition-fast),
      transform var(--transition-fast),
      box-shadow var(--transition-fast);
  }

  .app-shell-sidebar__link:hover,
  .app-shell-sidebar__link:focus-visible {
    background: var(--app-shell-sidebar-accent);
    transform: translateX(1px);
  }

  .app-shell-sidebar__link.is-active {
    background: var(--app-shell-sidebar-accent-strong);
    box-shadow: inset 0.28rem 0 0 var(--color-brand-secondary);
  }

  .app-shell-sidebar__link.is-featured {
    background: var(--app-shell-sidebar-featured);
    color: var(--app-shell-sidebar-featured-text);
    box-shadow: 0 12px 24px rgb(217 95 2 / 0.18);
  }

  .app-shell-sidebar__link.is-featured .app-shell-sidebar__icon {
    background: rgb(255 255 255 / 0.78);
  }

  .app-shell-sidebar__icon {
    display: inline-grid;
    place-items: center;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 0.9rem;
    background: color-mix(in srgb, white 68%, var(--color-brand-primary) 32%);
    box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.3);
  }

  .app-shell-sidebar__icon img {
    width: 1.1rem;
    height: 1.1rem;
    object-fit: contain;
    filter: brightness(0) saturate(100%) invert(33%) sepia(28%) saturate(989%) hue-rotate(136deg) brightness(94%)
      contrast(91%);
  }

  .app-shell-sidebar__link.is-active .app-shell-sidebar__icon img,
  .app-shell-sidebar__link:hover .app-shell-sidebar__icon img,
  .app-shell-sidebar__link:focus-visible .app-shell-sidebar__icon img {
    filter: brightness(0) saturate(100%) invert(21%) sepia(25%) saturate(1163%) hue-rotate(146deg) brightness(90%)
      contrast(92%);
  }

  .app-shell-sidebar__label {
    min-width: 0;
    line-height: 1.2;
    overflow-wrap: anywhere;
  }

  .app-shell-sidebar__backdrop {
    display: none;
  }

  .ui-body.has-app-shell-sidebar:not(.is-app-shell-expanded) .app-shell-sidebar__surface {
    justify-items: center;
    border-radius: 0 1.25rem 1.25rem 0;
    padding-inline: var(--space-2);
  }

  .ui-body.has-app-shell-sidebar:not(.is-app-shell-expanded) .app-shell-sidebar__brand {
    justify-items: center;
    width: 100%;
    padding-inline: var(--space-2);
  }

  .ui-body.has-app-shell-sidebar:not(.is-app-shell-expanded) :is(
    .app-shell-sidebar__eyebrow,
    .app-shell-sidebar__title,
    .app-shell-sidebar__summary,
    .app-shell-sidebar__section-title,
    .app-shell-sidebar__label
  ) {
    width: 0;
    height: 0;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
  }

  .ui-body.has-app-shell-sidebar:not(.is-app-shell-expanded) .app-shell-sidebar__sections,
  .ui-body.has-app-shell-sidebar:not(.is-app-shell-expanded) .app-shell-sidebar__section,
  .ui-body.has-app-shell-sidebar:not(.is-app-shell-expanded) .app-shell-sidebar__nav {
    width: 100%;
  }

  .ui-body.has-app-shell-sidebar:not(.is-app-shell-expanded) .app-shell-sidebar__link {
    grid-template-columns: 1fr;
    justify-items: center;
    padding-inline: 0;
  }

  .ui-body.has-app-shell-sidebar:not(.is-app-shell-expanded) .app-shell-sidebar__link::after {
    content: attr(data-sidebar-tooltip);
    position: absolute;
    top: 50%;
    left: calc(100% + var(--space-2));
    transform: translateY(-50%) translateX(-0.2rem);
    opacity: 0;
    pointer-events: none;
    white-space: nowrap;
    border-radius: var(--radius-sm);
    background: rgb(15 23 42 / 0.92);
    color: white;
    font-size: var(--font-size-xs);
    font-weight: 600;
    padding: 0.45rem 0.65rem;
    transition:
      opacity var(--transition-fast),
      transform var(--transition-fast);
  }

  .ui-body.has-app-shell-sidebar:not(.is-app-shell-expanded) .app-shell-sidebar__link:hover::after,
  .ui-body.has-app-shell-sidebar:not(.is-app-shell-expanded) .app-shell-sidebar__link:focus-visible::after {
    opacity: 1;
    transform: translateY(-50%) translateX(0);
  }

  @media (max-width: 64rem) {
    .ui-shell__layout--with-sidebar {
      grid-template-columns: 1fr;
    }

    .ui-shell__main {
      padding-inline-start: 0;
    }

    .app-shell-sidebar {
      position: fixed;
      inset: 4.7rem auto 0 0;
      width: min(19rem, calc(100vw - 1rem));
      min-height: calc(100dvh - 4.7rem);
      padding: var(--space-2);
      transform: translateX(-110%);
      opacity: 0;
      transition:
        transform var(--transition-base),
        opacity var(--transition-base);
    }

    .app-shell-sidebar__surface {
      min-height: calc(100dvh - 5.1rem);
      border-radius: 0 1.4rem 1.4rem 0;
      padding-inline: var(--space-3);
    }

    .ui-body.has-app-shell-sidebar :is(
      .app-shell-sidebar__eyebrow,
      .app-shell-sidebar__title,
      .app-shell-sidebar__summary,
      .app-shell-sidebar__section-title,
      .app-shell-sidebar__label
    ) {
      width: auto;
      height: auto;
      overflow: visible;
      opacity: 1;
      pointer-events: auto;
    }

    .ui-body.has-app-shell-sidebar .app-shell-sidebar__link {
      grid-template-columns: 2.5rem minmax(0, 1fr);
      justify-items: stretch;
      padding-inline: 0.7rem;
    }

    .ui-body.has-app-shell-sidebar .app-shell-sidebar__link::after {
      display: none;
    }

    .ui-body.is-app-shell-open .app-shell-sidebar {
      transform: translateX(0);
      opacity: 1;
    }

    .app-shell-sidebar__backdrop {
      position: fixed;
      inset: 4rem 0 0;
      z-index: calc(var(--z-header) - 3);
      display: block;
      border: 0;
      background: rgb(15 23 42 / 0.42);
      opacity: 0;
      pointer-events: none;
      transition: opacity var(--transition-base);
    }

    .ui-body.is-app-shell-open .app-shell-sidebar__backdrop {
      opacity: 1;
      pointer-events: auto;
    }
  }

  @media (max-width: 48rem) {
    .ui-header__shell-trigger {
      order: -1;
    }
  }
}
