@layer components {
  /* Revealed text secrets (OTP recovery codes and the like) arrive as several
     lines and must keep them. */
  .secret-text {
    white-space: pre-wrap;
  }

  /* Tag chips — rendered by shared/_tag_chips and inline labels on entries.
     Proportioned like .btn (its line height, 0.5em × 1.1em padding and a
     clear 1px border in place of its outline), only set smaller, so every
     chip reads as a scaled-down button wherever it appears. */
  .chip {
    background-color: var(--color-ink-lightest);
    border: 1px solid transparent;
    border-radius: 99rem;
    color: var(--color-ink);
    display: inline-block;
    font-size: var(--text-x-small);
    font-weight: 500;
    line-height: 1.375;
    padding: 0.5em 1.1em;
    text-decoration: none;
    /* A pill is one unit — it wraps as a whole or not at all, never mid-word
       down a narrow table column. */
    white-space: nowrap;

    @media (any-hover: hover) {
      /* The active chip is excluded (the .submenu__item precedent): lightening
         its background would leave inverted text on a near-white pill. It
         already reads as selected, so hover leaves it exactly as it is. */
      &:is(a):not(.chip--active):hover {
        background-color: var(--color-ink-lighter);
      }
    }
  }

  .chip--active {
    background-color: var(--color-ink);
    color: var(--color-ink-inverted);
  }

  /* The tag filter's chips act as buttons: one size step up from the label
     chips and button weight, still a size below a regular .btn. Spaced like a
     toolbar of buttons. */
  .tag-filter {
    gap: var(--block-space-half) var(--inline-space-half);

    > .chip {
      font-size: var(--text-small);
      font-weight: 600;
    }
  }

  .tag-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35em;
  }

  /* Person show page — the picture and basic info under the headline. No
     panel: it sits on the page and a hairline hands over to the timeline. */
  .person-profile {
    align-items: center;
    border-block-end: var(--border);
    display: flex;
    gap: var(--inline-space-double);
    padding-block-end: var(--block-space);
  }

  .person-profile__avatar {
    block-size: 5rem;
    border-radius: 50%;
    flex-shrink: 0;
    inline-size: 5rem;
    object-fit: cover;
  }

  .person-profile__avatar--initials {
    align-items: center;
    background-color: var(--color-ink-lightest);
    color: var(--color-ink-dark);
    display: flex;
    font-size: var(--text-large);
    font-weight: 600;
    justify-content: center;
    letter-spacing: 0.02em;
  }

  .person-profile__details {
    display: flex;
    flex-direction: column;
    gap: 0.4em;
    min-inline-size: 0;
  }

  .person-profile__facts {
    color: var(--color-ink-dark);
  }

  .person-profile__contacts {
    display: flex;
    flex-wrap: wrap;
    font-size: var(--text-small);
    gap: 0.25em var(--inline-space-double);
  }

  .person-profile__contact {
    align-items: center;
    display: inline-flex;
    gap: 0.15em;
    min-inline-size: 0;
  }

  .person-profile__contact-link {
    color: var(--color-ink);
    overflow-wrap: anywhere;
    text-decoration: underline;
    text-decoration-color: var(--color-ink-lighter);
    text-underline-offset: 0.2em;

    &:visited {
      color: var(--color-ink);
    }

    &:hover,
    &:focus-visible {
      color: var(--color-ink);
      text-decoration-color: currentColor;
    }
  }

  @media (max-width: 40em) {
    .person-profile__avatar {
      block-size: 4rem;
      inline-size: 4rem;
    }
  }

  /* The same avatar in the People index: card and table row sizes. After the
     media query so phones keep these sizes too. */
  .person-profile__avatar--card {
    block-size: 3.5rem;
    font-size: var(--text-medium);
    inline-size: 3.5rem;
  }

  .person-profile__avatar--row {
    block-size: 2.25rem;
    font-size: var(--text-x-small);
    inline-size: 2.25rem;
  }

  /* Timeline of entries */
  .timeline__entry {
    --panel-padding-block: var(--block-space-half);
    --panel-padding-inline: var(--block-space);

    position: relative;

    .record-menu {
      inset-block-start: var(--block-space-half);
      inset-inline-end: var(--block-space-half);
      position: absolute;
    }
  }

  .timeline__body {
    margin-block-end: 0.25em;
    overflow-wrap: anywhere;
  }

  .timeline__comment {
    border-inline-start: 2px solid var(--color-ink-lighter);
    font-style: italic;
    margin-block-end: 0.25em;
    padding-inline-start: 0.75em;
  }

  /* Tag picker (shared/_tag_picker) */
  .tag-picker {
    display: flex;
    flex-direction: column;
    gap: var(--block-space-half);

    /* An empty chips row must not add a phantom flex gap — without this the
       label-to-input spacing doubles compared to a regular fieldset. */
    .tag-chips:empty {
      display: none;
    }
  }

  /* Wraps the search input so the dropdown (anchored inset-inline: 0) always
     matches it. Mirrors .input's own sizing — fills the fieldset but capped
     by the same --input-max-width — so the pair behaves exactly like any
     regular input: full width on narrow forms, capped on wide ones. */
  .tag-picker__control {
    inline-size: 100%;
    max-inline-size: var(--input-max-width, 30em);
    position: relative;
  }

  /* The options list is a native popover: top-layer rendering overlays open
     modals instead of being clipped into their overflow scroll. Pinned to its
     input by picker_dropdown.js, which sets left/width plus either top or
     bottom — bottom when it has to flip above the input. Display stays scoped
     to :popover-open so the UA's closed state isn't overridden. */
  .tag-picker__options {
    --panel-padding-block: var(--block-space-half);
    --panel-padding-inline: var(--block-space-half);

    max-block-size: 14rem;
    overflow-y: auto;

    &:popover-open {
      display: flex;
      flex-direction: column;
      inset: auto; /* clear the popover UA inset: 0 */
      margin: 0;   /* clear the popover UA margin: auto */
      position: fixed;
    }

    /* When nothing matches, only "+ New tag…" is left — keep it visible. */
    &.tag-picker__options--empty .tag-picker__new {
      display: block;
    }
  }

  /* Person picker's selected state — looks like a regular input (uses the
     .input class for border/padding), just not editable; ✕ dismisses. */
  .person-picker__selected {
    align-items: center;
    display: flex;
    gap: 0.5em;
    justify-content: space-between;

    span {
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
  }

  /* Copy-to-clipboard icon next to phones/emails — sits inline with text. */
  .copy-button {
    font-size: 0.9em;
    vertical-align: middle;
  }

  .chip__remove {
    background: none;
    border: 0;
    color: inherit;
    cursor: pointer;
    font-size: 0.85em;
    margin-inline-start: 0.35em;
    padding: 0;
  }
}
