/* Services — pin sticky z-stack (Jitter: услуги.mp4)
   Track scrolls; pin (headline + cards) sticks, then leaves with scroll.
*/

.mi-services {
  --mi-services-title-h: calc(110px * var(--mi-s));
  --mi-services-stick-top: var(--mi-header-height);
  --mi-stack-step: 100vh;
  --mi-stack-count: 7;
  --mi-stack-shrink: 0.28;
  --mi-stack-fade: 0.3; /* closed peek → opacity 0.7 */

  position: relative;
  z-index: 2;
  width: 100%;
  background: var(--mi-color-surface-dark);
  color: var(--mi-color-inverse);
  padding: 0 var(--mi-gutter) calc(30px * var(--mi-s));
}

/* Gradient overlay at section top — sits below the fold on load,
   covers hero→services join (Figma fade h 661) */
.mi-services::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  z-index: 5;
  height: calc(330px * var(--mi-s));
  pointer-events: none;
  background: linear-gradient(
    180deg,
    rgba(17, 35, 49, 0) 0%,
    rgba(17, 35, 49, 0.28) 28%,
    rgba(17, 35, 49, 0.7) 62%,
    #112331 100%
  );
  transform: translateY(-100%);
}

/* Scroll length = equal steps between cards + one pin viewport */
.mi-services__track {
  position: relative;
  height: calc(
    (var(--mi-stack-count) - 1) * var(--mi-stack-step) + (100vh - var(--mi-services-stick-top))
  );
}

.mi-services__pin {
  position: sticky;
  top: var(--mi-services-stick-top);
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: calc(40px * var(--mi-s));
  width: 100%;
  max-width: var(--mi-content-width);
  margin-inline: auto;
  height: calc(100vh - var(--mi-services-stick-top));
  box-sizing: border-box;
  padding-bottom: calc(48px * var(--mi-s));
  overflow: hidden;
  background: var(--mi-color-surface-dark);
}

/* Headline sits on top edge of the card stage — leaves with pin */
.mi-services__head {
  position: relative;
  z-index: 5;
  flex: 0 0 auto;
  min-height: var(--mi-services-title-h);
  background: var(--mi-color-surface-dark);
}

.mi-services__stage {
  position: relative;
  z-index: 1;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
}

.mi-service-card {
  --mi-stack-i: 1;
  --mi-stack-p: 0;
  --mi-stack-buried: 0;
  --mi-card-y: 100%;
  position: absolute;
  inset: 0;
  z-index: var(--mi-stack-i);
  width: 100%;
  height: 100%;
  margin: 0;
  background: transparent;
  transform: translate3d(0, var(--mi-card-y), 0);
  will-change: transform;
}

.mi-service-card:nth-child(1) { --mi-stack-i: 1; }
.mi-service-card:nth-child(2) { --mi-stack-i: 2; }
.mi-service-card:nth-child(3) { --mi-stack-i: 3; }
.mi-service-card:nth-child(4) { --mi-stack-i: 4; }
.mi-service-card:nth-child(5) { --mi-stack-i: 5; }
.mi-service-card:nth-child(6) { --mi-stack-i: 6; }
.mi-service-card:nth-child(7) { --mi-stack-i: 7; }

.mi-service-card__shell {
  position: relative;
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  width: 100%;
  height: 100%;
  min-height: 0;
  max-height: calc(740px * var(--mi-s));
  padding: calc(80px * var(--mi-s));
  box-sizing: border-box;
  background: var(--mi-color-surface-soft);
  border-radius: var(--mi-radius-card);
  color: var(--mi-color-surface-dark);
  overflow: hidden;
  transform-origin: center center;
  transform: scale(calc(1 - var(--mi-stack-p) * var(--mi-stack-shrink)));
  opacity: calc(
    (1 - var(--mi-stack-buried)) * (1 - var(--mi-stack-p) * var(--mi-stack-fade))
  );
  will-change: transform, opacity;
}

.mi-service-card__body {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  width: calc(658px * var(--mi-s));
  max-width: 48%;
  min-height: 0;
  height: 100%;
}

.mi-service-card__title {
  margin: 0;
  font-family: var(--mi-font);
  font-size: var(--mi-fs-64);
  font-weight: 500;
  line-height: 1.1;
  color: var(--mi-color-surface-dark);
}

.mi-service-card__content {
  display: flex;
  flex-direction: column;
  gap: calc(40px * var(--mi-s));
  width: 100%;
}

.mi-service-card__text {
  margin: 0;
  font-family: var(--mi-font);
  font-size: var(--mi-fs-20);
  font-weight: 300;
  line-height: 1.5;
  color: var(--mi-color-surface-dark);
}

.mi-service-card__list,
.mi-service-card__details ul {
  margin: 0;
  padding: 0 0 0 calc(30px * var(--mi-s));
  list-style: disc;
  font-family: var(--mi-font);
  font-size: var(--mi-fs-20);
  font-weight: 300;
  line-height: 1.5;
  color: var(--mi-color-surface-dark);
}

.mi-service-card__details:empty {
  display: none;
}

.mi-service-card__text + .mi-service-card__list,
.mi-service-card__text + .mi-service-card__details {
  margin-top: calc(-20px * var(--mi-s));
}

.mi-service-card__count {
  position: absolute;
  top: calc(80px * var(--mi-s));
  right: calc(80px * var(--mi-s));
  z-index: 3;
  font-family: var(--mi-font);
  font-size: var(--mi-fs-40);
  font-weight: 500;
  line-height: 1.3;
  color: var(--mi-color-blue);
  white-space: nowrap;
}

.mi-service-card__media {
  position: absolute;
  top: 0;
  right: 0;
  width: calc(860px * var(--mi-s));
  max-width: 50%;
  height: 100%;
  border-radius: var(--mi-radius-card);
  overflow: hidden;
  z-index: 1;
}

.mi-service-card__media picture,
.mi-service-card__media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center right;
}

@media (prefers-reduced-motion: reduce) {
  .mi-services__track {
    height: auto;
  }

  .mi-services__pin {
    position: relative;
    top: auto;
    height: auto;
    overflow: visible;
  }

  .mi-services__stage {
    display: flex;
    flex-direction: column;
    gap: 40px;
  }

  .mi-service-card {
    position: relative;
    inset: auto;
    height: auto;
    transform: none !important;
  }

  .mi-service-card__shell {
    max-height: none;
    min-height: 740px;
    transform: none !important;
    opacity: 1 !important;
  }

  .mi-service-card {
    --mi-stack-buried: 0;
  }
}

@media (max-width: 991px) {
  /* Figma 101:542 is a 328 × 665 card inside the 360 × 800 stage.
     Scale the complete pinned scene together from 320px through 430px. */
  .mi-services {
    --mi-mobile-stage: clamp(711.111px, 222.222vw, 955.556px);
    --mi-services-title-h: clamp(31.111px, 9.722vw, 41.806px);
    --mi-services-stick-top: 0px;
    --mi-stack-step: var(--mi-mobile-stage);
    padding: 0 clamp(14.222px, 4.444vw, 19.111px);
  }

  .mi-services::before { display: none; }

  .mi-services__track {
    height: calc(
      (var(--mi-stack-count) - 1) * var(--mi-stack-step) + var(--mi-mobile-stage)
    );
  }

  .mi-services__pin {
    position: sticky;
    top: var(--mi-services-stick-top);
    height: var(--mi-mobile-stage);
    gap: clamp(17.778px, 5.556vw, 23.889px);
    padding: clamp(17.778px, 5.556vw, 23.889px) 0 clamp(53.333px, 16.667vw, 71.667px);
    padding-bottom: 30px;
    overflow: hidden;
  }

  .mi-services__head { min-height: 35px; }

  .mi-services__head .mi-section-title__label { display: none; }

  .mi-services__stage {
    display: block;
    margin: 0;
    overflow: hidden;
  }

  .mi-service-card {
    position: absolute;
    inset: 0;
    flex: none;
    width: 100%;
    height: 100%;
    margin-inline: auto;
  }

  .mi-service-card__shell {
    display: block;
    height: 100%;
    max-height: none;
    padding: 0;
    border-radius: 24px;
  }

  .mi-service-card__media {
    top: 0;
    right: 0;
    left: auto;
    width: 70.864%;
    max-width: none;
    height: 30.075%;
    border-radius: clamp(14.415px, 4.505vw, 19.352px);
  }

  .mi-service-card__body {
    width: auto;
    max-width: none;
    height: 100%;
    box-sizing: border-box;
    justify-content: flex-start;
    gap: clamp(14.222px, 4.444vw, 19.111px);
    padding: clamp(208px, 65vw, 279.5px) 7.317% 7.317%;
  }

  .mi-service-card__title {
    box-sizing: border-box;
    width: 100%;
    /* Keep the fixed top-right pagination outside every service title,
       including the final long title. */
    padding-right: 22%;
    font-size: clamp(24.889px, 7.778vw, 33.444px);
  }
  .mi-service-card__content { gap: clamp(8.889px, 2.778vw, 11.944px); margin-top: 0; }
  .mi-service-card__text,
  .mi-service-card__list,
  .mi-service-card__details ul { font-size: clamp(12.444px, 3.889vw, 16.722px); }

  .mi-service-card__text { margin-bottom: 12px; }

  .mi-service-card__count { top: clamp(208px, 65vw, 279.5px); right: 7.317%; font-size: clamp(21.333px, 6.667vw, 28.667px); line-height: 1.2; color: var(--mi-color-blue); }

}
