@layer cinder.tokens, cinder.foundation, cinder.components, cinder.utilities;
@layer cinder.components {
  /* ========================================
 * GROUPED LIST
 *
 * An inset group: one rounded surface holding the rows, separators that start at the text, and
 * a header and footer outside the surface. The group carries tone, not a border; the separators
 * are drawn by the rows. Parts are styled by class, so nothing a consumer interpolates into a
 * row is restyled.
 * ======================================== */

  .cinder-grouped-list {
    display: block;
    min-inline-size: 0;
  }

  /* The header and footer are outside the surface, so their text shares the page edge, the
   * surface's own edge, rather than the rows' inset; only text inside a surface takes its inset
   * (owner rule, COR-2768). Where a container is the same raised surface as the group (a modal
   * drawer), the group's edge is invisible, and that container sets the private label inset to the
   * rows' inset so the labels line up with the row text instead of with nothing. */
  .cinder-grouped-list__header,
  .cinder-grouped-list__footer {
    margin: 0;
    padding-inline: var(--_cinder-grouped-list-label-inset, 0);
  }

  .cinder-grouped-list__header {
    margin-block-end: var(--cinder-space-2);
  }

  .cinder-grouped-list__footer {
    margin-block-start: var(--cinder-space-2);
    font-size: var(--cinder-text-sm);
    color: var(--cinder-text-muted);
  }

  /* The way to the full set when the group shows only part of it (COR-2765): a `more` link 8px
   * under the group, or under its footer, on the group's edge like the footer, because it is
   * outside the surface (COR-2768). The link's own hit area reaches 44px under a coarse pointer without taking layout, so
   * the gap is the same under a mouse and a finger. */
  .cinder-grouped-list__more-row {
    /* A flex row, so the link's box starts at the row's top and no line-box strut pads the gap. */
    display: flex;
    margin: 0;
    margin-block-start: var(--cinder-space-2);
    padding-inline: var(--_cinder-grouped-list-label-inset, 0);
  }

  .cinder-grouped-list__group {
    margin: 0;
    padding: 0;
    list-style: none;
    overflow: hidden;
    position: relative;
    border-radius: var(--cinder-radius-surface);
    background: var(--cinder-surface-raised);
  }

  /* The page hairline parts the white group from the white light page; transparent in dark. A
     surface that is not the page (a modal drawer) can turn it off with
     `--_cinder-grouped-list-group-edge`. It is drawn on an overlay, so it takes no layout in either
     theme and a transparent edge moves nothing (COR-2697). */
  .cinder-grouped-list__group::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    pointer-events: none;
    border: var(--cinder-border-width) solid
      var(--_cinder-grouped-list-group-edge, var(--_cinder-page-edge));
  }

  @media (forced-colors: active) {
    .cinder-grouped-list__group {
      border: 1px solid CanvasText;
    }
  }

  /* ----------------------------------------
 * Quick-add first row
 * ---------------------------------------- */

  .cinder-grouped-list__add {
    margin: 0;
    padding-inline-start: var(--cinder-space-4);
    list-style: none;
  }

  .cinder-grouped-list__add-form {
    display: flex;
    align-items: center;
    gap: var(--cinder-space-3);
    min-block-size: 2.75rem;
    margin: 0;
    padding-inline-end: var(--cinder-space-4);
    border-block-end: var(--cinder-border-width) solid var(--cinder-border-faint);
  }

  .cinder-grouped-list__add:last-child > .cinder-grouped-list__add-form {
    border-block-end-color: transparent;
  }

  .cinder-grouped-list__add-glyph {
    display: inline-flex;
    flex: none;
    color: var(--cinder-accent-text);
  }

  .cinder-grouped-list__add-input {
    flex: 1 1 0;
    min-inline-size: 0;
    min-block-size: 2.75rem;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--cinder-text-default);
    font: inherit;
  }

  .cinder-grouped-list__add-input::placeholder {
    color: var(--cinder-text-muted);
  }

  .cinder-grouped-list__add-input:focus-visible {
    outline: none;
  }

  /* The ring wraps the whole row, inside the group, because the group clips. */
  .cinder-grouped-list__add:has(.cinder-grouped-list__add-input:focus-visible) {
    box-shadow: inset 0 0 0 var(--cinder-ring-width) var(--cinder-ring-color);
  }

  @media (forced-colors: active) {
    .cinder-grouped-list__add:has(.cinder-grouped-list__add-input:focus-visible) {
      outline: var(--cinder-ring-width) solid ButtonText;
      outline-offset: calc(var(--cinder-ring-width) * -1);
    }
  }
}
