@layer cinder.tokens, cinder.foundation, cinder.components, cinder.utilities;
@layer cinder.components {
  /* ========================================
 * NAVIGATION ITEM
 * ======================================== */

  .cinder-navigation-item {
    display: inline-flex;
    align-items: center;
    gap: var(--cinder-space-2);
    min-height: 2rem;
    padding-inline: var(--cinder-space-3);
    padding-block: var(--cinder-space-1-5);

    font-size: var(--cinder-text-sm);
    font-weight: var(--cinder-font-medium);
    line-height: var(--cinder-leading-none);
    text-decoration: none;

    color: var(--cinder-text-muted);
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    border-radius: var(--cinder-radius-sm) var(--cinder-radius-sm) 0 0;

    cursor: pointer;
    user-select: none;

    transition:
      color var(--cinder-duration-fast) var(--cinder-ease-standard),
      border-color var(--cinder-duration-fast) var(--cinder-ease-standard),
      background-color var(--cinder-duration-fast) var(--cinder-ease-standard);
  }

  /* A row divider separates stacked rows. Tabs a NavigationBar sets side by side, in its top row or
   * its bottom bar, draw none: there it reads as a short underline beneath every tab but the last.
   * The bar is part of both selectors because `horizontal` is also the default variant of an item
   * that a side navigation stacks. */
  .cinder-navigation-bar
    .cinder-navigation-item[data-variant='horizontal'][data-cinder-row-divider]::after,
  .cinder-navigation-bar[data-cinder-placement='bottom']
    .cinder-navigation-item[data-cinder-row-divider]::after {
    content: none;
  }

  /* ----------------------------------------
 * Hover — only when interactive (not disabled)
 * ---------------------------------------- */

  /* Sticky-hover suppression on touch: wrap hover-only chrome so it doesn't
 * "stick" after tap on touch devices that emulate :hover. */
  @media (hover: hover) {
    .cinder-navigation-item:hover:not([aria-disabled='true']) {
      color: var(--cinder-text-default);
      background-color: var(--cinder-surface-hover);
    }
  }

  /* ----------------------------------------
 * Focus visible
 * ---------------------------------------- */

  .cinder-navigation-item:focus-visible {
    outline: var(--cinder-ring-width) solid transparent;
    /* Ring replaces the border while focused rather than stacking on it — the two
       together read as one heavier shape than either was designed to be. */
    border-color: transparent;
    box-shadow: var(--_cinder-focus-ring-shadow);
  }

  /* Forced Colors Mode — box-shadow focus rings are invisible; use a real outline. */
  @media (forced-colors: active) {
    .cinder-navigation-item:focus-visible {
      outline: var(--cinder-ring-width) solid ButtonText;
      outline-offset: 3px;
    }
  }

  /* Vertical-variant focus ring — Strategy B-inset.
   *
   * Vertical items are full-bleed to the SideNavigation container edges
   * (`inline-size: 100%` below, inside an unpadded list/nav). The standard
   * OUTSET ring (offset 1px + width 3px = 4px overhang on every side) has no
   * gutter to grow into: it bleeds past the container boundary (clipped where
   * the app sidebar sets `overflow: hidden`) and overlaps the adjacent active
   * row's raised background, flattening the focus signal.
   * The policy-sanctioned B-inset variant (focus-ring-policy.md, trigger #1:
   * focusable row full-bleed against a container edge) paints a single-band
   * ring entirely within the item's own border box — no overhang, no neighbor
   * or container bleed, zero layout shift. The horizontal variant keeps the
   * outset ring (it is not full-bleed and lives on a different surface), so the
   * inset ring is scoped strictly to `[data-variant='vertical']`. The
   * `[data-variant='vertical']` attribute selector (specificity 0,2,0) wins
   * over the base rule (0,1,0) regardless of order; it is placed after for
   * clarity. The `--_cinder-navigation-item-ring` fallback hook matches the
   * tab/dropdown/number-input inset-ring convention so a variant can recolor
   * the ring without re-authoring the shadow. */
  .cinder-navigation-item[data-variant='vertical']:focus-visible {
    outline: var(--cinder-ring-width) solid transparent;
    box-shadow: inset 0 0 0 var(--cinder-ring-width)
      var(--_cinder-navigation-item-ring, var(--cinder-ring-color));
  }

  /* ----------------------------------------
 * Active state
 * ---------------------------------------- */

  .cinder-navigation-item[data-active='true'] {
    color: var(--cinder-text-default);
    border-bottom-color: var(--cinder-accent-solid);
  }

  /* ----------------------------------------
 * Disabled state
 * ---------------------------------------- */

  .cinder-navigation-item[aria-disabled='true'] {
    color: var(--cinder-text-disabled);
    cursor: not-allowed;
  }

  /* ----------------------------------------
 * Button-specific reset (when rendered as <button>)
 * ---------------------------------------- */

  button.cinder-navigation-item {
    appearance: none;
    background: transparent;
    padding-inline: var(--cinder-space-3);
  }

  /* ----------------------------------------
 * Icon and label (the `icon` snippet)
 *
 * The glyph is a 16px decoration beside the label; a bottom NavigationBar stacks it above the
 * label at 20px (`navigation-bar.css`). The label gives up room before the glyph does.
 * ---------------------------------------- */

  .cinder-navigation-item__icon {
    display: inline-flex;
    flex: none;
    align-items: center;
    justify-content: center;
  }

  .cinder-navigation-item__icon > svg {
    inline-size: 1rem;
    block-size: 1rem;
  }

  .cinder-navigation-item__label {
    min-inline-size: 0;
  }

  /* ----------------------------------------
 * Vertical variant — sidebar / vertical-tab contexts
 *
 * Row geometry for sidebar edges. The active row is a filled pill, never an accent stripe
 * (COR-1821), so toggling active state never shifts the label.
 * ---------------------------------------- */

  /* One control, one 30px row (COR-2010, rows 02m to 02p). Hover, focus and the active fill all
   * paint this whole box, never only the label or the icon. The row is 30px with a real line height
   * so descenders are never clipped, and a coarse pointer raises it to the list-row minimum (44px)
   * through `--cinder-list-row-min-height`, which is zero for a fine pointer. */
  .cinder-navigation-item[data-variant='vertical'] {
    display: flex;
    inline-size: 100%;
    box-sizing: border-box;
    justify-content: flex-start;
    gap: var(--cinder-space-2);
    min-block-size: max(1.875rem, var(--cinder-list-row-min-height));
    padding-inline: var(--cinder-space-2);
    padding-block: 0;
    font-weight: var(--cinder-font-medium);
    line-height: 1.25rem;
    border-bottom: none;
    border-radius: var(--cinder-radius-sm);
  }

  /* A disabled sidebar row differs from an enabled one by more than colour (COR-2665): the enabled
   * rows are muted text at the medium weight, so the disabled colour alone was a few points of
   * lightness away. The regular weight sets it apart in either theme, with no stripe or border;
   * a `disabledReason` (SideNavigation.Item) adds a second line that says why. */
  .cinder-navigation-item[data-variant='vertical'][aria-disabled='true'] {
    color: var(--cinder-text-disabled);
    font-weight: var(--cinder-font-normal);
  }

  /* The current page is a flat fill (owner, 2026-11-16): `--cinder-selected-background`, the soft
   * accent tint every selected row in the app shares (StackedListItem paints its selected row from
   * it too). In light the sidebar's `--cinder-surface` and `--cinder-surface-raised` are both white
   * since 2026-11-15, so the raised pill the row used to take vanished; the tint (about
   * oklch(94% 0.029 257) on white, 25% on the dark 18.5% surface) stands apart from the sidebar and
   * from the neutral 4% ink hover below in both themes, with no shadow, so it is a flat row and
   * never a raised chip. Leaving `box-shadow` alone also keeps the inset focus ring above on a
   * focused active row. The text stays default and semibold, because the accent is for actions
   * and links, so the place the person is in is never accent-coloured text (owner, 2026-11-10;
   * AC2). The ink tint (about 7%) remains where the row sits on a raised drawer panel
   * (`sidebar.css`). */
  .cinder-navigation-item[data-variant='vertical'][data-active='true'] {
    border-bottom-color: transparent;
    background-color: var(--cinder-selected-background);
    color: var(--cinder-text-default);
    font-weight: var(--cinder-font-semibold);
  }

  /* Hover on a sidebar row is a lighter neutral tint than the active row, the ink at 4% (row 02n),
   * never an accent wash: `--cinder-surface-hover` washes toward the accent in light mode by
   * design, which reads as an active tint on a sidebar, so a vertical row sets its own. */
  @media (hover: hover) {
    .cinder-navigation-item[data-variant='vertical']:hover:not(
        [aria-disabled='true'],
        [data-active='true']
      ) {
      background-color: color-mix(in oklch, var(--cinder-border-ink), transparent 96%);
    }
  }

  /* The active row takes no hover change (row 02n): it keeps its fill and its text. */
  @media (hover: hover) {
    .cinder-navigation-item[data-variant='vertical'][data-active='true']:hover {
      background-color: var(--cinder-selected-background);
      color: var(--cinder-text-default);
    }
  }

  /* Forced-colors fallback for the vertical-variant inset ring. Inset
   * box-shadow rings vanish in Windows High Contrast Mode, so repaint the
   * outline channel with a NEGATIVE offset that draws the outline INSIDE the
   * item border box — a positive/outset offset would reintroduce the overhang
   * this variant was changed to avoid. `ButtonText` is the policy-correct
   * system color for the anchor/button pressable the item renders as (not
   * `Highlight`, which is for selection). The `[data-variant='vertical']`
   * attribute selector duplicates the base rule's specificity (0,2,0) so it
   * wins inside the media block per the B-inset specificity rule. */
  @media (forced-colors: active) {
    .cinder-navigation-item[data-variant='vertical']:focus-visible {
      outline: var(--cinder-ring-width) solid ButtonText;
      outline-offset: calc(var(--cinder-ring-width) * -1);
    }

    /* The active row is a fill, and a fill collapses to Canvas here, so the
     * selected row would be indistinguishable. SelectedItem/SelectedItemText
     * are the system pair for a selected row; unlike an outline they coexist
     * with the focus ring above. */
    .cinder-navigation-item[data-variant='vertical'][data-active='true'] {
      background-color: SelectedItem;
      color: SelectedItemText;
    }

    .cinder-navigation-item[data-variant='vertical'][data-active='true']:hover {
      background-color: SelectedItem;
      color: SelectedItemText;
    }
  }
}
