@layer cinder.tokens, cinder.foundation, cinder.components, cinder.utilities;
@import '/assets/f47cf25678047dc1d0c5372c25b330b4ffdf35604610caa62c68ff9ad26b877e/components/grid/grid.css';
@layer cinder.components {
  /* ========================================
 * GRID LIST
 * ======================================== */

  .cinder-grid-list {
    list-style: none;
    margin: 0;
    padding: 0;
    inline-size: 100%;
  }

  /* ----------------------------------------
 * Item — visually a card, semantically an <li>.
 * Reuses Card tokens; no new visual variables.
 * ---------------------------------------- */

  .cinder-grid-list__item {
    position: relative; /* Anchors the stretched-link pseudo overlay. */
    display: flex;
    flex-direction: column;
    gap: var(--cinder-space-2);
    padding: var(--cinder-space-4);
    border-radius: var(--cinder-radius-lg);
    background: var(--cinder-surface-raised);
    border: var(--cinder-border-width) solid var(--cinder-border);
    color: var(--cinder-text-default);
    box-shadow: var(--cinder-shadow-sm);
    transition:
      box-shadow 150ms ease,
      border-color 150ms ease;
  }

  @media (hover: hover) {
    .cinder-grid-list__item:has(.cinder-grid-list__link:hover) {
      box-shadow: var(--cinder-shadow-md);
      border-color: var(--cinder-border);
    }
  }

  /* ----------------------------------------
 * Snippet wrappers — provide stable selectors and predictable layout.
 * All wrappers sit UNDER the stretched-link overlay except `.cinder-grid-list__actions`.
 * ---------------------------------------- */

  .cinder-grid-list__image,
  .cinder-grid-list__title,
  .cinder-grid-list__subtitle,
  .cinder-grid-list__meta {
    min-inline-size: 0; /* Allows long content to truncate inside flex parents. */
  }

  /* ----------------------------------------
 * Media bleed — under `mediaBleed` the image slot runs to the card's left, right and top
 * edges, inside the item's border. The negative margins equal the item's padding; the image
 * takes the item's radius on its top corners and clips to it. Title, subtitle, meta and
 * actions keep the item's padding, and the stretched-link overlay still covers the whole card,
 * with the focus ring drawn around it (see the stretched link below).
 * ---------------------------------------- */

  .cinder-grid-list__item[data-cinder-media-bleed] > .cinder-grid-list__image {
    margin-inline: calc(var(--cinder-space-4) * -1);
    margin-block-start: calc(var(--cinder-space-4) * -1);
    border-top-left-radius: var(--cinder-radius-lg);
    border-top-right-radius: var(--cinder-radius-lg);
    overflow: hidden;
  }

  .cinder-grid-list__title {
    font-size: var(--cinder-text-base);
    font-weight: var(--cinder-font-medium);
    color: var(--cinder-text-default);
  }

  .cinder-grid-list__subtitle {
    font-size: var(--cinder-text-sm);
    color: var(--cinder-text-muted);
  }

  /* Under `subtitleLines` the subtitle ends in an ellipsis after that many lines. The text stays
     in the DOM, so assistive technology still reads all of it. */
  .cinder-grid-list__subtitle[data-cinder-subtitle-lines] {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: var(--cinder-grid-list-subtitle-lines);
    line-clamp: var(--cinder-grid-list-subtitle-lines);
    overflow: hidden;
  }

  .cinder-grid-list__meta {
    font-size: var(--cinder-text-sm);
    color: var(--cinder-text-subtle);
  }

  /* ----------------------------------------
 * Stretched link — opt-in via `href` prop.
 *
 * The anchor wraps the title text but its ::after extends to cover the
 * entire item, so any pointer click anywhere on the item activates the link.
 * ---------------------------------------- */

  .cinder-grid-list__link {
    color: inherit;
    text-decoration: none;
  }

  .cinder-grid-list__link::after {
    content: '';
    position: absolute;
    inset: 0;
    /* Match the item's radius directly — `inherit` would resolve to 0 since the
     anchor's ancestor chain doesn't carry the radius token. */
    border-radius: var(--cinder-radius-lg);
    z-index: 0;
  }

  /* The focus ring wraps the whole card, so it is drawn on the stretched link's overlay, the way
     stacked-list-item.css does, and not on the anchor, which is only the title's text. The overlay
     grows by the card's border and a gap while the link has focus, so the ring floats outside the
     border with a gap between them. A selected card's outline sits over its border, inside it, so
     focused and selected differ by shape as well as by color. */
  .cinder-grid-list__link:focus-visible {
    /* cinder-focus-ring-owner: parent */
    outline: none;
  }

  .cinder-grid-list__link:focus-visible::after {
    --_cinder-grid-list-ring-reach: calc(
      var(--cinder-border-width) + var(--_cinder-focus-ring-filled-gap)
    );

    inset: calc(var(--_cinder-grid-list-ring-reach) * -1);
    border-radius: calc(var(--cinder-radius-lg) + var(--_cinder-grid-list-ring-reach));
    outline: var(--cinder-ring-width) solid transparent;
    box-shadow: var(--_cinder-focus-ring-shadow);
  }

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

  /* ----------------------------------------
 * Actions row — lifted above the stretched-link overlay so its
 * buttons remain clickable / focusable.
 * ---------------------------------------- */

  .cinder-grid-list__actions {
    position: relative;
    z-index: 1;
    display: flex;
    flex-wrap: wrap;
    gap: var(--cinder-space-2);
    margin-block-start: auto; /* Pin actions to the bottom of the card. */
  }

  /* Allow consumers to lift an arbitrary descendant above the overlay. */
  .cinder-grid-list__item [data-cinder-stretched-link-escape] {
    position: relative;
    z-index: 1;
  }

  /* ----------------------------------------
 * Selection — a selectable item draws a corner checkbox and, once selected, an outline.
 * The checkbox wrapper carries `data-cinder-stretched-link-escape`, so a press on it
 * toggles selection instead of following the link. It is hidden at rest and shown on
 * hover, on focus, under a coarse pointer, and on every item while the list has a
 * selection (`data-cinder-selecting`, set by GridList).
 * ---------------------------------------- */

  /* Where the box sits follows what it overlays, so it never covers the title:
   *  - With an image, it sits inside the image's top start corner, a step in from the image's
   *    edges. An inset image starts a padding in from the card; a bleed image starts at the card.
   *  - Without an image, it sits at the content's top start corner, and the title reserves the
   *    box's width (below), so the box and the title's first line share one centre line, as a
   *    leading checkbox does in StackedListItem.
   * The box is the Checkbox's painted 18px; its hit area is 24px, and 44px under a coarse pointer,
   * so the title also keeps clear of the part of the hit area that reaches past the box. */
  .cinder-grid-list__item {
    --_cinder-grid-list-select-size: calc(var(--cinder-space-4) + var(--cinder-space-0-5));
    --_cinder-grid-list-select-reach: var(--cinder-space-2);
  }

  @media (any-pointer: coarse) {
    .cinder-grid-list__item {
      --_cinder-grid-list-select-reach: var(--cinder-space-4);
    }
  }

  /* Declared after the escape rule above, and as specific, so `position: absolute` wins. */
  .cinder-grid-list__item .cinder-grid-list__select {
    /* The title's first line, which the box centres itself on (see Checkbox). */
    --_cinder-checkbox-line: calc(var(--cinder-text-base) * var(--cinder-leading-normal));

    position: absolute;
    inset-block-start: var(--cinder-space-4);
    /* Pinned to the start side by a logical margin on a shrink-wrapped box, so the corner follows
       the writing direction without an asymmetric inset. */
    inset-inline: 0;
    inline-size: fit-content;
    margin-inline: var(--cinder-space-4) auto;
    z-index: 1;
    opacity: 0;
  }

  /* A block-level field, so the wrapper's line box adds no strut above or below the box. */
  .cinder-grid-list__item .cinder-grid-list__select > .cinder-checkbox-field {
    display: flex;
  }

  .cinder-grid-list__item:has(> .cinder-grid-list__image) .cinder-grid-list__select {
    --_cinder-checkbox-line: var(--_cinder-grid-list-select-size);

    inset-block-start: calc(var(--cinder-space-4) + var(--cinder-space-2));
    margin-inline-start: calc(var(--cinder-space-4) + var(--cinder-space-2));
    border-radius: var(--cinder-radius-sm);
    /* The box sits on the picture, so it keeps its own backing. */
    background: var(--cinder-surface-raised);
  }

  .cinder-grid-list__item[data-cinder-media-bleed]:has(> .cinder-grid-list__image)
    .cinder-grid-list__select {
    inset-block-start: var(--cinder-space-2);
    margin-inline-start: var(--cinder-space-2);
  }

  /* The title and the lines under it share one edge, clear of the box. The actions row keeps the
     card's content edge. */
  .cinder-grid-list__item:has(.cinder-grid-list__select):not(:has(> .cinder-grid-list__image))
    > :is(.cinder-grid-list__title, .cinder-grid-list__subtitle, .cinder-grid-list__meta) {
    padding-inline-start: calc(
      var(--_cinder-grid-list-select-size) + var(--_cinder-grid-list-select-reach)
    );
  }

  .cinder-grid-list__item:has(.cinder-grid-list__select):not(:has(> .cinder-grid-list__image))
    > .cinder-grid-list__title {
    /* The line height the box centres on, written here so the two cannot drift apart. */
    line-height: var(--cinder-leading-normal);
  }

  .cinder-grid-list__item:hover .cinder-grid-list__select,
  .cinder-grid-list__item:focus-within .cinder-grid-list__select,
  .cinder-grid-list__item[data-cinder-selected] .cinder-grid-list__select,
  .cinder-grid-list[data-cinder-selecting] .cinder-grid-list__select {
    opacity: 1;
  }

  @media (any-pointer: coarse) {
    .cinder-grid-list__item .cinder-grid-list__select {
      opacity: 1;
    }
  }

  /* ----------------------------------------
 * Highlighted — marks an item that wants attention, such as one just uploaded. It colors the
 * border from the accent and is never the only signal: pair it with text or a badge.
 * Declared before the selected rule below, so a selected item's outline wins. Both rules
 * are scoped under `.cinder-grid-list` so they are as specific as the hover rule above
 * and, coming later, keep their border color while the link is hovered.
 * ---------------------------------------- */

  .cinder-grid-list .cinder-grid-list__item[data-cinder-highlighted] {
    border-color: var(--cinder-accent-border);
  }

  /* The outline sits over the item's border, so a selected item keeps its size. */
  .cinder-grid-list .cinder-grid-list__item[data-cinder-selected] {
    border-color: var(--cinder-accent-solid);
    outline: var(--cinder-ring-width) solid var(--cinder-accent-solid);
    outline-offset: calc(var(--cinder-border-width) * -1);
  }

  @media (forced-colors: active) {
    .cinder-grid-list .cinder-grid-list__item[data-cinder-selected] {
      outline-color: Highlight;
    }
  }
}
