@layer cinder.tokens, cinder.foundation, cinder.components, cinder.utilities;
@import '/assets/f47cf25678047dc1d0c5372c25b330b4ffdf35604610caa62c68ff9ad26b877e/components/button/button.css';
@import '/assets/f47cf25678047dc1d0c5372c25b330b4ffdf35604610caa62c68ff9ad26b877e/components/chip/chip.css';
@import '/assets/f47cf25678047dc1d0c5372c25b330b4ffdf35604610caa62c68ff9ad26b877e/components/copy-button/copy-button.css';

@layer cinder.components {
  /* ========================================
 * DESCRIPTION LIST
 * ======================================== */

  .cinder-description-list {
    margin: 0;
    display: flex;
    flex-direction: column;
  }

  /* Reset UA default margin-inline-start on <dd> (~40px in most browsers). */
  .cinder-description-list dt,
  .cinder-description-list dd {
    margin: 0;
  }

  .cinder-description-list__row {
    display: flex;
    flex-direction: column;
    gap: var(--cinder-space-1);
    padding: var(--cinder-space-2) var(--cinder-space-3);
  }

  /* The default variant draws no fill or frame, only a hairline between rows, so its rows start on
   * the content's leading edge like the heading above them (COR-2760). A linked row's tint still
   * reaches 12px past that edge (`.cinder-description-list__link::after`). */
  .cinder-description-list[data-cinder-variant='default'] .cinder-description-list__row {
    padding-inline: 0;
  }

  .cinder-description-list[data-cinder-variant='default']
    .cinder-description-list__row:not(:first-child) {
    border-block-start: var(--cinder-border-width) solid var(--cinder-border-muted);
  }

  /* <dd> hosts both definition and optional actions. */
  .cinder-description-list dd {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: var(--cinder-space-2);
  }

  .cinder-description-list__row[data-cinder-linked] > dd {
    flex-wrap: nowrap;
  }

  /* A value can be any string a record holds (an identifier, an address, a chat's title), and one
   * unbroken word of it must break inside the list rather than widen every variant's columns. */
  .cinder-description-list__definition {
    flex: 1 1 auto;
    min-width: 0;
    overflow-wrap: anywhere;
  }

  .cinder-description-list__actions {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: var(--cinder-space-1);
  }

  /* Striped variant: odd rows get a subtle background. */
  .cinder-description-list[data-cinder-variant='striped']
    .cinder-description-list__row:nth-child(odd) {
    background: var(--cinder-surface-inset);
  }

  /* Two-column variant: term and definition share a row. */
  .cinder-description-list[data-cinder-variant='two-column'] {
    container-type: inline-size;
  }

  /* The label column holds a label and no more: about 10rem at most, so a wide list gives the
   * value the rest of the width and the two never drift apart. The list draws no frame, fill or
   * divider of its own, so its rows take no inset at the start: the term sits on the text edge of
   * what surrounds the list. */
  .cinder-description-list[data-cinder-variant='two-column'] .cinder-description-list__row {
    display: grid;
    grid-template-columns: minmax(8rem, 10rem) 1fr;
    align-items: baseline;
    gap: var(--cinder-space-3);
    padding-inline: 0;
  }

  @supports (grid-template-columns: subgrid) {
    .cinder-description-list[data-cinder-variant='two-column'] {
      display: grid;
      grid-template-columns: minmax(8rem, 10rem) 1fr;
    }

    .cinder-description-list[data-cinder-variant='two-column'] .cinder-description-list__row {
      grid-template-columns: subgrid;
      grid-column: 1 / -1;
    }
  }

  /* The term is the quiet side of the pair: muted, so the value carries the row.
   * There are no row dividers in this variant (only the default variant draws them). */
  .cinder-description-list[data-cinder-variant='two-column'] dt {
    color: var(--cinder-text-muted);
  }

  /* Collapse two-column to stacked at narrow container widths, with the term close above its value. */
  @container (max-width: 28rem) {
    .cinder-description-list[data-cinder-variant='two-column'] .cinder-description-list__row {
      grid-template-columns: 1fr;
      gap: var(--cinder-space-1);
    }
  }

  /* `stack` puts the term above its value at every width. Only two-column
   * places them side by side, so only its rows need the override; the
   * subgrid track list collapses with them. */
  .cinder-description-list[data-cinder-variant='two-column'][data-cinder-stacked] {
    grid-template-columns: 1fr;
  }

  .cinder-description-list[data-cinder-variant='two-column'][data-cinder-stacked]
    .cinder-description-list__row {
    grid-template-columns: 1fr;
    gap: var(--cinder-space-1);
  }

  /* Narrow variant: <dt> is sr-only (position: absolute, out-of-flow) so <dd>
 * fills the visible row. flex-direction: row here matches the intended reading
 * direction if a future variant needs the dt in-flow; for now the sr-only dt
 * has no layout footprint and the dd is visually full-width. */
  .cinder-description-list[data-cinder-variant='narrow'] .cinder-description-list__row {
    flex-direction: row;
    align-items: baseline;
    gap: var(--cinder-space-2);
  }

  /* Fields variant: a record read as a list, the record-details anatomy shared with InspectorRow. The
   * term is a regular-weight muted label in a fixed 140px column, the value beside it in the default
   * color, and each row is at least 44px tall, with a quiet rule under each row. It is flat by
   * default, so it never draws a box inside a pane or a card; `framed` puts the rows in one tinted
   * group, on the raised fill when the list is narrower than 700px as an Inspector's group is. A row
   * with an `href` ends in a trailing chevron. It stacks below 23rem of its own width. */
  .cinder-description-list[data-cinder-variant='fields'] {
    container-type: inline-size;
    container-name: cinder-description-list;
    display: grid;
    grid-template-columns: 8.75rem minmax(0, 1fr);
  }

  /* The group's fill is a pseudo-element under the rows, not the list's own background: the list is
   * the container its width is measured on, and a container query can restyle the container's
   * pseudo-elements but not the container itself. */
  .cinder-description-list[data-cinder-variant='fields'][data-cinder-framed] {
    position: relative;
    isolation: isolate;
    padding-inline-start: var(--cinder-space-4);
    overflow: hidden;
    border-radius: var(--cinder-radius-surface);
  }

  .cinder-description-list[data-cinder-variant='fields'][data-cinder-framed]::before {
    content: '';
    position: absolute;
    inset: 0;
    z-index: -1;
    background: var(--cinder-surface-inset);
    pointer-events: none;
  }

  .cinder-description-list[data-cinder-variant='fields'] .cinder-description-list__row {
    display: grid;
    grid-template-columns: subgrid;
    grid-column: 1 / -1;
    align-items: center;
    /* No column gap: the list's grid has none, and a subgrid's larger gap is split half to each side
     * of the gutter, which set the value 6px past an InspectorRow's. The label's own end padding
     * keeps the 12px, as `.cinder-inspector-row__label` does, so the value starts at 140px. */
    column-gap: 0;
    row-gap: var(--cinder-space-3);
    min-block-size: 2.75rem;
    padding-block: var(--cinder-space-2-5);
    padding-inline: 0 var(--cinder-space-3);
    border-block-end: var(--cinder-border-width) solid var(--cinder-border-faint);
  }

  .cinder-description-list[data-cinder-variant='fields'] .cinder-description-list__row:last-child {
    border-block-end-color: transparent;
  }

  /* The label is set in the body size, as an InspectorRow's is; when the row stacks it drops to
   * the small size above its value (below). */
  .cinder-description-list[data-cinder-variant='fields'] dt {
    padding-inline-end: var(--cinder-space-3);
    color: var(--cinder-text-muted);
    font-size: var(--cinder-text-base);
    font-weight: var(--cinder-font-normal);
  }

  /* The value is set in the body size, as an InspectorRow's value is. */
  .cinder-description-list[data-cinder-variant='fields'] dd {
    color: var(--cinder-text-default);
    font-size: var(--cinder-text-base);
  }

  /* A linked row keeps InspectorRow's end inset, so its chevron lands where an InspectorRow's does. */
  .cinder-description-list[data-cinder-variant='fields']
    .cinder-description-list__row[data-cinder-linked] {
    padding-inline-end: var(--cinder-space-2);
  }

  /* Below 700px of the list's own width, as an Inspector below 700px of its own (COR-2394), a framed
   * group takes the raised fill of a grouped list, so a list and an Inspector of one width agree. A
   * size query measures the content box, so a framed list, with its 1rem start padding, switches at
   * 42.75rem. */
  @container cinder-description-list (width < 42.75rem) {
    .cinder-description-list[data-cinder-variant='fields'][data-cinder-framed]::before {
      border: var(--cinder-border-width) solid var(--_cinder-page-edge);
      background: var(--cinder-surface-raised);
    }
  }

  /* Below 23rem (368px) of the list's own width, too narrow for the 140px label, its 12px gap and a
   * readable value beside them, the term stacks above its value: a phone-width list at 375 does, a
   * rail or a drawer at desktop width does not. The list is the container, so the query restyles
   * its rows: each leaves the shared track list for one column of its own. A stacked label takes
   * the small size an InspectorRow's stacked label takes; a label beside its value keeps the body
   * size, so the two share a baseline. */
  @container (width < 23rem) {
    .cinder-description-list[data-cinder-variant='fields'] .cinder-description-list__row {
      grid-template-columns: minmax(0, 1fr);
      gap: var(--cinder-space-1);
    }

    .cinder-description-list[data-cinder-variant='fields'] dt {
      font-size: var(--cinder-text-sm);
    }
  }

  /* ----------------------------------------
   * Linked rows
   * ---------------------------------------- */

  /* A row with an `href` ends in a trailing chevron, the PropertyRow affordance, and the whole row is
   * the link's target: the link's `::before` stretches over the row as its hit area, under any
   * control the row holds, and its `::after` lies behind the row's text to draw the hover tint and
   * the focus ring. A row without one draws no chevron and no hover tint, so read-only facts never
   * look linked. The row isolates, so the tint sits above the group's fill and below the text. */
  .cinder-description-list__row[data-cinder-linked] {
    position: relative;
    isolation: isolate;
  }

  .cinder-description-list__link {
    flex: none;
    display: inline-flex;
    align-items: center;
    align-self: center;
    margin-inline-start: auto;
    color: var(--cinder-text-subtle);
  }

  .cinder-description-list__link::before {
    content: '';
    position: absolute;
    inset: 0;
  }

  /* The tint and the ring: on a flat list they reach a little past the row's start, rounded like a
   * control, so the tint never starts at the text and the ring never crosses the label's first
   * glyph. The tinted strip is part of the link, so a press anywhere the tint is drawn follows it
   * (it lies under the row's controls, which sit above the text). */
  .cinder-description-list__link::after {
    content: '';
    position: absolute;
    inset: 0;
    margin-inline-start: calc(var(--cinder-space-3) * -1);
    z-index: -1;
    border-radius: var(--cinder-radius-control);
  }

  /* On a framed list they reach the group's start edge, so no untinted strip is left there; the
   * group clips them to its own corners. */
  .cinder-description-list[data-cinder-framed] .cinder-description-list__link::after {
    margin-inline-start: calc(var(--cinder-space-4) * -1);
    border-radius: 0;
  }

  .cinder-description-list__row[data-cinder-linked]
    :is(button, input, select, textarea, a[href]:not(.cinder-description-list__link)) {
    position: relative;
    z-index: 1;
  }

  @media (hover: hover) {
    .cinder-description-list__row[data-cinder-linked]:hover .cinder-description-list__link::after {
      background: var(--cinder-surface-hover);
    }

    .cinder-description-list__row[data-cinder-linked]:hover .cinder-description-list__link {
      color: var(--cinder-text-default);
    }
  }

  .cinder-description-list__link:focus-visible {
    outline: var(--cinder-ring-width) solid transparent;
    color: var(--cinder-text-default);
  }

  /* The ring is drawn inside the tint's box, because a framed group clips its rows. */
  .cinder-description-list__link:focus-visible::after {
    box-shadow: inset 0 0 0 var(--cinder-ring-width) var(--cinder-ring-color);
  }

  @media (forced-colors: active) {
    .cinder-description-list__link:focus-visible::after {
      outline: var(--cinder-ring-width) solid ButtonText;
      outline-offset: calc(var(--cinder-ring-width) * -1);
    }
  }

  /* Facts variant: one row of equal columns, each a muted term above its value, between two quiet
   * rules. The columns wrap as the container narrows, so a phone stacks them two to a row. */
  .cinder-description-list[data-cinder-variant='facts'] {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(7rem, 1fr));
    gap: var(--cinder-space-3) var(--cinder-space-4);
    padding-block: var(--cinder-space-3);
    border-block: var(--cinder-border-width) solid var(--cinder-border-muted);
  }

  .cinder-description-list[data-cinder-variant='facts'] .cinder-description-list__row {
    padding: 0;
    min-width: 0;
  }

  .cinder-description-list[data-cinder-variant='facts'] dt {
    color: var(--cinder-text-muted);
  }

  /* A wide item takes the whole row of a column variant: a long value, several lines or code. */
  .cinder-description-list:is([data-cinder-variant='facts'], [data-cinder-variant='grid'])
    .cinder-description-list__row[data-cinder-wide] {
    grid-column: 1 / -1;
  }

  /* Grid variant: the pairs flow in as many equal columns as the list's own width fits, a muted term
   * above its value at the column's start edge, with no rules and no fill. The tracks follow the
   * list's inline size, never the viewport: a wide card reads three short pairs on one row, a phone
   * card two, and a column narrower than two tracks one. */
  .cinder-description-list[data-cinder-variant='grid'] {
    --_cinder-description-list-column-min: calc(var(--cinder-space-24) + var(--cinder-space-2));

    display: grid;
    grid-template-columns: repeat(
      auto-fill,
      minmax(min(100%, var(--_cinder-description-list-column-min)), 1fr)
    );
    gap: var(--cinder-space-2) var(--cinder-space-3);
  }

  .cinder-description-list[data-cinder-variant='grid'] .cinder-description-list__row {
    gap: 0;
    min-width: 0;
    padding: 0;
  }

  /* The term is the quiet half of the pair: the value's size, regular weight and muted, so the
   * value carries the column; both keep the body line height. */
  .cinder-description-list[data-cinder-variant='grid'] dt {
    color: var(--cinder-text-muted);
    font-size: var(--cinder-text-sm);
    font-weight: var(--cinder-font-normal);
    line-height: var(--cinder-leading-normal);
  }

  .cinder-description-list[data-cinder-variant='grid'] dd {
    color: var(--cinder-text-default);
  }

  /* ----------------------------------------
   * Formatted values
   * ---------------------------------------- */

  /* Code is shown whole in the code font and breaks anywhere, so a long value never widens a column. */
  .cinder-description-list__code {
    font-family: var(--cinder-font-mono);
    font-size: var(--cinder-text-xs);
    overflow-wrap: anywhere;
    white-space: pre-wrap;
    color: var(--cinder-text-default);
  }

  .cinder-description-list__timestamp {
    font-variant-numeric: tabular-nums;
    /* A dotted underline marks text that carries a hover title. */
    text-decoration: underline dotted var(--cinder-text-muted);
    text-underline-offset: 0.25em;
    cursor: help;
  }

  .cinder-description-list__identifier-group {
    display: inline-flex;
    align-items: center;
    font-size: var(--cinder-text-xs);
  }

  .cinder-description-list__identifier {
    font-family: var(--cinder-font-mono);
    font-size: var(--cinder-text-xs);
    color: var(--cinder-text-default);
  }

  .cinder-description-list__tags {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--cinder-space-2);
    min-inline-size: 0;
    max-inline-size: 100%;
  }

  .cinder-description-list__tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: var(--cinder-space-1);
    min-inline-size: 0;
    max-inline-size: 100%;
    list-style: none;
    margin: 0;
    padding: 0;
  }

  /* A tag never runs out of its row: a long one is shortened with an ellipsis, and its title holds
     the whole text. */
  .cinder-description-list__tag {
    display: flex;
    min-inline-size: 0;
    max-inline-size: 100%;
  }

  .cinder-description-list__tag .cinder-chip {
    min-inline-size: 0;
    max-inline-size: 100%;
  }

  .cinder-description-list__tag .cinder-chip__label {
    min-inline-size: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* A muted second line under the definition: what the value is called in the system (a check's
     name and version beside its words), not a second value. */
  .cinder-description-list__note {
    display: block;
    margin-block-start: var(--cinder-space-0-5);
    font-size: var(--cinder-text-xs);
    line-height: var(--cinder-leading-normal);
    color: var(--cinder-text-muted);
  }

  /* An identifier at the note's start (`agentRun`), in the mono family at the note's size. */
  .cinder-description-list__note-code {
    font-family: var(--cinder-font-mono);
    font-size: inherit;
  }

  .cinder-description-list__system-tags,
  .cinder-description-list__empty {
    font-size: var(--cinder-text-xs);
    color: var(--cinder-text-muted);
  }
}
