/*
 * THE PILL SURFACE — bordered, on the card ground, at the control height, so a
 * chip standing in a toolbar row reads level with the search field and the
 * buttons beside it.
 *
 * The ✕ overlaps the pill instead of sitting in its row, because the pill may be
 * a button and a button may not contain one. Its seat is therefore derived from
 * the band's own metrics rather than written as four numbers: half the
 * difference between the control height and the tallest node a control seats,
 * which is what centres a 28px button in a 40px pill.
 */
@layer theme, base, lotics, components, utilities;
@layer lotics.tokens, lotics.reset, lotics.components;

@layer lotics.components {
  .lotics-chip {
    --lotics-chip-remove-seat: calc(
      (var(--lotics-control-height) - var(--lotics-control-content-height)) / 2
    );
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    min-width: 0;
  }

  .lotics-chip__pill {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: var(--lotics-space-4);
    height: var(--lotics-control-height);
    padding-block: 0;
    padding-inline: var(--lotics-space-12);
    margin: 0;
    border-width: 1px;
    border-style: solid;
    border-color: var(--border);
    border-radius: var(--lotics-radius-control);
    background: var(--card);
    appearance: none;
    font-family: var(--font-sans);
    font-size: var(--lotics-text-sm);
    line-height: var(--lotics-leading-sm);
    letter-spacing: var(--lotics-tracking-sm);
    font-weight: var(--lotics-weight-regular);
    font-feature-settings: var(--lotics-font-features);
    color: var(--lotics-ink-default);
    /* A chip SETS A VALUE — it is the field's own content, not an act. */
    cursor: default;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: background-color var(--lotics-duration-fast) var(--lotics-ease-standard);
  }

  /* Content stops where the ✕ STARTS: the seat, the button, and one gutter. */
  .lotics-chip__pill[data-dismissible] {
    padding-right: calc(var(--lotics-chip-remove-seat) + var(--lotics-control-content-height) + var(--lotics-space-4));
  }

  .lotics-chip__pill[data-pressable]:hover {
    background: var(--lotics-wash-selected);
  }
  .lotics-chip__pill[data-pressable]:active {
    background: var(--lotics-wash-press);
  }

  .lotics-chip__pill:focus-visible {
    outline: var(--lotics-ring-width) solid var(--ring);
    outline-offset: 0;
  }

  .lotics-chip__remove {
    position: absolute;
    top: var(--lotics-chip-remove-seat);
    right: var(--lotics-chip-remove-seat);
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--lotics-control-content-height);
    height: var(--lotics-control-content-height);
    padding: 0;
    margin: 0;
    border: none;
    border-radius: var(--lotics-radius-full);
    background: transparent;
    appearance: none;
    /* The ✕ ACTS — it detaches the thing — so it takes the pointer the pill does not. */
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: background-color var(--lotics-duration-fast) var(--lotics-ease-standard);
  }

  /* It rides a surface the pointer has to cross to reach it, so it takes the
     CONTROL pair rather than the row's own — one rung up, or it washes to the
     same grey exactly when the pointer is on it. */
  .lotics-chip__remove:hover {
    background: var(--lotics-wash-control-hover);
  }
  .lotics-chip__remove:active {
    background: var(--lotics-wash-control-press);
  }

  .lotics-chip__remove:focus-visible {
    outline: var(--lotics-ring-width) solid var(--ring);
    outline-offset: 0;
  }
}
