/* Stats Counter */
.stats-counter {
  padding: var(--section-padding) 0;
  background-color: var(--color-background);
}

/* Header — logo + subtitle */
.stats-counter__header {
  text-align: center;
  margin-bottom: var(--spacing-lg);
}

.stats-counter__logo {
  display: block;
  margin: 0 auto var(--spacing-sm);
  height: auto;
}

.stats-counter__subtitle {
  font-size: var(--p-size);
  line-height: var(--p-lh);
  color: var(--color-text-primary);
  max-width: 600px;
  margin: 0 auto;
}

/* Wave background — full viewport width */
.stats-counter__items {
  position: relative;
  padding: var(--container-padding) 0 0;
}

/* Items grid — 3 columns */
.stats-counter__items > div {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--spacing-xl);
  max-width: 1080px;
  margin: 0 auto;
}

/* Center single item in last row (4, 7, 10... items total) */
.stats-counter__items > div > div:last-child:nth-child(3n+1) {
  grid-column: 2;
}

/* Row 1 wave — always visible */
.stats-counter__items > div::before {
  content: '';
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: 100vw;
  top: 0;
  bottom: 0;
  background: url('../../images/orange-wave-segment.svg') repeat-x center center;
  background-size: auto 40px;
  pointer-events: none;
  z-index: 0;
}

/* When 4+ items: row 1 wave covers top half, row 2 wave via ::after */
.stats-counter__items > div:has(> :nth-child(4))::before {
  bottom: calc(50% + var(--spacing-xl) / 2);
}

.stats-counter__items > div:has(> :nth-child(4))::after {
  content: '';
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: 100vw;
  top: calc(50% + var(--spacing-xl) / 2);
  bottom: 0;
  background: url('../../images/orange-wave-segment.svg') repeat-x center center;
  background-size: auto 40px;
  pointer-events: none;
  z-index: 0;
}

/* Drupal item wrapper — stretch to fill grid cell */
.stats-counter__items > div > div {
  display: flex;
}

.stats-counter__item {
  display: flex;
  align-items: center;
  flex: 1;
  gap: var(--spacing-sm);
  background-color: var(--color-background);
  position: relative;
  z-index: 1;
  box-shadow: 0 0 10px var(--color-medium-gray);
  border-radius: var(--radius-card-lg);
  padding: var(--spacing-md) var(--spacing-lg);
}

.stats-counter__number {
  font-size: var(--h2-size);
  line-height: var(--h2-lh);
  font-weight: 700;
  color: var(--color-primary);
  white-space: nowrap;
}

.stats-counter__label {
  font-size: var(--h5-size);
  line-height: var(--h5-lh);
  color: var(--color-text-dark);
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 1px;
}

/* Centered style — vertical cards */
.stats-counter--centered .stats-counter__items > div {
  align-items: center;
}

.stats-counter--centered .stats-counter__items > div > div {
  display: block;
}

.stats-counter--centered .stats-counter__item {
  flex-direction: column;
  text-align: center;
  padding: var(--spacing-md);
  box-shadow: none;
  border: 1px solid color-mix(in srgb, var(--color-error-orange) 30%, transparent);
  flex: none;
}

.stats-counter--centered .stats-counter__number {
  font-size: var(--h1-size);
  line-height: var(--h1-lh);
}

@media (max-width: 1023px) {
  .stats-counter__items > div {
    grid-template-columns: repeat(2, 300px);
    justify-content: center;
    gap: 32px;
  }

  .stats-counter__items > div::before,
  .stats-counter__items > div::after {
    display: none;
  }

  .stats-counter__items > div > div:last-child:nth-child(3n+1) {
    grid-column: auto;
  }

  .stats-counter {
    overflow: hidden;
  }

  .stats-counter .container,
  .stats-counter__items,
  .stats-counter__items > div {
    overflow: visible;
  }

  .stats-counter__items > div > div {
    justify-self: center;
    width: 300px;
    position: relative;
    overflow: visible;
  }

  /* Wave only on 1st and 3rd (odd) items to avoid overlap on same row */
  .stats-counter__items > div > div:nth-child(odd)::before {
    content: '';
    position: absolute;
    left: -9999px;
    right: -9999px;
    top: 0;
    bottom: 0;
    background: url('../../images/orange-wave-segment.svg') repeat-x -13px center;
    background-size: 47px 37px;
    pointer-events: none;
    z-index: 0;
  }

  .stats-counter__item {
    position: relative;
    z-index: 1;
  }

  /* Center the 3rd item that wraps to its own row */
  .stats-counter__items > div > div:last-child:nth-child(odd):nth-child(n+3) {
    grid-column: 1 / -1;
  }
}

@media (max-width: 767px) {
  .stats-counter {
    padding: var(--spacing-xl) 0;
  }

  .stats-counter__items {
    padding: 0;
  }

  .stats-counter__items > div {
    grid-template-columns: 280px;
    justify-content: center;
    gap: 32px;
  }

  .stats-counter__items > div::before,
  .stats-counter__items > div::after {
    display: none;
  }

  .stats-counter__items > div > div:last-child:nth-child(3n+1) {
    grid-column: auto;
  }

  .stats-counter__items > div > div:last-child:nth-child(odd):nth-child(n+3) {
    grid-column: auto;
    max-width: 320px;
  }

  .stats-counter__items > div > div {
    position: relative;
    width: 280px;
  }

  .stats-counter__items > div > div::before {
    content: '';
    position: absolute;
    left: -9999px;
    right: -9999px;
    top: 0;
    bottom: 0;
    background: url('../../images/orange-wave-segment.svg') repeat-x -13px center;
    background-size: 47px 37px;
    pointer-events: none;
    z-index: 0;
  }

  .stats-counter__item {
    width: 100%;
    position: relative;
    z-index: 1;
    box-shadow: none;
    border: 1px solid color-mix(in srgb, var(--color-error-orange) 30%, transparent);
  }
}
