/**
 * @file
 * Phase timeline: vertical rail by default, horizontal row when the
 * container (not the viewport) is wide enough, so it also stacks inside a
 * narrow Layout Builder column.
 *
 * Accent colour: --engage-accent is set per client theme in engage_base
 * (base _branding.less + clients/{client}); falls back to Olivero's primary.
 *
 * Light/dark: text inherits, tints are derived from the accent or the text
 * colour, and hollow markers are transparent, so the component follows the
 * surface it sits on. The accent switches with the page's declared
 * color-scheme (light-dark()), not the OS preference: engage front-end
 * themes are light-only, so following prefers-color-scheme would put a dark
 * component on a white page. A dark theme or section only needs
 * `color-scheme: dark` (and optionally --engage-accent-dark).
 */
.phase-timeline {
  --pt-accent-light: var(--engage-accent, var(--color--primary-50, #3f5ea8));
  --pt-accent: var(--pt-accent-light);
  --pt-track: #c5cedd;
  --pt-halo: rgba(63, 94, 168, 0.25);
  --pt-muted: #4d5761;
  --pt-marker: 1.25rem;
  --pt-line: 2px;
  --pt-gap: 1.5rem;

  container-type: inline-size;
  margin-block: 1.5rem;
}

@supports (color: color-mix(in srgb, red, blue)) {
  .phase-timeline {
    --pt-track: color-mix(in srgb, var(--pt-accent) 35%, transparent);
    --pt-halo: color-mix(in srgb, var(--pt-accent) 25%, transparent);
    --pt-muted: color-mix(in srgb, currentColor 75%, transparent);
  }
}

@supports (color: light-dark(#000, #fff)) {
  .phase-timeline {
    --pt-accent: light-dark(var(--pt-accent-light), var(--engage-accent-dark, color-mix(in srgb, var(--pt-accent-light) 45%, #fff)));
  }
}

.phase-timeline__list {
  display: grid;
  margin: 0;
  padding: 0;
  list-style: none;
}

/* Vertical (default): marker column + text, track runs down to the next. */
.phase-timeline__phase {
  position: relative;
  display: grid;
  grid-template-columns: var(--pt-marker) minmax(0, 1fr);
  align-content: start;
  column-gap: 0.875rem;
  margin: 0;
  padding: 0 0 var(--pt-gap);
}

.phase-timeline__phase:last-child {
  padding-block-end: 0;
}

.phase-timeline__phase:not(:last-child)::before {
  position: absolute;
  inset-block: var(--pt-marker) 0;
  inset-inline-start: calc((var(--pt-marker) - var(--pt-line)) / 2);
  width: var(--pt-line);
  content: "";
  background: var(--pt-track);
}

/* The track is solid from a completed phase onward to the next phase. */
.phase-timeline__phase--completed:not(:last-child)::before {
  background: var(--pt-accent);
}

.phase-timeline__marker {
  position: relative;
  z-index: 1;
  box-sizing: border-box;
  width: var(--pt-marker);
  height: var(--pt-marker);
  border: var(--pt-line) solid var(--pt-accent);
  border-radius: 50%;
  /* Hollow (upcoming) markers show the surface behind them; the track never
     runs under a marker, so no fill colour is needed in light or dark. */
  background: transparent;
}

.phase-timeline__phase--completed .phase-timeline__marker,
.phase-timeline__phase--current .phase-timeline__marker {
  background: var(--pt-accent);
}

.phase-timeline__phase--current .phase-timeline__marker {
  box-shadow: 0 0 0 0.3125rem var(--pt-halo);
}

.phase-timeline__body {
  min-width: 0;
  line-height: 1.45;
  overflow-wrap: break-word;
}

.phase-timeline__title {
  margin: 0;
  /* Themes hyphenate body text; keep short phase names whole. */
  hyphens: manual;
  font-size: 1.0625rem;
  font-weight: 700;
  line-height: 1.3;
}

.phase-timeline__dates {
  margin: 0.25rem 0 0;
  color: var(--pt-muted);
  font-size: 0.9375rem;
}

.phase-timeline__description {
  margin: 0.375rem 0 0;
  font-size: 0.9375rem;
}

.phase-timeline__link {
  display: inline-block;
  margin-block-start: 0.375rem;
  color: var(--pt-accent);
  font-size: 0.9375rem;
  font-weight: 600;
}

/*
 * Horizontal: one column per phase, track runs across to the next marker.
 * Up to four phases switch at 48rem; five or six need 60rem, with a narrower
 * gap to give their text more room. Stays horizontal in a typical 1280px
 * laptop's content column (about 1017px).
 */
@container (min-width: 48rem) {
  .phase-timeline:not(.phase-timeline--many) .phase-timeline__list {
    grid-template-columns: repeat(var(--phase-count), minmax(0, 1fr));
    column-gap: var(--pt-gap);
  }

  .phase-timeline:not(.phase-timeline--many) .phase-timeline__phase {
    grid-template-columns: minmax(0, 1fr);
    row-gap: 0.75rem;
    padding: 0;
  }

  .phase-timeline:not(.phase-timeline--many) .phase-timeline__phase:not(:last-child)::before {
    inset-block: calc((var(--pt-marker) - var(--pt-line)) / 2) auto;
    inset-inline: var(--pt-marker) calc(-1 * var(--pt-gap));
    width: auto;
    height: var(--pt-line);
  }
}

@container (min-width: 60rem) {
  .phase-timeline--many .phase-timeline__list {
    --pt-gap: 1rem;

    grid-template-columns: repeat(var(--phase-count), minmax(0, 1fr));
    column-gap: var(--pt-gap);
  }

  .phase-timeline--many .phase-timeline__phase {
    grid-template-columns: minmax(0, 1fr);
    row-gap: 0.75rem;
    padding: 0;
  }

  /* Keeps long single words, such as "Recommandations", from breaking. */
  .phase-timeline--many .phase-timeline__title {
    font-size: 1rem;
  }

  .phase-timeline--many .phase-timeline__phase:not(:last-child)::before {
    inset-block: calc((var(--pt-marker) - var(--pt-line)) / 2) auto;
    inset-inline: var(--pt-marker) calc(-1 * var(--pt-gap));
    width: auto;
    height: var(--pt-line);
  }
}
