/* Fit check (site/snippets/blocks/fitcheck.php, public/assets/js/fitcheck.js;
   the Search funnel, A4). Three to five situations in the reader's words,
   each with two sentences and the page to go to; the one that fits this
   page carries a mint tag and the call button. Linked by the block itself
   (peanut_page_css), once per page. Every selector names a fitcheck class.
   Tokens only.

   Without the script and in print: every row stands as a white card, its
   situation as a heading over its text and link, nothing hidden. The
   script adds .is-live: each heading holds a button (aria-expanded), the
   closed panels carry data-off.
   - From 64rem: the buttons in a column on the left, the panels on the
     right, all in one grid cell spanning every row (the tallest sets the
     height, the shown one fills it; the others are visibility hidden), so
     a press never moves the page and the panel column is never empty. The
     rows keep their own height: the cell's extra height goes to a last
     flexible row (grid-template-rows: one auto row a situation, then 1fr).
   - Below 64rem: an accordion, each panel under its row, closed ones out.
   White cards on every background, so the block reads on paper, butter,
   mint and ink alike; on ink the closed buttons turn to white outlines.
   Under the rows, Other services (A7): a label and a list of short lines,
   one column on phones, two from 48rem, after a 1px line; no script.
   Motion (the chevron's turn) lives in the motion layer only. */

@layer blocks {
  .fitcheck__head {
    max-width: 44rem;
    margin-block-end: var(--space-5);
  }

  .fitcheck__title {
    margin: 0;
  }

  .fitcheck__intro {
    margin: var(--space-3) 0 0;
  }

  .fitcheck__check {
    max-width: 68rem;
  }

  .fitcheck__hint {
    margin-block-end: var(--space-2);
  }

  /* ---------- without the script: a plain list of cards ---------- */
  .fitcheck__rows {
    display: grid;
    gap: var(--space-2);
  }

  .fitcheck__row {
    padding: var(--space-3);
    background: var(--color-white);
    border: var(--border);
    border-radius: var(--radius-sm);
    color: var(--color-ink);
  }

  .fitcheck__situation {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-1) var(--space-2);
    margin: 0 0 var(--space-2);
    font-family: var(--font-body);
    font-size: var(--step-0);
    font-weight: 600;
    line-height: 1.4;
  }

  .fitcheck__tag {
    display: inline-block;
    padding: 0.125rem 0.625rem;
    background: var(--color-brand);
    border: var(--border);
    border-radius: var(--radius-pill);
    color: var(--color-ink);
    font-size: var(--pill-font-size);
    font-weight: var(--pill-weight);
    letter-spacing: var(--pill-tracking);
    line-height: 1.6;
    text-transform: uppercase;
    white-space: nowrap;
  }

  .fitcheck__panel {
    --focus-ring: var(--color-ink);
    color: var(--color-ink);
  }

  .fitcheck__text {
    max-width: var(--measure);
    margin: 0;
  }

  .fitcheck__text a {
    color: inherit;
  }

  .fitcheck__go {
    margin-block-start: var(--space-3);
  }

  /* ---------- with the script ---------- */
  .fitcheck__check.is-live .fitcheck__rows {
    gap: var(--space-1);
  }

  .fitcheck__check.is-live .fitcheck__row {
    padding: 0;
    background: none;
    border: 0;
    border-radius: 0;
  }

  .fitcheck__check.is-live .fitcheck__situation {
    display: block;
    margin: 0;
  }

  /* the words on the left, the tag (Here row) under them, the chevron on the right */
  .fitcheck__btn {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    justify-items: start;
    gap: 0.375rem var(--space-2);
    width: 100%;
    min-height: 3.5rem;
    margin: 0;
    padding: 0.75rem var(--space-3);
    background: var(--color-white);
    border: var(--border);
    border-radius: var(--radius-sm);
    color: var(--color-ink);
    font: inherit;
    text-align: start;
    cursor: pointer;
  }

  .fitcheck__btn:hover {
    background: var(--color-paper);
  }

  .fitcheck__btn:focus-visible {
    outline: 3px solid var(--focus-ring);
    outline-offset: 2px;
  }

  .fitcheck__btn[aria-expanded="true"] {
    background: var(--color-ink);
    color: var(--color-white);
  }

  .fitcheck__btn .fitcheck__words {
    grid-column: 1;
    min-width: 0;
  }

  .fitcheck__btn .fitcheck__tag {
    grid-column: 1;
  }

  .fitcheck__btn .fitcheck__mark {
    grid-column: 2;
    grid-row: 1 / span 2;
    align-self: center;
  }

  /* the chevron: down when closed, up when open (below 64rem), right from 64rem */
  .fitcheck__mark {
    flex: none;
    width: 0.5625rem;
    height: 0.5625rem;
    margin-inline: 0.25rem;
    border-block-end: 1.5px solid currentColor;
    border-inline-end: 1.5px solid currentColor;
    transform: translateY(-0.15rem) rotate(45deg);
  }

  .fitcheck__btn[aria-expanded="true"] .fitcheck__mark {
    transform: translateY(0.15rem) rotate(-135deg);
  }

  /* ink band: the closed buttons as white outlines, the open one white */
  .section--ink .fitcheck__btn {
    background: transparent;
    border-color: var(--color-on-ink-line-strong);
    color: var(--color-white);
  }

  .section--ink .fitcheck__btn:hover {
    background: var(--color-on-ink-fill);
  }

  .section--ink .fitcheck__btn[aria-expanded="true"] {
    background: var(--color-white);
    border-color: var(--color-white);
    color: var(--color-ink);
  }

  /* the panel is a white card on an ink band too: the call keeps its ink fill
     there (blocks.css turns a filled button white on ink) */
  .section--ink .fitcheck__panel .btn--fill {
    --_bg: var(--color-ink);
    --_fg: var(--color-white);
    --_border: var(--color-ink);
    --_hover-bg: var(--color-white);
    --_hover-fg: var(--color-ink);
  }

  .fitcheck__check.is-live .fitcheck__panel {
    padding: var(--space-3);
    background: var(--color-white);
    border: var(--border);
    border-radius: var(--radius-sm);
  }

  /* narrow: the accordion, the open panel close under its row */
  @media screen and (max-width: 63.99rem) {
    .fitcheck__check.is-live .fitcheck__panel {
      margin-block-start: var(--space-1);
    }

    .fitcheck__check.is-live .fitcheck__panel[data-off] {
      display: none;
    }
  }

  /* wide: buttons on the left, every panel in one cell on the right */
  @media screen and (min-width: 64rem) {
    .fitcheck__check.is-live .fitcheck__rows {
      grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
      grid-template-rows: repeat(var(--fc-rows, 4), auto) 1fr;
      column-gap: var(--space-4);
    }

    .fitcheck__check.is-live .fitcheck__row {
      display: contents;
    }

    .fitcheck__check.is-live .fitcheck__situation {
      grid-column: 1;
    }

    .fitcheck__check.is-live .fitcheck__panel {
      display: flex;
      flex-direction: column;
      justify-content: center;
      grid-column: 2;
      grid-row: 1 / -1;
      padding: var(--space-4);
    }

    .fitcheck__check.is-live .fitcheck__panel[data-off] {
      visibility: hidden;
    }

    .fitcheck__check.is-live .fitcheck__text {
      font-size: var(--step-1);
      line-height: 1.6;
    }

    .fitcheck__mark,
    .fitcheck__btn[aria-expanded="true"] .fitcheck__mark {
      transform: rotate(-45deg);
    }

    .fitcheck__btn[aria-expanded="true"] .fitcheck__mark {
      width: 0.75rem;
      height: 0.75rem;
      border-width: 2px;
    }
  }

  /* ---------- other services (A7): always shown, no script ---------- */
  .fitcheck__also {
    max-width: 68rem;
    margin-block-start: var(--space-5);
    padding-block-start: var(--space-3);
    border-block-start: var(--border);
  }

  .section--ink .fitcheck__also {
    border-color: var(--color-on-ink-line-strong);
  }

  .fitcheck__also-label {
    margin: 0 0 var(--space-2);
  }

  .fitcheck__also-list {
    display: grid;
    gap: var(--space-2) var(--space-4);
    margin: 0;
    padding: 0;
    list-style: none;
  }

  .fitcheck__also-item {
    min-width: 0;
    max-width: var(--measure);
  }

  .fitcheck__also-item a {
    color: inherit;
    font-weight: 600;
  }

  @media screen and (min-width: 48rem) {
    .fitcheck__also-list {
      grid-template-columns: repeat(2, minmax(0, 1fr));
    }
  }

  /* ---------- print: every row and its panel ---------- */
  @media print {
    .fitcheck__hint,
    .fitcheck__mark {
      display: none;
    }

    .fitcheck__check.is-live .fitcheck__rows {
      display: grid;
      grid-template-columns: none;
      grid-template-rows: none;
    }

    .fitcheck__check.is-live .fitcheck__row {
      display: block;
      break-inside: avoid;
    }

    .fitcheck__check.is-live .fitcheck__panel,
    .fitcheck__check.is-live .fitcheck__panel[data-off] {
      display: block;
      visibility: visible;
      margin-block-start: var(--space-1);
    }

    .fitcheck__btn,
    .fitcheck__btn[aria-expanded="true"] {
      background: var(--color-white);
      color: var(--color-ink);
    }
  }
}

@layer motion {
  @media screen and (prefers-reduced-motion: no-preference) {
    html[data-fx~="diagrams"] .fitcheck__mark {
      transition: transform var(--duration) var(--ease);
    }
  }
}
