/* Shared by the Astro, React and Vanilla Accordion variants. */

/* A bordered stack of sections, with the same border, radius and type as Tabs
   and Menu. Each section is a full-width header button over its panel. */
.exo-accordion {
  font-family: var(--exo-font-family-sans, system-ui, sans-serif);
  color: var(--exo-color-text, #333333);
  background: var(--exo-color-bg, #ffffff);
  border: var(--exo-border-width-1, 1px) solid var(--exo-color-border, #dddddd);
  border-radius: var(--exo-radius-3, 6px);
}

.exo-accordion__item + .exo-accordion__item {
  border-top: var(--exo-border-width-1, 1px) solid var(--exo-color-border, #dddddd);
}

/* The heading only gives the header its place in the outline; it adds no styles of its own. */
.exo-accordion__heading {
  margin: 0;
  font: inherit;
}

.exo-accordion__header {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--exo-space-3, 8px);
  width: 100%;
  margin: 0;
  padding: var(--exo-space-3, 8px) var(--exo-space-4, 12px);
  font-family: inherit;
  font-size: var(--exo-font-size-sm, 14px);
  font-weight: var(--exo-font-weight-medium, 500);
  line-height: var(--exo-font-line-height-snug, 1.25);
  color: inherit;
  text-align: start;
  background: none;
  border: 0;
  /* Inner corners stay square; the first and last header follow the wrapper's radius. */
  border-radius: 0;
  cursor: pointer;
}

.exo-accordion__item:first-child .exo-accordion__header {
  border-start-start-radius: calc(var(--exo-radius-3, 6px) - var(--exo-border-width-1, 1px));
  border-start-end-radius: calc(var(--exo-radius-3, 6px) - var(--exo-border-width-1, 1px));
}

.exo-accordion__item:last-child .exo-accordion__header[aria-expanded="false"] {
  border-end-start-radius: calc(var(--exo-radius-3, 6px) - var(--exo-border-width-1, 1px));
  border-end-end-radius: calc(var(--exo-radius-3, 6px) - var(--exo-border-width-1, 1px));
}

.exo-accordion__header:hover:not(:disabled) {
  background: var(--exo-color-bg-hover, rgb(0 0 0 / 0.1));
}

/* Inset, so the outline isn't clipped by or drawn over the neighboring sections. */
.exo-accordion__header:focus-visible {
  outline: var(--exo-border-width-2, 2px) solid var(--exo-color-accent, #2f5fdb);
  outline-offset: calc(-1 * var(--exo-border-width-2, 2px));
}

.exo-accordion__header:disabled {
  color: var(--exo-color-text-muted, #666666);
  cursor: not-allowed;
}

.exo-accordion__title {
  min-width: 0;
}

.exo-accordion__icon {
  flex: none;
  color: var(--exo-color-text-muted, #666666);
  transition: transform var(--exo-duration-overlay, 180ms) var(--exo-easing-out, ease-out);
}

.exo-accordion__header[aria-expanded="true"] .exo-accordion__icon {
  transform: rotate(180deg);
}

/* The panel collapses by animating its single grid row from its full height
   to 0. A closed panel keeps its `hidden` attribute, which hides it without
   this stylesheet; with it, `visibility: hidden` keeps the content out of the
   tab order and the accessibility tree once the row has closed. */
.exo-accordion__panel {
  display: grid;
  grid-template-rows: 1fr;
  padding: 0 var(--exo-space-4, 12px) var(--exo-space-4, 12px);
  transition:
    grid-template-rows var(--exo-duration-overlay, 180ms) var(--exo-easing-out, ease-out),
    padding-block-end var(--exo-duration-overlay, 180ms) var(--exo-easing-out, ease-out),
    visibility var(--exo-duration-overlay, 180ms);
}

.exo-accordion__panel[hidden] {
  display: grid;
  grid-template-rows: 0fr;
  padding-block-end: 0;
  visibility: hidden;
}

.exo-accordion__content {
  min-height: 0;
  overflow: hidden;
  font-size: var(--exo-font-size-sm, 14px);
  line-height: var(--exo-font-line-height-normal, 1.5);
}

.exo-accordion__content > :first-child {
  margin-top: 0;
}

.exo-accordion__content > :last-child {
  margin-bottom: 0;
}

/*
 * The nav variant: the exo-ds site's navigation groups. No box; each section is a small caret and title
 * over its content, the sections split by a hairline. The panels open and close without animating.
 * Custom properties, read with a fallback so they can be set on the accordion or on any ancestor:
 *   --exo-accordion-nav-gap      the space between sections (and around their hairlines). Default --exo-space-5.
 *   --exo-accordion-nav-divider  the hairline color. Default --exo-color-text at 6%.
 */
.exo-accordion--nav {
  display: flex;
  flex-direction: column;
  gap: var(--exo-accordion-nav-gap, var(--exo-space-5, 16px));
  min-width: 0;
  color: inherit;
  background: none;
  border: 0;
  border-radius: 0;
}

/* Hidden sections (filtered out) are skipped, so they leave no stray hairline. */
.exo-accordion--nav > .exo-accordion__item {
  min-width: 0;
  border-top: 0;
}

.exo-accordion--nav > .exo-accordion__item:not([hidden]) ~ .exo-accordion__item:not([hidden]) {
  padding-top: var(--exo-accordion-nav-gap, var(--exo-space-5, 16px));
  border-top: var(--exo-border-width-1, 1px) solid var(--exo-accordion-nav-divider, color-mix(in srgb, currentColor 6%, transparent));
}

.exo-accordion--nav .exo-accordion__header {
  justify-content: flex-start;
  gap: var(--exo-space-2, 6px);
  padding: 0;
  font-size: var(--exo-font-size-xs, 12px);
  font-weight: inherit;
  line-height: var(--exo-font-line-height-snug, 1.25);
}

/* Beats the boxed variant's first and last corner rules. */
.exo-accordion--nav .exo-accordion__item .exo-accordion__header[aria-expanded] {
  border-radius: var(--exo-radius-1, 2px);
}

.exo-accordion--nav .exo-accordion__header:hover:not(:disabled) {
  background: none;
}

.exo-accordion--nav .exo-accordion__header:focus-visible {
  outline-offset: calc(-1 * var(--exo-border-width-1, 1px));
}

.exo-accordion__caret {
  flex: none;
  fill: currentColor;
  transition: transform var(--exo-duration-hover, 150ms) var(--exo-easing-out, ease-out);
}

.exo-accordion__header[aria-expanded="false"] .exo-accordion__caret {
  transform: rotate(-90deg);
}

.exo-accordion--nav .exo-accordion__panel {
  display: block;
  margin-top: var(--exo-space-3, 8px);
  padding: 0;
  transition: none;
}

.exo-accordion--nav .exo-accordion__panel[hidden] {
  display: none;
}

/* The content stacks its children (a link list, controls) and doesn't clip their focus outlines. */
.exo-accordion--nav .exo-accordion__content {
  display: flex;
  flex-direction: column;
  gap: var(--exo-space-3, 8px);
  min-width: 0;
  overflow: visible;
}

@media (prefers-reduced-motion: reduce) {
  .exo-accordion__icon,
  .exo-accordion__caret,
  .exo-accordion__panel {
    transition: none;
  }
}
