.chat-messages {
  position: relative;
  padding: 16px 0 40px 40px;

  .message-row {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-end;
    padding: 0 16px 4px 16px;

    .avatar {
      position: absolute;
      left: -32px;
      margin: 0;
    }

    .bubble {
      position: relative;
      display: flex;
      align-items: center;
      justify-content: center;
      padding: 12px;
      max-width: 100%;

      .message {
        white-space: pre-wrap;
        line-height: 1.2;
      }

      .time {
        position: absolute;
        display: none;
        width: 100%;
        font-size: 11px;
        margin-top: 8px;
        top: 100%;
        left: 0;
        white-space: nowrap;
      }
    }

    &.contact {
      .bubble {
        border-top-left-radius: 5px;
        border-bottom-left-radius: 5px;

        border-top-right-radius: 20px;
        border-bottom-right-radius: 20px;

        .time {
          margin-left: 12px;
        }
      }

      &.first-of-group {
        .bubble {
          border-top-left-radius: 20px;
        }
      }

      &.last-of-group {
        .bubble {
          border-bottom-left-radius: 20px;
        }
      }
    }

    &.me {
      padding-left: 40px;

      .avatar {
        order: 2;
        margin: 0 0 0 16px;
      }

      .bubble {
        margin-left: auto;

        border-top-left-radius: 20px;
        border-bottom-left-radius: 20px;

        border-top-right-radius: 5px;
        border-bottom-right-radius: 5px;

        .time {
          justify-content: flex-end;
          right: 0;
          margin-right: 12px;
        }
      }

      &.first-of-group {
        .bubble {
          border-top-right-radius: 20px;
        }
      }

      &.last-of-group {
        .bubble {
          border-bottom-right-radius: 20px;
        }
      }
    }

    &.contact + .me,
    &.me + .contact {
      padding-top: 20px;
      margin-top: 20px;
    }

    &.first-of-group {
      .bubble {
        border-top-left-radius: 20px;
        padding-top: 13px;
      }
    }

    &.last-of-group {
      .bubble {
        border-bottom-left-radius: 20px;
        padding-bottom: 13px;

        .time {
          display: flex;
        }
      }
    }
  }
}
