/* 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;
  }
}
