body.modal-active {
  overflow: hidden;
}

.modal-container {
  position: fixed;
  inset: 0;
  z-index: 10000;
  white-space: pre-line;

  &.out {
    .modal-background {
      animation: fadeOut 0.25s cubic-bezier(0.165, 0.84, 0.44, 1) forwards;
    }

    .modal {
      animation: modalFadeOut 0.25s cubic-bezier(0.165, 0.84, 0.44, 1) forwards;

      h3,
      p {
        animation: modalContentFadeOut 0.2s cubic-bezier(0.165, 0.84, 0.44, 1) forwards;
      }
    }
  }
}

.modal-background {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: linear-gradient(180deg, var(--azul) 0%, var(--blanco) 100%);
  animation: fadeIn 0.25s cubic-bezier(0.165, 0.84, 0.44, 1) forwards;
  z-index: 10001;
}

.modal {
  position: relative;
  display: inline-block;
  width: calc(100% - 2 * var(--spacing-sm));
  max-width: 720px;
  padding: var(--spacing-lg) var(--spacing-sm);
  background-color: transparent;
  border-radius: 1rem;
  overflow: hidden;
  color: var(--azulobs);
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.25);
  animation: modalFadeIn 0.25s 0.15s cubic-bezier(0.165, 0.84, 0.44, 1) forwards;
  z-index: 10002;

  @media (min-width: 768px) {
    padding: var(--spacing-lg) var(--spacing-xl);
    max-width: 760px;
  }

  @media (min-width: 1280px) {
    max-width: 820px;
  }

  &::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 0;
    background-image: 
      url("data:image/svg+xml,%3Csvg width='100' height='100' viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 20 Q 25 10, 50 20 T 100 20' fill='none' stroke='rgba(65, 108, 170, 0.08)' stroke-width='0.5'/%3E%3Cpath d='M0 30 Q 25 20, 50 30 T 100 30' fill='none' stroke='rgba(65, 108, 170, 0.06)' stroke-width='0.5'/%3E%3Cpath d='M0 70 Q 25 60, 50 70 T 100 70' fill='none' stroke='rgba(65, 108, 170, 0.06)' stroke-width='0.5'/%3E%3Cpath d='M0 80 Q 25 70, 50 80 T 100 80' fill='none' stroke='rgba(65, 108, 170, 0.08)' stroke-width='0.5'/%3E%3C/svg%3E");
    background-size: 300px 300px;
    background-position: center;
    pointer-events: none;
    opacity: 0.7;
    border-radius: 1rem;
    
    @media (min-width: 768px) {
      background-size: 400px 400px;
    }
    
    @media (min-width: 1280px) {
      background-size: 500px 500px;
    }
  }

  h3 {
    margin-bottom: var(--spacing-sm);
    color: var(--azul);
    opacity: 0;
    position: relative;
    z-index: 1;
    text-align: center;
    animation: modalContentFadeIn 0.25s 0.20s cubic-bezier(0.165, 0.84, 0.44, 1) forwards;

    @media (min-width: 1024px) {
      text-align: left;
    }
  }

  p {
    text-align: justify; 
    color: var(--azulobs);
    opacity: 0;
    position: relative;
    z-index: 1;
    animation: modalContentFadeIn 0.25s 0.24s cubic-bezier(0.165, 0.84, 0.44, 1) forwards;
  }
}

.modal-body {
  margin-top: var(--spacing-sm);
  position: relative;
  z-index: 1;

  @media (min-width: 768px) {
    margin-top: var(--spacing-md);
  }

  @media (min-width: 1024px) {
    display: flex;
    gap: 2rem;
    align-items: flex-start;
  }

  /* ✅ NUEVO: Cuando solo hay imagen (sin descripción) */
  &.modal-body--image-only {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: 0;
    padding: var(--spacing-sm) 0;

    @media (min-width: 768px) {
      padding: var(--spacing-md) 0;
    }

    @media (min-width: 1024px) {
      padding: var(--spacing-lg) 0;
    }

    .modal-image {
      width: 100%;
      max-width: 100%;
      margin-bottom: 0;

      @media (min-width: 768px) {
        max-width: 650px;
      }

      @media (min-width: 1024px) {
        flex: none;
        max-width: 700px;
      }

      @media (min-width: 1280px) {
        max-width: 750px;
      }

      img {
        border-radius: 0.75rem;
        box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
      }
    }
  }
}

.modal-image {
  margin-bottom: var(--spacing-sm);
  border-radius: 0.75rem;
  overflow: hidden;
  width: 90%;
  justify-self: center;
  position: relative;
  z-index: 1;

  img {
    width: 100%;
    height: auto;
    display: block;
    object-fit: cover;
    opacity: 0;
    transform: translateY(-8px);
    animation: modalImageFadeIn 0.25s 0.22s cubic-bezier(0.165, 0.84, 0.44, 1) forwards;
  }

  @media (min-width: 768px) {
    width: 80%;
  }

  @media (min-width: 1024px) {
    flex: 0 0 320px; 
    margin-bottom: 0;
  }
}

.modal-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  border: none;
  background: var(--blanco);
  color: var(--azul);
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
  transition:
    background 0.15s ease,
    transform 0.15s ease,
    box-shadow 0.15s ease;
  z-index: 2;

  &:hover {
    background: var(--azul);
    color: var(--blanco);
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.18);
  }
}

@keyframes fadeIn {
  0% {
    background: rgba(6, 6, 68, 0);
  }
  100% {
    background: #1a436da4;
  }
}

@keyframes fadeOut {
  0% {
    background: #1a446d;
  }
  100% {
    background: rgba(6, 6, 68, 0);
  }
}

@keyframes modalFadeIn {
  0% {
    background-color: transparent;
  }
  100% {
    background-color: var(--blanco);
  }
}

@keyframes modalFadeOut {
  0% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

@keyframes modalContentFadeIn {
  0% {
    opacity: 0;
    top: -20px;
  }
  100% {
    opacity: 1;
    top: 0;
  }
}

@keyframes modalContentFadeOut {
  0% {
    opacity: 1;
    top: 0;
  }
  100% {
    opacity: 0;
    top: -20px;
  }
}

@keyframes modalImageFadeIn {
  0% {
    opacity: 0;
    transform: translateY(-8px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}