// =============================================================================
// ACCORDION — Task #28 (v2 spacing update)
// Left intro column + right white accordion panel.
// Mobile-first: base = 375px, desktop via respond-to('desktop')
// Measurements: design/measurements-v2.json → "accordion"
//   Web:    section px-120 py-80; intro + panel gap 120px; panel p-24, gap-24
//   Mobile: section px-16 py-56; stacked column, gap-32 between intro and panel
// =============================================================================

@import '../mixins';

// ─── Section wrapper ─────────────────────────────────────────────────────────
.accordion-section {
  // Section rhythm: 56px mobile+tablet, 80px laptop+ (--section-space, tokens.scss).
  // Kept separate from the row/column layout switch below, which stays at
  // 'desktop' (1440px) — the two are unrelated and shouldn't share a breakpoint.
  padding-block: var(--section-space); // (bg via .bg-pampas on <section>; horizontal inset via .container)
  display: flex;
  flex-direction: column;                  // mobile: stacked
  gap: 32px;                               // mobile: gap-32 between intro and panel
  // This TwoCol container (Templates/Container/TwoCol.html, layout 210) is
  // still wrapped in the ce-frame's own .container, but unlike other content
  // elements it has no max-width of its own — it just fills .container's
  // full width (1800px at the xxxl tier). Capping + centering here, same
  // technique as .footer__cta-card/.newsletter-form__card, keeps this
  // composition from stretching edge-to-edge on very wide screens.
  max-width: var(--container-max);         // 1200px
  margin-inline: auto;
}

// ─── Container columns ───────────────────────────────────────────────────────
// Two-column composition: left col = core Text CE (content-only-intro),
// right col = pure accordion element. See design/DESIGN.md for container mapping.
.accordion-section__col {
  display: flex;
  flex-direction: column;
}

.accordion-section__col--intro {
  // content-only-intro carries its own background + padding, which would
  // double up with .accordion-section's own — neutralise them here so the
  // nested block behaves as a plain content column inside this container.
  .content-only-intro {
    background-color: transparent;
    padding: 0;

    &__body {
      margin-top: 32px;
    }
  }

  .btn {
    margin-top: 24px;
  }
}

// ─── Accordion panel ─────────────────────────────────────────────────────────
.accordion {
  background-color: var(--color-white);
  padding: 24px;                           // p-24
  display: flex;
  flex-direction: column;
  gap: 24px;                               // gap-24 between items
}

.accordion__item {
  display: flex;
  flex-direction: column;
}

.accordion__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  text-align: left;

  &:focus-visible {
    outline: 2px solid var(--color-gold);
    outline-offset: 2px;
  }
}

.accordion__label {
  font-family: var(--font-body);
  font-size: var(--fs-lg);                // 18px mobile (text-lg semibold)
  font-weight: 600;
  line-height: var(--lh-lg-tight);        // 28px
  text-transform: uppercase;
  color: var(--color-nandor);            // #49554c
}

// Plus/minus icon drawn in CSS
.accordion__icon {
  position: relative;
  width: 24px;
  height: 24px;
  flex-shrink: 0;

  &::before,
  &::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    background-color: var(--color-text-primary);
    transform: translate(-50%, -50%);
  }

  &::before {
    width: 14px;
    height: 1.5px;  // horizontal bar (minus)
  }

  &::after {
    width: 1.5px;
    height: 14px;   // vertical bar — hidden when open
    transition: transform 0.2s ease, opacity 0.2s ease;
  }
}

// Grid-rows collapse instead of animating to a guessed max-height: a fixed
// max-height transitions over that guessed distance regardless of the panel's
// real content height, so short panels snapped open/closed instead of easing
// smoothly. Animating 0fr → 1fr on the grid track measures the actual content
// height every time, so the motion is smooth at any content length — no JS
// height calculation needed, .accordion__content just needs overflow:hidden
// so it can shrink below its own content size mid-transition.
.accordion__panel {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.accordion__content {
  @include body-text;
  margin: 0;
  padding-top: 8px;                       // 8px header → body
  overflow: hidden;
  min-height: 0;
}

// Open state
.accordion__item.is-open {
  .accordion__panel {
    grid-template-rows: 1fr;
  }

  .accordion__icon::after {
    transform: translate(-50%, -50%) scaleY(0);
    opacity: 0;
  }
}

// ─── Desktop ─────────────────────────────────────────────────────────────────
@include respond-to('desktop') {
  .accordion-section {
    flex-direction: row;                   // desktop: side-by-side
    align-items: flex-start;
    gap: 120px;                            // gap-120 between intro and panel
  }

  .accordion-section__col--intro {
    width: 489px;
    flex-shrink: 0;
  }

  .accordion {
    flex: 1;
    min-width: 0;
  }

  .accordion__label {
    font-size: var(--fs-xl);             // 20px desktop
    line-height: var(--lh-xl);
  }
}
