@layer cinder.tokens, cinder.foundation, cinder.components, cinder.utilities;
@layer cinder.components {
  /* ========================================
 * DATA LIST
 *
 * DataList is the semantic list container (`<ul role="list">`). It owns the
 * list reset, the empty-state treatment and the hairline between rows (see
 * "Row separators" below). The row primitive (StackedListItem) draws no
 * separator of its own, so a Timeline item or a Skeleton row has none.
 * ======================================== */

  .cinder-data-list {
    display: flex;
    flex-direction: column;
    inline-size: 100%;
    /* List reset: a `<ul>` with list-style:none drops list semantics in Safari,
     * which is why the markup restates role="list". */
    margin: 0;
    padding: 0;
    list-style: none;
    /* The long-value default for every row in the list: an unbroken value (an identifier) wraps
     * anywhere, so no value widens the list past its frame. Rows inherit it. */
    min-inline-size: 0;
    overflow-wrap: anywhere;
  }

  /* ----------------------------------------
 * Groups: a label over a nested list of rows
 *
 * A group is an `<li>` holding the header and a nested list that the header names, so a screen
 * reader announces the day. The header puts muted text at the left
 * (`Today, Monday, Nov 2`) and the zone at the right (`Central time`).
 * ---------------------------------------- */

  .cinder-data-list-group {
    display: block;
  }

  .cinder-data-list-group__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--cinder-space-3);
    padding: var(--cinder-space-2) var(--cinder-space-3-5);
    /* Beside a ListDetail's Hide handle the rows keep their text that far from their end
       (`--_cinder-list-detail-handle-inset`); the trailing label keeps it too, so
       times and the label end on one edge. The hairline keeps its full width. */
    padding-inline-end: calc(
      var(--cinder-space-3-5) + var(--_cinder-list-detail-handle-inset, 0px)
    );
    line-height: var(--cinder-leading-normal);
  }

  .cinder-data-list-group__detail {
    color: var(--cinder-text-subtle);
    font-weight: var(--cinder-font-normal);
    white-space: nowrap;
  }

  .cinder-data-list-group__items {
    margin: 0;
    padding: 0;
    list-style: none;
  }

  /* The next group's header draws the divider, so a group's last row draws none. */
  .cinder-data-list-group__items > :last-child {
    border-block-end: 0;
  }

  /* ----------------------------------------
 * Row separators
 *
 * A quiet hairline between the rows of a list, the one exception to "no rules inside groups"
 * (the owner delegated it on 2026-11-25), so a reader can tell one row from the next. It is drawn
 * on a pseudo-element so it is inset to the row's text and never touches the
 * row's edges. Only rows that are direct children of a DataList or a group's list draw one:
 * Timeline items and Skeleton rows, which also use StackedListItem, are not, and a band row is a
 * group header that draws its own edge. The last row of a list, grouped or not, draws none, so
 * rows are separated only between each other.
 * ---------------------------------------- */

  :where(.cinder-data-list, .cinder-data-list-group__items)
    > .cinder-stacked-list-item:not(.cinder-stacked-list-item--band)::after {
    content: '';
    position: absolute;
    inset-block-end: 0;
    inset-inline: var(--cinder-space-4);
    border-block-end: var(--cinder-border-width) solid var(--cinder-border-muted);
    pointer-events: none;
  }

  /* A status-first row pads its inline edges a half step less than a plain one. */
  :where(.cinder-data-list, .cinder-data-list-group__items)
    > .cinder-stacked-list-item--lines:not([data-cinder-density='condensed'])::after {
    inset-inline: var(--cinder-space-3-5);
  }

  :where(.cinder-data-list, .cinder-data-list-group__items)
    > .cinder-stacked-list-item[data-cinder-density='condensed']:not(
      .cinder-stacked-list-item--band
    )::after {
    inset-inline: var(--cinder-space-3);
  }

  :where(.cinder-data-list, .cinder-data-list-group__items)
    > .cinder-stacked-list-item:last-child::after {
    content: none;
  }

  /* A group label or group row already marks the next group's start, so omit the preceding row's
   * divider. */
  :where(.cinder-data-list, .cinder-data-list-group__items)
    > .cinder-stacked-list-item:has(
      + :is(
        .cinder-data-list-group,
        .cinder-stacked-list-item--band,
        .cinder-stacked-list-item--group
      )
    )::after {
    content: none;
  }

  /* The live region for inserted rows. Until rows arrive it takes no space and is not drawn. Once
   * it holds an announcement it is the accent status strip of the design, "1 new run", above the
   * first group; the text stays in the same polite region, so it is spoken and drawn as one. */
  .cinder-data-list-live {
    position: absolute;
    inline-size: 1px;
    block-size: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  .cinder-data-list-live[data-announced] {
    position: static;
    inline-size: auto;
    block-size: auto;
    overflow: visible;
    clip-path: none;
    padding: var(--cinder-space-1-5) var(--cinder-space-3-5);
    background: var(--cinder-accent-background);
    color: var(--cinder-accent-text);
    font-size: var(--cinder-text-xs);
    line-height: var(--cinder-leading-normal);
  }

  /* Empty state: a single `<li>` so the `<ul>` stays valid. Component-owned
   * padding and muted color mean the empty example needs no inline styles. */
  .cinder-data-list-empty {
    padding-block: var(--cinder-space-6, 1.5rem);
    padding-inline: var(--cinder-space-4, 1rem);
    color: var(--cinder-text-muted);
    text-align: center;
  }
}
