/*
 * Service Area Map
 *
 * The map image is larger than the visible frame. The canvas (image + markers) is scaled and
 * offset so the "target box" (every city plus padding, passed in as --sgd-sam-t* fractions)
 * fits the free "slot" beside the text, while still covering the whole frame.
 */

.sgd-sam {
  --sgd-sam-bg: #0e1622;
  --sgd-sam-fg: #fff;
  --sgd-sam-muted: rgb(255 255 255 / 0.74);
  --sgd-sam-label-bg: rgb(9 16 27 / 0.92);
  --sgd-sam-label-fg: #fff;
  --sgd-sam-halo: rgb(9 16 27 / 0.9);
  --sgd-sam-region: rgb(180 205 235 / 0.4);
  --sgd-sam-ring: #fff;
  --sgd-sam-max-width: 1080px;
  --sgd-sam-gutter: max(1.25rem, 5cqw, (100cqw - var(--sgd-sam-max-width)) / 2);
  --sgd-sam-content: clamp(18rem, 30cqw, 27rem);

  container: sgd-sam / inline-size;
  position: relative;
  overflow: hidden;
  background: var(--sgd-sam-bg);
  color: var(--sgd-sam-fg);
  font-family: inherit;
  line-height: 1.5;
  text-align: start;

  &.sgd-sam--light {
    --sgd-sam-bg: #f2f5f8;
    --sgd-sam-fg: #0e1622;
    --sgd-sam-muted: rgb(14 22 34 / 0.72);
    --sgd-sam-label-bg: #fff;
    --sgd-sam-label-fg: #0e1622;
    --sgd-sam-halo: rgb(255 255 255 / 0.95);
    --sgd-sam-region: rgb(40 70 110 / 0.45);
  }

  *,
  *::before,
  *::after {
    box-sizing: border-box;
  }
}

.sgd-sam__inner {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "content" "map" "list" "credit";
}

/* Map frame and canvas */

.sgd-sam__frame {
  --slot-x: 1rem;
  --slot-y: 1rem;
  --slot-w: calc(100cqw - 2rem);
  --slot-h: calc(100cqh - 2rem);

  grid-area: map;
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  isolation: isolate;
  container: sgd-sam-frame / size;

  &::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 2;
    pointer-events: none;
    background: linear-gradient(180deg, var(--sgd-sam-bg), transparent 12%, transparent 88%, var(--sgd-sam-bg));
  }
}

.sgd-sam__canvas {
  --cw: max(
    min(var(--slot-w) / var(--sgd-sam-tw), var(--slot-h) * var(--sgd-sam-ratio) / var(--sgd-sam-th)),
    100cqw,
    100cqh * var(--sgd-sam-ratio)
  );

  position: absolute;
  width: var(--cw);
  aspect-ratio: var(--sgd-sam-ratio);
  left: clamp(
    100cqw - var(--cw),
    var(--slot-x) + var(--slot-w) / 2 - (var(--sgd-sam-tx) + var(--sgd-sam-tw) / 2) * var(--cw),
    0px
  );
  top: clamp(
    100cqh - var(--cw) / var(--sgd-sam-ratio),
    var(--slot-y) + var(--slot-h) / 2 - (var(--sgd-sam-ty) + var(--sgd-sam-th) / 2) * var(--cw) / var(--sgd-sam-ratio),
    0px
  );
}

.sgd-sam__image {
  display: block;
  width: 100%;
  max-width: none;
  height: 100%;
  user-select: none;
}

.sgd-sam__region {
  position: absolute;
  left: var(--x);
  top: var(--y);
  z-index: 1;
  display: none;
  translate: -50% -50%;
  color: var(--sgd-sam-region);
  font-size: 0.6875rem;
  font-style: italic;
  font-weight: 600;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  white-space: nowrap;
  pointer-events: none;
}

/* Markers */

.sgd-sam__marker {
  position: absolute;
  left: var(--x);
  top: var(--y);
  z-index: 3;
  width: 0;
  height: 0;
  color: inherit;
  text-decoration: none;

  &:hover,
  &.is-active {
    z-index: 5;
  }
}

.sgd-sam__dot {
  position: absolute;
  width: 0.6875rem;
  aspect-ratio: 1;
  translate: -50% -50%;
  border-radius: 50%;
  background: var(--sgd-sam-accent);
  box-shadow:
    0 0 0 2px var(--sgd-sam-ring),
    0 0 14px 3px color-mix(in srgb, var(--sgd-sam-accent) 65%, transparent);
  cursor: pointer;
  transition: scale 0.2s ease;

  &::before {
    content: "";
    position: absolute;
    inset: -0.4rem;
    border-radius: 50%;
  }

  &::after {
    content: "";
    position: absolute;
    inset: -2px;
    border: 2px solid var(--sgd-sam-accent);
    border-radius: 50%;
    opacity: 0;
  }

  .is-featured > & {
    width: 0.8125rem;
  }

  :is(.sgd-sam__marker:hover, .is-active) > & {
    scale: 1.35;

    &::after {
      animation: sgd-sam-pulse 1.6s ease-out infinite;
    }
  }
}

.sgd-sam__label {
  position: absolute;
  top: 0;
  left: 0.8rem;
  translate: 0 -50%;
  padding: 0.25em 0.65em;
  border-radius: 0.3rem;
  background: var(--sgd-sam-label-bg);
  color: var(--sgd-sam-label-fg);
  box-shadow: 0 4px 14px rgb(0 0 0 / 0.3);
  font-size: 0.8125rem;
  font-weight: 700;
  line-height: 1.3;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  scale: 0.92;
  transition: opacity 0.15s ease, scale 0.15s ease;

  .sgd-sam__marker--left > & {
    left: auto;
    right: 0.8rem;
  }

  .sgd-sam__marker--top > &,
  .sgd-sam__marker--bottom > & {
    left: 0;
    translate: -50% 0;
  }

  .sgd-sam__marker--top > & {
    top: auto;
    bottom: 0.8rem;
  }

  .sgd-sam__marker--bottom > & {
    top: 0.8rem;
  }

  :is(.sgd-sam__marker:hover, .is-active) > & {
    opacity: 1;
    scale: 1;
  }
}

/* Featured names stay visible as plain map labels. */
.is-featured:not(:hover, .is-active) > .sgd-sam__label {
  padding-inline: 0.15em;
  background: none;
  box-shadow: none;
  color: var(--sgd-sam-fg);
  opacity: 1;
  scale: 1;
  text-shadow:
    0 0 3px var(--sgd-sam-halo),
    0 0 8px var(--sgd-sam-halo),
    0 1px 2px var(--sgd-sam-halo);
}

/* Small maps: only featured cities with space around them keep their label; the rest show on tap. */
@container sgd-sam-frame (width < 520px) {
  .sgd-sam__label {
    font-size: 0.75rem;
  }

  .is-featured:not(.is-roomy, :hover, .is-active) > .sgd-sam__label {
    opacity: 0;
  }
}

@container sgd-sam-frame (width >= 880px) {
  .sgd-sam__region {
    display: block;
  }
}

/* Text */

.sgd-sam__content {
  grid-area: content;
  position: relative;
  z-index: 1;
  padding: 2.75rem var(--sgd-sam-gutter) 0.5rem;
}

.sgd-sam .sgd-sam__eyebrow {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0 0 0.85rem;
  padding: 0;
  color: var(--sgd-sam-accent);
  font-size: 0.8125rem;
  font-weight: 700;
  letter-spacing: 0.2em;
  line-height: 1.2;
  text-transform: uppercase;

  &::before {
    content: "";
    width: 2rem;
    height: 2px;
    background: currentColor;
  }
}

.sgd-sam .sgd-sam__title {
  margin: 0;
  padding: 0;
  color: var(--sgd-sam-fg);
  font-family: inherit;
  font-size: clamp(1.75rem, 1rem + 2.2cqw, 2.5rem);
  font-weight: 800;
  letter-spacing: 0.01em;
  line-height: 1.1;
  text-transform: uppercase;
  text-wrap: pretty;
}

.sgd-sam .sgd-sam__text {
  max-width: 38ch;
  margin: 1rem 0 0;
  padding: 0;
  color: var(--sgd-sam-muted);
  font-size: 1rem;
  line-height: 1.6;
}

/* City list */

.sgd-sam .sgd-sam__list {
  grid-area: list;
  position: relative;
  z-index: 3;
  margin: 0;
  padding: 0.5rem var(--sgd-sam-gutter) 1.5rem;
  list-style: none;
  columns: 2;
  column-gap: 1.5rem;
  line-height: 1.4;
}

.sgd-sam .sgd-sam__item {
  margin: 0;
  padding: 0.3rem 0;
  break-inside: avoid;
  font-size: 0.9375rem;
  font-weight: 600;

  > :is(a, span) {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    color: var(--sgd-sam-muted);
    text-decoration: none;
    transition: color 0.15s ease;

    &::before {
      content: "";
      flex: none;
      width: 0.4rem;
      aspect-ratio: 1;
      border-radius: 50%;
      background: var(--sgd-sam-accent);
      transition: scale 0.15s ease;
    }
  }

  &:hover > :is(a, span),
  &.is-active > :is(a, span),
  > a:focus-visible {
    color: var(--sgd-sam-fg);

    &::before {
      scale: 1.6;
    }
  }

  > a:focus-visible {
    outline: 2px solid var(--sgd-sam-accent);
    outline-offset: 3px;
    border-radius: 2px;
  }
}

.sgd-sam .sgd-sam__sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.sgd-sam .sgd-sam__credit {
  grid-area: credit;
  margin: 0;
  padding: 0 var(--sgd-sam-gutter) 1rem;
  color: var(--sgd-sam-muted);
  font-size: 0.625rem;
  line-height: 1.4;
  opacity: 0.6;

  a {
    color: inherit;
    text-decoration: underline;
  }
}

/* Medium: stacked, wider map */
@container sgd-sam (width >= 600px) {
  .sgd-sam__frame {
    aspect-ratio: 4 / 3;
  }

  .sgd-sam .sgd-sam__list {
    columns: 3;
  }
}

/* Wide: map fills the section, text and list sit over it on the left */
@container sgd-sam (width >= 900px) {
  .sgd-sam__inner {
    grid-template-columns: var(--sgd-sam-gutter) minmax(0, var(--sgd-sam-content)) minmax(0, 1fr);
    grid-template-rows: 1fr auto auto 1fr;
    grid-template-areas:
      ". .       ."
      ". content ."
      ". list    ."
      ". .       .";
    min-height: clamp(34rem, 42cqw, 50rem);
  }

  .sgd-sam__frame {
    --slot-x: calc(var(--sgd-sam-gutter) + var(--sgd-sam-content) + 2rem);
    --slot-y: 1.5rem;
    --slot-w: calc(100cqw - var(--slot-x) - max(1rem, var(--sgd-sam-gutter) / 2));
    --slot-h: calc(100cqh - 3rem);

    grid-area: 1 / 1 / -1 / -1;
    aspect-ratio: auto;

    &::after {
      background:
        linear-gradient(90deg,
          var(--sgd-sam-bg) calc(var(--sgd-sam-gutter) * 0.6),
          color-mix(in srgb, var(--sgd-sam-bg) 82%, transparent) calc(var(--sgd-sam-gutter) + var(--sgd-sam-content) * 0.7),
          transparent calc(var(--sgd-sam-gutter) + var(--sgd-sam-content) + 6rem)),
        linear-gradient(180deg, var(--sgd-sam-bg), transparent 14%, transparent 84%, var(--sgd-sam-bg));
    }
  }

  .sgd-sam__content {
    padding: 3rem 0 0;
  }

  .sgd-sam .sgd-sam__list {
    padding: 1.75rem 0 3rem;
    columns: 2;
  }

  .sgd-sam .sgd-sam__item {
    padding-block: 0.2rem;
  }

  .sgd-sam .sgd-sam__credit {
    position: absolute;
    right: 0.75rem;
    bottom: 0.5rem;
    z-index: 4;
    max-width: 60%;
    padding: 0;
    text-align: end;
  }
}

/* Divi builder preview while the map markup loads. */
.sgd-sam-builder--placeholder {
  padding: 4rem 1rem;
  background: #0e1622;
  color: #fff;
  text-align: center;
}

/* Entrance: markers drop in once the map scrolls into view (class added by script). */
.sgd-sam.is-revealed .sgd-sam__marker {
  animation: sgd-sam-drop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) backwards;
  animation-delay: calc(var(--i, 0) * 45ms + 150ms);
}

@keyframes sgd-sam-drop {
  from {
    opacity: 0;
    translate: 0 -0.75rem;
  }
}

@keyframes sgd-sam-pulse {
  from {
    opacity: 0.9;
    scale: 1;
  }

  to {
    opacity: 0;
    scale: 2.6;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sgd-sam *,
  .sgd-sam *::after {
    animation: none !important;
    transition: none !important;
  }
}
