@use "sass:map";
@use "../../styles/tokens" as *;
@use "../../styles/core/breakpoint.core" as *;
@use "../../styles/core/spacing.core" as *;

.ast-fifty-fifty {
  position: relative;

  @include spacing(margin-bottom, 32);

  // Intersection observer target for animations
  &[data-animate="true"] {
    .ast-fifty-fifty__content-wrapper {
      opacity: 0;
      transform: translateY(30px);
      transition: opacity 0.8s ease, transform 0.8s ease;
    }

    .ast-fifty-fifty__image-wrapper {
      opacity: 0;
      transform: scale(1.1);
      transition: opacity 0.8s ease, transform 0.8s ease;
    }

    &.ast-fifty-fifty--in-view {
      .ast-fifty-fifty__content-wrapper {
        opacity: 1;
        transform: translateY(0);
      }

      .ast-fifty-fifty__image-wrapper {
        opacity: 1;
        transform: scale(1);
      }
    }
  }
}

.ast-fifty-fifty--contained {
  background-color: var(--gray-50);
  border-radius: var(--spacing-12-lg);

  @include spacing(padding, 32);
  @include spacing(margin, 32);

  .section-grid {
    max-width: var(--container-main-width);
    margin: 0 auto;

    @include spacing(padding, 16);
  }
}

.ast-fifty-fifty--full-bleed {
  margin-left: calc(-50vw + 50%);
  margin-right: calc(-50vw + 50%);

  @include spacing(margin-bottom, 60);

  .ast-fifty-fifty__image-wrapper {
    border-radius: 0;
  }

  @include break(md) {
    @include spacing(margin-left, 16, true);
    @include spacing(margin-right, 16, true);
  }
}

.ast-fifty-fifty__image {
  display: flex;
  align-items: center;
  position: relative;

  // Parallax effect wrapper
  &.ast-fifty-fifty__image--parallax {
    overflow: hidden;
  }
}

.ast-fifty-fifty__image-wrapper {
  width: 100%;
  height: 100%;
  min-height: 300px;
  position: relative;
  overflow: hidden;
  border-radius: var(--spacing-8-lg);
  background-color: var(--gray-100);

  // Loading state
  &::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, var(--gray-100) 25%, var(--gray-200) 50%, var(--gray-100) 75%);
    background-size: 200% 100%;
    animation: shimmer 2s infinite;
    z-index: 1;
    opacity: 0;
    transition: opacity 0.3s ease;
  }

  &.ast-fifty-fifty__image-wrapper--loading::before {
    opacity: 1;
  }

  // Hover effects
  &:hover .ast-fifty-fifty__img {
    transform: scale(1.05);
  }

  // Focus-within for keyboard navigation
  &:focus-within {
    outline: 2px solid var(--blue-500);
    outline-offset: 2px;
  }
}

.ast-fifty-fifty__img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  transition: transform 0.6s ease;
  position: relative;
  z-index: 2;

  // Better image loading experience with global image handler
  &[loading="lazy"] {
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.6s ease;

    &.ast-img--loaded {
      opacity: 1;
    }
  }
}

.ast-fifty-fifty__content {
  display: flex;
  align-items: center;
  position: relative;

  @include spacing(padding, 16);
}

.ast-fifty-fifty__content-wrapper {
  width: 100%;
  max-width: 500px;
  position: relative;
}

.ast-fifty-fifty__content--left .ast-fifty-fifty__content-wrapper {
  margin-left: 0;
  margin-right: auto;
  text-align: left;
}

.ast-fifty-fifty__content--center .ast-fifty-fifty__content-wrapper {
  margin-left: auto;
  margin-right: auto;
  text-align: center;
}

.ast-fifty-fifty__subtitle {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-600);
  text-transform: uppercase;
  letter-spacing: var(--letter-spacing-wider);
  color: var(--blue-500);
  margin-top: 0;
  position: relative;

  @include spacing(margin-bottom, 8);

  // Animated underline
  &::after {
    content: "";
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 0;
    height: 2px;
    background-color: var(--blue-500);
    transition: width 0.3s ease;
  }

  .ast-fifty-fifty--in-view &::after {
    width: 100%;
  }

  .ast-fifty-fifty__content--center &::after {
    left: 50%;
    transform: translateX(-50%);
  }
}

.ast-fifty-fifty__title {
  font-size: var(--font-size-3xl);
  font-weight: var(--font-weight-700);
  line-height: var(--line-height-tight);
  color: var(--gray-800);
  margin-top: 0;
  position: relative;

  @include spacing(margin-bottom, 16);

  // Responsive typography
  @include break(md) {
    font-size: var(--font-size-4xl);
  }

  @include break(lg) {
    font-size: var(--font-size-5xl);
  }
}

.ast-fifty-fifty__body {
  font-size: var(--font-size-lg);
  line-height: var(--line-height-relaxed);
  color: var(--gray-600);

  @include spacing(margin-bottom, 24);

  p {
    margin-top: 0;

    @include spacing(margin-bottom, 16);

    &:last-child {
      margin-bottom: 0;
    }
  }

  // Enhanced typography
  strong {
    color: var(--gray-800);
    font-weight: var(--font-weight-600);
  }

  em {
    font-style: italic;
    color: var(--gray-700);
  }

  // Lists
  ul,
  ol {
    @include spacing(margin, 16);
    @include spacing(padding-left, 24);

    li {
      line-height: var(--line-height-normal);

      @include spacing(margin-bottom, 8);
    }
  }

  // Links
  a {
    color: var(--blue-500);
    text-decoration-line: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
    transition: color 0.2s ease;

    &:hover {
      color: var(--blue-600);
    }
  }
}

.ast-fifty-fifty__actions {
  display: flex;
  flex-wrap: wrap;

  @include spacing(gap, 16);
  @include spacing(margin-top, 16);

  .btn {
    transition: all 0.3s ease;
  }
}

.ast-fifty-fifty__content--center .ast-fifty-fifty__actions {
  justify-content: center;
}

/* Responsive adjustments */
@include break(sm) {
  .ast-fifty-fifty {
    @include spacing(margin-bottom, 24);
  }

  .ast-fifty-fifty__content {
    @include spacing(padding-top, 24);
  }

  .ast-fifty-fifty__title {
    font-size: var(--font-size-2xl);
  }

  .ast-fifty-fifty__body {
    font-size: var(--font-size-base);
  }

  .ast-fifty-fifty__image-wrapper {
    min-height: 250px;
  }

  .ast-fifty-fifty__actions {
    flex-direction: column;
    align-items: stretch;

    .btn {
      width: 100%;
      justify-content: center;
    }
  }

  .ast-fifty-fifty__content--center .ast-fifty-fifty__actions {
    align-items: center;

    .btn {
      width: auto;
      min-width: 200px;
    }
  }
}

@include break(md) {
  .ast-fifty-fifty__content {
    @include spacing(padding, 32);
  }

  .ast-fifty-fifty__image-wrapper {
    min-height: 400px;
  }
}

@include break(lg) {
  .ast-fifty-fifty__image-wrapper {
    min-height: 450px;
  }

  .ast-fifty-fifty__content {
    @include spacing(padding, 48);
  }

  .ast-fifty-fifty__content-wrapper {
    max-width: 600px;
  }
}

/* Order utilities for responsive reordering */
.order-1 {
  order: 1;
}

.order-2 {
  order: 2;
}

@media (max-width: 1023px) {
  /* On mobile and tablet, always show image first, content second */
  .ast-fifty-fifty__image {
    order: 1 !important;
  }

  .ast-fifty-fifty__content {
    order: 2 !important;
  }
}

/* Animation keyframes */
@keyframes shimmer {
  0% {
    background-position: -200% 0;
  }
  100% {
    background-position: 200% 0;
  }
}

// Loading animation keyframes
@keyframes loading-shimmer {
  0% {
    background-position: -200% 0;
  }
  100% {
    background-position: 200% 0;
  }
}
