@layer cinder.tokens, cinder.foundation, cinder.components, cinder.utilities;
@layer cinder.components {
  /* ========================================
 * SIDEBAR
 * Layout-level vertical navigation container. Combines a nav region and an
 * optional footer. Delegates the actual list to
 * `side-navigation.svelte`. Below the default breakpoint (639.98px, so tablets keep the icon rail) the consuming
 * component swaps the inline <aside> for a <Drawer>; this stylesheet covers
 * both surfaces because the inner regions render the same elements.
 * ======================================== */

  /* The expanded column is 190px and the icon rail 56px, the widths of the shell design. */
  .cinder-sidebar {
    display: flex;
    flex-direction: column;
    inline-size: 11.875rem;
    /* Fill the parent's cross-axis. `align-self: stretch` makes a flex item
     fill its parent's cross-axis size. An explicit `block-size` here would
     opt out of stretch behavior, so we deliberately leave it off. */
    align-self: stretch;
    /* On the white light page (COR-2697) the white sidebar parts from the page by the page hairline at
     * its inline end; in dark the surface still sits a fill step above the canvas, so the edge is
     * transparent there (COR-2315). The selected row takes the soft accent tint (`navigation-item.css`). */
    position: relative;
    background: var(--cinder-surface);
    overflow: hidden;
  }

  /* The page hairline at the inline end, on an overlay that takes no layout in either theme, so the
     rail keeps its full width. `border-inline-end` stays logical through Bun's CSS bundler. */
  .cinder-sidebar::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    pointer-events: none;
    border-inline-end: var(--cinder-border-width) solid var(--_cinder-page-edge);
  }

  /* The mobile surface is rendered inside <Drawer>, which already paints its
 * own surface and borders. Don't double up. */
  .cinder-sidebar.cinder-sidebar--mobile {
    inline-size: 100%;
    block-size: 100%;
    background: transparent;
  }

  .cinder-sidebar.cinder-sidebar--mobile::after {
    border-inline-end: none;
  }

  /* The drawer paints the raised surface behind a modal sidebar: the selected row is the ink at
   * about 7% there, over whatever the drawer paints. It sets only the fill, never `box-shadow`,
   * because a vertical row draws its focus ring in that channel. */
  .cinder-sidebar--mobile .cinder-navigation-item[data-variant='vertical'][data-active='true'],
  .cinder-sidebar--mobile
    .cinder-navigation-item[data-variant='vertical'][data-active='true']:hover {
    background-color: color-mix(in oklch, var(--cinder-border-ink), transparent 93%);
  }

  /* The drawer is the phone's navigation, so its rows are touch targets (44px) whatever the
   * pointer: the list-row minimum that raises a row to 44px is zero only for a fine pointer. */
  .cinder-sidebar--mobile .cinder-navigation-item[data-variant='vertical'] {
    min-block-size: 2.75rem;
  }

  @media (max-width: 639.98px) {
    .cinder-sidebar--desktop[data-cinder-sidebar-mobile-breakpoint='639.98px'] {
      display: flex;
      inline-size: 100%;
      block-size: 100%;
      background: transparent;
    }

    .cinder-sidebar--desktop[data-cinder-sidebar-mobile-breakpoint='639.98px']::after {
      border-inline-end: none;
    }

    .cinder-sidebar--desktop[data-cinder-sidebar-mobile-breakpoint='639.98px'][data-cinder-ssr-mobile-fallback] {
      display: none;
    }

    .cinder-sidebar--desktop[data-cinder-sidebar-mobile-breakpoint='639.98px'][data-cinder-collapsed] {
      display: none;
    }
  }

  /* Collapsed (icon-only) mode applies to the inline <aside>. The mobile drawer
 * surface ignores `data-cinder-collapsed` for sizing because drawer-closed is
 * the collapsed state on mobile. */
  .cinder-sidebar[data-cinder-collapsed]:not(.cinder-sidebar--mobile) {
    inline-size: 3.5rem;
  }

  .cinder-sidebar__nav {
    flex: 1;
    overflow-y: auto;
    padding-block: var(--cinder-space-3);
    padding-inline: var(--cinder-space-2);
    display: flex;
    flex-direction: column;
    gap: var(--cinder-space-2);
  }

  .cinder-sidebar__footer {
    /* margin-block-start: auto pins the footer to the bottom of the column independent
     * of siblings — so it stays bottom-aligned even when the optional nav (which carried
     * flex: 1) is omitted. */
    margin-block-start: auto;
    padding-block: var(--cinder-space-3);
    padding-inline: var(--cinder-space-3);
    border-block-start: 1px solid var(--cinder-border-muted);
    flex-shrink: 0;
  }

  /* ----------------------------------------
 * Collapsed (icon-only) treatment for descendant items.
 *
 * Decorative chrome (group badge, chevron, panel) is hidden with `display:
 * none` because it carries no accessible name.
 *
 * A row's count pill is the exception: it rides the icon's top-right corner on the rail
 * (`side-navigation-item.css`), so the hide rules below leave it alone.
 *
 * Label-bearing text is hidden using the visually-hidden technique rather
 * than `display: none` so the accessible name of each focusable element is
 * preserved in the accessibility tree. The visual result is icon-only, but a
 * screen-reader user still hears the section header or item text when focus
 * lands on the trigger or link.
 * ---------------------------------------- */

  .cinder-sidebar[data-cinder-collapsed] .cinder-side-navigation-group__badge,
  .cinder-sidebar[data-cinder-collapsed] .cinder-side-navigation-group__chevron,
  .cinder-sidebar[data-cinder-collapsed] .cinder-side-navigation-group__panel {
    display: none;
  }

  .cinder-sidebar[data-cinder-collapsed] .cinder-side-navigation-group__trigger {
    justify-content: center;
    padding-inline: var(--cinder-space-2);
  }

  .cinder-sidebar[data-cinder-collapsed] .cinder-side-navigation-group__label,
  .cinder-sidebar[data-cinder-collapsed]
    .cinder-side-navigation
    a.cinder-navigation-item
    > :not([aria-hidden='true']):not(svg):not(img):not(.cinder-side-navigation-item__count),
  .cinder-sidebar[data-cinder-collapsed]
    .cinder-side-navigation
    button.cinder-navigation-item
    > :not([aria-hidden='true']):not(svg):not(img):not(.cinder-side-navigation-item__count),
  .cinder-sidebar[data-cinder-collapsed]
    .cinder-sidebar__footer
    a.cinder-navigation-item
    > :not([aria-hidden='true']):not(svg):not(img):not(.cinder-side-navigation-item__count),
  .cinder-sidebar[data-cinder-collapsed]
    .cinder-sidebar__footer
    button.cinder-navigation-item
    > :not([aria-hidden='true']):not(svg):not(img):not(.cinder-side-navigation-item__count) {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
  }

  /* A static section keeps its items on the icon rail, and its label becomes a hairline between
 * sections: the words stay in the accessibility tree, clipped, and the rule marks where one
 * section ends and the next begins. */
  .cinder-sidebar[data-cinder-collapsed]
    .cinder-side-navigation-group[data-cinder-static]
    > .cinder-side-navigation-group__panel {
    display: flex;
  }

  .cinder-sidebar[data-cinder-collapsed]
    .cinder-side-navigation-group[data-cinder-static]:not([data-cinder-label-hidden]) {
    margin-block-start: var(--cinder-space-2);
    padding-block-start: var(--cinder-space-2);
    border-block-start: 1px solid var(--cinder-border-muted);
  }

  .cinder-sidebar[data-cinder-collapsed]
    .cinder-side-navigation-group[data-cinder-static]
    > .cinder-side-navigation-group__heading {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
  }

  /* The brand and the primary action drop their row-aligning padding on the rail, where there is
 * no label column to line up with, and centre over the icons. */
  .cinder-sidebar[data-cinder-collapsed] .cinder-side-navigation__brand {
    justify-content: center;
    padding-inline: 0;
  }

  /* The primary action collapses to its accent "+" on the rail, and the shortcut glyph steps
 * aside. `font-size: 0` hides the bare label text, which stays in the accessible name. */
  .cinder-sidebar[data-cinder-collapsed] .cinder-side-navigation__primary-action > :is(a, button) {
    justify-content: center;
    padding-inline: 0;
    gap: 0;
    font-size: 0;
  }

  .cinder-sidebar[data-cinder-collapsed]
    .cinder-side-navigation__primary-action
    > :is(a, button)
    [data-cinder-shortcut] {
    display: none;
  }

  /* Leaf items in collapsed mode collapse to icon-only width. `font-size: 0`
 * covers bare text children that cannot be selected directly; element
 * children are additionally visually hidden above. The DOM text remains
 * available for accessible-name computation. */
  .cinder-sidebar[data-cinder-collapsed] .cinder-side-navigation a.cinder-navigation-item,
  .cinder-sidebar[data-cinder-collapsed] .cinder-side-navigation button.cinder-navigation-item,
  .cinder-sidebar[data-cinder-collapsed] .cinder-sidebar__footer a.cinder-navigation-item,
  .cinder-sidebar[data-cinder-collapsed] .cinder-sidebar__footer button.cinder-navigation-item {
    justify-content: center;
    padding-inline: var(--cinder-space-2);
    gap: 0;
    font-size: 0;
  }

  .cinder-sidebar[data-cinder-collapsed] .cinder-side-navigation a.cinder-navigation-item > svg,
  .cinder-sidebar[data-cinder-collapsed]
    .cinder-side-navigation
    button.cinder-navigation-item
    > svg,
  .cinder-sidebar[data-cinder-collapsed] .cinder-sidebar__footer a.cinder-navigation-item > svg,
  .cinder-sidebar[data-cinder-collapsed]
    .cinder-sidebar__footer
    button.cinder-navigation-item
    > svg,
  .cinder-sidebar[data-cinder-collapsed] .cinder-side-navigation a.cinder-navigation-item > img,
  .cinder-sidebar[data-cinder-collapsed]
    .cinder-side-navigation
    button.cinder-navigation-item
    > img,
  .cinder-sidebar[data-cinder-collapsed] .cinder-sidebar__footer a.cinder-navigation-item > img,
  .cinder-sidebar[data-cinder-collapsed]
    .cinder-sidebar__footer
    button.cinder-navigation-item
    > img,
  .cinder-sidebar[data-cinder-collapsed]
    .cinder-side-navigation
    a.cinder-navigation-item
    > [aria-hidden='true'],
  .cinder-sidebar[data-cinder-collapsed]
    .cinder-side-navigation
    button.cinder-navigation-item
    > [aria-hidden='true'],
  .cinder-sidebar[data-cinder-collapsed]
    .cinder-sidebar__footer
    a.cinder-navigation-item
    > [aria-hidden='true'],
  .cinder-sidebar[data-cinder-collapsed]
    .cinder-sidebar__footer
    button.cinder-navigation-item
    > [aria-hidden='true'] {
    flex-shrink: 0;
    font-size: var(--cinder-text-sm);
  }

  /* ----------------------------------------
 * Collapsed with labels (`railLabels`, COR-2315)
 *
 * The rail is 76px and draws a short label under every icon, so it needs no tooltip. It is the
 * folded sidebar above with the labels put back, so each rule below carries the extra attribute
 * and element selectors that make it outrank the folded rule it undoes, whatever order the
 * stylesheets load in.
 * ---------------------------------------- */

  .cinder-sidebar[data-cinder-collapsed][data-cinder-rail-labels]:not(.cinder-sidebar--mobile) {
    inline-size: 4.75rem;
  }

  .cinder-sidebar[data-cinder-collapsed][data-cinder-rail-labels]
    .cinder-side-navigation
    :is(a, button).cinder-side-navigation-item {
    flex-direction: column;
    justify-content: center;
    gap: var(--cinder-space-0-5);
    inline-size: 100%;
    min-block-size: 3.25rem;
    margin-inline: 0;
    padding-block: var(--cinder-space-1-5);
    padding-inline: 0;
    text-align: center;
    font-size: 0.6875rem;
    line-height: 0.875rem;
  }

  /* The labelled rail's items span the 76px rail less one step each side (68px), so the nav gives
   * up its own inline padding here: an 11px label such as "Capabilities" needs about 62px. */
  .cinder-sidebar[data-cinder-collapsed][data-cinder-rail-labels]:not(.cinder-sidebar--mobile)
    .cinder-sidebar__nav {
    padding-inline: var(--cinder-space-1);
  }

  .cinder-sidebar[data-cinder-collapsed][data-cinder-rail-labels]
    .cinder-side-navigation
    :is(a, button).cinder-side-navigation-item[data-cinder-has-icon]
    > .cinder-side-navigation-item__label {
    position: static;
    display: block;
    inline-size: auto;
    max-inline-size: 100%;
    block-size: auto;
    margin: 0;
    overflow: hidden;
    clip: auto;
    clip-path: none;
    font-size: 0.6875rem;
    line-height: 0.875rem;
    /* A navigation label never ends in an ellipsis: a name that still cannot fit in 68px wraps to
     * a second line, centred, and the row grows to hold it. */
    text-overflow: clip;
    white-space: normal;
    overflow-wrap: break-word;
    text-wrap: balance;
  }

  /* The group break on the labelled rail is one step of space each side of the hairline: the
   * padding below it, and above it the margin plus the list's own gap (a token, 2px by default),
   * which together come to the same step. */
  .cinder-sidebar[data-cinder-collapsed][data-cinder-rail-labels]
    .cinder-side-navigation-group[data-cinder-static]:not([data-cinder-label-hidden]) {
    margin-block-start: calc(
      var(--cinder-space-2) - var(--cinder-side-navigation-list-gap, var(--cinder-space-1))
    );
    padding-block-start: var(--cinder-space-2);
  }

  /* The count and the dot ride the icon's top-right corner, which is left of the row's edge now
 * that the row is the rail's full width. */
  .cinder-sidebar[data-cinder-collapsed][data-cinder-rail-labels]
    .cinder-side-navigation-item[data-cinder-has-icon]
    :is(.cinder-side-navigation-item__count, .cinder-side-navigation-item__dot) {
    inset-block-start: var(--cinder-space-1-5);
  }
  .cinder-sidebar[data-cinder-collapsed][data-cinder-rail-labels]
    .cinder-side-navigation-item[data-cinder-has-icon]
    :is(.cinder-side-navigation-item__count, .cinder-side-navigation-item__dot):where(
      :not([dir='rtl'], [dir='rtl'] *),
      [dir='rtl'] [dir='ltr'],
      [dir='rtl'] [dir='ltr'] *
    ) {
    right: calc(50% - 1.25rem);
  }
  .cinder-sidebar[data-cinder-collapsed][data-cinder-rail-labels]
    .cinder-side-navigation-item[data-cinder-has-icon]
    :is(.cinder-side-navigation-item__count, .cinder-side-navigation-item__dot):where(
      :is([dir='rtl'], [dir='rtl'] *):not([dir='rtl'] [dir='ltr'], [dir='rtl'] [dir='ltr'] *)
    ) {
    left: calc(50% - 1.25rem);
  }
}
