/* ==========================================================================
   Endoscopy services
   Desktop (RTL): [heading + numbered nav + arrows] | [panel: text + CTA | image]
                  [ three static technology cards ]
   The stage carries the supplied background. On desktop (fine pointer, motion
   allowed) it pins under the header while the track scrolls past, and the
   scroll progress steps through the services (js/services.js).
   Edges align with the navbar's outermost elements (--nav-edge-left/right).
   ========================================================================== */

.services {
  --services-gutter: var(--space-4);
  --services-gap: var(--space-6);      /* 48px — nav ↔ panel, upper ↔ cards */
  --nav-width: 360px;
  --panel-padding: var(--space-4);     /* 32px */
  --panel-gap: var(--space-4);         /* 32px — text ↔ image */
  --panel-min-height: 336px;           /* 42 × 8 — text column; the image matches it */
  --swap-duration: 350ms;
  --swap-shift: var(--space-3);        /* 24px horizontal travel */

  scroll-margin-top: var(--header-height, 0px);
}

.services__stage {
  padding-block: var(--space-8);
  background: #f2f7f5 url("../assets/images/services/services-bg.webp") center / cover no-repeat;
}

.services__inner {
  margin-left: var(--nav-edge-left, var(--services-gutter));
  margin-right: var(--nav-edge-right, var(--services-gutter));
}

.services__upper {
  display: grid;
  grid-template-columns: minmax(0, var(--nav-width)) minmax(0, 1fr);
  align-items: center;
  gap: var(--services-gap);
}

/* ==========================================================================
   Service navigation (right)
   ========================================================================== */
.services-nav {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.services__title {
  margin: 0 0 var(--space-4);
  color: var(--color-primary-700);
  font-size: var(--font-size-h4);
  font-weight: var(--font-weight-bold);
  line-height: var(--line-height-h4);
}

.services__title-accent {
  color: var(--color-primary);
}

.services-nav__list {
  --circle: var(--space-6);            /* 48px */
  --item-padding: var(--space-1);      /* 8px */

  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  width: 100%;
}

/* Rail through the circles + fill up to the active one */
.services-nav__list::before,
.services-nav__list::after {
  content: "";
  position: absolute;
  top: calc(var(--item-padding) + var(--circle) / 2);
  bottom: calc(var(--item-padding) + var(--circle) / 2);
  inset-inline-start: calc(var(--item-padding) + var(--circle) / 2 - 1px);
  width: 2px;
  border-radius: var(--radius-pill);
  background: color-mix(in srgb, var(--color-primary-100) 70%, #ffffff);
}

.services-nav__list::after {
  background: var(--color-primary);
  transform: scaleY(var(--progress, 0));
  transform-origin: top;
  transition: transform var(--swap-duration) var(--ease-smooth);
}

.services-nav__item {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: var(--item-padding);
  padding-inline-end: var(--space-3);
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--color-neutral-900);
  font-size: var(--font-size-b1);
  font-weight: var(--font-weight-medium);
  line-height: var(--line-height-b1);
  text-align: start;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition:
    background-color var(--duration-slow) var(--ease-smooth),
    box-shadow var(--duration-slow) var(--ease-smooth),
    color var(--duration-slow) var(--ease-smooth);
}

.services-nav__num {
  display: grid;
  place-items: center;
  flex: none;
  width: var(--circle);
  height: var(--circle);
  border-radius: var(--radius-circle);
  background: color-mix(in srgb, var(--color-primary-100) 40%, #ffffff);
  color: var(--color-primary-600);
  font-size: var(--font-size-b2);
  font-weight: var(--font-weight-bold);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  transition:
    background-color var(--duration-slow) var(--ease-smooth),
    color var(--duration-slow) var(--ease-smooth),
    box-shadow var(--duration-slow) var(--ease-smooth);
}

.services-nav__item:hover {
  background-color: rgb(255 255 255 / 0.5);
  color: var(--color-primary-700);
}

.services-nav__item.is-active {
  background-color: var(--color-neutral-100);
  box-shadow: var(--shadow-soft);
  color: var(--color-primary-700);
  font-weight: var(--font-weight-bold);
}

.services-nav__item.is-active .services-nav__num {
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-700) 100%);
  color: var(--color-text-on-brand);
  box-shadow: 0 4px 12px rgb(46 146 151 / 0.32);
}

.services-nav__item:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 2px;
}

/* ---- Previous / next ---- */
.services-nav__arrows {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-3);
  padding-inline-start: var(--space-0-5); /* optical: shadows line up with the circles */
}

.round-btn {
  display: grid;
  place-items: center;
  width: var(--space-7);  /* 56px */
  height: var(--space-7);
  padding: 0;
  border: 0;
  border-radius: var(--radius-circle);
  background: var(--color-neutral-100);
  color: var(--color-primary-700);
  box-shadow: var(--shadow-soft);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition:
    box-shadow var(--duration-slow) var(--ease-smooth),
    color var(--duration-slow) var(--ease-smooth),
    transform var(--duration-fast) var(--ease-smooth);
}

.round-btn:hover {
  color: var(--color-primary);
  box-shadow: 0 2px 4px rgb(19 61 63 / 0.06), 0 8px 24px rgb(19 61 63 / 0.14);
}

.round-btn:active {
  transform: scale(0.94);
}

.round-btn:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 2px;
}

/* ==========================================================================
   Selected service panel (left)
   ========================================================================== */
.service-panel {
  --enter-x: calc(var(--swap-shift) * -1); /* "next" in RTL arrives from the left… */
  --leave-x: var(--swap-shift);            /* …and the old one leaves to the right */

  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  align-items: stretch;
  gap: var(--panel-gap);
  padding: var(--panel-padding);
  border: 1px solid rgb(255 255 255 / 0.7);
  border-radius: var(--radius-xl);
  background: rgb(255 255 255 / 0.72);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  box-shadow: 0 16px 48px rgb(19 61 63 / 0.08);
}

.service-panel[data-direction="prev"] {
  --enter-x: var(--swap-shift);
  --leave-x: calc(var(--swap-shift) * -1);
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .service-panel {
    background: rgb(255 255 255 / 0.94);
  }
}

.service-panel__body {
  position: relative;
  isolation: isolate;
  display: flex;
  flex-direction: column;
  align-items: flex-start; /* RTL: right edge */
  justify-content: center;
  min-height: var(--panel-min-height);
  padding-block: var(--space-2);
}

/* All four slides share one grid cell → the cell is as tall as the longest,
   so switching never shifts the layout. */
.service-panel__slides {
  display: grid;
  width: 100%;
}

.service-slide {
  grid-area: 1 / 1;
  position: relative;
  isolation: isolate;
  opacity: 0;
  visibility: hidden;
  transform: translateX(var(--enter-x));
}

.service-slide.is-active,
.service-slide.is-leaving {
  visibility: visible;
  transition:
    opacity var(--swap-duration) ease,
    transform var(--swap-duration) var(--ease-smooth);
}

.service-slide.is-active {
  opacity: 1;
  transform: none;
}

.service-slide.is-leaving {
  transform: translateX(var(--leave-x));
}

.service-slide__title {
  margin: 0;
  color: var(--color-primary-700);
  font-size: var(--font-size-h5);
  font-weight: var(--font-weight-bold);
  line-height: var(--line-height-h5);
}

.service-slide__desc {
  max-width: 30em;
  margin: var(--space-2) 0 0;
  color: var(--color-neutral-900);
  font-size: var(--font-size-b1);
  line-height: var(--line-height-b1);
  text-wrap: pretty;
}

.service-panel__cta {
  margin-top: var(--space-4);
}

/* Large, faint number of the selected service, in the corner beside the CTA */
.service-panel__num {
  position: absolute;
  z-index: -1;
  bottom: 0;
  left: 0; /* physical: dir="ltr" on the digits would flip inset-inline-end */
  color: color-mix(in srgb, var(--color-primary-100) 45%, #ffffff);
  font-size: 128px;
  font-weight: var(--font-weight-bold);
  line-height: 104px;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  user-select: none;
}

/* Image frame: contributes no height, so it is exactly as tall as the text */
.service-panel__media {
  position: relative;
  contain: size;
  margin: 0;
  border-radius: var(--radius-panel); /* 32px */
  background: color-mix(in srgb, var(--color-primary-100) 22%, #ffffff);
  overflow: hidden;
}

.service-panel__image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 45%;
  opacity: 0;
  transform: scale(1.04);
  transition:
    opacity var(--swap-duration) ease,
    transform calc(var(--swap-duration) * 2) var(--ease-smooth);
}

.service-panel__image.is-active {
  opacity: 1;
  transform: none;
}

/* ==========================================================================
   Technology cards (static)
   ========================================================================== */
.services .tech-cards { /* beats the global ul[role="list"] margin reset */
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-3);
  margin-top: var(--services-gap);
}

.tech-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: var(--space-4);
  border-radius: var(--radius-panel); /* 32px */
  background: var(--color-neutral-100);
  box-shadow: 0 2px 4px rgb(19 61 63 / 0.04), 0 12px 32px rgb(19 61 63 / 0.08);
  transition:
    background-color var(--duration-base) var(--ease-smooth),
    box-shadow var(--duration-base) var(--ease-smooth);
}

.tech-card__icon {
  display: grid;
  place-items: center;
  width: var(--space-7);  /* 56px */
  height: var(--space-7);
  border-radius: var(--radius-circle);
  background: color-mix(in srgb, var(--color-primary-100) 45%, #ffffff);
  color: var(--color-primary);
  transition:
    background-color var(--duration-base) var(--ease-smooth),
    color var(--duration-base) var(--ease-smooth);
}

.tech-card__icon svg {
  transition: transform var(--duration-slow) var(--ease-smooth);
}

.tech-card__title {
  margin: var(--space-3) 0 var(--space-1);
  color: var(--color-primary-700);
  font-size: var(--font-size-h7);
  font-weight: var(--font-weight-bold);
  line-height: var(--line-height-h7);
  transition: color var(--duration-base) var(--ease-smooth);
}

.tech-card__desc {
  margin: 0;
  color: var(--color-neutral-900);
  font-size: var(--font-size-b2);
  line-height: var(--line-height-b2);
  transition: color var(--duration-base) var(--ease-smooth);
}

/* Hover (mouse) and press (touch) share the brand state */
@media (hover: hover) {
  .tech-card:hover {
    background-color: var(--color-primary);
    box-shadow: 0 16px 40px rgb(46 146 151 / 0.28);
  }
}

.tech-card:active {
  background-color: var(--color-primary);
}

@media (hover: hover) {
  .tech-card:hover .tech-card__title,
  .tech-card:hover .tech-card__desc { color: var(--color-text-on-brand); }
  .tech-card:hover .tech-card__icon { background-color: rgb(255 255 255 / 0.16); color: var(--color-text-on-brand); }
  .tech-card:hover .tech-card__icon svg { transform: rotate(-8deg) scale(1.08); }
}

.tech-card:active .tech-card__title,
.tech-card:active .tech-card__desc { color: var(--color-text-on-brand); }
.tech-card:active .tech-card__icon { background-color: rgb(255 255 255 / 0.16); color: var(--color-text-on-brand); }
.tech-card:active .tech-card__icon svg { transform: rotate(-8deg) scale(1.08); }

/* ==========================================================================
   Scroll-pinned presentation (desktop, fine pointer, motion allowed).
   Must match PIN_QUERY in js/services.js.
   ========================================================================== */
@media (min-width: 1024px) and (hover: hover) and (pointer: fine) and (prefers-reduced-motion: no-preference) {
  /* Scroll distance the stage stays pinned for: 4 services × 45vh */
  .services__track::after {
    content: "";
    display: block;
    height: var(--services-scroll, 180vh);
  }

  .services__stage {
    position: sticky;
    top: var(--header-height, 0px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: calc(100vh - var(--header-height, 0px));
    padding-block: var(--space-5);
  }
}

@media (prefers-reduced-motion: reduce) {
  .services {
    --swap-duration: 0ms;
  }

  .tech-card__icon svg {
    transition: none;
  }
}

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 1599.98px) {
  .services {
    --services-gutter: var(--space-3);
    --nav-width: 320px;
    --panel-min-height: 320px;
  }

  .service-slide__desc {
    font-size: var(--font-size-b2);
    line-height: var(--line-height-b2);
  }
}

@media (max-width: 1439.98px) {
  .services {
    --services-gap: var(--space-5);
    --nav-width: 280px;
    --panel-padding: var(--space-3);
    --panel-gap: var(--space-3);
    --panel-min-height: 304px;
  }

  .services__title {
    font-size: var(--font-size-h5);
    line-height: var(--line-height-h5);
  }

  .services-nav__item {
    font-size: var(--font-size-b2);
    line-height: var(--line-height-b2);
  }

  .service-slide__title {
    font-size: var(--font-size-h6);
    line-height: var(--line-height-h6);
  }

  .service-panel__num {
    font-size: 104px;
    line-height: 88px;
  }

  .tech-card {
    padding: var(--space-3);
  }

  .tech-card__title {
    font-size: var(--font-size-b1);
    line-height: var(--line-height-b1);
  }
}

/* Short desktop screens: tighter vertical rhythm so more of the stage fits */
@media (min-width: 1024px) and (max-height: 820px) {
  .services {
    --services-gap: var(--space-4);
    --panel-min-height: 272px;
  }

  .services-nav__list {
    --circle: var(--space-5); /* 40px */
  }

  .services__title {
    margin-bottom: var(--space-2);
  }

  /* Cards go horizontal: icon beside title + text (~110px shorter) */
  .tech-card {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas:
      "icon title"
      "icon desc";
    align-content: start;
    column-gap: var(--space-2);
    padding: var(--space-3);
  }

  .tech-card__icon {
    grid-area: icon;
  }

  .tech-card__title {
    grid-area: title;
    margin: 0 0 var(--space-0-5);
    font-size: var(--font-size-b1);
    line-height: var(--line-height-b1);
  }

  .tech-card__desc {
    grid-area: desc;
  }
}

/* Tablet & mobile: selector becomes a 2 × 2 grid above the panel */
@media (max-width: 1023.98px) {
  .services {
    --services-gap: var(--space-4);
    --panel-min-height: 0px;
  }

  .services__stage {
    padding-block: var(--space-6);
  }

  .services__upper {
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-3);
  }

  .services__title {
    margin-bottom: var(--space-3);
  }

  .services-nav__list {
    --circle: var(--space-5); /* 40px */

    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .services-nav__list::before,
  .services-nav__list::after {
    display: none; /* the rail only reads in a vertical list */
  }

  .services-nav__item {
    padding-inline-end: var(--space-2);
    background-color: rgb(255 255 255 / 0.5);
    font-size: var(--font-size-b3);
    line-height: var(--line-height-b3);
  }

  .services-nav__num {
    font-size: var(--font-size-b3);
  }

  .services-nav__arrows {
    margin-top: var(--space-2);
  }

  .services-nav__item:hover {
    background-color: rgb(255 255 255 / 0.7);
  }

  .services-nav__item.is-active {
    background-color: var(--color-neutral-100);
  }

  .service-panel__body {
    padding-block: var(--space-1);
  }

  .service-panel__num {
    display: none; /* no free corner beside the CTA in the narrower column */
  }

  .service-panel__media {
    contain: none;
    min-height: 240px;
  }

  .services .tech-cards {
    gap: var(--space-2);
  }

  .tech-card {
    padding: var(--space-3);
  }

  .tech-card__title {
    font-size: var(--font-size-b1);
    line-height: var(--line-height-b1);
  }

  .tech-card__desc {
    font-size: var(--font-size-b3);
    line-height: var(--line-height-b3);
  }
}

/* Mobile: image on top, text below; cards stack */
@media (max-width: 767.98px) {
  .services {
    --services-gutter: var(--space-2);
    --panel-padding: var(--space-2);
    --panel-gap: var(--space-3);
  }

  .services__title {
    font-size: var(--font-size-h6);
    line-height: var(--line-height-h6);
  }

  /* Phones: back to a compact vertical list — full-width names read on one line */
  .services-nav__list {
    display: flex;
    gap: 0;
  }

  .services-nav__list::before,
  .services-nav__list::after {
    display: block;
  }

  .services-nav__item {
    background-color: transparent;
    font-size: var(--font-size-b2);
    line-height: var(--line-height-b2);
  }

  .service-panel {
    grid-template-columns: minmax(0, 1fr);
    border-radius: var(--radius-panel);
  }

  .service-panel__media {
    order: -1;
    min-height: 0;
    aspect-ratio: 4 / 3;
    border-radius: var(--space-3); /* nested inside the 32px panel */
  }

  .service-panel__body {
    padding: 0 var(--space-1) var(--space-1);
  }

  .service-slide__title {
    font-size: var(--font-size-h7);
    line-height: var(--line-height-h7);
  }

  .service-panel__cta {
    margin-top: var(--space-3);
    align-self: stretch;
    justify-content: space-between;
  }

  .services .tech-cards {
    grid-template-columns: minmax(0, 1fr);
  }

  .tech-card__title {
    font-size: var(--font-size-h7);
    line-height: var(--line-height-h7);
  }

  .tech-card__desc {
    font-size: var(--font-size-b2);
    line-height: var(--line-height-b2);
  }
}
