/* === Row layout (timeline__row) === */
.timeline__row {
  --speech-bubble-width: 1.4rem;
  --speech-bubble-color: var(--secondary-light);

  display: grid;
  grid-template-columns: minmax(0, 1fr) max-content minmax(0, 1fr);
  grid-template-rows: var(--grid-1);
  gap: var(--container-gap) var(--grid-gap);
  isolation: isolate;
}

/* Empty spacer column (creates the left/right zigzag offset) */
.timeline__empty {
  order: 1;
  visibility: hidden;
}

/* === Center line + icon === */
.timeline__line-wrapper {
  order: 2;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  height: 100%;
}

.timeline__line {
  position: absolute;
  left: 50%;
  top: 0;
  width: 2px;
  height: calc(100% + var(--space-xxl));
  transform: translateX(-50%);
  color: var(--secondary-light);
  z-index: -1;
}

.timeline__line .line,
.timeline__line {
  background-color: var(--secondary-light);
}

.timeline__icon-wrapper {
  width: fit-content;
  height: fit-content;
  margin-inline: auto;
  padding: var(--space-xs);
  background-color: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
}

.timeline__icon {
  display: block;
  width: var(--text-l);
  height: var(--text-l);
  aspect-ratio: 1;
  border-radius: 50%;
  background-color: var(--secondary);
}

/* === Card === */
.card-timeline {
  order: 3;
  position: relative;
  display: flex;
  flex-direction: column;
  row-gap: var(--content-gap);
  padding: var(--space-l);
  background-color: var(--secondary-light);
  border-radius: var(--radius-m);
}

/* Speech bubble pointing toward the line */
.card-timeline:after {
  content: '';
  position: absolute;
  display: block;
  width: 0;
  z-index: 1;
  border-style: solid;
  border-color: transparent var(--speech-bubble-color);
  border-width: var(--speech-bubble-width) var(--speech-bubble-width) var(--speech-bubble-width) 0;
  top: 50%;
  left: calc(-1 * var(--speech-bubble-width));
  margin-block-start: calc(-1 * var(--speech-bubble-width));
}

.card-timeline__container {
  display: flex;
  flex-direction: column;
  row-gap: var(--space-xs);
  align-items: flex-start;
}

.card-timeline__date {
  align-self: flex-start;
  font-weight: 600;
  line-height: 1.2;
  background-color: var(--accent);
  padding: 0.25em 0.5em;
  border-radius: var(--radius-xs);
}

.card-timeline__heading {
  font-size: var(--text-xl);
}

/* === Zigzag: even rows align to the right === */
.timeline__row:nth-child(even) .timeline__empty {
  order: 3;
}

.timeline__row:nth-child(even) .card-timeline {
  order: 1;
  text-align: end;
}

.timeline__row:nth-child(even) .card-timeline:after {
  left: auto;
  right: calc(-1 * var(--speech-bubble-width));
  border-width: var(--speech-bubble-width) 0 var(--speech-bubble-width) var(--speech-bubble-width);
}

.timeline__row:nth-child(even) .card-timeline .card-timeline__container {
  align-items: flex-end;
}

/* First / last rows: trim the connecting line */
.timeline__row:first-child .timeline__line {
  top: auto;
  bottom: calc(-1 * var(--space-xxl));
  height: calc(50% + var(--space-xxl));
}

.timeline__row:last-child .timeline__line {
  height: 50%;
}

/* === Tablet / mobile: collapse to a single left-aligned column === */
@media (max-width: 991px) {
  .timeline__row {
    grid-template-columns: max-content minmax(0, 1fr);
  }

  .timeline__empty {
    order: 3;
    display: none;
  }

  .timeline__line-wrapper {
    order: -1;
  }
}

@media (max-width: 767px) {
  .timeline__row:nth-child(even) .card-timeline {
    text-align: start;
  }

  .timeline__row:nth-child(even) .card-timeline .card-timeline__container {
    align-items: inherit;
  }

  .timeline__row:nth-child(even) .card-timeline:after {
    left: calc(-1 * var(--speech-bubble-width));
    right: auto;
    border-width: var(--speech-bubble-width) var(--speech-bubble-width) var(--speech-bubble-width) 0;
  }
}
