/**
 * @file
 * Accordion item styles.
 *
 * Values from Figma node 408:7130 — question Outfit Medium 20/1.5, answer Outfit
 * Light 16/1.5, 8px apart, 16px bottom padding above a 1px #ececec rule, with a
 * 24px icon 16px to the right of the text.
 */

.ln-accordion-item {
  --ln-accordion-item-fg: #1c1c1c;
  --ln-accordion-item-rule: #ececec;
  --ln-accordion-item-icon-size: 24px;
  --ln-accordion-item-icon-gap: 16px;
  --ln-accordion-item-duration: 0.25s;
  --ln-accordion-item-easing: ease;

  /* Unverified: the Figma chevron reads red but the exported asset could not be
     sampled. Matches the primary button red for now. */
  --ln-accordion-item-icon-color: #cf0000;

  padding-bottom: 16px;
  border-bottom: 1px solid var(--ln-accordion-item-rule);
  color: var(--ln-accordion-item-fg);
}

/* Row holding the question and the chevron. */
.ln-accordion-item__summary {
  display: flex;
  align-items: flex-start;
  gap: var(--ln-accordion-item-icon-gap);
  cursor: pointer;
  list-style: none;
}

/* Suppress the native disclosure triangle. */
.ln-accordion-item__summary::-webkit-details-marker {
  display: none;
}

.ln-accordion-item__summary::marker {
  content: '';
}

.ln-accordion-item__summary:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 4px;
}

.ln-accordion-item__question {
  flex: 1 1 0;
  min-width: 0;
  font-size: 20px;
  font-weight: 500;
  line-height: 1.5;
  text-align: left;
}

.ln-accordion-item__icon {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  width: var(--ln-accordion-item-icon-size);
  height: calc(20px * 1.5);
  color: var(--ln-accordion-item-icon-color);
  transition: transform var(--ln-accordion-item-duration) var(--ln-accordion-item-easing);
}

.ln-accordion-item__icon svg {
  display: block;
  width: 14px;
  height: auto;
}

/* Closed points down, open points up, per the icon's two Figma variants. */
.ln-accordion-item[open] .ln-accordion-item__icon {
  transform: rotate(180deg);
}

/**
 * [open] is still set while the panel is closing, so the chevron would otherwise
 * hold its rotated position and flip at the very end. Unwind it in step with the
 * slide instead.
 */
.ln-accordion-item[open].ln-accordion-item--closing .ln-accordion-item__icon {
  transform: none;
}

/**
 * Slide the panel open and closed.
 *
 * A closed <details> does not render its content at all, so there is normally
 * nothing for CSS to transition. ::details-content addresses that hidden
 * wrapper; it reached Baseline in September 2025 and ships in current Chrome,
 * Firefox and Safari.
 *
 * The row is animated as 0fr -> 1fr rather than height 0 -> auto on purpose.
 * Interpolating to the auto keyword needs `interpolate-size: allow-keywords`,
 * which is still Chromium-only, so that approach slides in Chrome and snaps in
 * Firefox and Safari. Fractions are plain numbers and interpolate everywhere
 * ::details-content is supported.
 *
 * content-visibility is transitioned with allow-discrete so the content stays
 * rendered for the duration of the closing animation instead of vanishing on
 * the first frame.
 *
 * Browsers without ::details-content simply open and close instantly, exactly as
 * before — the panel still works, it just does not animate.
 */
.ln-accordion-item::details-content {
  display: grid;
  grid-template-rows: 0fr;
  transition:
    grid-template-rows var(--ln-accordion-item-duration) var(--ln-accordion-item-easing),
    content-visibility var(--ln-accordion-item-duration) allow-discrete;
}

.ln-accordion-item[open]::details-content {
  grid-template-rows: 1fr;
}

/**
 * Collapsed by accordion-item.js while [open] is still set, so the content stays
 * rendered for the duration of the closing transition. Needs to outrank the
 * [open] rule above, hence the extra class in the selector.
 *
 * @see accordion-item.js
 */
.ln-accordion-item[open].ln-accordion-item--closing::details-content {
  grid-template-rows: 0fr;
}

/**
 * The animating grid item. Deliberately has no padding, border or margin: none
 * of those shrink below their specified size, so any of them would stop the row
 * reaching zero and leave a sliver of panel visible until [open] is removed.
 *
 * min-height and overflow let the row collapse below the content's natural
 * height; without them it cannot shrink to 0fr at all.
 */
.ln-accordion-item__answer {
  min-height: 0;
  overflow: hidden;
}

/* All spacing and typography live inside the clipped area. */
.ln-accordion-item__answer-inner {
  padding-top: 8px;
  font-size: 16px;
  font-weight: 300;
  line-height: 1.5;
}

.ln-accordion-item__answer-inner > :first-child {
  margin-top: 0;
}

.ln-accordion-item__answer-inner > :last-child {
  margin-bottom: 0;
}

/**
 * Respect a reduced-motion preference: snap open and closed with no slide and no
 * icon rotation animation. The duration is zeroed rather than the transitions
 * removed, so content-visibility still resolves discretely and the panel does not
 * get stuck mid-state.
 */
@media (prefers-reduced-motion: reduce) {
  .ln-accordion-item {
    --ln-accordion-item-duration: 0s;
  }
}
